Improve Federation boundaries
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
defmodule Mobilizon.Service.Admin.ActionLog do
|
||||
@moduledoc """
|
||||
Module to handle action log creations.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.{Admin, Users}
|
||||
alias Mobilizon.Admin.ActionLog
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
@doc """
|
||||
Log an admin action
|
||||
"""
|
||||
@spec log_action(Actor.t(), String.t(), String.t()) :: {:ok, ActionLog.t()}
|
||||
def log_action(%Actor{user_id: user_id, id: actor_id}, action, target) do
|
||||
with %User{role: role} <- Users.get_user!(user_id),
|
||||
{:role, true} <- {:role, role in [:administrator, :moderator]},
|
||||
{:ok, %ActionLog{} = create_action_log} <-
|
||||
Admin.create_action_log(%{
|
||||
"actor_id" => actor_id,
|
||||
"target_type" => to_string(target.__struct__),
|
||||
"target_id" => target.id,
|
||||
"action" => action,
|
||||
"changes" => stringify_struct(target)
|
||||
}) do
|
||||
{:ok, create_action_log}
|
||||
end
|
||||
end
|
||||
|
||||
defp stringify_struct(%_{} = struct) do
|
||||
association_fields = struct.__struct__.__schema__(:associations)
|
||||
|
||||
struct
|
||||
|> Map.from_struct()
|
||||
|> Map.drop(association_fields ++ [:__meta__])
|
||||
end
|
||||
|
||||
defp stringify_struct(struct), do: struct
|
||||
end
|
||||
@@ -14,4 +14,3 @@ defmodule Mobilizon.Service.Formatter.HTML do
|
||||
|
||||
def filter_tags(html), do: Scrubber.scrub(html, DefaultScrubbler)
|
||||
end
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ defmodule Mobilizon.Service.Workers.Helper do
|
||||
"""
|
||||
|
||||
alias Mobilizon.Config
|
||||
alias Mobilizon.Service.Workers.Helper
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
def worker_args(queue) do
|
||||
@@ -40,7 +41,7 @@ defmodule Mobilizon.Service.Workers.Helper do
|
||||
def enqueue(operation, params, worker_args \\ []) do
|
||||
params = Map.merge(%{"op" => operation}, params)
|
||||
queue_atom = String.to_existing_atom(unquote(queue))
|
||||
worker_args = worker_args ++ __MODULE__.worker_args(queue_atom)
|
||||
worker_args = worker_args ++ Helper.worker_args(queue_atom)
|
||||
|
||||
unquote(caller_module)
|
||||
|> apply(:new, [params, worker_args])
|
||||
|
||||
Reference in New Issue
Block a user