1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-23 00:14:48 +00:00

Add Actors.get_single_group_moderator_actor/1 and refactor

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-07-30 17:30:00 +02:00
parent c788c020db
commit 630de6fee9
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -794,11 +794,18 @@ defmodule Mobilizon.Actors do
@spec get_single_group_member_actor(integer() | String.t()) :: Actor.t() | nil @spec get_single_group_member_actor(integer() | String.t()) :: Actor.t() | nil
def get_single_group_member_actor(group_id) do def get_single_group_member_actor(group_id) do
do_get_single_group_member_actor(group_id, [:member, :moderator, :administrator, :creator])
end
@spec get_single_group_moderator_actor(integer() | String.t()) :: Actor.t() | nil
def get_single_group_moderator_actor(group_id) do
do_get_single_group_member_actor(group_id, [:moderator, :administrator, :creator])
end
@spec do_get_single_group_member_actor(integer() | String.t(), list(atom())) :: Actor.t() | nil
defp do_get_single_group_member_actor(group_id, roles) do
Member Member
|> where( |> where([m], m.parent_id == ^group_id and m.role in ^roles)
[m],
m.parent_id == ^group_id and m.role in [^:member, ^:moderator, ^:administrator, ^:creator]
)
|> join(:inner, [m], a in Actor, on: m.actor_id == a.id) |> join(:inner, [m], a in Actor, on: m.actor_id == a.id)
|> where([_m, a], is_nil(a.domain)) |> where([_m, a], is_nil(a.domain))
|> limit(1) |> limit(1)