Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
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
16 changes: 8 additions & 8 deletions lib/groupher_server/cms/cms.ex
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ defmodule GroupherServer.CMS do
defdelegate paged_published_comments(user, thread, filters), to: CommentCurd
defdelegate paged_published_comments(user, filters), to: CommentCurd

defdelegate paged_folded_article_comments(thread, article_id, filters), to: CommentCurd
defdelegate paged_folded_article_comments(thread, article_id, filters, user), to: CommentCurd
defdelegate paged_folded_comments(thread, article_id, filters), to: CommentCurd
defdelegate paged_folded_comments(thread, article_id, filters, user), to: CommentCurd

defdelegate paged_comment_replies(comment_id, filters), to: CommentCurd
defdelegate paged_comment_replies(comment_id, filters, user), to: CommentCurd
Expand All @@ -154,14 +154,14 @@ defmodule GroupherServer.CMS do
defdelegate upvote_comment(comment_id, user), to: CommentAction
defdelegate undo_upvote_comment(comment_id, user), to: CommentAction
defdelegate reply_comment(comment_id, args, user), to: CommentAction
defdelegate lock_article_comment(thread, article_id), to: CommentAction
defdelegate undo_lock_article_comment(thread, article_id), to: CommentAction
defdelegate lock_article_comments(thread, article_id), to: CommentAction
defdelegate undo_lock_article_comments(thread, article_id), to: CommentAction

defdelegate pin_comment(comment_id), to: CommentAction
defdelegate undo_pin_comment(comment_id), to: CommentAction

defdelegate fold_article_comment(comment_id, user), to: CommentAction
defdelegate unfold_article_comment(comment_id, user), to: CommentAction
defdelegate fold_comment(comment_id, user), to: CommentAction
defdelegate unfold_comment(comment_id, user), to: CommentAction

defdelegate emotion_to_comment(comment_id, args, user), to: CommentEmotion
defdelegate undo_emotion_to_comment(comment_id, args, user), to: CommentEmotion
Expand All @@ -172,12 +172,12 @@ defmodule GroupherServer.CMS do

# TODO: move report to abuse report module
defdelegate report_article(thread, article_id, reason, attr, user), to: AbuseReport
defdelegate report_article_comment(comment_id, reason, attr, user), to: AbuseReport
defdelegate report_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 paged_reports(filter), to: AbuseReport
defdelegate undo_report_article_comment(comment_id, user), to: AbuseReport
defdelegate undo_report_comment(comment_id, user), to: AbuseReport

# Passport CURD
defdelegate stamp_passport(rules, user), to: PassportCURD
Expand Down
6 changes: 3 additions & 3 deletions lib/groupher_server/cms/delegates/abuse_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
end

@doc "report a comment"
def report_article_comment(comment_id, reason, attr, %User{} = user) do
def report_comment(comment_id, reason, attr, %User{} = user) do
with {:ok, comment} <- ORM.find(Comment, comment_id) do
Multi.new()
|> Multi.run(:create_abuse_report, fn _, _ ->
Expand All @@ -184,15 +184,15 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
end)
|> Multi.run(:fold_comment_report_too_many, fn _, %{create_abuse_report: abuse_report} ->
if abuse_report.report_cases_count >= @report_threshold_for_fold,
do: CMS.fold_article_comment(comment, user),
do: CMS.fold_comment(comment, user),
else: {:ok, comment}
end)
|> Repo.transaction()
|> result()
end
end

def undo_report_article_comment(comment_id, %User{} = user) do
def undo_report_comment(comment_id, %User{} = user) do
undo_report_article(:comment, comment_id, user)
end

Expand Down
12 changes: 6 additions & 6 deletions lib/groupher_server/cms/delegates/comment_action.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ defmodule GroupherServer.CMS.Delegate.CommentAction do
end

@doc "fold a comment"
def fold_article_comment(%Comment{} = comment, %User{} = _user) do
def fold_comment(%Comment{} = comment, %User{} = _user) do
comment |> ORM.update(%{is_folded: true})
end

@doc "fold a comment"
def fold_article_comment(comment_id, %User{} = _user) do
def fold_comment(comment_id, %User{} = _user) do
with {:ok, comment} <- ORM.find(Comment, comment_id) do
comment |> ORM.update(%{is_folded: true})
end
end

@doc "unfold a comment"
def unfold_article_comment(comment_id, %User{} = _user) do
def unfold_comment(comment_id, %User{} = _user) do
with {:ok, comment} <- ORM.find(Comment, comment_id) do
comment |> ORM.update(%{is_folded: false})
end
Expand Down Expand Up @@ -145,7 +145,7 @@ defmodule GroupherServer.CMS.Delegate.CommentAction do
|> Repo.transaction()
|> result()
else
false -> raise_error(:article_comment_locked, "this article is forbid comment")
false -> raise_error(:article_comments_locked, "this article is forbid comment")
{:error, error} -> {:error, error}
end
end
Expand Down Expand Up @@ -228,7 +228,7 @@ defmodule GroupherServer.CMS.Delegate.CommentAction do
end

@doc "lock comment of a article"
def lock_article_comment(thread, id) do
def lock_article_comments(thread, id) do
with {:ok, info} <- match(thread),
{:ok, article} <- ORM.find(info.model, id) do
article_meta = ensure(article.meta, @default_article_meta)
Expand All @@ -239,7 +239,7 @@ defmodule GroupherServer.CMS.Delegate.CommentAction do
end

@doc "undo lock comment of a article"
def undo_lock_article_comment(thread, id) do
def undo_lock_article_comments(thread, id) do
with {:ok, info} <- match(thread),
{:ok, article} <- ORM.find(info.model, id) do
article_meta = ensure(article.meta, @default_article_meta)
Expand Down
6 changes: 3 additions & 3 deletions lib/groupher_server/cms/delegates/comment_curd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
|> done()
end

def paged_folded_article_comments(thread, article_id, filters) do
def paged_folded_comments(thread, article_id, filters) do
where_query = dynamic([c], c.is_folded and not c.is_pinned)
do_paged_comment(thread, article_id, filters, where_query, nil)
end

def paged_folded_article_comments(thread, article_id, filters, user) do
def paged_folded_comments(thread, article_id, filters, user) do
where_query = dynamic([c], c.is_folded and not c.is_pinned)
do_paged_comment(thread, article_id, filters, where_query, user)
end
Expand Down Expand Up @@ -153,7 +153,7 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
|> Repo.transaction()
|> result()
else
false -> raise_error(:article_comment_locked, "this article is forbid comment")
false -> raise_error(:article_comments_locked, "this article is forbid comment")
{:error, error} -> {:error, error}
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/groupher_server/cms/delegates/hooks/cite.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule GroupherServer.CMS.Delegate.Hooks.Cite do

cited_type: thread or comment
artiment: article or comment
# cited_article_comment_id, [xxx_article]_id, [block_id, block2_id, ...],
# cited_comment_id, [xxx_article]_id, [block_id, block2_id, ...],

注意 cited_by_type 不能命名为 cited_by_thread

Expand Down
2 changes: 1 addition & 1 deletion lib/groupher_server/cms/models/comment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule GroupherServer.CMS.Model.Comment do
# 每篇文章最多含有置顶评论的条数
@pinned_comment_limit 10

@doc "latest participants stores in article article_comment_participants field"
@doc "latest participants stores in article comment_participants field"
def max_participator_count(), do: @max_participator_count
@doc "latest replies stores in comment replies field, used for frontend display"
def max_parent_replies_count(), do: @max_parent_replies_count
Expand Down
4 changes: 2 additions & 2 deletions lib/groupher_server/cms/models/comment_upvote.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ defmodule GroupherServer.CMS.Model.CommentUpvote do
end

@doc false
def changeset(%CommentUpvote{} = article_comment_upvote, attrs) do
article_comment_upvote
def changeset(%CommentUpvote{} = comment_upvote, attrs) do
comment_upvote
|> cast(attrs, @required_fields)
|> validate_required(@required_fields)
|> foreign_key_constraint(:comment_id)
Expand Down
7 changes: 4 additions & 3 deletions lib/groupher_server_web/resolvers/cms_resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ defmodule GroupherServerWeb.Resolvers.CMS do
# #######################
# thread reaction ..
# #######################
def lock_article_comment(_root, ~m(id thread)a, _info), do: CMS.lock_article_comment(thread, id)
def lock_article_comments(_root, ~m(id thread)a, _info),
do: CMS.lock_article_comments(thread, id)

def undo_lock_article_comment(_root, ~m(id thread)a, _info) do
CMS.undo_lock_article_comment(thread, id)
def undo_lock_article_comments(_root, ~m(id thread)a, _info) do
CMS.undo_lock_article_comments(thread, id)
end

def sink_article(_root, ~m(id thread)a, _info), do: CMS.sink_article(thread, id)
Expand Down
4 changes: 2 additions & 2 deletions lib/groupher_server_web/schema/Helper/mutations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ defmodule GroupherServerWeb.Schema.Helper.Mutations do
middleware(M.Authorize, :login)
middleware(M.PassportLoader, source: :community)
middleware(M.Passport, claim: unquote("cms->c?->#{to_string(thread)}.lock_comment"))
resolve(&R.CMS.lock_article_comment/3)
resolve(&R.CMS.lock_article_comments/3)
end

@desc unquote("undo lock to a #{thread}")
Expand All @@ -273,7 +273,7 @@ defmodule GroupherServerWeb.Schema.Helper.Mutations do
middleware(M.Authorize, :login)
middleware(M.PassportLoader, source: :community)
middleware(M.Passport, claim: unquote("cms->c?->#{to_string(thread)}.undo_lock_comment"))
resolve(&R.CMS.undo_lock_article_comment/3)
resolve(&R.CMS.undo_lock_article_comments/3)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/groupher_server_web/schema/cms/cms_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
emotion_fields()
end

object :article_comment_meta do
object :comment_meta do
field(:is_article_author_upvoted, :boolean)
field(:is_reply_to_others, :boolean)

Expand All @@ -263,7 +263,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
field(:upvotes_count, :integer)
field(:is_article_author, :boolean)
field(:emotions, :comment_emotions)
field(:meta, :article_comment_meta)
field(:meta, :comment_meta)
field(:replies_count, :integer)
field(:reply_to, :comment_reply)
field(:viewer_has_upvoted, :boolean)
Expand All @@ -281,7 +281,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
field(:upvotes_count, :integer)
field(:emotions, :comment_emotions)
field(:is_article_author, :boolean)
field(:meta, :article_comment_meta)
field(:meta, :comment_meta)
field(:reply_to, :comment_reply)
field(:replies, list_of(:comment_reply))
field(:replies_count, :integer)
Expand Down
2 changes: 1 addition & 1 deletion lib/helper/error_code.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule Helper.ErrorCode do
def ecode(:mirror_article), do: @article_base + 5
def ecode(:invalid_domain_tag), do: @article_base + 6
def ecode(:undo_sink_old_article), do: @article_base + 7
def ecode(:article_comment_locked), do: @article_base + 8
def ecode(:article_comments_locked), do: @article_base + 8
def ecode(:require_questioner), do: @article_base + 9
def ecode(:cite_artilce), do: @article_base + 10
# def ecode(:already_solved), do: @article_base + 10
Expand Down
10 changes: 5 additions & 5 deletions test/groupher_server/cms/abuse_reports/comment_report_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do
describe "[article comment report/unreport]" do
test "report a comment should have a abuse report record", ~m(user post)a do
{:ok, comment} = CMS.create_comment(:post, post.id, mock_comment(), user)
{:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user)
{:ok, _comment} = CMS.report_comment(comment.id, mock_comment(), "attr", user)

filter = %{content_type: :comment, content_id: comment.id, page: 1, size: 20}
{:ok, all_reports} = CMS.paged_reports(filter)
Expand All @@ -34,8 +34,8 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do
test "different user report a comment should have same report with different report cases",
~m(user user2 post)a do
{:ok, comment} = CMS.create_comment(:post, post.id, mock_comment(), user)
{:ok, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user)
{:ok, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user2)
{:ok, _} = CMS.report_comment(comment.id, mock_comment(), "attr", user)
{:ok, _} = CMS.report_comment(comment.id, mock_comment(), "attr", user2)

filter = %{content_type: :comment, content_id: comment.id, page: 1, size: 20}
{:ok, all_reports} = CMS.paged_reports(filter)
Expand All @@ -53,8 +53,8 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do

test "same user can not report a comment twice", ~m(user post)a do
{:ok, comment} = CMS.create_comment(:post, post.id, mock_comment(), user)
{:ok, comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user)
assert {:error, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user)
{:ok, comment} = CMS.report_comment(comment.id, mock_comment(), "attr", user)
assert {:error, _} = CMS.report_comment(comment.id, mock_comment(), "attr", user)
end
end
end
4 changes: 2 additions & 2 deletions test/groupher_server/cms/articles/post_meta_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ defmodule GroupherServer.Test.CMS.PostMeta do
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)
assert not post.meta.is_comment_locked

{:ok, _} = CMS.lock_article_comment(:post, post.id)
{:ok, _} = CMS.lock_article_comments(:post, post.id)
{:ok, post} = ORM.find_by(Post, id: post.id)

assert post.meta.is_comment_locked

{:ok, _} = CMS.undo_lock_article_comment(:post, post.id)
{:ok, _} = CMS.undo_lock_article_comments(:post, post.id)
{:ok, post} = ORM.find_by(Post, id: post.id)

assert not post.meta.is_comment_locked
Expand Down
Loading