Allow to accept / reject participants
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -24,6 +24,7 @@ defmodule MobilizonWeb.API.Events do
|
||||
begins_on: begins_on,
|
||||
ends_on: ends_on,
|
||||
category: category,
|
||||
join_options: join_options,
|
||||
options: options
|
||||
} <- prepare_args(args),
|
||||
event <-
|
||||
@@ -39,7 +40,8 @@ defmodule MobilizonWeb.API.Events do
|
||||
ends_on: ends_on,
|
||||
physical_address: physical_address,
|
||||
category: category,
|
||||
options: options
|
||||
options: options,
|
||||
join_options: join_options
|
||||
}
|
||||
) do
|
||||
ActivityPub.create(%{
|
||||
@@ -73,6 +75,7 @@ defmodule MobilizonWeb.API.Events do
|
||||
begins_on: begins_on,
|
||||
ends_on: ends_on,
|
||||
category: category,
|
||||
join_options: join_options,
|
||||
options: options
|
||||
} <-
|
||||
prepare_args(Map.merge(event, args)),
|
||||
@@ -89,6 +92,7 @@ defmodule MobilizonWeb.API.Events do
|
||||
ends_on: ends_on,
|
||||
physical_address: physical_address,
|
||||
category: category,
|
||||
join_options: join_options,
|
||||
options: options
|
||||
},
|
||||
event.uuid,
|
||||
@@ -112,7 +116,8 @@ defmodule MobilizonWeb.API.Events do
|
||||
options: options,
|
||||
tags: tags,
|
||||
begins_on: begins_on,
|
||||
category: category
|
||||
category: category,
|
||||
join_options: join_options
|
||||
} = args
|
||||
) do
|
||||
with physical_address <- Map.get(args, :physical_address, nil),
|
||||
@@ -132,6 +137,7 @@ defmodule MobilizonWeb.API.Events do
|
||||
begins_on: begins_on,
|
||||
ends_on: Map.get(args, :ends_on, nil),
|
||||
category: category,
|
||||
join_options: join_options,
|
||||
options: options
|
||||
}
|
||||
end
|
||||
|
||||
@@ -4,9 +4,9 @@ defmodule MobilizonWeb.API.Participations do
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
require Logger
|
||||
|
||||
@spec join(Event.t(), Actor.t()) :: {:ok, Participant.t()}
|
||||
def join(%Event{id: event_id} = event, %Actor{id: actor_id} = actor) do
|
||||
@@ -21,4 +21,42 @@ defmodule MobilizonWeb.API.Participations do
|
||||
{:ok, activity, participant}
|
||||
end
|
||||
end
|
||||
|
||||
def accept(
|
||||
%Participant{} = participation,
|
||||
%Actor{} = moderator
|
||||
) do
|
||||
with {:ok, activity, _} <-
|
||||
ActivityPub.accept(
|
||||
%{
|
||||
to: [participation.actor.url],
|
||||
actor: moderator.url,
|
||||
object: participation.url
|
||||
},
|
||||
"#{MobilizonWeb.Endpoint.url()}/accept/join/#{participation.id}"
|
||||
),
|
||||
{:ok, %Participant{role: :participant} = participation} <-
|
||||
Events.update_participant(participation, %{"role" => :participant}) do
|
||||
{:ok, activity, participation}
|
||||
end
|
||||
end
|
||||
|
||||
def reject(
|
||||
%Participant{} = participation,
|
||||
%Actor{} = moderator
|
||||
) do
|
||||
with {:ok, activity, _} <-
|
||||
ActivityPub.reject(
|
||||
%{
|
||||
to: [participation.actor.url],
|
||||
actor: moderator.url,
|
||||
object: participation.url
|
||||
},
|
||||
"#{MobilizonWeb.Endpoint.url()}/reject/join/#{participation.id}"
|
||||
),
|
||||
{:ok, %Participant{} = participation} <-
|
||||
Events.delete_participant(participation) do
|
||||
{:ok, activity, participation}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user