From 23bea760ce3941384fbbb68b90a58c18fc8b218c Mon Sep 17 00:00:00 2001 From: Injoon Hwang Date: Thu, 30 Mar 2023 14:28:39 +0000 Subject: [PATCH 1/7] Update article url to URLField --- .../core/migrations/0044_alter_article_url.py | 20 +++++++++++++++++++ apps/core/models/article.py | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 apps/core/migrations/0044_alter_article_url.py diff --git a/apps/core/migrations/0044_alter_article_url.py b/apps/core/migrations/0044_alter_article_url.py new file mode 100644 index 00000000..95f642eb --- /dev/null +++ b/apps/core/migrations/0044_alter_article_url.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.16 on 2023-03-29 20:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("core", "0043_board_comment_access_mask"), + ] + + operations = [ + migrations.AlterField( + model_name="article", + name="url", + field=models.URLField( + blank=True, default=None, null=True, verbose_name="포탈 링크" + ), + ), + ] diff --git a/apps/core/models/article.py b/apps/core/models/article.py index bf7fb7d1..77a46f32 100644 --- a/apps/core/models/article.py +++ b/apps/core/models/article.py @@ -138,11 +138,12 @@ class Meta(MetaDataModel.Meta): verbose_name="마지막 댓글 시간", ) - url = models.TextField( + url = models.URLField( null=True, + max_length=200, blank=True, default=None, - verbose_name="링크", + verbose_name="포탈 링크", ) content_updated_at = models.DateTimeField( From e9221ad9213a395920ce113188ac7a79a88fcc80 Mon Sep 17 00:00:00 2001 From: Injoon Hwang Date: Thu, 30 Mar 2023 14:35:25 +0000 Subject: [PATCH 2/7] Add str method to Attachments --- apps/core/models/attachment.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/core/models/attachment.py b/apps/core/models/attachment.py index 528108a9..63f938a6 100644 --- a/apps/core/models/attachment.py +++ b/apps/core/models/attachment.py @@ -24,3 +24,6 @@ class Meta(MetaDataModel.Meta): max_length=128, verbose_name="타입", ) + + def __str__(self) -> str: + return self.file.name From e6f99a05fefb8f8ba0a66c0dcd572acd9927b784 Mon Sep 17 00:00:00 2001 From: Injoon Hwang Date: Fri, 31 Mar 2023 00:11:16 +0000 Subject: [PATCH 3/7] Make Article.hidden_at nullable --- apps/core/admin.py | 8 +++--- .../0045_alter_hidden_at_to_nullable.py | 27 +++++++++++++++++++ .../0046_update_hidden_at_min_time_to_null.py | 21 +++++++++++++++ apps/core/models/article.py | 6 +++-- apps/core/models/comment.py | 6 +++-- 5 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 apps/core/migrations/0045_alter_hidden_at_to_nullable.py create mode 100644 apps/core/migrations/0046_update_hidden_at_min_time_to_null.py diff --git a/apps/core/admin.py b/apps/core/admin.py index 16f680d3..d60cfa30 100644 --- a/apps/core/admin.py +++ b/apps/core/admin.py @@ -32,9 +32,9 @@ def lookups(self, request, model_admin): def queryset(self, request, queryset): if self.value() == "hidden": - return queryset.exclude(hidden_at=MIN_TIME) + return queryset.exclude(hidden_at=None) if self.value() == "not_hidden": - return queryset.filter(hidden_at=MIN_TIME) + return queryset.filter(hidden_at=None) @admin.register(Board) @@ -110,7 +110,7 @@ class ArticleAdmin(MetaDataModelAdmin): @admin.action(description=gettext("Restore hidden articles")) def restore_hidden_articles(self, request, queryset): - rows_updated = queryset.update(hidden_at=MIN_TIME) + rows_updated = queryset.update(hidden_at=None) self.message_user(request, f"{rows_updated}개의 게시물(들)이 성공적으로 복구되었습니다.") @@ -138,7 +138,7 @@ class CommentAdmin(MetaDataModelAdmin): @admin.action(description=gettext("Restore hidden comments")) def restore_hidden_comments(self, request, queryset): - rows_updated = queryset.update(hidden_at=MIN_TIME) + rows_updated = queryset.update(hidden_at=None) self.message_user(request, f"{rows_updated}개의 댓글(들)이 성공적으로 복구되었습니다.") diff --git a/apps/core/migrations/0045_alter_hidden_at_to_nullable.py b/apps/core/migrations/0045_alter_hidden_at_to_nullable.py new file mode 100644 index 00000000..f2dad329 --- /dev/null +++ b/apps/core/migrations/0045_alter_hidden_at_to_nullable.py @@ -0,0 +1,27 @@ +# Generated by Django 3.2.16 on 2023-03-30 22:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("core", "0044_alter_article_url"), + ] + + operations = [ + migrations.AlterField( + model_name="article", + name="hidden_at", + field=models.DateTimeField( + blank=True, default=None, null=True, verbose_name="숨김 시간" + ), + ), + migrations.AlterField( + model_name="comment", + name="hidden_at", + field=models.DateTimeField( + blank=True, default=None, null=True, verbose_name="숨김 시간" + ), + ), + ] diff --git a/apps/core/migrations/0046_update_hidden_at_min_time_to_null.py b/apps/core/migrations/0046_update_hidden_at_min_time_to_null.py new file mode 100644 index 00000000..8f818099 --- /dev/null +++ b/apps/core/migrations/0046_update_hidden_at_min_time_to_null.py @@ -0,0 +1,21 @@ +# Generated by yuwol + +from django.db import migrations + +from ara.settings import MIN_TIME + + +def update_hidden_at(apps, schema_editor): + Article = apps.get_model("core", "Article") + Article.objects.filter(hidden_at=MIN_TIME).update(hidden_at=None) + + +class Migration(migrations.Migration): + + dependencies = [ + ("core", "0045_alter_hidden_at_to_nullable"), + ] + + operations = [ + migrations.RunPython(update_hidden_at, atomic=True), + ] diff --git a/apps/core/models/article.py b/apps/core/models/article.py index 77a46f32..c80b4de3 100644 --- a/apps/core/models/article.py +++ b/apps/core/models/article.py @@ -153,7 +153,9 @@ class Meta(MetaDataModel.Meta): ) hidden_at = models.DateTimeField( - default=MIN_TIME, + null=True, + blank=True, + default=None, verbose_name="숨김 시간", ) @@ -248,7 +250,7 @@ def update_vote_status(self): self.save() def is_hidden_by_reported(self) -> bool: - return self.hidden_at != MIN_TIME + return self.hidden_at is not None @property def created_by_nickname(self): diff --git a/apps/core/models/comment.py b/apps/core/models/comment.py index c6f022a3..e08cbc78 100644 --- a/apps/core/models/comment.py +++ b/apps/core/models/comment.py @@ -94,7 +94,9 @@ class Meta(MetaDataModel.Meta): verbose_name="댓글", ) hidden_at = models.DateTimeField( - default=MIN_TIME, + null=True, + blank=True, + default=None, verbose_name="숨김 시간", ) @@ -147,7 +149,7 @@ def get_parent_article(self): return self.parent_comment.parent_article def is_hidden_by_reported(self) -> bool: - return self.hidden_at != MIN_TIME + return self.hidden_at is not None def is_deleted(self) -> bool: return self.deleted_at != MIN_TIME From 89eb53bb397a2743ad30c140a42f9c4457bec488 Mon Sep 17 00:00:00 2001 From: Injoon Hwang Date: Fri, 31 Mar 2023 00:16:40 +0000 Subject: [PATCH 4/7] Make Comment.hidden_at nullable --- apps/core/migrations/0046_update_hidden_at_min_time_to_null.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/core/migrations/0046_update_hidden_at_min_time_to_null.py b/apps/core/migrations/0046_update_hidden_at_min_time_to_null.py index 8f818099..0c2f294d 100644 --- a/apps/core/migrations/0046_update_hidden_at_min_time_to_null.py +++ b/apps/core/migrations/0046_update_hidden_at_min_time_to_null.py @@ -9,6 +9,9 @@ def update_hidden_at(apps, schema_editor): Article = apps.get_model("core", "Article") Article.objects.filter(hidden_at=MIN_TIME).update(hidden_at=None) + Comment = apps.get_model("core", "Comment") + Comment.objects.filter(hidden_at=MIN_TIME).update(hidden_at=None) + class Migration(migrations.Migration): From 9094d25cc39a1d85057c8ab041d422366c9dcbb7 Mon Sep 17 00:00:00 2001 From: TriangleYJ Date: Fri, 31 Mar 2023 08:59:02 +0000 Subject: [PATCH 5/7] Change runner to bap server --- .github/workflows/github-actions.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 49c3b87c..70385dcd 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -24,7 +24,9 @@ env: jobs: deploy: name: Run Tests - runs-on: ubuntu-20.04 + # runs-on: ubuntu-20.04 + runs-on: [self-hosted] + steps: - name: Checkout uses: actions/checkout@v2 From 326da5605c28f084e411c6748abcb639621f1eb8 Mon Sep 17 00:00:00 2001 From: TriangleYJ Date: Fri, 31 Mar 2023 11:34:17 +0000 Subject: [PATCH 6/7] Disable FCM --- ara/firebase.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ara/firebase.py b/ara/firebase.py index 055c1ade..851baf39 100644 --- a/ara/firebase.py +++ b/ara/firebase.py @@ -4,6 +4,9 @@ def fcm_notify_comment(user, title, body, open_url): + ################## Disable FCM #################### + return + targets = FCMToken.objects.filter(user=user) for i in targets: try: @@ -16,6 +19,9 @@ def fcm_notify_comment(user, title, body, open_url): def fcm_simple(FCM_token, title="Title", body="Body", open_url="/"): # This registration token comes from the client FCM SDKs. # See documentation on defining a message payload. + + ################## Disable FCM #################### + return message = messaging.Message( notification=messaging.Notification( title=title, From 8a6a07d7ca9544a818667e67f90147a3a3304abc Mon Sep 17 00:00:00 2001 From: Injoon Hwang Date: Fri, 31 Mar 2023 16:25:57 +0000 Subject: [PATCH 7/7] Refactor article admin page --- apps/core/admin.py | 54 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/apps/core/admin.py b/apps/core/admin.py index d60cfa30..d6d29883 100644 --- a/apps/core/admin.py +++ b/apps/core/admin.py @@ -81,6 +81,7 @@ class FAQAdmin(MetaDataModelAdmin): @admin.register(Article) class ArticleAdmin(MetaDataModelAdmin): + actions = ("restore_hidden_articles",) list_filter = ( "name_type", "is_content_sexual", @@ -91,28 +92,63 @@ class ArticleAdmin(MetaDataModelAdmin): ) list_display = ( "title", + "parent_board", + "user_nickname", + "user_email", "hit_count", - "positive_vote_count", - "negative_vote_count", - "name_type", - "is_content_sexual", - "is_content_social", "report_count", + "created_at", "hidden_at", ) - raw_id_fields = ( + raw_id_fields = ("created_by",) + search_fields = ( + "title", + "content", + "hidden_at", + "created_by__email", + ) + fields = ( + "title", + "content", "created_by", - "parent_topic", "parent_board", + "parent_topic", + "name_type", + ("is_content_sexual", "is_content_social"), + ("hit_count", "migrated_hit_count"), + ("positive_vote_count", "migrated_positive_vote_count"), + ("negative_vote_count", "migrated_negative_vote_count"), + ("comment_count", "report_count"), + "attachments", + "content_updated_at", + "commented_at", + "url", + "hidden_at", ) - search_fields = ("title", "content", "hidden_at", "created_by__email") - actions = ("restore_hidden_articles",) + readonly_fields = ( + "hit_count", + "positive_vote_count", + "negative_vote_count", + "comment_count", + "report_count", + "commented_at", + "content_updated_at", + ) + filter_horizontal = ("attachments",) @admin.action(description=gettext("Restore hidden articles")) def restore_hidden_articles(self, request, queryset): rows_updated = queryset.update(hidden_at=None) self.message_user(request, f"{rows_updated}개의 게시물(들)이 성공적으로 복구되었습니다.") + @admin.display(description="닉네임") + def user_nickname(self, obj: Article): + return obj.created_by_nickname + + @admin.display(description="이메일") + def user_email(self, obj: Article): + return obj.created_by.email + @admin.register(Comment) class CommentAdmin(MetaDataModelAdmin):