Change some String.to_atom/1 to String.to_existing_atom/1
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
b7915a6467
commit
21698f754d
|
@ -123,7 +123,7 @@ 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
|
||||||
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_atom(key), val}),
|
with 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)) do
|
||||||
struct(struct, data)
|
struct(struct, data)
|
||||||
end
|
end
|
||||||
|
@ -135,7 +135,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
||||||
for(
|
for(
|
||||||
{key, val} <- changes,
|
{key, val} <- changes,
|
||||||
into: %{},
|
into: %{},
|
||||||
do: {String.to_atom(key), process_eventual_type(changeset, key, val)}
|
do: {String.to_existing_atom(key), process_eventual_type(changeset, key, val)}
|
||||||
) do
|
) do
|
||||||
struct(struct, data)
|
struct(struct, data)
|
||||||
end
|
end
|
||||||
|
@ -144,11 +144,11 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
||||||
# 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
|
||||||
defp process_eventual_type(changeset, key, val) do
|
defp process_eventual_type(changeset, key, val) do
|
||||||
cond do
|
cond do
|
||||||
changeset[String.to_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
|
||||||
|
|
||||||
changeset[String.to_atom(key)] == :naive_datetime and not is_nil(val) ->
|
changeset[String.to_existing_atom(key)] == :naive_datetime and not is_nil(val) ->
|
||||||
{:ok, datetime} = NaiveDateTime.from_iso8601(val)
|
{:ok, datetime} = NaiveDateTime.from_iso8601(val)
|
||||||
datetime
|
datetime
|
||||||
|
|
||||||
|
|
|
@ -296,18 +296,6 @@ defmodule Mobilizon.Actors do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# defp transform_media_file(nil), do: nil
|
|
||||||
|
|
||||||
# defp transform_media_file(file) do
|
|
||||||
# file = for({key, val} <- file, into: %{}, do: {String.to_atom(key), val})
|
|
||||||
|
|
||||||
# if is_nil(file) do
|
|
||||||
# nil
|
|
||||||
# else
|
|
||||||
# struct(Mobilizon.Medias.File, file)
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
@delete_actor_default_options [reserve_username: true, suspension: false]
|
@delete_actor_default_options [reserve_username: true, suspension: false]
|
||||||
|
|
||||||
def delete_actor(%Actor{} = actor, options \\ @delete_actor_default_options) do
|
def delete_actor(%Actor{} = actor, options \\ @delete_actor_default_options) do
|
||||||
|
|
Loading…
Reference in a new issue