Fix creating an mz activity when updating an event with some subfields
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
d31bdc99f8
commit
fea97f3713
@ -64,7 +64,8 @@ defmodule Mobilizon.Events.Event do
|
|||||||
tags: [Tag.t()],
|
tags: [Tag.t()],
|
||||||
participants: [Actor.t()],
|
participants: [Actor.t()],
|
||||||
contacts: [Actor.t()],
|
contacts: [Actor.t()],
|
||||||
language: String.t()
|
language: String.t(),
|
||||||
|
metadata: [EventMetadata.t()]
|
||||||
}
|
}
|
||||||
|
|
||||||
@update_required_attrs [:title, :begins_on, :organizer_actor_id]
|
@update_required_attrs [:title, :begins_on, :organizer_actor_id]
|
||||||
|
@ -19,7 +19,6 @@ defmodule Mobilizon.Events do
|
|||||||
|
|
||||||
alias Mobilizon.Events.{
|
alias Mobilizon.Events.{
|
||||||
Event,
|
Event,
|
||||||
EventOptions,
|
|
||||||
EventParticipantStats,
|
EventParticipantStats,
|
||||||
FeedToken,
|
FeedToken,
|
||||||
Participant,
|
Participant,
|
||||||
@ -329,37 +328,28 @@ defmodule Mobilizon.Events do
|
|||||||
defp build_changes(changes) do
|
defp build_changes(changes) do
|
||||||
changes
|
changes
|
||||||
|> Map.take(Event.__schema__(:fields))
|
|> Map.take(Event.__schema__(:fields))
|
||||||
|> maybe_add_address(changes)
|
|> maybe_add_field(:physical_address)
|
||||||
|> maybe_add_options(changes)
|
|> maybe_add_field(:options)
|
||||||
|
|> maybe_add_field(:metadata)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec maybe_add_address(map(), map()) :: map()
|
@spec maybe_add_field(map(), atom()) :: map()
|
||||||
defp maybe_add_address(changes, %{physical_address: %Ecto.Changeset{} = changeset}),
|
defp maybe_add_field(changes, field) do
|
||||||
do:
|
case Map.get(changes, field) do
|
||||||
Map.put(
|
%Ecto.Changeset{} = changeset ->
|
||||||
changes,
|
Map.put(
|
||||||
:physical_address,
|
changes,
|
||||||
changeset
|
field,
|
||||||
|> Ecto.Changeset.apply_changes()
|
changeset
|
||||||
|> Map.from_struct()
|
|> Ecto.Changeset.apply_changes()
|
||||||
|> Map.take(Address.__schema__(:fields))
|
|> Map.from_struct()
|
||||||
)
|
|> Map.take(Address.__schema__(:fields))
|
||||||
|
)
|
||||||
|
|
||||||
defp maybe_add_address(changes, _), do: Map.drop(changes, [:physical_address])
|
_ ->
|
||||||
|
Map.drop(changes, [field])
|
||||||
@spec maybe_add_options(map(), map()) :: map()
|
end
|
||||||
defp maybe_add_options(changes, %{options: %Ecto.Changeset{} = changeset}),
|
end
|
||||||
do:
|
|
||||||
Map.put(
|
|
||||||
changes,
|
|
||||||
:options,
|
|
||||||
changeset
|
|
||||||
|> Ecto.Changeset.apply_changes()
|
|
||||||
|> Map.from_struct()
|
|
||||||
|> Map.take(EventOptions.__schema__(:fields))
|
|
||||||
)
|
|
||||||
|
|
||||||
defp maybe_add_options(changes, _), do: Map.drop(changes, [:options])
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Deletes an event.
|
Deletes an event.
|
||||||
|
Loading…
Reference in New Issue
Block a user