mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-18 15:08:00 +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'
57 lines
1.8 KiB
Elixir
57 lines
1.8 KiB
Elixir
defmodule PhilomenaWeb.Image.Comment.HideController do
|
|
use PhilomenaWeb, :controller
|
|
|
|
alias Philomena.Comments.Comment
|
|
alias Philomena.Comments
|
|
|
|
plug PhilomenaWeb.CanaryMapPlug, create: :hide, delete: :hide
|
|
plug :load_and_authorize_resource, model: Comment, id_name: "comment_id", persisted: true
|
|
|
|
def create(conn, %{"comment" => comment_params}) do
|
|
comment = conn.assigns.comment
|
|
user = conn.assigns.current_user
|
|
|
|
case Comments.hide_comment(comment, comment_params, user) do
|
|
{:ok, comment} ->
|
|
conn
|
|
|> put_flash(:info, "Comment successfully hidden!")
|
|
|> moderation_log(details: &log_details/2, data: comment)
|
|
|> redirect(to: ~p"/images/#{comment.image_id}" <> "#comment_#{comment.id}")
|
|
|
|
_error ->
|
|
conn
|
|
|> put_flash(:error, "Unable to hide comment!")
|
|
|> redirect(to: ~p"/images/#{comment.image_id}" <> "#comment_#{comment.id}")
|
|
end
|
|
end
|
|
|
|
def delete(conn, _params) do
|
|
comment = conn.assigns.comment
|
|
|
|
case Comments.unhide_comment(comment) do
|
|
{:ok, comment} ->
|
|
conn
|
|
|> put_flash(:info, "Comment successfully unhidden!")
|
|
|> moderation_log(details: &log_details/2, data: comment)
|
|
|> redirect(to: ~p"/images/#{comment.image_id}" <> "#comment_#{comment.id}")
|
|
|
|
{:error, _changeset} ->
|
|
conn
|
|
|> put_flash(:error, "Unable to unhide comment!")
|
|
|> redirect(to: ~p"/images/#{comment.image_id}" <> "#comment_#{comment.id}")
|
|
end
|
|
end
|
|
|
|
defp log_details(action, comment) do
|
|
body =
|
|
case action do
|
|
:create -> "Hidden comment on image >>#{comment.image_id} (#{comment.deletion_reason})"
|
|
:delete -> "Restored comment on image >>#{comment.image_id}"
|
|
end
|
|
|
|
%{
|
|
body: body,
|
|
subject_path: ~p"/images/#{comment.image_id}" <> "#comment_#{comment.id}"
|
|
}
|
|
end
|
|
end
|