diff --git a/lib/groupher_server/cms/article_comment.ex b/lib/groupher_server/cms/article_comment.ex index f50544e58..b846e66d4 100644 --- a/lib/groupher_server/cms/article_comment.ex +++ b/lib/groupher_server/cms/article_comment.ex @@ -20,7 +20,7 @@ defmodule GroupherServer.CMS.ArticleComment do @required_fields ~w(body_html author_id)a @optional_fields ~w(post_id job_id reply_to_id replies_count is_folded is_reported is_deleted floor is_article_author)a - @updatable_fields ~w(is_folded is_reported is_deleted floor upvotes_count is_pined)a + @updatable_fields ~w(is_folded is_reported is_deleted floor upvotes_count is_pinned)a @max_participator_count 5 @max_parent_replies_count 3 @@ -66,7 +66,7 @@ defmodule GroupherServer.CMS.ArticleComment do field(:upvotes_count, :integer, default: 0) # 是否置顶 - field(:is_pined, :boolean, default: false) + field(:is_pinned, :boolean, default: false) belongs_to(:author, Accounts.User, foreign_key: :author_id) belongs_to(:post, Post, foreign_key: :post_id) diff --git a/lib/groupher_server/cms/cms.ex b/lib/groupher_server/cms/cms.ex index 574ab6a94..1b7b1218f 100644 --- a/lib/groupher_server/cms/cms.ex +++ b/lib/groupher_server/cms/cms.ex @@ -86,8 +86,8 @@ defmodule GroupherServer.CMS do # ArticleOperation # >> set flag on article, like: pin / unpin article defdelegate set_community_flags(community_info, queryable, attrs), to: ArticleOperation - defdelegate pin_content(queryable, community_id), to: ArticleOperation - defdelegate undo_pin_content(queryable, community_id), to: ArticleOperation + defdelegate pin_article(thread, id, community_id), to: ArticleOperation + defdelegate undo_pin_article(thread, id, community_id), to: ArticleOperation defdelegate lock_article_comment(content), to: ArticleOperation diff --git a/lib/groupher_server/cms/community.ex b/lib/groupher_server/cms/community.ex index 935dd903c..4ee423521 100644 --- a/lib/groupher_server/cms/community.ex +++ b/lib/groupher_server/cms/community.ex @@ -19,10 +19,14 @@ defmodule GroupherServer.CMS.Community do CommunityCheatsheet } + @max_pinned_article_count_per_thread 2 + @required_fields ~w(title desc user_id logo raw)a # @required_fields ~w(title desc user_id)a @optional_fields ~w(label geo_info index aka)a + def max_pinned_article_count_per_thread, do: @max_pinned_article_count_per_thread + schema "communities" do field(:title, :string) field(:aka, :string) diff --git a/lib/groupher_server/cms/delegates/article_comment.ex b/lib/groupher_server/cms/delegates/article_comment.ex index fde9881c8..7d4fe6534 100644 --- a/lib/groupher_server/cms/delegates/article_comment.ex +++ b/lib/groupher_server/cms/delegates/article_comment.ex @@ -46,7 +46,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do def list_article_comments(thread, article_id, filters, mode, user \\ nil) def list_article_comments(thread, article_id, filters, :timeline, user) do - where_query = dynamic([c], not c.is_folded and not c.is_reported and not c.is_pined) + where_query = dynamic([c], not c.is_folded and not c.is_reported and not c.is_pinned) do_list_article_comment(thread, article_id, filters, where_query, user) end @@ -57,19 +57,19 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do where_query = dynamic( [c], - is_nil(c.reply_to_id) and not c.is_folded and not c.is_reported and not c.is_pined + is_nil(c.reply_to_id) and not c.is_folded and not c.is_reported and not c.is_pinned ) do_list_article_comment(thread, article_id, filters, where_query, user) end def list_folded_article_comments(thread, article_id, filters) do - where_query = dynamic([c], c.is_folded and not c.is_reported and not c.is_pined) + where_query = dynamic([c], c.is_folded and not c.is_reported and not c.is_pinned) do_list_article_comment(thread, article_id, filters, where_query, nil) end def list_folded_article_comments(thread, article_id, filters, user) do - where_query = dynamic([c], c.is_folded and not c.is_reported and not c.is_pined) + where_query = dynamic([c], c.is_folded and not c.is_reported and not c.is_pinned) do_list_article_comment(thread, article_id, filters, where_query, user) end @@ -129,7 +129,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do end end) |> Multi.run(:update_comment_flag, fn _, _ -> - ORM.update(comment, %{is_pined: true}) + ORM.update(comment, %{is_pinned: true}) end) |> Multi.run(:add_pined_comment, fn _, _ -> ArticlePinedComment @@ -147,7 +147,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do with {:ok, comment} <- ORM.find(ArticleComment, comment_id) do Multi.new() |> Multi.run(:update_comment_flag, fn _, _ -> - ORM.update(comment, %{is_pined: false}) + ORM.update(comment, %{is_pinned: false}) end) |> Multi.run(:remove_pined_comment, fn _, _ -> ORM.findby_delete(ArticlePinedComment, %{article_comment_id: comment.id}) diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index 7a18a0ae8..a299b7ae9 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -3,7 +3,10 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do CURD operation on post/job ... """ import Ecto.Query, warn: false - import GroupherServer.CMS.Utils.Matcher + + import GroupherServer.CMS.Utils.Matcher2 + + import GroupherServer.CMS.Utils.Matcher, only: [match_action: 2, dynamic_where: 2] import Helper.Utils, only: [done: 1, pick_by: 2, integerfy: 1] import Helper.ErrorCode import ShortMaps @@ -11,7 +14,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do alias GroupherServer.{Accounts, CMS, Delivery, Email, Repo, Statistics} alias Accounts.User - alias CMS.{Author, Community, Embeds, Delegate, Tag} + alias CMS.{Author, Community, PinnedArticle, Embeds, Delegate, Tag} alias Delegate.ArticleOperation alias Helper.{Later, ORM, QueryBuilder} @@ -271,28 +274,22 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do end defp read_state_query(queryable, %{read: false} = _filter, _user) do - # queryable - # |> join(:left, [content, f, c], viewers in assoc(content, :viewers)) - # |> where([content, f, c, viewers], viewers.user_id != ^user.id) - # |> where([content, f, c, viewers], content.id != viewers.post_id) - # |> IO.inspect(label: "query") queryable end defp read_state_query(queryable, _, _), do: queryable - # only first page need pin contents - # TODO: use seperate pined table, which is much more smaller - defp add_pin_contents_ifneed(contents, CMS.Post, %{community: community} = filter) do + defp add_pin_contents_ifneed(contents, querable, %{community: _community} = filter) do with {:ok, _} <- should_add_pin?(filter), + {:ok, info} <- match(querable), {:ok, normal_contents} <- contents, true <- Map.has_key?(filter, :community), true <- 1 == Map.get(normal_contents, :page_number) do {:ok, pined_content} = - CMS.PinedPost + PinnedArticle |> join(:inner, [p], c in assoc(p, :community)) - |> join(:inner, [p], content in assoc(p, :post)) - |> where([p, c, content], c.raw == ^community) + |> join(:inner, [p], content in assoc(p, ^info.thread)) + |> where([p, c, content], c.raw == ^filter.community) |> select([p, c, content], content) # 10 pined contents per community/thread, at most |> ORM.paginater(%{page: 1, size: 10}) @@ -305,38 +302,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do end end - defp add_pin_contents_ifneed(contents, CMS.Job, %{community: _community} = filter) do - merge_pin_contents(contents, :job, CMS.PinedJob, filter) - end - - defp add_pin_contents_ifneed(contents, CMS.Repo, %{community: _community} = filter) do - merge_pin_contents(contents, :repo, CMS.PinedRepo, filter) - end - defp add_pin_contents_ifneed(contents, _querable, _filter), do: contents - defp merge_pin_contents(contents, thread, pin_schema, %{community: _community} = filter) do - with {:ok, _} <- should_add_pin?(filter), - {:ok, normal_contents} <- contents, - true <- Map.has_key?(filter, :community), - true <- 1 == Map.get(normal_contents, :page_number) do - {:ok, pined_content} = - pin_schema - |> join(:inner, [p], c in assoc(p, :community)) - |> join(:inner, [p], content in assoc(p, ^thread)) - |> where([p, c, content], c.raw == ^filter.community) - |> select([p, c, content], content) - # 10 pined contents per community/thread, at most - |> ORM.paginater(%{page: 1, size: 10}) - |> done() - - concat_contents(pined_content, normal_contents) - else - _error -> - contents - end - end - # if filter contains like: tags, sort.., then don't add pin content defp should_add_pin?(%{page: 1, tag: :all, sort: :desc_inserted, read: :all} = filter) do filter @@ -356,7 +323,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do pind_entries = pined_content |> Map.get(:entries) - |> Enum.map(&struct(&1, %{pin: true})) + |> Enum.map(&struct(&1, %{is_pinned: true})) normal_entries = normal_contents |> Map.get(:entries) diff --git a/lib/groupher_server/cms/delegates/article_operation.ex b/lib/groupher_server/cms/delegates/article_operation.ex index e33c3ec9b..c01c14003 100644 --- a/lib/groupher_server/cms/delegates/article_operation.ex +++ b/lib/groupher_server/cms/delegates/article_operation.ex @@ -4,9 +4,12 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do """ import GroupherServer.CMS.Utils.Matcher import Ecto.Query, warn: false - # import Helper.ErrorCode + + import Helper.ErrorCode import ShortMaps + import GroupherServer.CMS.Utils.Matcher2 + alias Helper.Types, as: T alias Helper.ORM alias GroupherServer.CMS.{ @@ -18,59 +21,43 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do JobCommunityFlag, RepoCommunityFlag, Tag, - PinedPost, - PinedJob, - PinedRepo + PinnedArticle } alias GroupherServer.CMS.Repo, as: CMSRepo alias GroupherServer.Repo - def pin_content(%Post{id: post_id}, %Community{id: community_id}) do - with {:ok, pined} <- - ORM.findby_or_insert( - PinedPost, - ~m(post_id community_id)a, - ~m(post_id community_id)a - ) do - Post |> ORM.find(pined.post_id) - end - end - - def pin_content(%Job{id: job_id}, %Community{id: community_id}) do - attrs = ~m(job_id community_id)a + @max_pinned_article_count_per_thread Community.max_pinned_article_count_per_thread() - with {:ok, pined} <- ORM.findby_or_insert(PinedJob, attrs, attrs) do - Job |> ORM.find(pined.job_id) + @spec pin_article(T.article_thread(), Integer.t(), Integer.t()) :: {:ok, PinnedArticle.t()} + def pin_article(thread, article_id, community_id) do + with {:ok, info} <- match(thread), + args <- pack_pin_args(thread, article_id, community_id), + {:ok, _} <- check_pinned_article_count(args.community_id, thread), + {:ok, _} <- ORM.create(PinnedArticle, args) do + ORM.find(info.model, article_id) end end - def pin_content(%CMSRepo{id: repo_id}, %Community{id: community_id}) do - attrs = ~m(repo_id community_id)a - - with {:ok, pined} <- ORM.findby_or_insert(PinedRepo, attrs, attrs) do - CMSRepo |> ORM.find(pined.repo_id) + @spec undo_pin_article(T.article_thread(), Integer.t(), Integer.t()) :: {:ok, PinnedArticle.t()} + def undo_pin_article(thread, article_id, community_id) do + with {:ok, info} <- match(thread), + args <- pack_pin_args(thread, article_id, community_id) do + ORM.findby_delete(PinnedArticle, args) + ORM.find(info.model, article_id) end end - def undo_pin_content(%Post{id: post_id}, %Community{id: community_id}) do - with {:ok, pined} <- ORM.find_by(PinedPost, ~m(post_id community_id)a), - {:ok, deleted} <- ORM.delete(pined) do - Post |> ORM.find(deleted.post_id) - end - end + defp pack_pin_args(thread, article_id, community_id) do + with {:ok, info} <- match(thread), + {:ok, community} <- ORM.find(Community, community_id) do + thread_upcase = thread |> to_string |> String.upcase() - def undo_pin_content(%Job{id: job_id}, %Community{id: community_id}) do - with {:ok, pined} <- ORM.find_by(PinedJob, ~m(job_id community_id)a), - {:ok, deleted} <- ORM.delete(pined) do - Job |> ORM.find(deleted.job_id) - end - end - - def undo_pin_content(%CMSRepo{id: repo_id}, %Community{id: community_id}) do - with {:ok, pined} <- ORM.find_by(PinedRepo, ~m(repo_id community_id)a), - {:ok, deleted} <- ORM.delete(pined) do - CMSRepo |> ORM.find(deleted.repo_id) + Map.put( + %{community_id: community.id, thread: thread_upcase}, + info.foreign_key, + article_id + ) end end @@ -255,18 +242,20 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do |> Repo.update() end - # make sure the reuest tag is in the current community thread - # example: you can't set a other thread tag to this thread's article + # check if the thread has aready enough pined articles + defp check_pinned_article_count(community_id, thread) do + thread_upcase = thread |> to_string |> String.upcase() - # defp tag_in_community_thread?(%Community{id: communityId}, thread, tag) do - # with {:ok, community} <- ORM.find(Community, communityId) do - # matched_tags = - # Tag - # |> where([t], t.community_id == ^community.id) - # |> where([t], t.thread == ^to_string(thread)) - # |> Repo.all() + query = + from(p in PinnedArticle, + where: p.community_id == ^community_id and p.thread == ^thread_upcase + ) - # tag in matched_tags - # end - # end + pinned_articles = query |> Repo.all() + + case length(pinned_articles) >= @max_pinned_article_count_per_thread do + true -> raise_error(:too_much_pinned_article, "too much pinned article") + _ -> {:ok, :pass} + end + end end diff --git a/lib/groupher_server/cms/job.ex b/lib/groupher_server/cms/job.ex index 6e79ac383..8312702d5 100644 --- a/lib/groupher_server/cms/job.ex +++ b/lib/groupher_server/cms/job.ex @@ -56,7 +56,7 @@ defmodule GroupherServer.CMS.Job do has_many(:community_flags, {"jobs_communities_flags", JobCommunityFlag}) # NOTE: this one is tricky, pin is dynamic changed when return by func: add_pin_contents_ifneed - field(:pin, :boolean, default_value: false, virtual: true) + field(:is_pinned, :boolean, default: false, virtual: true) field(:trash, :boolean, default_value: false, virtual: true) has_many(:article_comments, {"articles_comments", ArticleComment}) diff --git a/lib/groupher_server/cms/pined_job.ex b/lib/groupher_server/cms/pined_job.ex deleted file mode 100644 index 09e14031e..000000000 --- a/lib/groupher_server/cms/pined_job.ex +++ /dev/null @@ -1,30 +0,0 @@ -defmodule GroupherServer.CMS.PinedJob do - @moduledoc false - alias __MODULE__ - - use Ecto.Schema - import Ecto.Changeset - - alias GroupherServer.CMS - alias CMS.{Community, Job} - - @required_fields ~w(job_id community_id)a - - @type t :: %PinedJob{} - schema "pined_jobs" do - belongs_to(:job, Job, foreign_key: :job_id) - belongs_to(:community, Community, foreign_key: :community_id) - - timestamps(type: :utc_datetime) - end - - @doc false - def changeset(%PinedJob{} = pined_job, attrs) do - pined_job - |> cast(attrs, @required_fields) - |> validate_required(@required_fields) - |> foreign_key_constraint(:job_id) - |> foreign_key_constraint(:community_id) - |> unique_constraint(:pined_jobs, name: :pined_jobs_job_id_community_id_index) - end -end diff --git a/lib/groupher_server/cms/pined_post.ex b/lib/groupher_server/cms/pined_post.ex deleted file mode 100644 index f93236070..000000000 --- a/lib/groupher_server/cms/pined_post.ex +++ /dev/null @@ -1,30 +0,0 @@ -defmodule GroupherServer.CMS.PinedPost do - @moduledoc false - alias __MODULE__ - - use Ecto.Schema - import Ecto.Changeset - - alias GroupherServer.CMS - alias CMS.{Community, Post} - - @required_fields ~w(post_id community_id)a - - @type t :: %PinedPost{} - schema "pined_posts" do - belongs_to(:post, Post, foreign_key: :post_id) - belongs_to(:community, Community, foreign_key: :community_id) - - timestamps(type: :utc_datetime) - end - - @doc false - def changeset(%PinedPost{} = pined_post, attrs) do - pined_post - |> cast(attrs, @required_fields) - |> validate_required(@required_fields) - |> foreign_key_constraint(:post_id) - |> foreign_key_constraint(:community_id) - |> unique_constraint(:pined_posts, name: :pined_posts_post_id_community_id_index) - end -end diff --git a/lib/groupher_server/cms/pined_repo.ex b/lib/groupher_server/cms/pined_repo.ex deleted file mode 100644 index 2bc6b309d..000000000 --- a/lib/groupher_server/cms/pined_repo.ex +++ /dev/null @@ -1,30 +0,0 @@ -defmodule GroupherServer.CMS.PinedRepo do - @moduledoc false - alias __MODULE__ - - use Ecto.Schema - import Ecto.Changeset - - alias GroupherServer.CMS - alias CMS.{Community, Repo} - - @required_fields ~w(repo_id community_id)a - - @type t :: %PinedRepo{} - schema "pined_repos" do - belongs_to(:repo, Repo, foreign_key: :repo_id) - belongs_to(:community, Community, foreign_key: :community_id) - - timestamps(type: :utc_datetime) - end - - @doc false - def changeset(%PinedRepo{} = pined_repo, attrs) do - pined_repo - |> cast(attrs, @required_fields) - |> validate_required(@required_fields) - |> foreign_key_constraint(:repo_id) - |> foreign_key_constraint(:community_id) - |> unique_constraint(:pined_repos, name: :pined_repos_repo_id_community_id_index) - end -end diff --git a/lib/groupher_server/cms/pinned_article.ex b/lib/groupher_server/cms/pinned_article.ex new file mode 100644 index 000000000..1fd93c3c3 --- /dev/null +++ b/lib/groupher_server/cms/pinned_article.ex @@ -0,0 +1,40 @@ +defmodule GroupherServer.CMS.PinnedArticle do + @moduledoc false + alias __MODULE__ + + use Ecto.Schema + import Ecto.Changeset + + alias GroupherServer.CMS + alias CMS.{Community, Post, Job, Repo} + + @required_fields ~w(community_id thread)a + @optional_fields ~w(post_id job_id repo_id)a + + @type t :: %PinnedArticle{} + schema "pinned_articles" do + belongs_to(:post, Post, foreign_key: :post_id) + belongs_to(:job, Job, foreign_key: :job_id) + belongs_to(:repo, Repo, foreign_key: :repo_id) + belongs_to(:community, Community, foreign_key: :community_id) + + field(:thread, :string) + + timestamps(type: :utc_datetime) + end + + @doc false + def changeset(%PinnedArticle{} = pinned_article, attrs) do + pinned_article + |> cast(attrs, @optional_fields ++ @required_fields) + |> validate_required(@required_fields) + |> foreign_key_constraint(:post_id) + |> foreign_key_constraint(:job_id) + |> foreign_key_constraint(:repo_id) + |> foreign_key_constraint(:community_id) + |> unique_constraint(:pinned_articles, name: :pinned_articles_post_id_community_id_index) + + # |> unique_constraint(:pinned_articles, name: :pinned_articles_job_id_community_id_index) + # |> unique_constraint(:pinned_articles, name: :pinned_articles_repo_id_community_id_index) + end +end diff --git a/lib/groupher_server/cms/post.ex b/lib/groupher_server/cms/post.ex index 3089f567f..8dcd016e2 100644 --- a/lib/groupher_server/cms/post.ex +++ b/lib/groupher_server/cms/post.ex @@ -45,7 +45,8 @@ defmodule GroupherServer.CMS.Post do has_many(:community_flags, {"posts_communities_flags", PostCommunityFlag}) # NOTE: this one is tricky, pin is dynamic changed when return by func: add_pin_contents_ifneed - field(:pin, :boolean, default_value: false, virtual: true) + # field(:pin, :boolean, default_value: false, virtual: true) + field(:is_pinned, :boolean, default: false, virtual: true) field(:trash, :boolean, default_value: false, virtual: true) belongs_to(:author, Author) diff --git a/lib/groupher_server/cms/repo.ex b/lib/groupher_server/cms/repo.ex index 9a133f3d7..21f47b4e5 100644 --- a/lib/groupher_server/cms/repo.ex +++ b/lib/groupher_server/cms/repo.ex @@ -56,7 +56,7 @@ defmodule GroupherServer.CMS.Repo do has_many(:community_flags, {"repos_communities_flags", RepoCommunityFlag}) # NOTE: this one is tricky, pin is dynamic changed when return by func: add_pin_contents_ifneed - field(:pin, :boolean, default_value: false) + field(:is_pinned, :boolean, default: false, virtual: true) field(:trash, :boolean, default_value: false) field(:last_sync, :utc_datetime) diff --git a/lib/groupher_server/cms/utils/matcher2.ex b/lib/groupher_server/cms/utils/matcher2.ex index ea6e60db1..de6975ddf 100644 --- a/lib/groupher_server/cms/utils/matcher2.ex +++ b/lib/groupher_server/cms/utils/matcher2.ex @@ -7,7 +7,7 @@ defmodule GroupherServer.CMS.Utils.Matcher2 do alias GroupherServer.CMS - alias CMS.{ArticleComment, Post, Job} + alias CMS.{ArticleComment, Post, Job, Repo} def match(:article_comment) do {:ok, %{model: ArticleComment, foreign_key: :article_comment_id}} @@ -25,14 +25,31 @@ defmodule GroupherServer.CMS.Utils.Matcher2 do {:error, "not supported"} end + # used for paged pin articles + def match(Post) do + {:ok, %{thread: :post}} + end + def match(:post) do {:ok, %{model: Post, foreign_key: :post_id}} end + def match(Job) do + {:ok, %{thread: :job}} + end + def match(:job) do {:ok, %{model: Job, foreign_key: :job_id}} end + def match(Repo) do + {:ok, %{thread: :repo}} + end + + def match(:repo) do + {:ok, %{model: Repo, foreign_key: :repo_id}} + end + def match(:post, :query, id), do: {:ok, dynamic([c], c.post_id == ^id)} def match(:job, :query, id), do: {:ok, dynamic([c], c.job_id == ^id)} end diff --git a/lib/groupher_server_web/resolvers/cms_resolver.ex b/lib/groupher_server_web/resolvers/cms_resolver.ex index 0f3beec44..5d8f50fd6 100644 --- a/lib/groupher_server_web/resolvers/cms_resolver.ex +++ b/lib/groupher_server_web/resolvers/cms_resolver.ex @@ -99,36 +99,12 @@ defmodule GroupherServerWeb.Resolvers.CMS do # ####################### # content flag .. # ####################### - def pin_content(_root, ~m(id community_id thread)a, _info) do - do_pin_content(id, community_id, thread) + def pin_article(_root, ~m(id community_id thread)a, _info) do + CMS.pin_article(thread, id, community_id) end - def undo_pin_content(_root, ~m(id community_id thread)a, _info) do - do_undo_pin_content(id, community_id, thread) - end - - def do_pin_content(id, community_id, :post) do - CMS.pin_content(%CMS.Post{id: id}, %Community{id: community_id}) - end - - def do_pin_content(id, community_id, :job) do - CMS.pin_content(%CMS.Job{id: id}, %Community{id: community_id}) - end - - def do_pin_content(id, community_id, :repo) do - CMS.pin_content(%CMS.Repo{id: id}, %Community{id: community_id}) - end - - def do_undo_pin_content(id, community_id, :post) do - CMS.undo_pin_content(%CMS.Post{id: id}, %Community{id: community_id}) - end - - def do_undo_pin_content(id, community_id, :job) do - CMS.undo_pin_content(%CMS.Job{id: id}, %Community{id: community_id}) - end - - def do_undo_pin_content(id, community_id, :repo) do - CMS.undo_pin_content(%CMS.Repo{id: id}, %Community{id: community_id}) + def undo_pin_article(_root, ~m(id community_id thread)a, _info) do + CMS.undo_pin_article(thread, id, community_id) end def trash_content(_root, ~m(id thread community_id)a, _info) do diff --git a/lib/groupher_server_web/schema/cms/cms_types.ex b/lib/groupher_server_web/schema/cms/cms_types.ex index 49b5525d8..b4ba920da 100644 --- a/lib/groupher_server_web/schema/cms/cms_types.ex +++ b/lib/groupher_server_web/schema/cms/cms_types.ex @@ -35,7 +35,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:body, :string) field(:views, :integer) # NOTE: only meaningful in paged-xxx queries - field(:pin, :boolean) + field(:is_pinned, :boolean) field(:trash, :boolean) field(:tags, list_of(:tag), resolve: dataloader(CMS, :tags)) @@ -92,7 +92,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:body, :string) field(:views, :integer) - field(:pin, :boolean) + field(:is_pinned, :boolean) field(:trash, :boolean) field(:author, :user, resolve: dataloader(CMS, :author)) @@ -143,10 +143,9 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:contributors, list_of(:repo_contributor)) field(:views, :integer) - field(:pin, :boolean) + field(:is_pinned, :boolean) field(:trash, :boolean) # TODO: remove - # field(:pin, :boolean) # field(:trash, :boolean) field(:last_sync, :datetime) @@ -362,7 +361,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:id, :id) field(:body_html, :string) field(:author, :user, resolve: dataloader(CMS, :author)) - field(:is_pined, :boolean) + field(:is_pinned, :boolean) field(:floor, :integer) field(:upvotes_count, :integer) field(:emotions, :article_comment_emotions) diff --git a/lib/groupher_server_web/schema/cms/mutations/job.ex b/lib/groupher_server_web/schema/cms/mutations/job.ex index b50ff30e4..930d7f721 100644 --- a/lib/groupher_server_web/schema/cms/mutations/job.ex +++ b/lib/groupher_server_web/schema/cms/mutations/job.ex @@ -46,7 +46,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Job do middleware(M.Authorize, :login) middleware(M.PassportLoader, source: :community) middleware(M.Passport, claim: "cms->c?->job.pin") - resolve(&R.CMS.pin_content/3) + resolve(&R.CMS.pin_article/3) end @desc "unpin a job" @@ -58,7 +58,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Job do middleware(M.Authorize, :login) middleware(M.PassportLoader, source: :community) middleware(M.Passport, claim: "cms->c?->job.undo_pin") - resolve(&R.CMS.undo_pin_content/3) + resolve(&R.CMS.undo_pin_article/3) end @desc "trash a job, not delete" diff --git a/lib/groupher_server_web/schema/cms/mutations/post.ex b/lib/groupher_server_web/schema/cms/mutations/post.ex index 11fdc57c0..860c4d84d 100644 --- a/lib/groupher_server_web/schema/cms/mutations/post.ex +++ b/lib/groupher_server_web/schema/cms/mutations/post.ex @@ -34,7 +34,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Post do middleware(M.Authorize, :login) middleware(M.PassportLoader, source: :community) middleware(M.Passport, claim: "cms->c?->post.pin") - resolve(&R.CMS.pin_content/3) + resolve(&R.CMS.pin_article/3) end @desc "unpin a post" @@ -46,7 +46,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Post do middleware(M.Authorize, :login) middleware(M.PassportLoader, source: :community) middleware(M.Passport, claim: "cms->c?->post.undo_pin") - resolve(&R.CMS.undo_pin_content/3) + resolve(&R.CMS.undo_pin_article/3) end @desc "trash a post, not delete" diff --git a/lib/groupher_server_web/schema/cms/mutations/repo.ex b/lib/groupher_server_web/schema/cms/mutations/repo.ex index 26ddb79f5..934fbd673 100644 --- a/lib/groupher_server_web/schema/cms/mutations/repo.ex +++ b/lib/groupher_server_web/schema/cms/mutations/repo.ex @@ -78,7 +78,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Repo do middleware(M.Authorize, :login) middleware(M.PassportLoader, source: :community) middleware(M.Passport, claim: "cms->c?->repo.pin") - resolve(&R.CMS.pin_content/3) + resolve(&R.CMS.pin_article/3) end @desc "unpin a repo" @@ -90,7 +90,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Repo do middleware(M.Authorize, :login) middleware(M.PassportLoader, source: :community) middleware(M.Passport, claim: "cms->c?->repo.undo_pin") - resolve(&R.CMS.undo_pin_content/3) + resolve(&R.CMS.undo_pin_article/3) end @desc "trash a repo, not delete" diff --git a/lib/helper/error_code.ex b/lib/helper/error_code.ex index 95b375380..0faecb2ac 100644 --- a/lib/helper/error_code.ex +++ b/lib/helper/error_code.ex @@ -7,6 +7,7 @@ defmodule Helper.ErrorCode do @throttle_base 4200 @account_base 4300 @comment_base 4400 + @article_base 4500 @spec raise_error(Atom.t(), String.t()) :: {:error, [message: String.t(), code: Integer.t()]} def raise_error(code_atom, msg) do @@ -38,8 +39,10 @@ defmodule Helper.ErrorCode do def ecode(:throttle_inverval), do: @throttle_base + 1 def ecode(:throttle_hour), do: @throttle_base + 2 def ecode(:throttle_day), do: @throttle_base + 3 - # + # comment def ecode(:create_comment), do: @comment_base + 1 + # article + def ecode(:too_much_pinned_article), do: @article_base + 1 def ecode, do: @default_base # def ecode(_), do: @default_base diff --git a/priv/repo/migrations/20210429014800_create_pined_article.exs b/priv/repo/migrations/20210429014800_create_pined_article.exs new file mode 100644 index 000000000..faa68f38c --- /dev/null +++ b/priv/repo/migrations/20210429014800_create_pined_article.exs @@ -0,0 +1,19 @@ +defmodule GroupherServer.Repo.Migrations.CreatePinedArticle do + use Ecto.Migration + + def change do + create table(:pinned_articles) do + add(:post_id, references(:cms_posts, on_delete: :delete_all)) + add(:job_id, references(:cms_jobs, on_delete: :delete_all)) + add(:community_id, references(:communities, on_delete: :delete_all), null: false) + add(:thread, :string) + + timestamps() + end + + create(index(:pinned_articles, [:post_id])) + create(index(:pinned_articles, [:job_id])) + create(index(:pinned_articles, [:community_id])) + create(unique_index(:pinned_articles, [:post_id, :job_id, :community_id])) + end +end diff --git a/priv/repo/migrations/20210429065645_adjust_pin_field_on_articles.exs b/priv/repo/migrations/20210429065645_adjust_pin_field_on_articles.exs new file mode 100644 index 000000000..7733817cd --- /dev/null +++ b/priv/repo/migrations/20210429065645_adjust_pin_field_on_articles.exs @@ -0,0 +1,19 @@ +defmodule GroupherServer.Repo.Migrations.AdjustPinFieldOnArticles do + use Ecto.Migration + + def change do + alter table(:cms_posts) do + add(:is_pinned, :boolean, default: false) + end + + alter table(:cms_jobs) do + add(:is_pinned, :boolean, default: false) + end + + alter table(:cms_repos) do + add(:is_pinned, :boolean, default: false) + end + + rename(table(:articles_comments), :is_pined, to: :is_pinned) + end +end diff --git a/priv/repo/migrations/20210429083236_remove_old_pined_tables.exs b/priv/repo/migrations/20210429083236_remove_old_pined_tables.exs new file mode 100644 index 000000000..9568ebb76 --- /dev/null +++ b/priv/repo/migrations/20210429083236_remove_old_pined_tables.exs @@ -0,0 +1,19 @@ +defmodule GroupherServer.Repo.Migrations.RemoveOldPinedTables do + use Ecto.Migration + + def change do + drop(table(:pined_posts)) + drop(table(:pined_jobs)) + drop(table(:pined_repos)) + + alter table(:pinned_articles) do + add(:repo_id, references(:cms_repos, on_delete: :delete_all)) + end + + create(index(:pinned_articles, [:repo_id])) + drop(unique_index(:pinned_articles, [:post_id, :job_id, :community_id])) + create(unique_index(:pinned_articles, [:post_id, :community_id])) + create(unique_index(:pinned_articles, [:job_id, :community_id])) + create(unique_index(:pinned_articles, [:repo_id, :community_id])) + end +end diff --git a/test/groupher_server/cms/article_comment_test.exs b/test/groupher_server/cms/article_comment_test.exs index a0fca20c5..b6d708d77 100644 --- a/test/groupher_server/cms/article_comment_test.exs +++ b/test/groupher_server/cms/article_comment_test.exs @@ -223,12 +223,12 @@ defmodule GroupherServer.Test.CMS.ArticleComment do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert not comment.is_pined + assert not comment.is_pinned {:ok, comment} = CMS.pin_article_comment(comment.id) {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert comment.is_pined + assert comment.is_pinned {:ok, pined_record} = ArticlePinedComment |> ORM.find_by(%{post_id: post.id}) assert pined_record.post_id == post.id @@ -240,7 +240,7 @@ defmodule GroupherServer.Test.CMS.ArticleComment do {:ok, _comment} = CMS.pin_article_comment(comment.id) {:ok, comment} = CMS.undo_pin_article_comment(comment.id) - assert not comment.is_pined + assert not comment.is_pinned assert {:error, _} = ArticlePinedComment |> ORM.find_by(%{article_comment_id: comment.id}) end diff --git a/test/groupher_server/cms/article_pin_test.exs b/test/groupher_server/cms/article_pin_test.exs new file mode 100644 index 000000000..6fc09d951 --- /dev/null +++ b/test/groupher_server/cms/article_pin_test.exs @@ -0,0 +1,67 @@ +defmodule GroupherServer.Test.CMS.ArticlePin do + @moduledoc false + + use GroupherServer.TestTools + + alias Helper.ORM + alias GroupherServer.CMS + + alias CMS.{ + Community, + PinnedArticle + # Post, + # Job + } + + @max_pinned_article_count_per_thread Community.max_pinned_article_count_per_thread() + + setup do + {:ok, user} = db_insert(:user) + {:ok, community} = db_insert(:community) + + {:ok, post} = CMS.create_content(community, :post, mock_attrs(:post), user) + {:ok, job} = CMS.create_content(community, :job, mock_attrs(:job), user) + {:ok, repo} = CMS.create_content(community, :repo, mock_attrs(:repo), user) + + {:ok, ~m(user community post job repo)a} + end + + describe "[cms post pin]" do + @tag :wip + test "can pin a post", ~m(community post)a do + {:ok, _} = CMS.pin_article(:post, post.id, community.id) + {:ok, pind_article} = ORM.find_by(PinnedArticle, %{post_id: post.id}) + + assert pind_article.post_id == post.id + end + + @tag :wip2 + test "one community & thread can only pin certern count of post", ~m(community post user)a do + Enum.reduce(1..@max_pinned_article_count_per_thread, [], fn _, acc -> + {:ok, new_post} = CMS.create_content(community, :post, mock_attrs(:post), user) + {:ok, _} = CMS.pin_article(:post, new_post.id, community.id) + acc + end) + + {:ok, new_post} = CMS.create_content(community, :post, mock_attrs(:post), user) + {:error, reason} = CMS.pin_article(:post, new_post.id, community.id) + assert reason |> Keyword.get(:code) == ecode(:too_much_pinned_article) + end + + @tag :wip + test "can not pin a non-exsit post", ~m(community)a do + assert {:error, _} = CMS.pin_article(:post, 8848, community.id) + end + + @tag :wip2 + test "can undo pin to a post", ~m(community post)a do + {:ok, _} = CMS.pin_article(:post, post.id, community.id) + + assert {:ok, unpinned} = CMS.undo_pin_article(:post, post.id, community.id) + + assert {:error, _} = ORM.find_by(PinnedArticle, %{post_id: post.id}) + end + end + + # TODO: Job, Repo +end diff --git a/test/groupher_server/cms/content_pin_test.exs b/test/groupher_server/cms/content_pin_test.exs deleted file mode 100644 index 1be36fb27..000000000 --- a/test/groupher_server/cms/content_pin_test.exs +++ /dev/null @@ -1,72 +0,0 @@ -defmodule GroupherServer.Test.CMS.ContentsPin do - use GroupherServer.TestTools - - # alias Helper.ORM - alias GroupherServer.CMS - - # alias CMS.{ - # Post, - # PinedPost, - # Job, - # PinedJob, - # } - - setup do - {:ok, user} = db_insert(:user) - {:ok, community} = db_insert(:community) - - {:ok, post} = CMS.create_content(community, :post, mock_attrs(:post), user) - {:ok, job} = CMS.create_content(community, :job, mock_attrs(:job), user) - {:ok, repo} = CMS.create_content(community, :repo, mock_attrs(:repo), user) - - {:ok, ~m(user community post job repo)a} - end - - describe "[cms post pin]" do - test "can pin a post", ~m(community post)a do - {:ok, pined_post} = CMS.pin_content(post, community) - - assert pined_post.id == post.id - end - - test "can undo pin to a post", ~m(community post)a do - {:ok, pined_post} = CMS.pin_content(post, community) - assert pined_post.id == post.id - - assert {:ok, unpined} = CMS.undo_pin_content(post, community) - assert unpined.id == post.id - end - end - - describe "[cms job pin]" do - test "can pin a job", ~m(community job)a do - {:ok, pined_job} = CMS.pin_content(job, community) - - assert pined_job.id == job.id - end - - test "can undo pin to a job", ~m(community job)a do - {:ok, pined_job} = CMS.pin_content(job, community) - assert pined_job.id == job.id - - assert {:ok, unpined} = CMS.undo_pin_content(job, community) - assert unpined.id == job.id - end - end - - describe "[cms repo pin]" do - test "can pin a repo", ~m(community repo)a do - {:ok, pined_repo} = CMS.pin_content(repo, community) - - assert pined_repo.id == repo.id - end - - test "can undo pin to a repo", ~m(community repo)a do - {:ok, pined_repo} = CMS.pin_content(repo, community) - assert pined_repo.id == repo.id - - assert {:ok, unpined} = CMS.undo_pin_content(repo, community) - assert unpined.id == repo.id - end - end -end diff --git a/test/groupher_server_web/mutation/cms/cms_test.exs b/test/groupher_server_web/mutation/cms/cms_test.exs index 7bb9bbf83..25c55a46f 100644 --- a/test/groupher_server_web/mutation/cms/cms_test.exs +++ b/test/groupher_server_web/mutation/cms/cms_test.exs @@ -216,7 +216,7 @@ defmodule GroupherServer.Test.Mutation.CMS.Basic do assert belong_community["id"] == to_string(community.id) end - # TODO: @tag :wip2 + # TODO: @tag :wip # test "auth user create duplicate tag fails", ~m(community)a do # variables = mock_attrs(:tag, %{communityId: community.id}) diff --git a/test/groupher_server_web/mutation/cms/job_flag_test.exs b/test/groupher_server_web/mutation/cms/job_flag_test.exs index bd3cfd468..6d18874ab 100644 --- a/test/groupher_server_web/mutation/cms/job_flag_test.exs +++ b/test/groupher_server_web/mutation/cms/job_flag_test.exs @@ -108,21 +108,22 @@ defmodule GroupherServer.Test.Mutation.JobFlag do mutation($id: ID!, $communityId: ID!){ undoPinJob(id: $id, communityId: $communityId) { id - pin + isPinned } } """ + @tag :wip test "auth user can undo pin job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} passport_rules = %{community.raw => %{"job.undo_pin" => true}} rule_conn = simu_conn(:user, cms: passport_rules) - CMS.pin_content(job, community) + CMS.pin_article(:job, job.id, community.id) updated = rule_conn |> mutation_result(@query, variables, "undoPinJob") assert updated["id"] == to_string(job.id) - # assert updated["pin"] == false + assert updated["isPinned"] == false end test "unauth user undo pin job fails", ~m(user_conn guest_conn community job)a do diff --git a/test/groupher_server_web/mutation/cms/post_flag_test.exs b/test/groupher_server_web/mutation/cms/post_flag_test.exs index 4f52f78a4..87830602d 100644 --- a/test/groupher_server_web/mutation/cms/post_flag_test.exs +++ b/test/groupher_server_web/mutation/cms/post_flag_test.exs @@ -84,6 +84,7 @@ defmodule GroupherServer.Test.Mutation.PostFlag do } } """ + @tag :wip test "auth user can pin post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -108,17 +109,18 @@ defmodule GroupherServer.Test.Mutation.PostFlag do mutation($id: ID!, $communityId: ID!){ undoPinPost(id: $id, communityId: $communityId) { id - pin + isPinned } } """ + @tag :wip test "auth user can undo pin post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} passport_rules = %{community.raw => %{"post.undo_pin" => true}} rule_conn = simu_conn(:user, cms: passport_rules) - CMS.pin_content(post, community) + CMS.pin_article(:post, post.id, community.id) updated = rule_conn |> mutation_result(@query, variables, "undoPinPost") assert updated["id"] == to_string(post.id) diff --git a/test/groupher_server_web/mutation/cms/repo_flag_test.exs b/test/groupher_server_web/mutation/cms/repo_flag_test.exs index 87620254d..882cc6e9a 100644 --- a/test/groupher_server_web/mutation/cms/repo_flag_test.exs +++ b/test/groupher_server_web/mutation/cms/repo_flag_test.exs @@ -108,17 +108,18 @@ defmodule GroupherServer.Test.Mutation.RepoFlag do mutation($id: ID!, $communityId: ID!){ undoPinRepo(id: $id, communityId: $communityId) { id - pin + isPinned } } """ + @tag :wip test "auth user can undo pin repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} passport_rules = %{community.raw => %{"repo.undo_pin" => true}} rule_conn = simu_conn(:user, cms: passport_rules) - CMS.pin_content(repo, community) + CMS.pin_article(:repo, repo.id, community.id) updated = rule_conn |> mutation_result(@query, variables, "undoPinRepo") assert updated["id"] == to_string(repo.id) diff --git a/test/groupher_server_web/query/cms/article_comment_test.exs b/test/groupher_server_web/query/cms/article_comment_test.exs index b40c65075..392aef6d7 100644 --- a/test/groupher_server_web/query/cms/article_comment_test.exs +++ b/test/groupher_server_web/query/cms/article_comment_test.exs @@ -68,7 +68,7 @@ defmodule GroupherServer.Test.Query.ArticleComment do id nickname } - isPined + isPinned floor upvotesCount diff --git a/test/groupher_server_web/query/cms/jobs_flags_test.exs b/test/groupher_server_web/query/cms/jobs_flags_test.exs index 41ee4857f..b992b3343 100644 --- a/test/groupher_server_web/query/cms/jobs_flags_test.exs +++ b/test/groupher_server_web/query/cms/jobs_flags_test.exs @@ -39,7 +39,7 @@ defmodule GroupherServer.Test.Query.JobsFlags do pagedJobs(filter: $filter) { entries { id - pin + isPinned communities { raw } @@ -51,6 +51,7 @@ defmodule GroupherServer.Test.Query.JobsFlags do } } """ + @tag :wip test "if have pined jobs, the pined jobs should at the top of entries", ~m(guest_conn community job_m)a do variables = %{filter: %{community: community.raw}} @@ -62,23 +63,24 @@ defmodule GroupherServer.Test.Query.JobsFlags do assert results["pageSize"] == @page_size assert results["totalCount"] == @total_count - {:ok, _pined_post} = CMS.pin_content(job_m, community) + {:ok, _pined_post} = CMS.pin_article(:job, job_m.id, community.id) results = guest_conn |> query_result(@query, variables, "pagedJobs") entries_first = results["entries"] |> List.first() assert results["totalCount"] == @total_count assert entries_first["id"] == to_string(job_m.id) - assert entries_first["pin"] == true + assert entries_first["isPinned"] == true end + @tag :wip test "pind jobs should not appear when page > 1", ~m(guest_conn community)a do variables = %{filter: %{page: 2, size: 20}} results = guest_conn |> query_result(@query, variables, "pagedJobs") assert results |> is_valid_pagination? random_id = results["entries"] |> Enum.shuffle() |> List.first() |> Map.get("id") - {:ok, _pined_post} = CMS.pin_content(%Job{id: random_id}, community) + {:ok, _pined_post} = CMS.pin_article(:job, random_id, community.id) # {:ok, _} = CMS.set_community_flags(community, %Job{id: random_id}, %{pin: true}) results = guest_conn |> query_result(@query, variables, "pagedJobs") diff --git a/test/groupher_server_web/query/cms/posts_flags_test.exs b/test/groupher_server_web/query/cms/posts_flags_test.exs index 286eaae66..15ed9be50 100644 --- a/test/groupher_server_web/query/cms/posts_flags_test.exs +++ b/test/groupher_server_web/query/cms/posts_flags_test.exs @@ -39,7 +39,7 @@ defmodule GroupherServer.Test.Query.PostsFlags do pagedPosts(filter: $filter) { entries { id - pin + isPinned communities { raw } @@ -51,6 +51,7 @@ defmodule GroupherServer.Test.Query.PostsFlags do } } """ + @tag :wip test "if have pined posts, the pined posts should at the top of entries", ~m(guest_conn community post_m)a do variables = %{filter: %{community: community.raw}} @@ -62,16 +63,17 @@ defmodule GroupherServer.Test.Query.PostsFlags do assert results["pageSize"] == @page_size assert results["totalCount"] == @total_count - {:ok, _pined_post} = CMS.pin_content(post_m, community) + {:ok, _pined_post} = CMS.pin_article(:post, post_m.id, community.id) results = guest_conn |> query_result(@query, variables, "pagedPosts") entries_first = results["entries"] |> List.first() assert results["totalCount"] == @total_count assert entries_first["id"] == to_string(post_m.id) - assert entries_first["pin"] == true + assert entries_first["isPinned"] == true end + @tag :wip test "pind posts should not appear when page > 1", ~m(guest_conn community)a do variables = %{filter: %{page: 2, size: 20}} results = guest_conn |> query_result(@query, variables, "pagedPosts") @@ -79,7 +81,7 @@ defmodule GroupherServer.Test.Query.PostsFlags do random_id = results["entries"] |> Enum.shuffle() |> List.first() |> Map.get("id") - {:ok, _pined_post} = CMS.pin_content(%Post{id: random_id}, community) + {:ok, _pined_post} = CMS.pin_article(:post, random_id, community.id) # {:ok, _} = CMS.set_community_flags(community, %Post{id: random_id}, %{pin: true}) results = guest_conn |> query_result(@query, variables, "pagedPosts") diff --git a/test/groupher_server_web/query/cms/repos_flags_test.exs b/test/groupher_server_web/query/cms/repos_flags_test.exs index 27e770c84..021056e0c 100644 --- a/test/groupher_server_web/query/cms/repos_flags_test.exs +++ b/test/groupher_server_web/query/cms/repos_flags_test.exs @@ -38,7 +38,7 @@ defmodule GroupherServer.Test.Query.ReposFlags do pagedRepos(filter: $filter) { entries { id - pin + isPinned communities { raw } @@ -61,16 +61,17 @@ defmodule GroupherServer.Test.Query.ReposFlags do assert results["pageSize"] == @page_size assert results["totalCount"] == @total_count - {:ok, _pined_post} = CMS.pin_content(repo_m, community) + {:ok, _pined_post} = CMS.pin_article(:repo, repo_m.id, community.id) results = guest_conn |> query_result(@query, variables, "pagedRepos") entries_first = results["entries"] |> List.first() assert results["totalCount"] == @total_count assert entries_first["id"] == to_string(repo_m.id) - assert entries_first["pin"] == true + assert entries_first["isPinned"] == true end + @tag :wip test "pind repos should not appear when page > 1", ~m(guest_conn community)a do variables = %{filter: %{page: 2, size: 20}} results = guest_conn |> query_result(@query, variables, "pagedRepos") @@ -78,7 +79,7 @@ defmodule GroupherServer.Test.Query.ReposFlags do random_id = results["entries"] |> Enum.shuffle() |> List.first() |> Map.get("id") - {:ok, _pined_post} = CMS.pin_content(%Repo{id: random_id}, community) + {:ok, _pined_post} = CMS.pin_article(:repo, random_id, community.id) results = guest_conn |> query_result(@query, variables, "pagedRepos") assert results["entries"] |> Enum.any?(&(&1["id"] !== random_id))