mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
dfeefb1651
git grep -l 'defp log_details(_conn' | xargs sed -i -e 's/defp log_details(_conn, /defp log_details(/g' git grep -l '&log_details/3' | xargs sed -i -e 's|\&log_details/3|\&log_details/2|g'
47 lines
1.2 KiB
Elixir
47 lines
1.2 KiB
Elixir
defmodule PhilomenaWeb.Image.DestroyController do
|
|
use PhilomenaWeb, :controller
|
|
|
|
alias Philomena.Images.Image
|
|
alias Philomena.Images
|
|
|
|
plug PhilomenaWeb.CanaryMapPlug, create: :destroy
|
|
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
|
plug :verify_deleted when action in [:create]
|
|
|
|
def create(conn, _params) do
|
|
image = conn.assigns.image
|
|
|
|
case Images.destroy_image(image) do
|
|
{:ok, image} ->
|
|
conn
|
|
|> put_flash(:info, "Image contents destroyed.")
|
|
|> moderation_log(details: &log_details/2, data: image)
|
|
|> redirect(to: ~p"/images/#{image}")
|
|
|
|
_error ->
|
|
conn
|
|
|> put_flash(:error, "Failed to destroy image.")
|
|
|> redirect(to: ~p"/images/#{image}")
|
|
end
|
|
end
|
|
|
|
defp verify_deleted(conn, _opts) do
|
|
case conn.assigns.image.hidden_from_users do
|
|
true ->
|
|
conn
|
|
|
|
_false ->
|
|
conn
|
|
|> put_flash(:error, "Cannot destroy a non-hidden image!")
|
|
|> redirect(to: ~p"/images/#{conn.assigns.image}")
|
|
|> halt()
|
|
end
|
|
end
|
|
|
|
defp log_details(_action, image) do
|
|
%{
|
|
body: "Hard-deleted image >>#{image.id}",
|
|
subject_path: ~p"/images/#{image}"
|
|
}
|
|
end
|
|
end
|