Improve searching for group actors
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -13,7 +13,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Followers do
|
||||
@spec find_followers_for_group(Actor.t(), map(), map()) :: {:ok, Page.t()}
|
||||
def find_followers_for_group(
|
||||
%Actor{id: group_id} = group,
|
||||
%{page: page, limit: limit} = args,
|
||||
args,
|
||||
%{
|
||||
context: %{
|
||||
current_user: %User{role: user_role},
|
||||
@@ -21,15 +21,23 @@ defmodule Mobilizon.GraphQL.Resolvers.Followers do
|
||||
}
|
||||
}
|
||||
) do
|
||||
followers = group_followers(group, args)
|
||||
|
||||
if Actors.is_moderator?(actor_id, group_id) or is_moderator(user_role) do
|
||||
{:ok,
|
||||
Actors.list_paginated_followers_for_actor(group, Map.get(args, :approved), page, limit)}
|
||||
{:ok, followers}
|
||||
else
|
||||
{:error, :unauthorized}
|
||||
{:ok, %Page{followers | elements: []}}
|
||||
end
|
||||
end
|
||||
|
||||
def find_followers_for_group(_, _, _), do: {:error, :unauthenticated}
|
||||
def find_followers_for_group(%Actor{} = group, args, _) do
|
||||
followers = group_followers(group, args)
|
||||
{:ok, %Page{followers | elements: []}}
|
||||
end
|
||||
|
||||
defp group_followers(group, %{page: page, limit: limit} = args) do
|
||||
Actors.list_paginated_followers_for_actor(group, Map.get(args, :approved), page, limit)
|
||||
end
|
||||
|
||||
@spec update_follower(any(), map(), map()) :: {:ok, Follower.t()} | {:error, any()}
|
||||
def update_follower(_, %{id: follower_id, approved: approved}, %{
|
||||
|
||||
@@ -21,7 +21,14 @@ defmodule Mobilizon.GraphQL.Resolvers.Search do
|
||||
"""
|
||||
@spec search_groups(any(), map(), Absinthe.Resolution.t()) ::
|
||||
{:ok, Page.t(Actor.t())} | {:error, String.t()}
|
||||
def search_groups(_parent, %{page: page, limit: limit} = args, _resolution) do
|
||||
def search_groups(
|
||||
_parent,
|
||||
%{page: page, limit: limit} = args,
|
||||
%{context: context} = _resolution
|
||||
) do
|
||||
current_actor = Map.get(context, :current_actor, nil)
|
||||
current_actor_id = if current_actor, do: current_actor.id, else: nil
|
||||
args = Map.put(args, :current_actor_id, current_actor_id)
|
||||
Search.search_actors(args, page, limit, :Group)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user