Fix editing event from original instance on a group event

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

View File

@ -147,28 +147,48 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
# Set the participant to approved if the default role for new participants is :participant # Set the participant to approved if the default role for new participants is :participant
defp approve_if_default_role_is_participant(event, activity_data, participant, role) do defp approve_if_default_role_is_participant(event, activity_data, participant, role) do
if event.local do case event do
cond do %Event{attributed_to: %Actor{id: group_id, url: group_url}} ->
Mobilizon.Events.get_default_participant_role(event) === :participant && case Actors.get_single_group_moderator_actor(group_id) do
role == :participant -> %Actor{} = actor ->
{:accept, do_approve(event, activity_data, participant, role, %{
ActivityPub.accept( "actor" => actor.url,
:join, "attributedTo" => group_url
participant, })
true,
%{"actor" => event.organizer_actor.url}
)}
Mobilizon.Events.get_default_participant_role(event) === :not_approved && _ ->
role == :not_approved -> {:ok, activity_data, participant}
Scheduler.pending_participation_notification(event) end
{:ok, activity_data, participant}
true -> %Event{local: true} ->
{:ok, activity_data, participant} do_approve(event, activity_data, participant, role, %{
end "actor" => event.organizer_actor.url
else })
{:ok, activity_data, participant}
_ ->
{:ok, activity_data, participant}
end
end
defp do_approve(event, activity_data, participant, role, additionnal) do
cond do
Mobilizon.Events.get_default_participant_role(event) === :participant &&
role == :participant ->
{:accept,
ActivityPub.accept(
:join,
participant,
true,
additionnal
)}
Mobilizon.Events.get_default_participant_role(event) === :not_approved &&
role == :not_approved ->
Scheduler.pending_participation_notification(event)
{:ok, activity_data, participant}
true ->
{:ok, activity_data, participant}
end end
end end