Skip to content

Commit

Permalink
Merge pull request #381 from sparcs-kaist/develop
Browse files Browse the repository at this point in the history
Disable FCM & Update article admin page
  • Loading branch information
injoonH authored Apr 1, 2023
2 parents f19773d + f06456f commit bdaeb0b
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 49 additions & 13 deletions apps/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -81,6 +81,7 @@ class FAQAdmin(MetaDataModelAdmin):

@admin.register(Article)
class ArticleAdmin(MetaDataModelAdmin):
actions = ("restore_hidden_articles",)
list_filter = (
"name_type",
"is_content_sexual",
Expand All @@ -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=MIN_TIME)
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):
Expand All @@ -138,7 +174,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}개의 댓글(들)이 성공적으로 복구되었습니다.")


Expand Down
20 changes: 20 additions & 0 deletions apps/core/migrations/0044_alter_article_url.py
Original file line number Diff line number Diff line change
@@ -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="포탈 링크"
),
),
]
27 changes: 27 additions & 0 deletions apps/core/migrations/0045_alter_hidden_at_to_nullable.py
Original file line number Diff line number Diff line change
@@ -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="숨김 시간"
),
),
]
24 changes: 24 additions & 0 deletions apps/core/migrations/0046_update_hidden_at_min_time_to_null.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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)

Comment = apps.get_model("core", "Comment")
Comment.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),
]
11 changes: 7 additions & 4 deletions apps/core/models/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -152,7 +153,9 @@ class Meta(MetaDataModel.Meta):
)

hidden_at = models.DateTimeField(
default=MIN_TIME,
null=True,
blank=True,
default=None,
verbose_name="숨김 시간",
)

Expand Down Expand Up @@ -247,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):
Expand Down
3 changes: 3 additions & 0 deletions apps/core/models/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ class Meta(MetaDataModel.Meta):
max_length=128,
verbose_name="타입",
)

def __str__(self) -> str:
return self.file.name
6 changes: 4 additions & 2 deletions apps/core/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="숨김 시간",
)

Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions ara/firebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down

0 comments on commit bdaeb0b

Please sign in to comment.