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

Commit 8d82bf5

Browse files
authored
refactor(cert): use @article_threads to auto generate rules (#384)
1 parent 0fb98e9 commit 8d82bf5

File tree

2 files changed

+54
-96
lines changed

2 files changed

+54
-96
lines changed

lib/groupher_server_web/middleware/passport.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
defmodule GroupherServerWeb.Middleware.Passport do
1010
@moduledoc """
1111
c? -> community / communities
12-
t? -> thread, could be post / job / tut ...
12+
t? -> article thread, could be post / job / tut ...
1313
"""
1414
@behaviour Absinthe.Middleware
1515

lib/helper/certification.ex

Lines changed: 53 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@ defmodule Helper.Certification do
22
@moduledoc """
33
valid editors and passport details
44
"""
5+
import Helper.Utils, only: [get_config: 2]
6+
7+
@article_threads get_config(:article, :threads)
8+
@article_rules [
9+
"edit",
10+
"mark_delete",
11+
"undo_mark_delete",
12+
"delete",
13+
"community.mirror",
14+
"community.unmirror",
15+
"community.move",
16+
"pin",
17+
"undo_pin",
18+
"sink",
19+
"undo_sink",
20+
"lock_comment",
21+
"undo_lock_comment",
22+
"article_tag.create",
23+
"article_tag.update",
24+
"article_tag.delete",
25+
"article_tag.set",
26+
"article_tag.unset"
27+
]
28+
529
def editor_titles(:cms) do
630
["chief editor", "post editor"]
731
end
@@ -28,108 +52,42 @@ defmodule Helper.Certification do
2852
# }
2953
# }
3054

55+
defp build_article_rules(rule_list) do
56+
Enum.reduce(rule_list, [], fn rule, acc ->
57+
articles_rules = @article_threads |> Enum.map(&"#{&1}.#{rule}")
58+
acc ++ articles_rules
59+
end)
60+
end
61+
3162
@doc """
3263
基础权限,社区权限
3364
"""
3465
def all_rules(:cms) do
3566
%{
36-
general: [
37-
"root",
38-
"system_accountant",
39-
"system_notification.publish",
40-
"stamp_passport",
41-
# community
42-
"editor.set",
43-
"editor.unset",
44-
"editor.update",
45-
"community.create",
46-
"community.update",
47-
"community.delete",
48-
"category.create",
49-
"category.delete",
50-
"category.update",
51-
"category.set",
52-
"category.unset",
53-
"thread.create",
54-
"post.community.mirror",
55-
"post.community.move",
56-
"post.community.unmirror",
57-
"job.community.mirror",
58-
"job.community.move",
59-
"job.community.unmirror",
60-
# flag on content
61-
# pin/undo_pin
62-
"post.pin",
63-
"post.undo_pin",
64-
"job.pin",
65-
"job.undo_pin",
66-
"repo.pin",
67-
"repo.undo_pin",
68-
# sink/undo_sink
69-
"post.sink",
70-
"post.undo_sink",
71-
"job.sink",
72-
"job.undo_sink",
73-
"repo.sink",
74-
"repo.undo_sink",
75-
# lock/undo_lock article comment
76-
"post.lock_comment",
77-
"post.undo_lock_comment",
78-
"job.lock_comment",
79-
"job.undo_lock_comment",
80-
"repo.lock_comment",
81-
"repo.undo_lock_comment",
82-
#
83-
"post.mark_delete",
84-
"post.undo_mark_delete",
85-
"job.mark_delete",
86-
"job.undo_mark_delete",
87-
"repo.mark_delete",
88-
"repo.undo_mark_delete"
89-
],
67+
general:
68+
build_article_rules(@article_rules) ++
69+
[
70+
"root",
71+
"system_accountant",
72+
"system_notification.publish",
73+
"stamp_passport",
74+
# community
75+
"editor.set",
76+
"editor.unset",
77+
"editor.update",
78+
"community.create",
79+
"community.update",
80+
"community.delete",
81+
"category.create",
82+
"category.delete",
83+
"category.update",
84+
"category.set",
85+
"category.unset",
86+
"thread.create"
87+
],
9088
community: [
91-
# thread
9289
"thread.set",
93-
"thread.unset",
94-
"post.edit",
95-
"post.mark_delete",
96-
"post.delete",
97-
"job.edit",
98-
"job.mark_delete",
99-
"job.delete",
100-
# post article_tag
101-
"post.article_tag.create",
102-
"post.article_tag.update",
103-
"post.article_tag.delete",
104-
"post.article_tag.set",
105-
"post.article_tag.unset",
106-
# post flag
107-
"post.pin",
108-
"post.undo_pin",
109-
"post.mark_delete",
110-
"post.undo_mark_delete",
111-
# job article_tag
112-
"job.article_tag.create",
113-
"job.article_tag.update",
114-
"job.article_tag.delete",
115-
"job.article_tag.set",
116-
"job.article_tag.unset",
117-
# job flag
118-
"job.pin",
119-
"job.undo_pin",
120-
"job.mark_delete",
121-
"job.undo_mark_delete",
122-
# repo article_tag
123-
"repo.article_tag.create",
124-
"repo.article_tag.update",
125-
"repo.article_tag.delete",
126-
"repo.article_tag.set",
127-
"repo.article_tag.unset",
128-
# repo flag
129-
"repo.pin",
130-
"repo.undo_pin",
131-
"repo.mark_delete",
132-
"repo.undo_mark_delete"
90+
"thread.unset"
13391
]
13492
}
13593
end

0 commit comments

Comments
 (0)