mirror of
https://framagit.org/framasoft/mobilizon.git
synced 2024-12-21 23:44:30 +00:00
Fix action logs containing group suspension events
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
39ea05a04a
commit
8519364e77
2 changed files with 25 additions and 16 deletions
|
@ -42,7 +42,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
||||||
target_type
|
target_type
|
||||||
|> String.to_existing_atom()
|
|> String.to_existing_atom()
|
||||||
|> transform_action_log(action, action_log)
|
|> transform_action_log(action, action_log)
|
||||||
|> Map.merge(%{actor: actor, id: id, inserted_at: inserted_at})
|
|> add_extra_data(actor, id, inserted_at)
|
||||||
end)
|
end)
|
||||||
|> Enum.filter(& &1)
|
|> Enum.filter(& &1)
|
||||||
|
|
||||||
|
@ -54,6 +54,12 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
||||||
{:error, dgettext("errors", "You need to be logged-in and a moderator to list action logs")}
|
{:error, dgettext("errors", "You need to be logged-in and a moderator to list action logs")}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp add_extra_data(nil, _actor, _id, _inserted_at), do: nil
|
||||||
|
|
||||||
|
defp add_extra_data(map, actor, id, inserted_at) do
|
||||||
|
Map.merge(map, %{actor: actor, id: id, inserted_at: inserted_at})
|
||||||
|
end
|
||||||
|
|
||||||
@spec transform_action_log(module(), atom(), ActionLog.t()) :: map()
|
@spec transform_action_log(module(), atom(), ActionLog.t()) :: map()
|
||||||
defp transform_action_log(
|
defp transform_action_log(
|
||||||
Report,
|
Report,
|
||||||
|
@ -127,22 +133,22 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
||||||
# Changes are stored as %{"key" => "value"} so we need to convert them back as struct
|
# Changes are stored as %{"key" => "value"} so we need to convert them back as struct
|
||||||
@spec convert_changes_to_struct(module(), map()) :: struct()
|
@spec convert_changes_to_struct(module(), map()) :: struct()
|
||||||
defp convert_changes_to_struct(struct, %{"report_id" => _report_id} = changes) do
|
defp convert_changes_to_struct(struct, %{"report_id" => _report_id} = changes) do
|
||||||
with data <- for({key, val} <- changes, into: %{}, do: {String.to_existing_atom(key), val}),
|
data = for({key, val} <- changes, into: %{}, do: {String.to_existing_atom(key), val})
|
||||||
data <- Map.put(data, :report, Mobilizon.Reports.get_report(data.report_id)) do
|
data = Map.put(data, :report, Mobilizon.Reports.get_report(data.report_id))
|
||||||
struct(struct, data)
|
struct(struct, data)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp convert_changes_to_struct(struct, changes) do
|
defp convert_changes_to_struct(struct, changes) do
|
||||||
with changeset <- struct.__changeset__,
|
changeset = struct.__changeset__
|
||||||
data <-
|
|
||||||
for(
|
data =
|
||||||
{key, val} <- changes,
|
for(
|
||||||
into: %{},
|
{key, val} <- changes,
|
||||||
do: {String.to_existing_atom(key), process_eventual_type(changeset, key, val)}
|
into: %{},
|
||||||
) do
|
do: {String.to_existing_atom(key), process_eventual_type(changeset, key, val)}
|
||||||
struct(struct, data)
|
)
|
||||||
end
|
|
||||||
|
struct(struct, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
# datetimes are not unserialized as DateTime/NaiveDateTime so we do it manually with changeset data
|
# datetimes are not unserialized as DateTime/NaiveDateTime so we do it manually with changeset data
|
||||||
|
@ -150,6 +156,9 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
||||||
DateTime.t() | NaiveDateTime.t() | any()
|
DateTime.t() | NaiveDateTime.t() | any()
|
||||||
defp process_eventual_type(changeset, key, val) do
|
defp process_eventual_type(changeset, key, val) do
|
||||||
cond do
|
cond do
|
||||||
|
changeset[String.to_existing_atom(key)] == Mobilizon.Actors.ActorType and not is_nil(val) ->
|
||||||
|
String.to_existing_atom(val)
|
||||||
|
|
||||||
changeset[String.to_existing_atom(key)] == :utc_datetime and not is_nil(val) ->
|
changeset[String.to_existing_atom(key)] == :utc_datetime and not is_nil(val) ->
|
||||||
{:ok, datetime, _} = DateTime.from_iso8601(val)
|
{:ok, datetime, _} = DateTime.from_iso8601(val)
|
||||||
datetime
|
datetime
|
||||||
|
|
|
@ -64,13 +64,13 @@ defmodule Mobilizon.GraphQL.Schema.AdminType do
|
||||||
%Comment{}, _ ->
|
%Comment{}, _ ->
|
||||||
:comment
|
:comment
|
||||||
|
|
||||||
%Actor{type: "Person"}, _ ->
|
%Actor{type: :Person}, _ ->
|
||||||
:person
|
:person
|
||||||
|
|
||||||
%User{}, _ ->
|
%User{}, _ ->
|
||||||
:user
|
:user
|
||||||
|
|
||||||
%Actor{type: "Group"}, _ ->
|
%Actor{type: :Group}, _ ->
|
||||||
:group
|
:group
|
||||||
|
|
||||||
_, _ ->
|
_, _ ->
|
||||||
|
|
Loading…
Reference in a new issue