Skip to content

Commit

Permalink
refactor(article): highlight "me" field
Browse files Browse the repository at this point in the history
  • Loading branch information
CapooL committed May 9, 2024
1 parent ae322e1 commit 99bb702
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions hinghwa-dict-backend/article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ def get(self, request, id) -> JsonResponse:
me = {"liked": False, "is_author": False}
return JsonResponse({"article": article, "me": me}, status=200)
if (
not article.visibility
and not user.is_superuser
and not user == article.author
not article.visibility
and not user.is_superuser
and not user == article.author
):
raise ArticleNotFoundException()
article.views += 1
Expand Down Expand Up @@ -254,11 +254,19 @@ def get(self, request, id) -> JsonResponse:

article = Article.objects.filter(id=id)
if not article.exists() or not (
article[0].visibility or user.is_superuser or user == article[0].author
article[0].visibility or user.is_superuser or user == article[0].author
):
raise ArticleNotFoundException()
article = article[0]
comments = [comment_normal(comment) for comment in article.comments.all()]
comments = []
for comment in article.comments.all():
me = {"like": comment.like_users.filter(id=user.id).exists()}
comments.append(
{
"comment": comment_all(comment),
"me": me,
}
)
return JsonResponse({"comments": comments}, status=200)

# AT0401 发表文章评论
Expand All @@ -267,7 +275,7 @@ def post(self, request, id) -> JsonResponse:
user = token_user(token)
article = Article.objects.filter(id=id)
if not article.exists() or not (
article[0].visibility or user.is_superuser or user == article[0].author
article[0].visibility or user.is_superuser or user == article[0].author
):
raise ArticleNotFoundException()
article = article[0]
Expand All @@ -289,13 +297,13 @@ def delete(self, request, id) -> JsonResponse:
user = token_user(token)
article = Article.objects.filter(id=id)
if not article.exists() or not (
article[0].visibility or user.is_superuser or user == article[0].author
article[0].visibility or user.is_superuser or user == article[0].author
):
raise ArticleNotFoundException()
body = demjson3.decode(request.body)
comment = Comment.objects.get(id=body["id"])
if token_pass(request.headers, comment.user.id) or token_pass(
request.headers, -1
request.headers, -1
):
# 应原注释要求,超级管理员也能删
comment.delete()
Expand Down

0 comments on commit 99bb702

Please sign in to comment.