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

Commit 7e55780

Browse files
committed
refactor(abuse-report): remove is_reported field
1 parent c53d7c7 commit 7e55780

Some content is hidden

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

60 files changed

+260
-301
lines changed

lib/groupher_server/accounts/user.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ defmodule GroupherServer.Accounts.User do
6161
# field(:paid_member, :boolean)
6262
# field(:platinum_member, :boolean)
6363

64-
field(:is_reported, :boolean, default: false)
6564
embeds_one(:meta, Embeds.UserMeta, on_replace: :update)
6665

6766
has_one(:customization, Customization)

lib/groupher_server/cms/abuse_report.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ defmodule GroupherServer.CMS.AbuseReport do
99
alias CMS.{ArticleComment, Embeds, Post, Job, Repo}
1010

1111
# @required_fields ~w(article_comment_id user_id recived_user_id)a
12-
@optional_fields ~w(article_comment_id post_id job_id repo_id account_id operate_user_id deal_with is_closed report_cases_count)a
13-
@update_fields ~w(operate_user_id deal_with is_closed report_cases_count)a
12+
@optional_fields ~w(article_comment_id post_id job_id repo_id account_id operate_user_id deal_with is_confirmed report_cases_count)a
13+
@update_fields ~w(operate_user_id deal_with is_confirmed report_cases_count)a
1414

1515
@type t :: %AbuseReport{}
1616
schema "abuse_reports" do
@@ -26,7 +26,7 @@ defmodule GroupherServer.CMS.AbuseReport do
2626
belongs_to(:operate_user, Accounts.User, foreign_key: :operate_user_id)
2727

2828
field(:deal_with, :string)
29-
field(:is_closed, :boolean, default: false)
29+
field(:is_confirmed, :boolean, default: false)
3030

3131
timestamps(type: :utc_datetime)
3232
end

lib/groupher_server/cms/article_comment.ex

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ defmodule GroupherServer.CMS.ArticleComment do
2020
# alias Helper.HTML
2121

2222
@required_fields ~w(body_html author_id)a
23-
@optional_fields ~w(post_id job_id repo_id reply_to_id replies_count is_folded is_reported is_deleted floor is_article_author)a
24-
@updatable_fields ~w(is_folded is_reported is_deleted floor upvotes_count is_pinned)a
23+
@optional_fields ~w(post_id job_id repo_id reply_to_id replies_count is_folded is_deleted floor is_article_author)a
24+
@updatable_fields ~w(is_folded is_deleted floor upvotes_count is_pinned)a
2525

2626
@max_participator_count 5
2727
@max_parent_replies_count 3
@@ -56,8 +56,6 @@ defmodule GroupherServer.CMS.ArticleComment do
5656
field(:body_html, :string)
5757
# 是否被折叠
5858
field(:is_folded, :boolean, default: false)
59-
# 是否被举报
60-
field(:is_reported, :boolean, default: false)
6159
# 是否被删除
6260
field(:is_deleted, :boolean, default: false)
6361
# 楼层

lib/groupher_server/cms/delegates/abuse_report.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
2323
# operate_user_id,
2424
# min_case_count,
2525
# max_case_count,
26-
# is_closed
2726
# page
2827
# size
2928
# }
@@ -34,7 +33,6 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
3433
@export_report_keys [
3534
:id,
3635
:deal_with,
37-
:is_closed,
3836
:operate_user,
3937
:report_cases,
4038
:report_cases_count,
@@ -107,6 +105,9 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
107105
end
108106
end
109107

108+
@doc """
109+
report an account
110+
"""
110111
def report_account(account_id, reason, attr, user) do
111112
with {:ok, info} <- match(:account_user),
112113
{:ok, account} <- ORM.find(info.model, account_id) do
@@ -352,6 +353,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
352353
end
353354

354355
defp result({:ok, %{update_report_flag: result}}), do: result |> done()
356+
defp result({:ok, %{update_content_reported_flag: result}}), do: result |> done()
355357

356358
defp result({:error, _, result, _steps}) do
357359
{:error, result}

lib/groupher_server/cms/delegates/article_comment.ex

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
3333
def list_article_comments(thread, article_id, filters, mode, user \\ nil)
3434

3535
def list_article_comments(thread, article_id, filters, :timeline, user) do
36-
where_query = dynamic([c], not c.is_folded and not c.is_reported and not c.is_pinned)
36+
where_query = dynamic([c], not c.is_folded and not c.is_pinned)
3737
do_list_article_comment(thread, article_id, filters, where_query, user)
3838
end
3939

@@ -44,26 +44,19 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
4444
where_query =
4545
dynamic(
4646
[c],
47-
is_nil(c.reply_to_id) and not c.is_folded and not c.is_reported and not c.is_pinned
47+
is_nil(c.reply_to_id) and not c.is_folded and not c.is_pinned
4848
)
4949

5050
do_list_article_comment(thread, article_id, filters, where_query, user)
5151
end
5252

5353
def list_folded_article_comments(thread, article_id, filters) do
54-
where_query = dynamic([c], c.is_folded and not c.is_reported and not c.is_pinned)
54+
where_query = dynamic([c], c.is_folded and not c.is_pinned)
5555
do_list_article_comment(thread, article_id, filters, where_query, nil)
5656
end
5757

5858
def list_folded_article_comments(thread, article_id, filters, user) do
59-
where_query = dynamic([c], c.is_folded and not c.is_reported and not c.is_pinned)
60-
do_list_article_comment(thread, article_id, filters, where_query, user)
61-
end
62-
63-
def list_reported_article_comments(thread, article_id, filters, user \\ nil)
64-
65-
def list_reported_article_comments(thread, article_id, filters, user) do
66-
where_query = dynamic([c], c.is_reported)
59+
where_query = dynamic([c], c.is_folded and not c.is_pinned)
6760
do_list_article_comment(thread, article_id, filters, where_query, user)
6861
end
6962

@@ -227,8 +220,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
227220
%{page: page, size: size} = filters
228221
query = from(c in ArticleComment, preload: [reply_to: :author])
229222

230-
where_query =
231-
dynamic([c], not c.is_reported and not c.is_folded and c.reply_to_id == ^comment_id)
223+
where_query = dynamic([c], not c.is_folded and c.reply_to_id == ^comment_id)
232224

233225
query
234226
|> where(^where_query)

lib/groupher_server/cms/delegates/article_comment_action.ex

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do
108108
|> Multi.run(:create_abuse_report, fn _, _ ->
109109
CMS.create_report(:article_comment, comment_id, reason, attr, user)
110110
end)
111-
|> Multi.run(:update_report_flag, fn _, _ ->
112-
# TODO: update report count in meta
113-
ORM.update(comment, %{is_reported: true})
114-
end)
115111
|> Multi.run(:fold_comment_report_too_many, fn _, %{create_abuse_report: abuse_report} ->
116112
if abuse_report.report_cases_count >= @report_threshold_for_fold,
117113
do: fold_article_comment(comment, user),
@@ -349,7 +345,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do
349345
defp upsert_comment_result({:ok, %{create_article_comment: result}}), do: {:ok, result}
350346
defp upsert_comment_result({:ok, %{add_reply_to: result}}), do: {:ok, result}
351347
defp upsert_comment_result({:ok, %{check_article_author_upvoted: result}}), do: {:ok, result}
352-
defp upsert_comment_result({:ok, %{update_report_flag: result}}), do: {:ok, result}
348+
defp upsert_comment_result({:ok, %{fold_comment_report_too_many: result}}), do: {:ok, result}
353349
defp upsert_comment_result({:ok, %{update_comment_flag: result}}), do: {:ok, result}
354350
defp upsert_comment_result({:ok, %{delete_article_comment: result}}), do: {:ok, result}
355351

lib/groupher_server/cms/helper/matcher2.ex

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do
1515
%{
1616
model: ArticleComment,
1717
foreign_key: :article_comment_id,
18+
preload: :article_comment,
1819
default_meta: CMS.Embeds.ArticleCommentMeta.default_meta()
1920
}}
2021
end
@@ -36,6 +37,7 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do
3637
%{
3738
model: User,
3839
foreign_key: :account_id,
40+
preload: :account,
3941
default_meta: Accounts.Embeds.UserMeta.default_meta()
4042
}}
4143
end
@@ -47,7 +49,12 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do
4749

4850
def match(:post) do
4951
{:ok,
50-
%{model: Post, foreign_key: :post_id, default_meta: CMS.Embeds.ArticleMeta.default_meta()}}
52+
%{
53+
model: Post,
54+
foreign_key: :post_id,
55+
preload: :post,
56+
default_meta: CMS.Embeds.ArticleMeta.default_meta()
57+
}}
5158
end
5259

5360
def match(Job) do
@@ -56,7 +63,12 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do
5663

5764
def match(:job) do
5865
{:ok,
59-
%{model: Job, foreign_key: :job_id, default_meta: CMS.Embeds.ArticleMeta.default_meta()}}
66+
%{
67+
model: Job,
68+
foreign_key: :job_id,
69+
preload: :job,
70+
default_meta: CMS.Embeds.ArticleMeta.default_meta()
71+
}}
6072
end
6173

6274
def match(Repo) do
@@ -65,7 +77,12 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do
6577

6678
def match(:repo) do
6779
{:ok,
68-
%{model: Repo, foreign_key: :repo_id, default_meta: CMS.Embeds.ArticleMeta.default_meta()}}
80+
%{
81+
model: Repo,
82+
foreign_key: :repo_id,
83+
preload: :repo,
84+
default_meta: CMS.Embeds.ArticleMeta.default_meta()
85+
}}
6986
end
7087

7188
def match(:post, :query, id), do: {:ok, dynamic([c], c.post_id == ^id)}

lib/groupher_server/cms/job.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule GroupherServer.CMS.Job do
2424

2525
@timestamps_opts [type: :utc_datetime_usec]
2626
@required_fields ~w(title company company_logo body digest length)a
27-
@optional_fields ~w(origial_community_id desc company_link link_addr copy_right salary exp education field finance scale article_comments_count article_comments_participators_count upvotes_count collects_count is_reported)a
27+
@optional_fields ~w(origial_community_id desc company_link link_addr copy_right salary exp education field finance scale article_comments_count article_comments_participators_count upvotes_count collects_count)a
2828

2929
@type t :: %Job{}
3030
schema "cms_jobs" do
@@ -57,7 +57,6 @@ defmodule GroupherServer.CMS.Job do
5757
# NOTE: this one is tricky, pin is dynamic changed when return by func: add_pin_contents_ifneed
5858
field(:is_pinned, :boolean, default: false, virtual: true)
5959
field(:trash, :boolean, default_value: false, virtual: true)
60-
field(:is_reported, :boolean, default: false)
6160

6261
has_many(:upvotes, {"article_upvotes", ArticleUpvote})
6362
field(:upvotes_count, :integer, default: 0)

lib/groupher_server/cms/post.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule GroupherServer.CMS.Post do
2626

2727
@timestamps_opts [type: :utc_datetime_usec]
2828
@required_fields ~w(title body digest length)a
29-
@optional_fields ~w(origial_community_id link_addr copy_right link_addr link_icon article_comments_count article_comments_participators_count upvotes_count collects_count is_reported)a
29+
@optional_fields ~w(origial_community_id link_addr copy_right link_addr link_icon article_comments_count article_comments_participators_count upvotes_count collects_count)a
3030

3131
@type t :: %Post{}
3232
schema "cms_posts" do
@@ -48,7 +48,6 @@ defmodule GroupherServer.CMS.Post do
4848
# field(:pin, :boolean, default_value: false, virtual: true)
4949
field(:is_pinned, :boolean, default: false, virtual: true)
5050
field(:trash, :boolean, default_value: false, virtual: true)
51-
field(:is_reported, :boolean, default: false)
5251

5352
field(:viewer_has_viewed, :boolean, default: false, virtual: true)
5453
field(:viewer_has_upvoted, :boolean, default: false, virtual: true)

lib/groupher_server/cms/repo.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defmodule GroupherServer.CMS.Repo do
2525

2626
@timestamps_opts [type: :utc_datetime_usec]
2727
@required_fields ~w(title owner_name owner_url repo_url desc readme star_count issues_count prs_count fork_count watch_count upvotes_count collects_count)a
28-
@optional_fields ~w(origial_community_id last_sync homepage_url release_tag license is_reported)a
28+
@optional_fields ~w(origial_community_id last_sync homepage_url release_tag license)a
2929

3030
@type t :: %Repo{}
3131
schema "cms_repos" do
@@ -61,7 +61,6 @@ defmodule GroupherServer.CMS.Repo do
6161
# NOTE: this one is tricky, pin is dynamic changed when return by func: add_pin_contents_ifneed
6262
field(:is_pinned, :boolean, default: false, virtual: true)
6363
field(:trash, :boolean, default_value: false)
64-
field(:is_reported, :boolean, default: false)
6564

6665
has_many(:upvotes, {"article_upvotes", ArticleUpvote})
6766
field(:upvotes_count, :integer, default: 0)

0 commit comments

Comments
 (0)