Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
4 changes: 2 additions & 2 deletions lib/groupher_server/accounts/embeds/collect_folder_meta.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule GroupherServer.CMS.Embeds.CollectFolderMeta.Macros do
defmodule GroupherServer.Accounts.Embeds.CollectFolderMeta.Macros do
@moduledoc """
general fields for each folder meta

Expand Down Expand Up @@ -31,7 +31,7 @@ defmodule GroupherServer.Accounts.Embeds.CollectFolderMeta do
"""
use Ecto.Schema
import Ecto.Changeset
import GroupherServer.CMS.Embeds.CollectFolderMeta.Macros
import GroupherServer.Accounts.Embeds.CollectFolderMeta.Macros

alias GroupherServer.Accounts.CollectFolder

Expand Down
28 changes: 28 additions & 0 deletions lib/groupher_server/accounts/embeds/user_meta.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule GroupherServer.Accounts.Embeds.UserMeta do
@moduledoc """
general article meta info for article-like content, like post, job, works ...
"""
use Ecto.Schema
use Accessible
import Ecto.Changeset

@optional_fields ~w(reported_count)a

@default_meta %{
reported_count: 0,
reported_user_ids: []
}

@doc "for test usage"
def default_meta(), do: @default_meta

embedded_schema do
field(:reported_count, :integer, default: 0)
field(:reported_user_ids, {:array, :integer}, default: [])
end

def changeset(struct, params) do
struct
|> cast(params, @optional_fields)
end
end
7 changes: 7 additions & 0 deletions lib/groupher_server/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ defmodule GroupherServer.Accounts.User do
alias __MODULE__

use Ecto.Schema
use Accessible

# import GroupherServerWeb.Schema.Helper.Fields
import Ecto.Changeset

alias GroupherServer.Accounts.{
Achievement,
Embeds,
Customization,
EducationBackground,
CollectFolder,
Expand Down Expand Up @@ -59,6 +61,9 @@ defmodule GroupherServer.Accounts.User do
# field(:sponsor_member, :boolean)
# field(:paid_member, :boolean)
# field(:platinum_member, :boolean)
field(:viewer_has_reported, :boolean, default: false, virtual: true)

embeds_one(:meta, Embeds.UserMeta, on_replace: :update)

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

# |> unique_constraint(:username)
Expand All @@ -80,6 +86,7 @@ defmodule GroupherServer.Accounts.User do
|> cast(attrs, @optional_fields ++ @required_fields)
|> cast_embed(:education_backgrounds, with: &EducationBackground.changeset/2)
|> cast_embed(:work_backgrounds, with: &WorkBackground.changeset/2)
|> cast_embed(:meta, required: false, with: &Embeds.UserMeta.changeset/2)
|> validate_length(:nickname, min: 3, max: 30)
|> validate_length(:bio, min: 3, max: 100)
|> validate_inclusion(:sex, ["dude", "girl"])
Expand Down
6 changes: 3 additions & 3 deletions lib/groupher_server/cms/abuse_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ defmodule GroupherServer.CMS.AbuseReport do
alias __MODULE__

use Ecto.Schema
use Accessible
import Ecto.Changeset

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

# @required_fields ~w(article_comment_id user_id recived_user_id)a
@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
@update_fields ~w(operate_user_id deal_with is_closed report_cases_count)a
@optional_fields ~w(article_comment_id post_id job_id repo_id account_id operate_user_id deal_with report_cases_count)a
@update_fields ~w(operate_user_id deal_with report_cases_count)a

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

field(:deal_with, :string)
field(:is_closed, :boolean, default: false)

timestamps(type: :utc_datetime)
end
Expand Down
9 changes: 5 additions & 4 deletions lib/groupher_server/cms/article_comment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ defmodule GroupherServer.CMS.ArticleComment do
alias CMS.{
Post,
Job,
Repo,
Embeds,
ArticleCommentUpvote
}

# alias Helper.HTML

@required_fields ~w(body_html author_id)a
@optional_fields ~w(post_id job_id reply_to_id replies_count is_folded is_reported is_deleted floor is_article_author)a
@updatable_fields ~w(is_folded is_reported is_deleted floor upvotes_count is_pinned)a
@optional_fields ~w(post_id job_id repo_id reply_to_id replies_count is_folded is_deleted floor is_article_author)a
@updatable_fields ~w(is_folded is_deleted floor upvotes_count is_pinned)a

@max_participator_count 5
@max_parent_replies_count 3
Expand Down Expand Up @@ -55,8 +56,6 @@ defmodule GroupherServer.CMS.ArticleComment do
field(:body_html, :string)
# 是否被折叠
field(:is_folded, :boolean, default: false)
# 是否被举报
field(:is_reported, :boolean, default: false)
# 是否被删除
field(:is_deleted, :boolean, default: false)
# 楼层
Expand All @@ -72,6 +71,8 @@ defmodule GroupherServer.CMS.ArticleComment do

belongs_to(:post, Post, foreign_key: :post_id)
belongs_to(:job, Job, foreign_key: :job_id)
belongs_to(:repo, Repo, foreign_key: :repo_id)

belongs_to(:reply_to, ArticleComment, foreign_key: :reply_to_id)

embeds_many(:replies, ArticleComment, on_replace: :delete)
Expand Down
11 changes: 4 additions & 7 deletions lib/groupher_server/cms/cms.ex
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ defmodule GroupherServer.CMS do

defdelegate list_folded_article_comments(thread, article_id, filters), to: ArticleComment
defdelegate list_folded_article_comments(thread, article_id, filters, user), to: ArticleComment
defdelegate list_reported_article_comments(thread, article_id, filters), to: ArticleComment

defdelegate list_reported_article_comments(thread, article_id, filters, user),
to: ArticleComment

defdelegate list_comment_replies(comment_id, filters), to: ArticleComment
defdelegate list_comment_replies(comment_id, filters, user), to: ArticleComment
Expand Down Expand Up @@ -160,11 +156,12 @@ defmodule GroupherServer.CMS do
defdelegate list_comments_participators(thread, content_id, filters), to: CommentCURD

# TODO: move report to abuse report module
defdelegate create_report(type, content_id, reason, attr, user), to: AbuseReport
defdelegate report_article(thread, article_id, reason, attr, user), to: AbuseReport
defdelegate report_article_comment(comment_id, reason, attr, user), to: AbuseReport
defdelegate report_account(account_id, reason, attr, user), to: AbuseReport
defdelegate undo_report_account(account_id, user), to: AbuseReport
defdelegate undo_report_article(thread, article_id, user), to: AbuseReport
defdelegate list_reports(type, content_id, filter), to: AbuseReport
defdelegate report_article_comment(comment_id, reason, attr, user), to: ArticleCommentAction
defdelegate list_reports(filter), to: AbuseReport
defdelegate undo_report_article_comment(comment_id, user), to: AbuseReport

# Passport CURD
Expand Down
Loading