Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commitd38603f

Browse files
authored
refactor(tag): remove refined concept (#332)
1 parent543323e commitd38603f

File tree

5 files changed

+3
-216
lines changed

5 files changed

+3
-216
lines changed

‎lib/groupher_server/cms/delegates/article_curd.ex‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
133133
ArticleOperation.update_edit_status(update_content)
134134
end)
135135
|>Multi.run(:update_tag,fn_,_->
136-
# TODO: move it to ArticleOperationmoudel
136+
# TODO: move it to ArticleOperationmodule
137137
exec_update_tags(content,args)
138138
end)
139139
|>Repo.transaction()
@@ -426,13 +426,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
426426
Enum.reduce(tags_ids,[],fnt,acc->
427427
{:ok,tag}=ORM.find(Tag,t.id)
428428

429-
casetag.title=="refined"do
430-
true->
431-
acc
432-
433-
false->
434-
acc++[tag]
435-
end
429+
acc++[tag]
436430
end)
437431

438432
content

‎lib/groupher_server/cms/delegates/article_operation.ex‎

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,13 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
121121

122122
@doc"""
123123
set general tag for post / tuts ...
124-
refined tag can't set by this func, use set_refined_tag instead
125124
"""
126125
# check community first
127126
defset_tag(thread,%Tag{id:tag_id},content_id)do
128127
with{:ok,action}<-match_action(thread,:tag),
129128
{:ok,content}<-ORM.find(action.target,content_id,preload::tags),
130129
{:ok,tag}<-ORM.find(action.reactor,tag_id)do
131-
casetag.title!="refined"do
132-
true->
133-
update_content_tag(content,tag)
134-
135-
false->
136-
{:error,"use set_refined_tag instead"}
137-
end
130+
update_content_tag(content,tag)
138131

139132
# NOTE: this should be control by Middleware
140133
# case tag_in_community_thread?(%Community{id: communitId}, thread, tag) do
@@ -158,36 +151,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
158151
end
159152
end
160153

161-
@doc"""
162-
set refined_tag to common content
163-
"""
164-
defset_refined_tag(%Community{id:community_id},thread,content_id)do
165-
with{:ok,action}<-match_action(thread,:tag),
166-
{:ok,content}<-ORM.find(action.target,content_id,preload::tags),
167-
{:ok,tag}<-
168-
ORM.find_by(action.reactor,%{
169-
title:"refined",
170-
community_id:community_id
171-
})do
172-
update_content_tag(content,tag)
173-
end
174-
end
175-
176-
@doc"""
177-
unset refined_tag to common content
178-
"""
179-
defunset_refined_tag(%Community{id:community_id},thread,content_id)do
180-
with{:ok,action}<-match_action(thread,:tag),
181-
{:ok,content}<-ORM.find(action.target,content_id,preload::tags),
182-
{:ok,tag}<-
183-
ORM.find_by(action.reactor,%{
184-
title:"refined",
185-
community_id:community_id
186-
})do
187-
update_content_tag(content,tag,:drop)
188-
end
189-
end
190-
191154
defpupdate_content_tag(content,%Tag{}=tag,opt\\:add)do
192155
new_tags=ifopt==:add,do:content.tags++[tag],else:content.tags--[tag]
193156

‎lib/groupher_server_web/schema/cms/mutations/operation.ex‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,6 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Operation do
9393
resolve(&R.CMS.set_tag/3)
9494
end
9595

96-
@desc"set a refined tag to content"
97-
field:set_refined_tag,:tagdo
98-
arg(:id,non_null(:id))
99-
arg(:community_id,non_null(:id))
100-
arg(:thread,:cms_thread,default_value::post)
101-
102-
middleware(M.Authorize,:login)
103-
middleware(M.PassportLoader,source::community)
104-
middleware(M.Passport,claim:"cms->c?->t?.refinedtag.set")
105-
106-
resolve(&R.CMS.set_refined_tag/3)
107-
end
108-
10996
@desc"unset a tag to content"
11097
field:unset_tag,:tagdo
11198
# thread id
@@ -121,19 +108,6 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Operation do
121108
resolve(&R.CMS.unset_tag/3)
122109
end
123110

124-
@desc"unset a refined tag to content"
125-
field:unset_refined_tag,:tagdo
126-
arg(:id,non_null(:id))
127-
arg(:community_id,non_null(:id))
128-
arg(:thread,:cms_thread,default_value::post)
129-
130-
middleware(M.Authorize,:login)
131-
middleware(M.PassportLoader,source::community)
132-
middleware(M.Passport,claim:"cms->c?->t?.refinedtag.set")
133-
134-
resolve(&R.CMS.unset_refined_tag/3)
135-
end
136-
137111
# TODO: use community loader
138112
field:set_community,:communitydo
139113
arg(:id,non_null(:id))

‎test/groupher_server_web/mutation/cms/job_test.exs‎

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,6 @@ defmodule GroupherServer.Test.Mutation.Job do
309309
}
310310
}
311311
"""
312-
@set_refined_tag_query"""
313-
mutation($communityId: ID!, $thread: CmsThread, $id: ID!) {
314-
setRefinedTag(communityId: $communityId, thread: $thread, id: $id) {
315-
id
316-
title
317-
}
318-
}
319-
"""
320312
test"auth user can set a valid tag to job",~m(job)ado
321313
{:ok,community}=db_insert(:community)
322314
{:ok,tag}=db_insert(:tag,%{thread:"job",community:community})
@@ -332,33 +324,6 @@ defmodule GroupherServer.Test.Mutation.Job do
332324
asserttag.idinassoc_tags
333325
end
334326

335-
test"can not set refined tag to job",~m(job)ado
336-
{:ok,community}=db_insert(:community)
337-
{:ok,tag}=db_insert(:tag,%{thread:"job",community:community,title:"refined"})
338-
339-
passport_rules=%{community.title=>%{"job.tag.set"=>true}}
340-
rule_conn=simu_conn(:user,cms:passport_rules)
341-
342-
variables=%{id:job.id,tagId:tag.id,communityId:community.id}
343-
344-
assertrule_conn|>mutation_get_error?(@set_tag_query,variables)
345-
end
346-
347-
test"auth user can set refined tag to job",~m(job)ado
348-
{:ok,community}=db_insert(:community)
349-
{:ok,tag}=db_insert(:tag,%{thread:"job",community:community,title:"refined"})
350-
351-
passport_rules=%{community.title=>%{"job.refinedtag.set"=>true}}
352-
rule_conn=simu_conn(:user,cms:passport_rules)
353-
354-
variables=%{id:job.id,communityId:community.id,thread:"JOB"}
355-
rule_conn|>mutation_result(@set_refined_tag_query,variables,"setRefinedTag")
356-
{:ok,found}=ORM.find(CMS.Job,job.id,preload::tags)
357-
358-
assoc_tags=found.tags|>Enum.map(&&1.id)
359-
asserttag.idinassoc_tags
360-
end
361-
362327
# TODO: should fix in auth layer
363328
# test "auth user set a other community's tag to job fails", ~m(job)a do
364329
# {:ok, community} = db_insert(:community)
@@ -391,32 +356,5 @@ defmodule GroupherServer.Test.Mutation.Job do
391356
asserttag.idinassoc_tags
392357
asserttag2.idinassoc_tags
393358
end
394-
395-
@unset_refined_tag_query"""
396-
mutation($communityId: ID!, $thread: CmsThread, $id: ID!) {
397-
unsetRefinedTag(communityId: $communityId, thread: $thread, id: $id) {
398-
id
399-
title
400-
}
401-
}
402-
"""
403-
test"can unset refined tag to a job",~m(job)ado
404-
{:ok,community}=db_insert(:community)
405-
{:ok,tag}=db_insert(:tag,%{thread:"job",community:community,title:"refined"})
406-
407-
passport_rules=%{community.title=>%{"job.refinedtag.set"=>true}}
408-
rule_conn=simu_conn(:user,cms:passport_rules)
409-
410-
variables=%{id:job.id,communityId:community.id,thread:"JOB"}
411-
rule_conn|>mutation_result(@set_refined_tag_query,variables,"setRefinedTag")
412-
413-
variables=%{id:job.id,communityId:community.id,thread:"JOB"}
414-
rule_conn|>mutation_result(@unset_refined_tag_query,variables,"unsetRefinedTag")
415-
416-
{:ok,found}=ORM.find(CMS.Job,job.id,preload::tags)
417-
418-
assoc_tags=found.tags|>Enum.map(&&1.id)
419-
asserttag.idnot inassoc_tags
420-
end
421359
end
422360
end

‎test/groupher_server_web/mutation/cms/post_test.exs‎

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -233,26 +233,6 @@ defmodule GroupherServer.Test.Mutation.Post do
233233
asserttag2.idintag_ids
234234
end
235235

236-
test"can update post with refined tag",~m(owner_conn post)ado
237-
{:ok,tag_refined}=db_insert(:tag,%{title:"refined"})
238-
{:ok,tag2}=db_insert(:tag)
239-
240-
unique_num=System.unique_integer([:positive,:monotonic])
241-
242-
variables=%{
243-
id:post.id,
244-
title:"updated title#{unique_num}",
245-
tags:[%{id:tag_refined.id},%{id:tag2.id}]
246-
}
247-
248-
updated=owner_conn|>mutation_result(@query,variables,"updatePost")
249-
{:ok,post}=ORM.find(CMS.Post,updated["id"],preload::tags)
250-
tag_ids=post.tags|>Utils.pick_by(:id)
251-
252-
asserttag_refined.idnot intag_ids
253-
asserttag2.idintag_ids
254-
end
255-
256236
test"post can be update by owner",~m(owner_conn post)ado
257237
unique_num=System.unique_integer([:positive,:monotonic])
258238

@@ -332,14 +312,6 @@ defmodule GroupherServer.Test.Mutation.Post do
332312
}
333313
}
334314
"""
335-
@set_refined_tag_query"""
336-
mutation($communityId: ID!, $thread: CmsThread, $id: ID!) {
337-
setRefinedTag(communityId: $communityId, thread: $thread, id: $id) {
338-
id
339-
title
340-
}
341-
}
342-
"""
343315
test"auth user can set a valid tag to post",~m(post)ado
344316
{:ok,community}=db_insert(:community)
345317
{:ok,tag}=db_insert(:tag,%{thread:"post",community:community})
@@ -355,33 +327,6 @@ defmodule GroupherServer.Test.Mutation.Post do
355327
asserttag.idinassoc_tags
356328
end
357329

358-
test"can not set refined tag to post",~m(post)ado
359-
{:ok,community}=db_insert(:community)
360-
{:ok,tag}=db_insert(:tag,%{thread:"post",community:community,title:"refined"})
361-
362-
passport_rules=%{community.title=>%{"post.tag.set"=>true}}
363-
rule_conn=simu_conn(:user,cms:passport_rules)
364-
365-
variables=%{id:post.id,tagId:tag.id}
366-
367-
assertrule_conn|>mutation_get_error?(@set_tag_query,variables)
368-
end
369-
370-
test"auth user can set refined tag to post",~m(post)ado
371-
{:ok,community}=db_insert(:community)
372-
{:ok,tag}=db_insert(:tag,%{thread:"post",community:community,title:"refined"})
373-
374-
passport_rules=%{community.title=>%{"post.refinedtag.set"=>true}}
375-
rule_conn=simu_conn(:user,cms:passport_rules)
376-
377-
variables=%{id:post.id,communityId:community.id}
378-
rule_conn|>mutation_result(@set_refined_tag_query,variables,"setRefinedTag")
379-
{:ok,found}=ORM.find(CMS.Post,post.id,preload::tags)
380-
381-
assoc_tags=found.tags|>Enum.map(&&1.id)
382-
asserttag.idinassoc_tags
383-
end
384-
385330
# TODO: should fix in auth layer
386331
# test "auth user set a other community tag to post fails", ~m(post)a do
387332
# {:ok, community} = db_insert(:community)
@@ -423,14 +368,6 @@ defmodule GroupherServer.Test.Mutation.Post do
423368
}
424369
}
425370
"""
426-
@unset_refined_tag_query"""
427-
mutation($communityId: ID!, $thread: CmsThread, $id: ID!) {
428-
unsetRefinedTag(communityId: $communityId, thread: $thread, id: $id) {
429-
id
430-
title
431-
}
432-
}
433-
"""
434371
test"can unset tag to a post",~m(post)ado
435372
{:ok,community}=db_insert(:community)
436373

@@ -463,25 +400,6 @@ defmodule GroupherServer.Test.Mutation.Post do
463400
asserttag.idnot inassoc_tags
464401
asserttag2.idinassoc_tags
465402
end
466-
467-
test"can unset refined tag to a post",~m(post)ado
468-
{:ok,community}=db_insert(:community)
469-
{:ok,tag}=db_insert(:tag,%{thread:"post",community:community,title:"refined"})
470-
471-
passport_rules=%{community.title=>%{"post.refinedtag.set"=>true}}
472-
rule_conn=simu_conn(:user,cms:passport_rules)
473-
474-
variables=%{id:post.id,communityId:community.id}
475-
rule_conn|>mutation_result(@set_refined_tag_query,variables,"setRefinedTag")
476-
477-
variables=%{id:post.id,communityId:community.id}
478-
rule_conn|>mutation_result(@unset_refined_tag_query,variables,"unsetRefinedTag")
479-
480-
{:ok,found}=ORM.find(CMS.Post,post.id,preload::tags)
481-
482-
assoc_tags=found.tags|>Enum.map(&&1.id)
483-
asserttag.idnot inassoc_tags
484-
end
485403
end
486404

487405
describe"[mutation post community]"do

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp