Even more fixes

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-06-15 19:41:11 +02:00
parent 2e85a4a3d3
commit ef6a1a21ac
17 changed files with 213 additions and 67 deletions

View File

@@ -425,6 +425,16 @@ defmodule Mobilizon.Events do
|> Repo.all()
end
@spec is_user_moderator_for_event?(integer | String.t(), integer | String.t()) :: boolean
def is_user_moderator_for_event?(user_id, event_id) do
Participant
|> join(:inner, [p], a in Actor, on: p.actor_id == a.id)
|> where([p, _a], p.event_id == ^event_id)
|> where([_p, a], a.user_id == ^user_id)
|> where([p, _a], p.role == ^:creator)
|> Repo.exists?()
end
@doc """
Finds close events to coordinates.
Radius is in meters and defaults to 50km.
@@ -741,7 +751,8 @@ defmodule Mobilizon.Events do
|> Repo.one()
end
@default_participant_roles [:participant, :moderator, :administrator, :creator]
@moderator_roles [:moderator, :administrator, :creator]
@default_participant_roles [:participant] ++ @moderator_roles
@doc """
Returns the list of participants for an event.
@@ -810,7 +821,7 @@ defmodule Mobilizon.Events do
where:
p.event_id == ^event_id and
p.actor_id ==
^actor_id and p.role in ^[:moderator, :administrator, :creator]
^actor_id and p.role in ^@moderator_roles
)
) == nil)
end