Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 2c5aa42

Browse files
committed
refactor(abuse-report): wip
1 parent e9439eb commit 2c5aa42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+220
-171
lines changed

lib/groupher_server/cms/cms.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ defmodule GroupherServer.CMS do
165165
defdelegate undo_report_article(thread, article_id, user), to: AbuseReport
166166
defdelegate list_reports(type, content_id, filter), to: AbuseReport
167167
defdelegate report_article_comment(comment_id, reason, attr, user), to: ArticleCommentAction
168-
defdelegate unreport_article_comment(comment_id, user), to: ArticleCommentAction
168+
defdelegate undo_report_article_comment(comment_id, user), to: AbuseReport
169169

170170
# Passport CURD
171171
defdelegate stamp_passport(rules, user), to: PassportCURD

lib/groupher_server/cms/delegates/abuse_report.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
4949
end
5050
end
5151

52+
def undo_report_article_comment(comment_id, %User{} = user) do
53+
undo_report_article(:article_comment, comment_id, user)
54+
end
55+
5256
@doc """
5357
undo report article content
5458
"""

lib/groupher_server/cms/delegates/article_comment_action.ex

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do
122122
end
123123
end
124124

125-
@doc "unreport a comment"
126-
def unreport_article_comment(comment_id, %User{} = _user) do
127-
with {:ok, comment} <- ORM.find(ArticleComment, comment_id) do
128-
comment |> ORM.update(%{is_reported: false})
129-
end
130-
end
131-
132125
@doc "reply to exsiting comment"
133126
def reply_article_comment(comment_id, content, %User{} = user) do
134127
with {:ok, target_comment} <-

test/groupher_server/cms/abuse_reports/comment_report_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do
1515
end
1616

1717
describe "[article comment report/unreport]" do
18-
@tag :wip2
18+
@tag :wip3
1919
test "report a comment should have a abuse report record", ~m(user post)a do
2020
{:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user)
2121
{:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user)
@@ -30,7 +30,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do
3030
assert List.first(report_cases).user.login == user.login
3131
end
3232

33-
@tag :wip2
33+
@tag :wip3
3434
test "different user report a comment should have same report with different report cases",
3535
~m(user user2 post)a do
3636
{:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user)

test/groupher_server/cms/abuse_reports/job_report_test.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do
1717
end
1818

1919
describe "[article job report/unreport]" do
20-
@tag :wip2
20+
@tag :wip3
2121
test "report a job should have a abuse report record", ~m(community user job_attrs)a do
2222
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
2323
{:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user)
@@ -37,7 +37,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do
3737
assert job.meta.reported_count == 1
3838
end
3939

40-
@tag :wip2
40+
@tag :wip3
4141
test "can undo a report", ~m(community user job_attrs)a do
4242
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
4343
{:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user)
@@ -47,7 +47,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do
4747
assert all_reports.total_count == 0
4848
end
4949

50-
@tag :wip2
50+
@tag :wip3
5151
test "can undo a report with other user report it too",
5252
~m(community user user2 job_attrs)a do
5353
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
@@ -72,7 +72,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do
7272
assert Enum.any?(report.report_cases, &(&1.user.login == user2.login))
7373
end
7474

75-
@tag :wip2
75+
@tag :wip3
7676
test "different user report a comment should have same report with different report cases",
7777
~m(community user user2 job_attrs)a do
7878
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
@@ -93,7 +93,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do
9393
assert List.last(report_cases).user.login == user2.login
9494
end
9595

96-
@tag :wip2
96+
@tag :wip3
9797
test "same user can not report a comment twice", ~m(community job_attrs user)a do
9898
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
9999

test/groupher_server/cms/abuse_reports/post_report_test.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
1717
end
1818

1919
describe "[article post report/unreport]" do
20-
@tag :wip2
20+
@tag :wip3
2121
test "report a post should have a abuse report record", ~m(community user post_attrs)a do
2222
{:ok, post} = CMS.create_content(community, :post, post_attrs, user)
2323
{:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user)
@@ -37,7 +37,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
3737
assert post.meta.reported_count == 1
3838
end
3939

40-
@tag :wip2
40+
@tag :wip3
4141
test "can undo a report", ~m(community user post_attrs)a do
4242
{:ok, post} = CMS.create_content(community, :post, post_attrs, user)
4343
{:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user)
@@ -47,7 +47,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
4747
assert all_reports.total_count == 0
4848
end
4949

50-
@tag :wip2
50+
@tag :wip3
5151
test "can undo a report with other user report it too",
5252
~m(community user user2 post_attrs)a do
5353
{:ok, post} = CMS.create_content(community, :post, post_attrs, user)
@@ -72,7 +72,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
7272
assert Enum.any?(report.report_cases, &(&1.user.login == user2.login))
7373
end
7474

75-
@tag :wip2
75+
@tag :wip3
7676
test "different user report a comment should have same report with different report cases",
7777
~m(community user user2 post_attrs)a do
7878
{:ok, post} = CMS.create_content(community, :post, post_attrs, user)
@@ -93,7 +93,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
9393
assert List.last(report_cases).user.login == user2.login
9494
end
9595

96-
@tag :wip2
96+
@tag :wip3
9797
test "same user can not report a comment twice", ~m(community post_attrs user)a do
9898
{:ok, post} = CMS.create_content(community, :post, post_attrs, user)
9999

test/groupher_server/cms/comments/job_comment_emotions_test.exs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
2121
end
2222

2323
describe "[emotion in paged article comment]" do
24-
@tag :wip2
24+
@tag :wip3
2525
test "login user should got viewer has emotioned status", ~m(job user)a do
2626
total_count = 0
2727
page_number = 10
@@ -76,7 +76,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
7676
assert @default_emotions == emotions
7777
end
7878

79-
@tag :wip2
79+
@tag :wip3
8080
test "can make emotion to comment", ~m(job user user2)a do
8181
parent_content = "parent comment"
8282
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user)
@@ -91,7 +91,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
9191
assert user_exist_in?(user2, emotions.latest_downvote_users)
9292
end
9393

94-
@tag :wip2
94+
@tag :wip3
9595
test "can undo emotion to comment", ~m(job user user2)a do
9696
parent_content = "parent comment"
9797
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user)
@@ -114,7 +114,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
114114
assert not user_exist_in?(user2, emotions.latest_downvote_users)
115115
end
116116

117-
@tag :wip2
117+
@tag :wip3
118118
test "same user make same emotion to same comment.", ~m(job user)a do
119119
parent_content = "parent comment"
120120
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user)
@@ -128,7 +128,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
128128
assert user_exist_in?(user, parent_comment.emotions.latest_downvote_users)
129129
end
130130

131-
@tag :wip2
131+
@tag :wip3
132132
test "same user same emotion to same comment only have one user_emotion record",
133133
~m(job user)a do
134134
parent_content = "parent comment"
@@ -152,7 +152,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
152152
assert record.heart
153153
end
154154

155-
@tag :wip2
155+
@tag :wip3
156156
test "different user can make same emotions on same comment", ~m(job user user2 user3)a do
157157
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user)
158158

test/groupher_server/cms/comments/job_comment_replies_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do
3333
assert exist_in?(replyed_comment, parent_comment.replies)
3434
end
3535

36-
@tag :wip2
36+
@tag :wip3
3737
test "deleted comment can not be reply", ~m(job user user2)a do
3838
parent_content = "parent comment"
3939
reply_content = "reply comment"
@@ -64,7 +64,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do
6464
assert exist_in?(replyed_comment_2, parent_comment.replies)
6565
end
6666

67-
@tag :wip2
67+
@tag :wip3
6868
test "reply to reply inside a comment should belong same parent comment",
6969
~m(job user user2)a do
7070
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user)
@@ -90,7 +90,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do
9090
assert replyed_comment_3.reply_to_id == replyed_comment_2.id
9191
end
9292

93-
@tag :wip2
93+
@tag :wip3
9494
test "reply to reply inside a comment should have is_reply_to_others flag in meta",
9595
~m(job user user2)a do
9696
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user)
@@ -110,7 +110,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do
110110
assert replyed_comment_3.meta.is_reply_to_others
111111
end
112112

113-
@tag :wip2
113+
@tag :wip3
114114
test "comment replies only contains @max_parent_replies_count replies", ~m(job user)a do
115115
total_reply_count = @max_parent_replies_count + 1
116116

test/groupher_server/cms/comments/job_comment_test.exs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
3939
assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta
4040
end
4141

42-
@tag :wip2
42+
@tag :wip3
4343
test "comment can be updated", ~m(job user)a do
4444
{:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user)
4545

@@ -130,7 +130,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
130130
assert comment.meta.is_article_author_upvoted
131131
end
132132

133-
@tag :wip2
133+
@tag :wip3
134134
test "user upvote job comment will add id to upvoted_user_ids", ~m(job user)a do
135135
comment = "job_comment"
136136
{:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user)
@@ -139,7 +139,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
139139
assert user.id in comment.meta.upvoted_user_ids
140140
end
141141

142-
@tag :wip2
142+
@tag :wip3
143143
test "user undo upvote job comment will remove id from upvoted_user_ids",
144144
~m(job user user2)a do
145145
comment = "job_comment"
@@ -290,12 +290,38 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
290290

291291
assert comment.is_reported
292292

293-
{:ok, _comment} = CMS.unreport_article_comment(comment.id, user)
293+
{:ok, _comment} = CMS.undo_report_article_comment(comment.id, user)
294294
{:ok, comment} = ORM.find(ArticleComment, comment.id)
295295
assert not comment.is_reported
296296
end
297297

298-
@tag :wip
298+
@tag :wip2
299+
test "can undo a report with other user report it too",
300+
~m(user user2 job)a do
301+
{:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user)
302+
303+
{:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user)
304+
{:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user2)
305+
306+
{:ok, all_reports} = CMS.list_reports(:article_comment, comment.id, %{page: 1, size: 20})
307+
assert all_reports.total_count == 1
308+
309+
report = all_reports.entries |> List.first()
310+
assert report.report_cases |> length == 2
311+
assert Enum.any?(report.report_cases, &(&1.user.login == user.login))
312+
assert Enum.any?(report.report_cases, &(&1.user.login == user2.login))
313+
314+
{:ok, _report} = CMS.undo_report_article(:article_comment, comment.id, user)
315+
316+
{:ok, all_reports} = CMS.list_reports(:article_comment, comment.id, %{page: 1, size: 20})
317+
assert all_reports.total_count == 1
318+
319+
report = all_reports.entries |> List.first()
320+
assert report.report_cases |> length == 1
321+
assert Enum.any?(report.report_cases, &(&1.user.login == user2.login))
322+
end
323+
324+
@tag :wip3
299325
test "report user < @report_threshold_for_fold will not fold comment", ~m(user job)a do
300326
{:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user)
301327

@@ -435,7 +461,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
435461
assert paged_comments.total_count == total_count
436462
end
437463

438-
@tag :wip2
464+
@tag :wip3
439465
test "paged article comments should not contains folded and repoted comments",
440466
~m(user job)a do
441467
total_count = 15
@@ -543,7 +569,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
543569
end
544570

545571
describe "[article comment delete]" do
546-
@tag :wip2
572+
@tag :wip3
547573
test "delete comment still exsit in paged list and content is gone", ~m(user job)a do
548574
total_count = 10
549575
page_number = 1
@@ -568,7 +594,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
568594
assert deleted_comment.body_html == @delete_hint
569595
end
570596

571-
@tag :wip2
597+
@tag :wip3
572598
test "delete comment still update article's comments_count field", ~m(user job)a do
573599
{:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user)
574600
{:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user)
@@ -586,7 +612,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
586612
assert job.article_comments_count == 4
587613
end
588614

589-
@tag :wip2
615+
@tag :wip3
590616
test "delete comment still delete pined record if needed", ~m(user job)a do
591617
total_count = 10
592618

test/groupher_server/cms/comments/post_comment_emotions_test.exs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do
2121
end
2222

2323
describe "[emotion in paged article comment]" do
24-
@tag :wip2
24+
@tag :wip3
2525
test "login user should got viewer has emotioned status", ~m(post user)a do
2626
total_count = 0
2727
page_number = 10
@@ -76,7 +76,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do
7676
assert @default_emotions == emotions
7777
end
7878

79-
@tag :wip2
79+
@tag :wip3
8080
test "can make emotion to comment", ~m(post user user2)a do
8181
parent_content = "parent comment"
8282
{:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user)
@@ -91,7 +91,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do
9191
assert user_exist_in?(user2, emotions.latest_downvote_users)
9292
end
9393

94-
@tag :wip2
94+
@tag :wip3
9595
test "can undo emotion to comment", ~m(post user user2)a do
9696
parent_content = "parent comment"
9797
{:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user)
@@ -114,7 +114,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do
114114
assert not user_exist_in?(user2, emotions.latest_downvote_users)
115115
end
116116

117-
@tag :wip2
117+
@tag :wip3
118118
test "same user make same emotion to same comment.", ~m(post user)a do
119119
parent_content = "parent comment"
120120
{:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user)
@@ -128,7 +128,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do
128128
assert user_exist_in?(user, parent_comment.emotions.latest_downvote_users)
129129
end
130130

131-
@tag :wip2
131+
@tag :wip3
132132
test "same user same emotion to same comment only have one user_emotion record",
133133
~m(post user)a do
134134
parent_content = "parent comment"
@@ -152,7 +152,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do
152152
assert record.heart
153153
end
154154

155-
@tag :wip2
155+
@tag :wip3
156156
test "different user can make same emotions on same comment", ~m(post user user2 user3)a do
157157
{:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user)
158158

0 commit comments

Comments
 (0)