Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(dashboard): moderators workflow improve #18

Merged
merged 13 commits into from
Sep 8, 2023
Merged
2 changes: 1 addition & 1 deletion cover/excoveralls.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/groupher_server/accounts/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ defmodule GroupherServer.Accounts do

# achievement
defdelegate achieve(user, operation, key), to: Achievements
defdelegate paged_editable_communities(user, filter), to: Achievements
defdelegate paged_moderatorable_communities(user, filter), to: Achievements
defdelegate downgrade_achievement(user, action, count), to: Achievements
# defdelegate paged_editable_communities(filter), to: Achievements
# defdelegate paged_moderatorable_communities(filter), to: Achievements

# publish
defdelegate paged_published_articles(user, thread, filter), to: Publish
Expand Down
8 changes: 4 additions & 4 deletions lib/groupher_server/accounts/delegates/achievements.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule GroupherServer.Accounts.Delegate.Achievements do
alias Helper.{ORM, SpecType}
alias GroupherServer.Accounts.Model.{Achievement, User}

alias GroupherServer.CMS.Model.CommunityEditor
alias GroupherServer.CMS.Model.CommunityModerator

@collect_weight get_config(:general, :user_achieve_collect_weight)
@upvote_weight get_config(:general, :user_achieve_upvote_weight)
Expand Down Expand Up @@ -125,12 +125,12 @@ defmodule GroupherServer.Accounts.Delegate.Achievements do
end

@doc """
list communities which the user is editor in it
list communities which the user is moderator in it
"""

def paged_editable_communities(%User{id: user_id}, %{page: page, size: size}) do
def paged_moderatorable_communities(%User{id: user_id}, %{page: page, size: size}) do
with {:ok, user} <- ORM.find(User, user_id) do
CommunityEditor
CommunityModerator
|> where([e], e.user_id == ^user.id)
|> join(:inner, [e], c in assoc(e, :community))
|> select([e, c], c)
Expand Down
2 changes: 1 addition & 1 deletion lib/groupher_server/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule GroupherServer.Application do
# Start the endpoint when the application starts
supervisor(GroupherServerWeb.Endpoint, []),
# Start your own worker by calling: GroupherServer.Worker.start_link(arg1, arg2, arg3)
worker(Helper.Scheduler, []),
# worker(Helper.Scheduler, []),
{Rihanna.Supervisor, [postgrex: GroupherServer.Repo.config()]}
] ++ cache_workers()

Expand Down
8 changes: 4 additions & 4 deletions lib/groupher_server/billing/billing.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule GroupherServer.Billing do
@moduledoc false

alias GroupherServer.Billing.Delegate.CURD
alias GroupherServer.Billing.Delegate.CRUD

defdelegate create_record(user, attrs), to: CURD
defdelegate paged_records(user, filter), to: CURD
defdelegate update_record_state(record_id, state), to: CURD
defdelegate create_record(user, attrs), to: CRUD
defdelegate paged_records(user, filter), to: CRUD
defdelegate update_record_state(record_id, state), to: CRUD
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule GroupherServer.Billing.Delegate.CURD do
defmodule GroupherServer.Billing.Delegate.CRUD do
@moduledoc """
create update & list for billings
"""
Expand Down
192 changes: 98 additions & 94 deletions lib/groupher_server/cms/cms.ex
Original file line number Diff line number Diff line change
@@ -1,66 +1,67 @@
defmodule GroupherServer.CMS do
@moduledoc """
this module defined basic method to handle [CMS] content [CURD] ..
this module defined basic method to handle [CMS] content [CRUD] ..
[CMS]: post, job, ...
[CURD]: create, update, delete ...
[CRUD]: create, update, delete ...
"""

alias GroupherServer.CMS.Delegate

alias Delegate.{
AbuseReport,
ArticleCURD,
BlogCURD,
ArticleCRUD,
BlogCRUD,
ArticleCommunity,
ArticleEmotion,
CitedArtiment,
CommentCURD,
CommentCRUD,
ArticleCollect,
ArticleUpvote,
CommentAction,
CommentEmotion,
ArticleTag,
CommunitySync,
CommunityCURD,
CommunityCRUD,
CommunityOperation,
PassportCURD,
PassportCRUD,
Search,
Seeds
}

# do not pattern match in delegating func, do it on one delegating inside
# see https://github.com/elixir-lang/elixir/issues/5306

# Community CURD: editors, thread, tag
defdelegate read_community(args), to: CommunityCURD
defdelegate read_community(args, user), to: CommunityCURD
defdelegate paged_communities(filter, user), to: CommunityCURD
defdelegate paged_communities(filter), to: CommunityCURD
defdelegate create_community(args), to: CommunityCURD
defdelegate apply_community(args), to: CommunityCURD
defdelegate update_community(community, args), to: CommunityCURD
defdelegate update_dashboard(comunity, key, args), to: CommunityCURD
defdelegate approve_community_apply(id), to: CommunityCURD
defdelegate deny_community_apply(id), to: CommunityCURD
defdelegate is_community_exist?(slug), to: CommunityCURD
defdelegate has_pending_community_apply?(user), to: CommunityCURD
# Community CRUD: moderators, thread, tag
defdelegate read_community(args), to: CommunityCRUD
defdelegate read_community(args, opt), to: CommunityCRUD
defdelegate read_community(args, user, opt), to: CommunityCRUD

defdelegate paged_communities(filter, user), to: CommunityCRUD
defdelegate paged_communities(filter), to: CommunityCRUD
defdelegate create_community(args), to: CommunityCRUD
defdelegate apply_community(args), to: CommunityCRUD
defdelegate update_community(community, args), to: CommunityCRUD
defdelegate update_dashboard(comunity, key, args), to: CommunityCRUD
defdelegate approve_community_apply(community), to: CommunityCRUD
defdelegate deny_community_apply(id), to: CommunityCRUD
defdelegate is_community_exist?(slug), to: CommunityCRUD
defdelegate has_pending_community_apply?(user), to: CommunityCRUD

# TODO: delete after prod seed
defdelegate update_community_count_field(community, user_id, type, opt), to: CommunityCURD
defdelegate update_community_count_field(community, thread), to: CommunityCURD
# >> editor ..
defdelegate update_editor(user, community, title), to: CommunityCURD
defdelegate update_community_count_field(community, user_id, type, opt), to: CommunityCRUD
defdelegate update_community_count_field(community, thread), to: CommunityCRUD

# >> geo info ..
defdelegate community_geo_info(community), to: CommunityCURD
# >> subscribers / editors
defdelegate community_members(type, community, filters), to: CommunityCURD
defdelegate community_members(type, community, filters, user), to: CommunityCURD
defdelegate community_geo_info(community), to: CommunityCRUD
# >> subscribers
defdelegate community_members(type, community, filters), to: CommunityCRUD
defdelegate community_members(type, community, filters, user), to: CommunityCRUD
# >> category
defdelegate create_category(category_attrs, user), to: CommunityCURD
defdelegate update_category(category_attrs), to: CommunityCURD
defdelegate create_category(category_attrs, user), to: CommunityCRUD
defdelegate update_category(category_attrs), to: CommunityCRUD
# >> thread
defdelegate create_thread(attrs), to: CommunityCURD
defdelegate count(community, part), to: CommunityCURD
defdelegate create_thread(attrs), to: CommunityCRUD
defdelegate count(community, part), to: CommunityCRUD
# >> tag
defdelegate create_article_tag(community, thread, attrs, user), to: ArticleTag
defdelegate update_article_tag(tag_id, attrs), to: ArticleTag
Expand All @@ -74,9 +75,11 @@ defmodule GroupherServer.CMS do
# >> category
defdelegate set_category(community, category), to: CommunityOperation
defdelegate unset_category(community, category), to: CommunityOperation
# >> editor
defdelegate set_editor(community, title, user), to: CommunityOperation
defdelegate unset_editor(community, user), to: CommunityOperation
# >> moderator
defdelegate add_moderator(community, role, user, cur_user), to: CommunityOperation
defdelegate remove_moderator(community, user, cur_user), to: CommunityOperation
defdelegate update_moderator_passport(community, role, user, cur_user), to: CommunityOperation

# >> thread
defdelegate set_thread(community, thread), to: CommunityOperation
defdelegate unset_thread(community, thread), to: CommunityOperation
Expand All @@ -89,42 +92,42 @@ defmodule GroupherServer.CMS do
defdelegate subscribe_default_community_ifnot(user, remote_ip), to: CommunityOperation
defdelegate subscribe_default_community_ifnot(user), to: CommunityOperation

# ArticleCURD
defdelegate read_article(community_slug, thread, id), to: ArticleCURD
defdelegate read_article(community_slug, thread, id, user), to: ArticleCURD
# ArticleCRUD
defdelegate read_article(community_slug, thread, id), to: ArticleCRUD
defdelegate read_article(community_slug, thread, id, user), to: ArticleCRUD

defdelegate set_article_illegal(thread, id, attrs), to: ArticleCURD
defdelegate set_article_illegal(article, attrs), to: ArticleCURD
defdelegate unset_article_illegal(thread, id, attrs), to: ArticleCURD
defdelegate unset_article_illegal(article, attrs), to: ArticleCURD
defdelegate set_article_audit_failed(article, state), to: ArticleCURD
defdelegate set_article_illegal(thread, id, attrs), to: ArticleCRUD
defdelegate set_article_illegal(article, attrs), to: ArticleCRUD
defdelegate unset_article_illegal(thread, id, attrs), to: ArticleCRUD
defdelegate unset_article_illegal(article, attrs), to: ArticleCRUD
defdelegate set_article_audit_failed(article, state), to: ArticleCRUD

defdelegate paged_articles(thread, filter), to: ArticleCURD
defdelegate paged_articles(thread, filter, user), to: ArticleCURD
defdelegate grouped_kanban_posts(community_id), to: ArticleCURD
defdelegate paged_kanban_posts(community_slug, filter), to: ArticleCURD
defdelegate paged_articles(thread, filter), to: ArticleCRUD
defdelegate paged_articles(thread, filter, user), to: ArticleCRUD
defdelegate grouped_kanban_posts(community_id), to: ArticleCRUD
defdelegate paged_kanban_posts(community_slug, filter), to: ArticleCRUD

defdelegate paged_published_articles(thread, filter, user), to: ArticleCURD
defdelegate paged_audit_failed_articles(thread, filter), to: ArticleCURD
defdelegate paged_published_articles(thread, filter, user), to: ArticleCRUD
defdelegate paged_audit_failed_articles(thread, filter), to: ArticleCRUD

defdelegate create_article(community, thread, attrs, user), to: ArticleCURD
defdelegate update_article(article, attrs), to: ArticleCURD
defdelegate create_article(community, thread, attrs, user), to: ArticleCRUD
defdelegate update_article(article, attrs), to: ArticleCRUD

defdelegate mark_delete_article(thread, id), to: ArticleCURD
defdelegate undo_mark_delete_article(thread, id), to: ArticleCURD
defdelegate delete_article(article), to: ArticleCURD
defdelegate delete_article(article, reason), to: ArticleCURD
defdelegate mark_delete_article(thread, id), to: ArticleCRUD
defdelegate undo_mark_delete_article(thread, id), to: ArticleCRUD
defdelegate delete_article(article), to: ArticleCRUD
defdelegate delete_article(article, reason), to: ArticleCRUD

defdelegate set_post_cat(post, cat), to: ArticleCURD
defdelegate set_post_state(post, state), to: ArticleCURD
defdelegate set_post_cat(post, cat), to: ArticleCRUD
defdelegate set_post_state(post, state), to: ArticleCRUD

defdelegate update_active_timestamp(thread, article), to: ArticleCURD
defdelegate sink_article(thread, id), to: ArticleCURD
defdelegate undo_sink_article(thread, id), to: ArticleCURD
defdelegate update_active_timestamp(thread, article), to: ArticleCRUD
defdelegate sink_article(thread, id), to: ArticleCRUD
defdelegate undo_sink_article(thread, id), to: ArticleCRUD

defdelegate archive_articles(thread), to: ArticleCURD
defdelegate batch_mark_delete_articles(community, thread, id_list), to: ArticleCURD
defdelegate batch_undo_mark_delete_articles(community, thread, id_list), to: ArticleCURD
defdelegate archive_articles(thread), to: ArticleCRUD
defdelegate batch_mark_delete_articles(community, thread, id_list), to: ArticleCRUD
defdelegate batch_undo_mark_delete_articles(community, thread, id_list), to: ArticleCRUD

defdelegate paged_citing_contents(type, id, filter), to: CitedArtiment

Expand Down Expand Up @@ -164,41 +167,41 @@ defmodule GroupherServer.CMS do
defdelegate emotion_to_article(thread, article_id, args, user), to: ArticleEmotion
defdelegate undo_emotion_to_article(thread, article_id, args, user), to: ArticleEmotion

# Comment CURD
# Comment CRUD

defdelegate set_comment_illegal(comment_id, attrs), to: CommentCURD
defdelegate unset_comment_illegal(comment_id, attrs), to: CommentCURD
defdelegate paged_audit_failed_comments(filter), to: CommentCURD
defdelegate set_comment_illegal(comment_id, attrs), to: CommentCRUD
defdelegate unset_comment_illegal(comment_id, attrs), to: CommentCRUD
defdelegate paged_audit_failed_comments(filter), to: CommentCRUD

defdelegate set_comment_audit_failed(comment, state), to: CommentCURD
defdelegate set_comment_audit_failed(comment, state), to: CommentCRUD

defdelegate comments_state(thread, article_id), to: CommentCURD
defdelegate comments_state(thread, article_id, user), to: CommentCURD
defdelegate one_comment(id), to: CommentCURD
defdelegate one_comment(id, user), to: CommentCURD
defdelegate comments_state(thread, article_id), to: CommentCRUD
defdelegate comments_state(thread, article_id, user), to: CommentCRUD
defdelegate one_comment(id), to: CommentCRUD
defdelegate one_comment(id, user), to: CommentCRUD

defdelegate update_user_in_comments_participants(user), to: CommentCURD
defdelegate paged_comments(thread, article_id, filters, mode), to: CommentCURD
defdelegate paged_comments(thread, article_id, filters, mode, user), to: CommentCURD
defdelegate update_user_in_comments_participants(user), to: CommentCRUD
defdelegate paged_comments(thread, article_id, filters, mode), to: CommentCRUD
defdelegate paged_comments(thread, article_id, filters, mode, user), to: CommentCRUD

defdelegate paged_published_comments(user, thread, filters), to: CommentCURD
defdelegate paged_published_comments(user, filters), to: CommentCURD
defdelegate paged_published_comments(user, thread, filters), to: CommentCRUD
defdelegate paged_published_comments(user, filters), to: CommentCRUD

defdelegate paged_folded_comments(thread, article_id, filters), to: CommentCURD
defdelegate paged_folded_comments(thread, article_id, filters, user), to: CommentCURD
defdelegate paged_folded_comments(thread, article_id, filters), to: CommentCRUD
defdelegate paged_folded_comments(thread, article_id, filters, user), to: CommentCRUD

defdelegate paged_comment_replies(comment_id, filters), to: CommentCURD
defdelegate paged_comment_replies(comment_id, filters, user), to: CommentCURD
defdelegate paged_comment_replies(comment_id, filters), to: CommentCRUD
defdelegate paged_comment_replies(comment_id, filters, user), to: CommentCRUD

defdelegate paged_comments_participants(thread, content_id, filters), to: CommentCURD
defdelegate paged_comments_participants(thread, content_id, filters), to: CommentCRUD

defdelegate create_comment(thread, article_id, args, user), to: CommentCURD
defdelegate update_comment(comment, content), to: CommentCURD
defdelegate delete_comment(comment), to: CommentCURD
defdelegate mark_comment_solution(comment, user), to: CommentCURD
defdelegate undo_mark_comment_solution(comment, user), to: CommentCURD
defdelegate create_comment(thread, article_id, args, user), to: CommentCRUD
defdelegate update_comment(comment, content), to: CommentCRUD
defdelegate delete_comment(comment), to: CommentCRUD
defdelegate mark_comment_solution(comment, user), to: CommentCRUD
defdelegate undo_mark_comment_solution(comment, user), to: CommentCRUD

defdelegate archive_comments(), to: CommentCURD
defdelegate archive_comments(), to: CommentCRUD

defdelegate upvote_comment(comment_id, user), to: CommentAction
defdelegate undo_upvote_comment(comment_id, user), to: CommentAction
Expand Down Expand Up @@ -228,12 +231,13 @@ defmodule GroupherServer.CMS do
defdelegate paged_reports(filter), to: AbuseReport
defdelegate undo_report_comment(comment_id, user), to: AbuseReport

# Passport CURD
defdelegate stamp_passport(rules, user), to: PassportCURD
defdelegate erase_passport(rules, user), to: PassportCURD
defdelegate get_passport(user), to: PassportCURD
defdelegate paged_passports(community, key), to: PassportCURD
defdelegate delete_passport(user), to: PassportCURD
# Passport CRUD
defdelegate stamp_passport(rules, user), to: PassportCRUD
defdelegate erase_passport(rules, user), to: PassportCRUD
defdelegate get_passport(user), to: PassportCRUD
defdelegate paged_passports(community, key), to: PassportCRUD
defdelegate all_passport_rules(), to: PassportCRUD
defdelegate delete_passport(user), to: PassportCRUD

# search
defdelegate search_articles(thread, args), to: Search
Expand Down
4 changes: 2 additions & 2 deletions lib/groupher_server/cms/constant.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule GroupherServer.CMS.Constant do
@community_normal 0
@community_applying 1

@apply_public "PUBLIC"
@apply_web "WEB"

@article_cat_map %{
feature: 1,
Expand Down Expand Up @@ -47,7 +47,7 @@ defmodule GroupherServer.CMS.Constant do
def pending(:normal), do: @community_normal
def pending(:applying), do: @community_applying

def apply_category(:public), do: @apply_public
def apply_category(:web), do: @apply_web

def article_cat, do: @article_cat_map

Expand Down
1 change: 0 additions & 1 deletion lib/groupher_server/cms/delegates/Seeds/prod/turning.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Prod.Turning do
with {:ok, home_community} <- ORM.find_by(Community, %{slug: "home"}),
{:ok, bot} <- seed_bot(),
{:ok, threads} <- seed_threads(:home) do
# IO.inspect(home_community, label: "seed_home_tags home_community")
threadify_communities([home_community], threads.entries)
tagfy_threads([home_community], threads.entries, bot, :home)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/groupher_server/cms/delegates/abuse_report.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule GroupherServer.CMS.Delegate.AbuseReport do
@moduledoc """
CURD and operations for article comments
CRUD and operations for article comments
"""
import Ecto.Query, warn: false
import Helper.Utils, only: [done: 1, strip_struct: 1, get_config: 2]
Expand Down
Loading
Loading