Add API to join and leave an event
This commit is contained in:
committed by
Thomas Citharel
parent
421fbda9fa
commit
250f0b3bd1
@@ -138,15 +138,10 @@ defmodule Mobilizon.Actors.User do
|
||||
{:ok, user}
|
||||
end
|
||||
|
||||
def owns_actor(%User{default_actor_id: default_actor_id}, %Actor{id: actor_id})
|
||||
when default_actor_id == actor_id do
|
||||
{:is_owned, true}
|
||||
end
|
||||
|
||||
def owns_actor(%User{actors: actors}, actor_id) do
|
||||
case Enum.any?(actors, fn a -> a.id == actor_id end) do
|
||||
true -> {:is_owned, true}
|
||||
_ -> {:is_owned, false}
|
||||
case Enum.find(actors, fn a -> a.id == actor_id end) do
|
||||
nil -> {:is_owned, false}
|
||||
actor -> {:is_owned, true, actor}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -600,6 +600,16 @@ defmodule Mobilizon.Events do
|
||||
Repo.get_by!(Participant, event_id: event_id, actor_id: actor_id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get a single participant
|
||||
"""
|
||||
def get_participant(event_id, actor_id) do
|
||||
case Repo.get_by(Participant, event_id: event_id, actor_id: actor_id) do
|
||||
nil -> {:error, :participant_not_found}
|
||||
participant -> {:ok, participant}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a participant.
|
||||
|
||||
@@ -665,6 +675,18 @@ defmodule Mobilizon.Events do
|
||||
Participant.changeset(participant, %{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get the default participant role depending on the event visbility
|
||||
"""
|
||||
def get_default_participant_role(%Event{} = event) do
|
||||
case event.visibility do
|
||||
# Participant
|
||||
:public -> 1
|
||||
# Not approved
|
||||
_ -> 0
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
List event participation requests for an actor
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user