2019-12-10 21:29:48 +01:00
|
|
|
defmodule PhilomenaWeb.Image.Comment.DeleteController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
|
|
|
alias Philomena.Comments.Comment
|
|
|
|
alias Philomena.Comments
|
|
|
|
|
2019-12-12 05:41:33 +01:00
|
|
|
plug PhilomenaWeb.CanaryMapPlug, create: :hide
|
2019-12-10 21:29:48 +01:00
|
|
|
plug :load_and_authorize_resource, model: Comment, id_name: "comment_id", persisted: true
|
|
|
|
|
2019-12-12 05:41:33 +01:00
|
|
|
def create(conn, _params) do
|
2019-12-11 23:21:14 +01:00
|
|
|
comment = conn.assigns.comment
|
|
|
|
|
|
|
|
case Comments.destroy_comment(comment) do
|
|
|
|
{:ok, comment} ->
|
|
|
|
Comments.reindex_comment(comment)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_flash(:info, "Comment successfully destroyed!")
|
2024-06-23 16:42:29 +02:00
|
|
|
|> moderation_log(details: &log_details/2, data: comment)
|
2024-04-29 02:55:27 +02:00
|
|
|
|> redirect(to: ~p"/images/#{comment.image_id}" <> "#comment_#{comment.id}")
|
2019-12-12 05:41:33 +01:00
|
|
|
|
2019-12-11 23:21:14 +01:00
|
|
|
{:error, _changeset} ->
|
|
|
|
conn
|
|
|
|
|> put_flash(:error, "Unable to destroy comment!")
|
2024-04-29 02:55:27 +02:00
|
|
|
|> redirect(to: ~p"/images/#{comment.image_id}" <> "#comment_#{comment.id}")
|
2019-12-11 23:21:14 +01:00
|
|
|
end
|
2019-12-10 21:29:48 +01:00
|
|
|
end
|
2021-11-07 19:51:55 +01:00
|
|
|
|
2024-06-23 16:42:29 +02:00
|
|
|
defp log_details(_action, comment) do
|
2021-11-07 19:51:55 +01:00
|
|
|
%{
|
|
|
|
body: "Destroyed comment on image >>#{comment.image_id}",
|
2024-04-29 02:55:27 +02:00
|
|
|
subject_path: ~p"/images/#{comment.image_id}" <> "#comment_#{comment.id}"
|
2021-11-07 19:51:55 +01:00
|
|
|
}
|
|
|
|
end
|
2019-12-10 21:29:48 +01:00
|
|
|
end
|