mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-04-11 05:57:37 +02:00
commit
783defce35
1 changed files with 16 additions and 1 deletions
|
@ -5,7 +5,13 @@ defmodule PhilomenaWeb.Admin.DnpEntry.TransitionController do
|
|||
alias Philomena.DnpEntries
|
||||
|
||||
plug :verify_authorized
|
||||
plug :load_resource, model: DnpEntry, only: [:create], id_name: "dnp_entry_id", persisted: true
|
||||
|
||||
plug :load_resource,
|
||||
model: DnpEntry,
|
||||
only: [:create],
|
||||
id_name: "dnp_entry_id",
|
||||
preload: [:tag],
|
||||
persisted: true
|
||||
|
||||
def create(conn, %{"state" => new_state}) do
|
||||
case DnpEntries.transition_dnp_entry(
|
||||
|
@ -16,6 +22,7 @@ defmodule PhilomenaWeb.Admin.DnpEntry.TransitionController do
|
|||
{:ok, dnp_entry} ->
|
||||
conn
|
||||
|> put_flash(:info, "Successfully updated DNP entry.")
|
||||
|> moderation_log(details: &log_details/2, data: dnp_entry)
|
||||
|> redirect(to: ~p"/dnp/#{dnp_entry}")
|
||||
|
||||
{:error, _changeset} ->
|
||||
|
@ -31,4 +38,12 @@ defmodule PhilomenaWeb.Admin.DnpEntry.TransitionController do
|
|||
_false -> PhilomenaWeb.NotAuthorizedPlug.call(conn)
|
||||
end
|
||||
end
|
||||
|
||||
defp log_details(_action, dnp_entry) do
|
||||
%{
|
||||
body:
|
||||
"#{String.capitalize(dnp_entry.aasm_state)} DNP entry #{dnp_entry.id} on #{dnp_entry.tag.name}",
|
||||
subject_path: ~p"/dnp/#{dnp_entry}"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue