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.

Commit8123f57

Browse files
committed
feat(article-community): add shrotcut for mirror_to_home
1 parent66bc091 commit8123f57

File tree

15 files changed

+777
-18
lines changed

15 files changed

+777
-18
lines changed

‎lib/groupher_server/cms/cms.ex‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ defmodule GroupherServer.CMS do
144144
defdelegatemove_to_blackhole(thread,article_id,article_ids),to:ArticleCommunity
145145
defdelegatemove_to_blackhole(thread,article_id),to:ArticleCommunity
146146

147+
defdelegatemirror_to_home(thread,article_id,article_ids),to:ArticleCommunity
148+
defdelegatemirror_to_home(thread,article_id),to:ArticleCommunity
149+
147150
defdelegateemotion_to_article(thread,article_id,args,user),to:ArticleEmotion
148151
defdelegateundo_emotion_to_article(thread,article_id,args,user),to:ArticleEmotion
149152

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,33 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do
134134
end
135135
end
136136

137+
@doc"""
138+
shortcut for mirror article to home page
139+
"""
140+
defmirror_to_home(thread,article_id,article_tag_ids\\[])do
141+
preload=[:communities,:article_tags]
142+
143+
with{:ok,info}<-match(thread),
144+
{:ok,community}<-ORM.find_by(Community,%{raw:"home"}),
145+
{:ok,article}<-ORM.find(info.model,article_id,preload:preload)do
146+
Multi.new()
147+
|>Multi.run(:set_community,fn_,_->
148+
article
149+
|>Ecto.Changeset.change()
150+
|>Ecto.Changeset.put_assoc(:communities,article.communities++[community])
151+
|>Repo.update()
152+
end)
153+
|>Multi.run(:set_target_tags,fn_,%{set_community:article}->
154+
ArticleTag.set_article_tags(community,thread,article,%{article_tags:article_tag_ids})
155+
end)
156+
|>Repo.transaction()
157+
|>result()
158+
end
159+
end
160+
161+
@doc"""
162+
shortcut for move article to blackhole
163+
"""
137164
defmove_to_blackhole(thread,article_id,article_tag_ids\\[])do
138165
preload=[:communities,:original_community,:article_tags]
139166

‎lib/groupher_server_web/resolvers/cms_resolver.ex‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ defmodule GroupherServerWeb.Resolvers.CMS do
297297
CMS.move_article(thread,id,community_id,article_tags)
298298
end
299299

300+
defmirror_to_home(_root,~m(thread id article_tags)a,_info)do
301+
CMS.mirror_to_home(thread,id,article_tags)
302+
end
303+
300304
defmove_to_blackhole(_root,~m(thread id article_tags)a,_info)do
301305
CMS.move_to_blackhole(thread,id,article_tags)
302306
end

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Operation do
142142
resolve(&R.CMS.move_article/3)
143143
end
144144

145+
@desc"mirror article to home community"
146+
field:mirror_to_home,:articledo
147+
arg(:id,non_null(:id))
148+
arg(:thread,:thread,default_value::post)
149+
arg(:article_tags,list_of(:id),default_value:[])
150+
151+
middleware(M.Authorize,:login)
152+
middleware(M.Passport,claim:"cms->homemirror")
153+
resolve(&R.CMS.mirror_to_home/3)
154+
end
155+
145156
@desc"move article to other community"
146157
field:move_to_blackhole,:articledo
147158
arg(:id,non_null(:id))

‎lib/helper/certification.ex‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ defmodule Helper.Certification do
6969
[
7070
"root",
7171
"blackeye",
72+
"homemirror",
7273
"system_accountant",
7374
"system_notification.publish",
7475
"stamp_passport",

‎test/groupher_server/cms/article_community/blog_test.exs‎

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Blog do
6767
article_tag_attrs=mock_attrs(:article_tag)
6868
article_tag_attrs2=mock_attrs(:article_tag)
6969

70-
{:ok,article_tag0}=CMS.create_article_tag(community,:blog,article_tag_attrs,user)
70+
{:ok,article_tag0}=CMS.create_article_tag(community,:blog,article_tag_attrs0,user)
7171
{:ok,article_tag}=CMS.create_article_tag(community2,:blog,article_tag_attrs,user)
7272
{:ok,article_tag2}=CMS.create_article_tag(community2,:blog,article_tag_attrs2,user)
7373

@@ -176,6 +176,78 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Blog do
176176
assertreason|>is_error?(:mirror_article)
177177
end
178178

179+
@tag:wip
180+
test"blog can be mirror to home",~m(community blog_attrs user)ado
181+
{:ok,home_community}=db_insert(:community,%{raw:"home"})
182+
183+
{:ok,blog}=CMS.create_article(community,:blog,blog_attrs,user)
184+
assertblog.original_community_id==community.id
185+
186+
{:ok,_}=CMS.mirror_to_home(:blog,blog.id)
187+
{:ok,blog}=ORM.find(Blog,blog.id,preload:[:original_community,:communities])
188+
189+
assertblog.original_community_id==community.id
190+
assertblog.communities|>length==2
191+
192+
assertexist_in?(community,blog.communities)
193+
assertexist_in?(home_community,blog.communities)
194+
195+
filter=%{page:1,size:10,community:community.raw}
196+
{:ok,paged_articles}=CMS.paged_articles(:blog,filter)
197+
198+
assertexist_in?(blog,paged_articles.entries)
199+
assertpaged_articles.total_count===1
200+
201+
filter=%{page:1,size:10,community:home_community.raw}
202+
{:ok,paged_articles}=CMS.paged_articles(:blog,filter)
203+
204+
assertexist_in?(blog,paged_articles.entries)
205+
assertpaged_articles.total_count===1
206+
end
207+
208+
@tag:wip
209+
test"blog can be mirror to home with tags",~m(community blog_attrs user)ado
210+
{:ok,home_community}=db_insert(:community,%{raw:"home"})
211+
212+
article_tag_attrs0=mock_attrs(:article_tag)
213+
article_tag_attrs=mock_attrs(:article_tag)
214+
215+
{:ok,article_tag0}=
216+
CMS.create_article_tag(home_community,:blog,article_tag_attrs0,user)
217+
218+
{:ok,article_tag}=CMS.create_article_tag(home_community,:blog,article_tag_attrs,user)
219+
220+
{:ok,blog}=CMS.create_article(community,:blog,blog_attrs,user)
221+
assertblog.original_community_id==community.id
222+
223+
{:ok,_}=CMS.mirror_to_home(:blog,blog.id,[article_tag0.id,article_tag.id])
224+
225+
{:ok,blog}=
226+
ORM.find(Blog,blog.id,preload:[:original_community,:communities,:article_tags])
227+
228+
assertblog.original_community_id==community.id
229+
assertblog.communities|>length==2
230+
231+
assertexist_in?(community,blog.communities)
232+
assertexist_in?(home_community,blog.communities)
233+
234+
assertblog.article_tags|>length==2
235+
assertexist_in?(article_tag0,blog.article_tags)
236+
assertexist_in?(article_tag,blog.article_tags)
237+
238+
filter=%{page:1,size:10,community:community.raw}
239+
{:ok,paged_articles}=CMS.paged_articles(:blog,filter)
240+
241+
assertexist_in?(blog,paged_articles.entries)
242+
assertpaged_articles.total_count===1
243+
244+
filter=%{page:1,size:10,community:home_community.raw}
245+
{:ok,paged_articles}=CMS.paged_articles(:blog,filter)
246+
247+
assertexist_in?(blog,paged_articles.entries)
248+
assertpaged_articles.total_count===1
249+
end
250+
179251
test"blog can be move to blackhole",~m(community blog_attrs user)ado
180252
{:ok,blackhole_community}=db_insert(:community,%{raw:"blackhole"})
181253

@@ -204,7 +276,7 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Blog do
204276
article_tag_attrs=mock_attrs(:article_tag)
205277

206278
{:ok,article_tag0}=
207-
CMS.create_article_tag(blackhole_community,:blog,article_tag_attrs,user)
279+
CMS.create_article_tag(blackhole_community,:blog,article_tag_attrs0,user)
208280

209281
{:ok,article_tag}=
210282
CMS.create_article_tag(blackhole_community,:blog,article_tag_attrs,user)

‎test/groupher_server/cms/article_community/drink_test.exs‎

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Drink do
6868
article_tag_attrs=mock_attrs(:article_tag)
6969
article_tag_attrs2=mock_attrs(:article_tag)
7070

71-
{:ok,article_tag0}=CMS.create_article_tag(community,:drink,article_tag_attrs,user)
71+
{:ok,article_tag0}=CMS.create_article_tag(community,:drink,article_tag_attrs0,user)
7272
{:ok,article_tag}=CMS.create_article_tag(community2,:drink,article_tag_attrs,user)
7373
{:ok,article_tag2}=CMS.create_article_tag(community2,:drink,article_tag_attrs2,user)
7474

@@ -177,6 +177,78 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Drink do
177177
assertreason|>is_error?(:mirror_article)
178178
end
179179

180+
@tag:wip
181+
test"drink can be mirror to home",~m(community drink_attrs user)ado
182+
{:ok,home_community}=db_insert(:community,%{raw:"home"})
183+
184+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
185+
assertdrink.original_community_id==community.id
186+
187+
{:ok,_}=CMS.mirror_to_home(:drink,drink.id)
188+
{:ok,drink}=ORM.find(Drink,drink.id,preload:[:original_community,:communities])
189+
190+
assertdrink.original_community_id==community.id
191+
assertdrink.communities|>length==2
192+
193+
assertexist_in?(community,drink.communities)
194+
assertexist_in?(home_community,drink.communities)
195+
196+
filter=%{page:1,size:10,community:community.raw}
197+
{:ok,paged_articles}=CMS.paged_articles(:drink,filter)
198+
199+
assertexist_in?(drink,paged_articles.entries)
200+
assertpaged_articles.total_count===1
201+
202+
filter=%{page:1,size:10,community:home_community.raw}
203+
{:ok,paged_articles}=CMS.paged_articles(:drink,filter)
204+
205+
assertexist_in?(drink,paged_articles.entries)
206+
assertpaged_articles.total_count===1
207+
end
208+
209+
@tag:wip
210+
test"drink can be mirror to home with tags",~m(community drink_attrs user)ado
211+
{:ok,home_community}=db_insert(:community,%{raw:"home"})
212+
213+
article_tag_attrs0=mock_attrs(:article_tag)
214+
article_tag_attrs=mock_attrs(:article_tag)
215+
216+
{:ok,article_tag0}=
217+
CMS.create_article_tag(home_community,:drink,article_tag_attrs0,user)
218+
219+
{:ok,article_tag}=CMS.create_article_tag(home_community,:drink,article_tag_attrs,user)
220+
221+
{:ok,drink}=CMS.create_article(community,:drink,drink_attrs,user)
222+
assertdrink.original_community_id==community.id
223+
224+
{:ok,_}=CMS.mirror_to_home(:drink,drink.id,[article_tag0.id,article_tag.id])
225+
226+
{:ok,drink}=
227+
ORM.find(Drink,drink.id,preload:[:original_community,:communities,:article_tags])
228+
229+
assertdrink.original_community_id==community.id
230+
assertdrink.communities|>length==2
231+
232+
assertexist_in?(community,drink.communities)
233+
assertexist_in?(home_community,drink.communities)
234+
235+
assertdrink.article_tags|>length==2
236+
assertexist_in?(article_tag0,drink.article_tags)
237+
assertexist_in?(article_tag,drink.article_tags)
238+
239+
filter=%{page:1,size:10,community:community.raw}
240+
{:ok,paged_articles}=CMS.paged_articles(:drink,filter)
241+
242+
assertexist_in?(drink,paged_articles.entries)
243+
assertpaged_articles.total_count===1
244+
245+
filter=%{page:1,size:10,community:home_community.raw}
246+
{:ok,paged_articles}=CMS.paged_articles(:drink,filter)
247+
248+
assertexist_in?(drink,paged_articles.entries)
249+
assertpaged_articles.total_count===1
250+
end
251+
180252
test"drink can be move to blackhole",~m(community drink_attrs user)ado
181253
{:ok,blackhole_community}=db_insert(:community,%{raw:"blackhole"})
182254

@@ -190,6 +262,12 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Drink do
190262
assertdrink.communities|>length==1
191263

192264
assertexist_in?(blackhole_community,drink.communities)
265+
266+
filter=%{page:1,size:10,community:blackhole_community.raw}
267+
{:ok,paged_articles}=CMS.paged_articles(:drink,filter)
268+
269+
assertexist_in?(drink,paged_articles.entries)
270+
assertpaged_articles.total_count===1
193271
end
194272

195273
test"drink can be move to blackhole with tags",~m(community drink_attrs user)ado
@@ -199,7 +277,7 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Drink do
199277
article_tag_attrs=mock_attrs(:article_tag)
200278

201279
{:ok,article_tag0}=
202-
CMS.create_article_tag(blackhole_community,:drink,article_tag_attrs,user)
280+
CMS.create_article_tag(blackhole_community,:drink,article_tag_attrs0,user)
203281

204282
{:ok,article_tag}=
205283
CMS.create_article_tag(blackhole_community,:drink,article_tag_attrs,user)

‎test/groupher_server/cms/article_community/guide_test.exs‎

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Guide do
6868
article_tag_attrs=mock_attrs(:article_tag)
6969
article_tag_attrs2=mock_attrs(:article_tag)
7070

71-
{:ok,article_tag0}=CMS.create_article_tag(community,:guide,article_tag_attrs,user)
71+
{:ok,article_tag0}=CMS.create_article_tag(community,:guide,article_tag_attrs0,user)
7272
{:ok,article_tag}=CMS.create_article_tag(community2,:guide,article_tag_attrs,user)
7373
{:ok,article_tag2}=CMS.create_article_tag(community2,:guide,article_tag_attrs2,user)
7474

@@ -177,6 +177,78 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Guide do
177177
assertreason|>is_error?(:mirror_article)
178178
end
179179

180+
@tag:wip
181+
test"guide can be mirror to home",~m(community guide_attrs user)ado
182+
{:ok,home_community}=db_insert(:community,%{raw:"home"})
183+
184+
{:ok,guide}=CMS.create_article(community,:guide,guide_attrs,user)
185+
assertguide.original_community_id==community.id
186+
187+
{:ok,_}=CMS.mirror_to_home(:guide,guide.id)
188+
{:ok,guide}=ORM.find(Guide,guide.id,preload:[:original_community,:communities])
189+
190+
assertguide.original_community_id==community.id
191+
assertguide.communities|>length==2
192+
193+
assertexist_in?(community,guide.communities)
194+
assertexist_in?(home_community,guide.communities)
195+
196+
filter=%{page:1,size:10,community:community.raw}
197+
{:ok,paged_articles}=CMS.paged_articles(:guide,filter)
198+
199+
assertexist_in?(guide,paged_articles.entries)
200+
assertpaged_articles.total_count===1
201+
202+
filter=%{page:1,size:10,community:home_community.raw}
203+
{:ok,paged_articles}=CMS.paged_articles(:guide,filter)
204+
205+
assertexist_in?(guide,paged_articles.entries)
206+
assertpaged_articles.total_count===1
207+
end
208+
209+
@tag:wip
210+
test"guide can be mirror to home with tags",~m(community guide_attrs user)ado
211+
{:ok,home_community}=db_insert(:community,%{raw:"home"})
212+
213+
article_tag_attrs0=mock_attrs(:article_tag)
214+
article_tag_attrs=mock_attrs(:article_tag)
215+
216+
{:ok,article_tag0}=
217+
CMS.create_article_tag(home_community,:guide,article_tag_attrs0,user)
218+
219+
{:ok,article_tag}=CMS.create_article_tag(home_community,:guide,article_tag_attrs,user)
220+
221+
{:ok,guide}=CMS.create_article(community,:guide,guide_attrs,user)
222+
assertguide.original_community_id==community.id
223+
224+
{:ok,_}=CMS.mirror_to_home(:guide,guide.id,[article_tag0.id,article_tag.id])
225+
226+
{:ok,guide}=
227+
ORM.find(Guide,guide.id,preload:[:original_community,:communities,:article_tags])
228+
229+
assertguide.original_community_id==community.id
230+
assertguide.communities|>length==2
231+
232+
assertexist_in?(community,guide.communities)
233+
assertexist_in?(home_community,guide.communities)
234+
235+
assertguide.article_tags|>length==2
236+
assertexist_in?(article_tag0,guide.article_tags)
237+
assertexist_in?(article_tag,guide.article_tags)
238+
239+
filter=%{page:1,size:10,community:community.raw}
240+
{:ok,paged_articles}=CMS.paged_articles(:guide,filter)
241+
242+
assertexist_in?(guide,paged_articles.entries)
243+
assertpaged_articles.total_count===1
244+
245+
filter=%{page:1,size:10,community:home_community.raw}
246+
{:ok,paged_articles}=CMS.paged_articles(:guide,filter)
247+
248+
assertexist_in?(guide,paged_articles.entries)
249+
assertpaged_articles.total_count===1
250+
end
251+
180252
test"guide can be move to blackhole",~m(community guide_attrs user)ado
181253
{:ok,blackhole_community}=db_insert(:community,%{raw:"blackhole"})
182254

@@ -190,6 +262,12 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Guide do
190262
assertguide.communities|>length==1
191263

192264
assertexist_in?(blackhole_community,guide.communities)
265+
266+
filter=%{page:1,size:10,community:blackhole_community.raw}
267+
{:ok,paged_articles}=CMS.paged_articles(:guide,filter)
268+
269+
assertexist_in?(guide,paged_articles.entries)
270+
assertpaged_articles.total_count===1
193271
end
194272

195273
test"guide can be move to blackhole with tags",~m(community guide_attrs user)ado
@@ -199,7 +277,7 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Guide do
199277
article_tag_attrs=mock_attrs(:article_tag)
200278

201279
{:ok,article_tag0}=
202-
CMS.create_article_tag(blackhole_community,:guide,article_tag_attrs,user)
280+
CMS.create_article_tag(blackhole_community,:guide,article_tag_attrs0,user)
203281

204282
{:ok,article_tag}=
205283
CMS.create_article_tag(blackhole_community,:guide,article_tag_attrs,user)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp