Skip to content

Commit

Permalink
Merge pull request #384 from sparcs-kaist/feature/integrate-talk
Browse files Browse the repository at this point in the history
  • Loading branch information
retroinspect authored May 25, 2023
2 parents ee78884 + d764cad commit 8989178
Show file tree
Hide file tree
Showing 19 changed files with 320 additions and 173 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ env:
jobs:
deploy:
name: Run Tests
# runs-on: ubuntu-20.04
runs-on: [self-hosted]
runs-on: ubuntu-20.04

steps:
- name: Checkout
Expand Down
9 changes: 4 additions & 5 deletions apps/core/migrations/0038_rename_is_anonymous_to_name_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

from django.db import migrations, models

import apps.core.models.board
from apps.core.models.board import NameType


class Migration(migrations.Migration):

dependencies = [
("core", "0037_board_banner_url"),
]
Expand All @@ -21,7 +20,7 @@ class Migration(migrations.Migration):
model_name="article",
name="name_type",
field=models.SmallIntegerField(
default=apps.core.models.board.BoardNameType["REGULAR"],
default=NameType["REGULAR"],
verbose_name="익명 혹은 실명 여부",
),
),
Expand All @@ -35,7 +34,7 @@ class Migration(migrations.Migration):
name="name_type",
field=models.SmallIntegerField(
db_index=True,
default=apps.core.models.board.BoardNameType["REGULAR"],
default=NameType["REGULAR"],
help_text="게시판의 글과 댓글들이 익명 혹은 실명이도록 합니다.",
verbose_name="익명/실명 게시판",
),
Expand All @@ -49,7 +48,7 @@ class Migration(migrations.Migration):
model_name="comment",
name="name_type",
field=models.SmallIntegerField(
default=apps.core.models.board.BoardNameType["REGULAR"],
default=NameType["REGULAR"],
verbose_name="익명 혹은 실명",
),
),
Expand Down
23 changes: 23 additions & 0 deletions apps/core/migrations/0047_alter_board_name_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.16 on 2023-05-09 13:57

import apps.core.models.board
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0046_update_hidden_at_min_time_to_null"),
]

operations = [
migrations.AlterField(
model_name="board",
name="name_type",
field=models.SmallIntegerField(
db_index=True,
default=apps.core.models.board.NameType["REGULAR"],
help_text="글과 댓글을 어떤 이름 설정(닉네임/익명/실명)으로 작성할 수 있는지 정의합니다.",
verbose_name="닉네임/익명/실명글 허용 여부 설정",
),
),
]
43 changes: 43 additions & 0 deletions apps/core/migrations/0048_update_board_name_type_flag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by retro on 2023-05-09 14:03

from django.db import migrations

from apps.core.models.board import Board, NameType
from apps.core.models.article import Article
from apps.core.models.comment import Comment
from django.db import transaction


@transaction.atomic
def update_nametypes(apps, schema_editor):
regular_boards = Board.objects.filter(name_type=0).values()
anonymous_boards = Board.objects.filter(name_type=1).values()
realname_boards = Board.objects.filter(name_type=2).values()

realname_boards.update(name_type=NameType.REALNAME)
anonymous_boards.update(name_type=NameType.ANONYMOUS)
regular_boards.update(name_type=NameType.REGULAR)

regular_articles = Article.objects.filter(name_type=0).values()
anonymous_articles = Article.objects.filter(name_type=1).values()
realname_articles = Article.objects.filter(name_type=2).values()

realname_articles.update(name_type=NameType.REALNAME)
anonymous_articles.update(name_type=NameType.ANONYMOUS)
regular_articles.update(name_type=NameType.REGULAR)

regular_comments = Comment.objects.filter(name_type=0).values()
anonymous_comments = Comment.objects.filter(name_type=1).values()
realname_comments = Comment.objects.filter(name_type=2).values()

realname_comments.update(name_type=NameType.REALNAME)
anonymous_comments.update(name_type=NameType.ANONYMOUS)
regular_comments.update(name_type=NameType.REGULAR)


class Migration(migrations.Migration):
dependencies = [
("core", "0047_alter_board_name_type"),
]

operations = [migrations.RunPython(update_nametypes)]
10 changes: 5 additions & 5 deletions apps/core/models/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)

from .block import Block
from .board import BoardAccessPermissionType, BoardNameType
from .board import NameType, BoardAccessPermissionType
from .comment import Comment
from .communication_article import SchoolResponseStatus
from .report import Report
Expand Down Expand Up @@ -54,7 +54,7 @@ class Meta(MetaDataModel.Meta):
)

name_type = models.SmallIntegerField(
default=BoardNameType.REGULAR,
default=NameType.REGULAR,
verbose_name="익명 혹은 실명 여부",
)
is_content_sexual = models.BooleanField(
Expand Down Expand Up @@ -259,7 +259,7 @@ def created_by_nickname(self):
# API 상에서 보이는 사용자 (익명일 경우 익명화된 글쓴이, 그 외는 그냥 글쓴이)
@cached_property
def postprocessed_created_by(self) -> Union[settings.AUTH_USER_MODEL, Dict]:
if self.name_type == BoardNameType.REGULAR:
if self.name_type == NameType.REGULAR:
return self.created_by

user_unique_num = self.created_by.id + self.id + HASH_SECRET_VALUE
Expand All @@ -268,7 +268,7 @@ def postprocessed_created_by(self) -> Union[settings.AUTH_USER_MODEL, Dict]:
user_hash_int = int(user_hash[-4:], 16)
user_profile_picture = get_profile_picture(user_hash_int)

if self.name_type == BoardNameType.ANONYMOUS:
if self.name_type == NameType.ANONYMOUS:
return {
"id": user_hash,
"username": gettext("anonymous"),
Expand All @@ -279,7 +279,7 @@ def postprocessed_created_by(self) -> Union[settings.AUTH_USER_MODEL, Dict]:
},
}

if self.name_type == BoardNameType.REALNAME:
if self.name_type == NameType.REALNAME:
user_realname = self.created_by.profile.realname
return {
"id": user_unique_num,
Expand Down
17 changes: 9 additions & 8 deletions apps/core/models/board.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from enum import IntEnum
from enum import IntEnum, IntFlag, auto

from django.db import models
from django_extensions.db.fields import AutoSlugField

from ara.db.models import MetaDataModel


class BoardNameType(IntEnum):
REGULAR = 0
ANONYMOUS = 1
REALNAME = 2
class NameType(IntFlag):
REGULAR = auto()
ANONYMOUS = auto()
REALNAME = auto()


class BoardAccessPermissionType(IntEnum):
Expand Down Expand Up @@ -78,10 +78,11 @@ class Meta(MetaDataModel.Meta):
default=False,
db_index=True,
)

name_type = models.SmallIntegerField(
verbose_name="익명/실명 게시판",
help_text="게시판의 글과 댓글들이 익명 혹은 실명이도록 합니다.",
default=BoardNameType.REGULAR,
verbose_name="닉네임/익명/실명글 허용 여부 설정",
help_text="글과 댓글을 어떤 이름 설정(닉네임/익명/실명)으로 작성할 수 있는지 정의합니다.",
default=NameType.REGULAR,
db_index=True,
)
is_school_communication = models.BooleanField(
Expand Down
10 changes: 5 additions & 5 deletions apps/core/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ara.settings import HASH_SECRET_VALUE, MIN_TIME

from .block import Block
from .board import BoardNameType
from .board import NameType
from .report import Report


Expand All @@ -40,7 +40,7 @@ class Meta(MetaDataModel.Meta):
)

name_type = models.SmallIntegerField(
default=BoardNameType.REGULAR,
default=NameType.REGULAR,
verbose_name="익명 혹은 실명",
)

Expand Down Expand Up @@ -167,7 +167,7 @@ def update_report_count(self):
# API 상에서 보이는 사용자 (익명일 경우 익명화된 글쓴이, 그 외는 그냥 글쓴이)
@cached_property
def postprocessed_created_by(self) -> Union[settings.AUTH_USER_MODEL, Dict]:
if self.name_type == BoardNameType.REGULAR:
if self.name_type == NameType.REGULAR:
return self.created_by

parent_article = self.get_parent_article()
Expand All @@ -182,7 +182,7 @@ def postprocessed_created_by(self) -> Union[settings.AUTH_USER_MODEL, Dict]:
user_hash_int = int(user_hash[-4:], 16)
user_profile_picture = get_profile_picture(user_hash_int)

if self.name_type == BoardNameType.ANONYMOUS:
if self.name_type == NameType.ANONYMOUS:
if parent_article_created_by_id == comment_created_by_id:
user_name = gettext("author")
else:
Expand All @@ -200,7 +200,7 @@ def postprocessed_created_by(self) -> Union[settings.AUTH_USER_MODEL, Dict]:
},
}

if self.name_type == BoardNameType.REALNAME:
if self.name_type == NameType.REALNAME:
if parent_article_created_by_id == comment_created_by_id:
user_realname = gettext("author")
else:
Expand Down
11 changes: 7 additions & 4 deletions apps/core/serializers/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from apps.core.documents import ArticleDocument
from apps.core.models import Article, ArticleHiddenReason, Block, Board, Comment, Scrap
from apps.core.models.board import BoardAccessPermissionType, BoardNameType
from apps.core.models.board import BoardAccessPermissionType, NameType
from apps.core.serializers.board import BoardSerializer
from apps.core.serializers.mixins.hidden import (
HiddenSerializerFieldMixin,
Expand Down Expand Up @@ -68,7 +68,7 @@ def get_content(self, obj) -> typing.Optional[str]:
return None

def get_created_by(self, obj) -> dict:
if obj.name_type in (BoardNameType.ANONYMOUS, BoardNameType.REALNAME):
if obj.name_type in (NameType.ANONYMOUS, NameType.REALNAME):
return obj.postprocessed_created_by
else:
data = PublicUserSerializer(obj.postprocessed_created_by).data
Expand Down Expand Up @@ -329,14 +329,17 @@ def get_my_comment_profile(self, obj):
obj.parent_board.is_school_communication
and created_by.profile.is_school_admin
):
name_type = BoardNameType.REGULAR
name_type = NameType.REGULAR

fake_comment = Comment(
created_by=created_by,
name_type=name_type,
parent_article=obj,
)
if fake_comment.name_type in (BoardNameType.ANONYMOUS, BoardNameType.REALNAME):
if fake_comment.name_type in (
NameType.ANONYMOUS,
NameType.REALNAME,
):
return fake_comment.postprocessed_created_by
else:
data = PublicUserSerializer(fake_comment.postprocessed_created_by).data
Expand Down
4 changes: 2 additions & 2 deletions apps/core/serializers/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework import serializers

from apps.core.models import Block, Comment, CommentHiddenReason
from apps.core.models.board import BoardNameType
from apps.core.models.board import NameType
from apps.core.serializers.mixins.hidden import (
HiddenSerializerFieldMixin,
HiddenSerializerMixin,
Expand Down Expand Up @@ -36,7 +36,7 @@ def get_content(self, obj) -> typing.Optional[str]:
return None

def get_created_by(self, obj) -> dict:
if obj.name_type in (BoardNameType.ANONYMOUS, BoardNameType.REALNAME):
if obj.name_type in (NameType.ANONYMOUS, NameType.REALNAME):
return obj.postprocessed_created_by
else:
data = PublicUserSerializer(obj.postprocessed_created_by).data
Expand Down
Loading

0 comments on commit 8989178

Please sign in to comment.