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

Commit 19e7df7

Browse files
authored
refactor(abuse-report): re-design & re-org code base (#352)
* refactor(abuse-report): wip * refactor(abuse-report): wip * refactor(abuse-report): wip * refactor(abuse-report): wip * refactor(abuse-report): wip * refactor(abuse-report): remove is_reported field * refactor(abuse-report): add reported_user_ids * refactor(abuse-report): debug viewer_has_reported * refactor(abuse-report): clean up * refactor(abuse-report): wip * refactor(abuse-report): wip * refactor(abuse-report): wip * refactor(abuse-report): fix error
1 parent ea95380 commit 19e7df7

File tree

76 files changed

+1378
-513
lines changed

Some content is hidden

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

76 files changed

+1378
-513
lines changed

lib/groupher_server/accounts/embeds/collect_folder_meta.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule GroupherServer.CMS.Embeds.CollectFolderMeta.Macros do
1+
defmodule GroupherServer.Accounts.Embeds.CollectFolderMeta.Macros do
22
@moduledoc """
33
general fields for each folder meta
44
@@ -31,7 +31,7 @@ defmodule GroupherServer.Accounts.Embeds.CollectFolderMeta do
3131
"""
3232
use Ecto.Schema
3333
import Ecto.Changeset
34-
import GroupherServer.CMS.Embeds.CollectFolderMeta.Macros
34+
import GroupherServer.Accounts.Embeds.CollectFolderMeta.Macros
3535

3636
alias GroupherServer.Accounts.CollectFolder
3737

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
defmodule GroupherServer.Accounts.Embeds.UserMeta do
2+
@moduledoc """
3+
general article meta info for article-like content, like post, job, works ...
4+
"""
5+
use Ecto.Schema
6+
use Accessible
7+
import Ecto.Changeset
8+
9+
@optional_fields ~w(reported_count)a
10+
11+
@default_meta %{
12+
reported_count: 0,
13+
reported_user_ids: []
14+
}
15+
16+
@doc "for test usage"
17+
def default_meta(), do: @default_meta
18+
19+
embedded_schema do
20+
field(:reported_count, :integer, default: 0)
21+
field(:reported_user_ids, {:array, :integer}, default: [])
22+
end
23+
24+
def changeset(struct, params) do
25+
struct
26+
|> cast(params, @optional_fields)
27+
end
28+
end

lib/groupher_server/accounts/user.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ defmodule GroupherServer.Accounts.User do
33
alias __MODULE__
44

55
use Ecto.Schema
6+
use Accessible
67

78
# import GroupherServerWeb.Schema.Helper.Fields
89
import Ecto.Changeset
910

1011
alias GroupherServer.Accounts.{
1112
Achievement,
13+
Embeds,
1214
Customization,
1315
EducationBackground,
1416
CollectFolder,
@@ -59,6 +61,9 @@ defmodule GroupherServer.Accounts.User do
5961
# field(:sponsor_member, :boolean)
6062
# field(:paid_member, :boolean)
6163
# field(:platinum_member, :boolean)
64+
field(:viewer_has_reported, :boolean, default: false, virtual: true)
65+
66+
embeds_one(:meta, Embeds.UserMeta, on_replace: :update)
6267

6368
has_one(:customization, Customization)
6469
has_one(:purchase, Purchase)
@@ -70,6 +75,7 @@ defmodule GroupherServer.Accounts.User do
7075
def changeset(%User{} = user, attrs) do
7176
user
7277
|> update_changeset(attrs)
78+
|> cast_embed(:meta, required: false, with: &Embeds.UserMeta.changeset/2)
7379
|> validate_required(@required_fields)
7480

7581
# |> unique_constraint(:username)
@@ -80,6 +86,7 @@ defmodule GroupherServer.Accounts.User do
8086
|> cast(attrs, @optional_fields ++ @required_fields)
8187
|> cast_embed(:education_backgrounds, with: &EducationBackground.changeset/2)
8288
|> cast_embed(:work_backgrounds, with: &WorkBackground.changeset/2)
89+
|> cast_embed(:meta, required: false, with: &Embeds.UserMeta.changeset/2)
8390
|> validate_length(:nickname, min: 3, max: 30)
8491
|> validate_length(:bio, min: 3, max: 100)
8592
|> validate_inclusion(:sex, ["dude", "girl"])

lib/groupher_server/cms/abuse_report.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ defmodule GroupherServer.CMS.AbuseReport do
33
alias __MODULE__
44

55
use Ecto.Schema
6+
use Accessible
67
import Ecto.Changeset
78

89
alias GroupherServer.{Accounts, CMS}
910
alias CMS.{ArticleComment, Embeds, Post, Job, Repo}
1011

1112
# @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
13+
@optional_fields ~w(article_comment_id post_id job_id repo_id account_id operate_user_id deal_with report_cases_count)a
14+
@update_fields ~w(operate_user_id deal_with report_cases_count)a
1415

1516
@type t :: %AbuseReport{}
1617
schema "abuse_reports" do
@@ -26,7 +27,6 @@ defmodule GroupherServer.CMS.AbuseReport do
2627
belongs_to(:operate_user, Accounts.User, foreign_key: :operate_user_id)
2728

2829
field(:deal_with, :string)
29-
field(:is_closed, :boolean, default: false)
3030

3131
timestamps(type: :utc_datetime)
3232
end

lib/groupher_server/cms/article_comment.ex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ defmodule GroupherServer.CMS.ArticleComment do
1212
alias CMS.{
1313
Post,
1414
Job,
15+
Repo,
1516
Embeds,
1617
ArticleCommentUpvote
1718
}
1819

1920
# alias Helper.HTML
2021

2122
@required_fields ~w(body_html author_id)a
22-
@optional_fields ~w(post_id job_id reply_to_id replies_count is_folded is_reported is_deleted floor is_article_author)a
23-
@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
2425

2526
@max_participator_count 5
2627
@max_parent_replies_count 3
@@ -55,8 +56,6 @@ defmodule GroupherServer.CMS.ArticleComment do
5556
field(:body_html, :string)
5657
# 是否被折叠
5758
field(:is_folded, :boolean, default: false)
58-
# 是否被举报
59-
field(:is_reported, :boolean, default: false)
6059
# 是否被删除
6160
field(:is_deleted, :boolean, default: false)
6261
# 楼层
@@ -72,6 +71,8 @@ defmodule GroupherServer.CMS.ArticleComment do
7271

7372
belongs_to(:post, Post, foreign_key: :post_id)
7473
belongs_to(:job, Job, foreign_key: :job_id)
74+
belongs_to(:repo, Repo, foreign_key: :repo_id)
75+
7576
belongs_to(:reply_to, ArticleComment, foreign_key: :reply_to_id)
7677

7778
embeds_many(:replies, ArticleComment, on_replace: :delete)

lib/groupher_server/cms/cms.ex

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ defmodule GroupherServer.CMS do
121121

122122
defdelegate list_folded_article_comments(thread, article_id, filters), to: ArticleComment
123123
defdelegate list_folded_article_comments(thread, article_id, filters, user), to: ArticleComment
124-
defdelegate list_reported_article_comments(thread, article_id, filters), to: ArticleComment
125-
126-
defdelegate list_reported_article_comments(thread, article_id, filters, user),
127-
to: ArticleComment
128124

129125
defdelegate list_comment_replies(comment_id, filters), to: ArticleComment
130126
defdelegate list_comment_replies(comment_id, filters, user), to: ArticleComment
@@ -160,11 +156,12 @@ defmodule GroupherServer.CMS do
160156
defdelegate list_comments_participators(thread, content_id, filters), to: CommentCURD
161157

162158
# TODO: move report to abuse report module
163-
defdelegate create_report(type, content_id, reason, attr, user), to: AbuseReport
164159
defdelegate report_article(thread, article_id, reason, attr, user), to: AbuseReport
160+
defdelegate report_article_comment(comment_id, reason, attr, user), to: AbuseReport
161+
defdelegate report_account(account_id, reason, attr, user), to: AbuseReport
162+
defdelegate undo_report_account(account_id, user), to: AbuseReport
165163
defdelegate undo_report_article(thread, article_id, user), to: AbuseReport
166-
defdelegate list_reports(type, content_id, filter), to: AbuseReport
167-
defdelegate report_article_comment(comment_id, reason, attr, user), to: ArticleCommentAction
164+
defdelegate list_reports(filter), to: AbuseReport
168165
defdelegate undo_report_article_comment(comment_id, user), to: AbuseReport
169166

170167
# Passport CURD

0 commit comments

Comments
 (0)