Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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