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.

refactor(tag): remove refined concept#332

Merged
mydearxym merged 1 commit intodevfromremove-refined-concept
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes fromall 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
10 changes: 2 additions & 8 deletionslib/groupher_server/cms/delegates/article_curd.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -133,7 +133,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
ArticleOperation.update_edit_status(update_content)
end)
|> Multi.run(:update_tag, fn _, _ ->
# TODO: move it to ArticleOperationmoudel
# TODO: move it to ArticleOperationmodule
exec_update_tags(content, args)
end)
|> Repo.transaction()
Expand DownExpand Up@@ -426,13 +426,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
Enum.reduce(tags_ids, [], fn t, acc ->
{:ok, tag} = ORM.find(Tag, t.id)

case tag.title == "refined" do
true ->
acc

false ->
acc ++ [tag]
end
acc ++ [tag]
end)

content
Expand Down
39 changes: 1 addition & 38 deletionslib/groupher_server/cms/delegates/article_operation.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,20 +121,13 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do

@doc """
set general tag for post / tuts ...
refined tag can't set by this func, use set_refined_tag instead
"""
# check community first
def set_tag(thread, %Tag{id: tag_id}, content_id) do
with {:ok, action} <- match_action(thread, :tag),
{:ok, content} <- ORM.find(action.target, content_id, preload: :tags),
{:ok, tag} <- ORM.find(action.reactor, tag_id) do
case tag.title != "refined" do
true ->
update_content_tag(content, tag)

false ->
{:error, "use set_refined_tag instead"}
end
update_content_tag(content, tag)

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

@doc """
set refined_tag to common content
"""
def set_refined_tag(%Community{id: community_id}, thread, content_id) do
with {:ok, action} <- match_action(thread, :tag),
{:ok, content} <- ORM.find(action.target, content_id, preload: :tags),
{:ok, tag} <-
ORM.find_by(action.reactor, %{
title: "refined",
community_id: community_id
}) do
update_content_tag(content, tag)
end
end

@doc """
unset refined_tag to common content
"""
def unset_refined_tag(%Community{id: community_id}, thread, content_id) do
with {:ok, action} <- match_action(thread, :tag),
{:ok, content} <- ORM.find(action.target, content_id, preload: :tags),
{:ok, tag} <-
ORM.find_by(action.reactor, %{
title: "refined",
community_id: community_id
}) do
update_content_tag(content, tag, :drop)
end
end

defp update_content_tag(content, %Tag{} = tag, opt \\ :add) do
new_tags = if opt == :add, do: content.tags ++ [tag], else: content.tags -- [tag]

Expand Down
26 changes: 0 additions & 26 deletionslib/groupher_server_web/schema/cms/mutations/operation.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,19 +93,6 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Operation do
resolve(&R.CMS.set_tag/3)
end

@desc "set a refined tag to content"
field :set_refined_tag, :tag do
arg(:id, non_null(:id))
arg(:community_id, non_null(:id))
arg(:thread, :cms_thread, default_value: :post)

middleware(M.Authorize, :login)
middleware(M.PassportLoader, source: :community)
middleware(M.Passport, claim: "cms->c?->t?.refinedtag.set")

resolve(&R.CMS.set_refined_tag/3)
end

@desc "unset a tag to content"
field :unset_tag, :tag do
# thread id
Expand All@@ -121,19 +108,6 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Operation do
resolve(&R.CMS.unset_tag/3)
end

@desc "unset a refined tag to content"
field :unset_refined_tag, :tag do
arg(:id, non_null(:id))
arg(:community_id, non_null(:id))
arg(:thread, :cms_thread, default_value: :post)

middleware(M.Authorize, :login)
middleware(M.PassportLoader, source: :community)
middleware(M.Passport, claim: "cms->c?->t?.refinedtag.set")

resolve(&R.CMS.unset_refined_tag/3)
end

# TODO: use community loader
field :set_community, :community do
arg(:id, non_null(:id))
Expand Down
62 changes: 0 additions & 62 deletionstest/groupher_server_web/mutation/cms/job_test.exs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -309,14 +309,6 @@ defmodule GroupherServer.Test.Mutation.Job do
}
}
"""
@set_refined_tag_query """
mutation($communityId: ID!, $thread: CmsThread, $id: ID!) {
setRefinedTag(communityId: $communityId, thread: $thread, id: $id) {
id
title
}
}
"""
test "auth user can set a valid tag to job", ~m(job)a do
{:ok, community} = db_insert(:community)
{:ok, tag} = db_insert(:tag, %{thread: "job", community: community})
Expand All@@ -332,33 +324,6 @@ defmodule GroupherServer.Test.Mutation.Job do
assert tag.id in assoc_tags
end

test "can not set refined tag to job", ~m(job)a do
{:ok, community} = db_insert(:community)
{:ok, tag} = db_insert(:tag, %{thread: "job", community: community, title: "refined"})

passport_rules = %{community.title => %{"job.tag.set" => true}}
rule_conn = simu_conn(:user, cms: passport_rules)

variables = %{id: job.id, tagId: tag.id, communityId: community.id}

assert rule_conn |> mutation_get_error?(@set_tag_query, variables)
end

test "auth user can set refined tag to job", ~m(job)a do
{:ok, community} = db_insert(:community)
{:ok, tag} = db_insert(:tag, %{thread: "job", community: community, title: "refined"})

passport_rules = %{community.title => %{"job.refinedtag.set" => true}}
rule_conn = simu_conn(:user, cms: passport_rules)

variables = %{id: job.id, communityId: community.id, thread: "JOB"}
rule_conn |> mutation_result(@set_refined_tag_query, variables, "setRefinedTag")
{:ok, found} = ORM.find(CMS.Job, job.id, preload: :tags)

assoc_tags = found.tags |> Enum.map(& &1.id)
assert tag.id in assoc_tags
end

# TODO: should fix in auth layer
# test "auth user set a other community's tag to job fails", ~m(job)a do
# {:ok, community} = db_insert(:community)
Expand DownExpand Up@@ -391,32 +356,5 @@ defmodule GroupherServer.Test.Mutation.Job do
assert tag.id in assoc_tags
assert tag2.id in assoc_tags
end

@unset_refined_tag_query """
mutation($communityId: ID!, $thread: CmsThread, $id: ID!) {
unsetRefinedTag(communityId: $communityId, thread: $thread, id: $id) {
id
title
}
}
"""
test "can unset refined tag to a job", ~m(job)a do
{:ok, community} = db_insert(:community)
{:ok, tag} = db_insert(:tag, %{thread: "job", community: community, title: "refined"})

passport_rules = %{community.title => %{"job.refinedtag.set" => true}}
rule_conn = simu_conn(:user, cms: passport_rules)

variables = %{id: job.id, communityId: community.id, thread: "JOB"}
rule_conn |> mutation_result(@set_refined_tag_query, variables, "setRefinedTag")

variables = %{id: job.id, communityId: community.id, thread: "JOB"}
rule_conn |> mutation_result(@unset_refined_tag_query, variables, "unsetRefinedTag")

{:ok, found} = ORM.find(CMS.Job, job.id, preload: :tags)

assoc_tags = found.tags |> Enum.map(& &1.id)
assert tag.id not in assoc_tags
end
end
end
82 changes: 0 additions & 82 deletionstest/groupher_server_web/mutation/cms/post_test.exs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -233,26 +233,6 @@ defmodule GroupherServer.Test.Mutation.Post do
assert tag2.id in tag_ids
end

test "can update post with refined tag", ~m(owner_conn post)a do
{:ok, tag_refined} = db_insert(:tag, %{title: "refined"})
{:ok, tag2} = db_insert(:tag)

unique_num = System.unique_integer([:positive, :monotonic])

variables = %{
id: post.id,
title: "updated title #{unique_num}",
tags: [%{id: tag_refined.id}, %{id: tag2.id}]
}

updated = owner_conn |> mutation_result(@query, variables, "updatePost")
{:ok, post} = ORM.find(CMS.Post, updated["id"], preload: :tags)
tag_ids = post.tags |> Utils.pick_by(:id)

assert tag_refined.id not in tag_ids
assert tag2.id in tag_ids
end

test "post can be update by owner", ~m(owner_conn post)a do
unique_num = System.unique_integer([:positive, :monotonic])

Expand DownExpand Up@@ -332,14 +312,6 @@ defmodule GroupherServer.Test.Mutation.Post do
}
}
"""
@set_refined_tag_query """
mutation($communityId: ID!, $thread: CmsThread, $id: ID!) {
setRefinedTag(communityId: $communityId, thread: $thread, id: $id) {
id
title
}
}
"""
test "auth user can set a valid tag to post", ~m(post)a do
{:ok, community} = db_insert(:community)
{:ok, tag} = db_insert(:tag, %{thread: "post", community: community})
Expand All@@ -355,33 +327,6 @@ defmodule GroupherServer.Test.Mutation.Post do
assert tag.id in assoc_tags
end

test "can not set refined tag to post", ~m(post)a do
{:ok, community} = db_insert(:community)
{:ok, tag} = db_insert(:tag, %{thread: "post", community: community, title: "refined"})

passport_rules = %{community.title => %{"post.tag.set" => true}}
rule_conn = simu_conn(:user, cms: passport_rules)

variables = %{id: post.id, tagId: tag.id}

assert rule_conn |> mutation_get_error?(@set_tag_query, variables)
end

test "auth user can set refined tag to post", ~m(post)a do
{:ok, community} = db_insert(:community)
{:ok, tag} = db_insert(:tag, %{thread: "post", community: community, title: "refined"})

passport_rules = %{community.title => %{"post.refinedtag.set" => true}}
rule_conn = simu_conn(:user, cms: passport_rules)

variables = %{id: post.id, communityId: community.id}
rule_conn |> mutation_result(@set_refined_tag_query, variables, "setRefinedTag")
{:ok, found} = ORM.find(CMS.Post, post.id, preload: :tags)

assoc_tags = found.tags |> Enum.map(& &1.id)
assert tag.id in assoc_tags
end

# TODO: should fix in auth layer
# test "auth user set a other community tag to post fails", ~m(post)a do
# {:ok, community} = db_insert(:community)
Expand DownExpand Up@@ -423,14 +368,6 @@ defmodule GroupherServer.Test.Mutation.Post do
}
}
"""
@unset_refined_tag_query """
mutation($communityId: ID!, $thread: CmsThread, $id: ID!) {
unsetRefinedTag(communityId: $communityId, thread: $thread, id: $id) {
id
title
}
}
"""
test "can unset tag to a post", ~m(post)a do
{:ok, community} = db_insert(:community)

Expand DownExpand Up@@ -463,25 +400,6 @@ defmodule GroupherServer.Test.Mutation.Post do
assert tag.id not in assoc_tags
assert tag2.id in assoc_tags
end

test "can unset refined tag to a post", ~m(post)a do
{:ok, community} = db_insert(:community)
{:ok, tag} = db_insert(:tag, %{thread: "post", community: community, title: "refined"})

passport_rules = %{community.title => %{"post.refinedtag.set" => true}}
rule_conn = simu_conn(:user, cms: passport_rules)

variables = %{id: post.id, communityId: community.id}
rule_conn |> mutation_result(@set_refined_tag_query, variables, "setRefinedTag")

variables = %{id: post.id, communityId: community.id}
rule_conn |> mutation_result(@unset_refined_tag_query, variables, "unsetRefinedTag")

{:ok, found} = ORM.find(CMS.Post, post.id, preload: :tags)

assoc_tags = found.tags |> Enum.map(& &1.id)
assert tag.id not in assoc_tags
end
end

describe "[mutation post community]" do
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp