2022-03-22 22:23:30 +01:00
|
|
|
defmodule PhilomenaWeb.Image.Comment.ApproveController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
|
|
|
alias Philomena.Comments.Comment
|
|
|
|
alias Philomena.Comments
|
|
|
|
alias Philomena.UserStatistics
|
|
|
|
|
|
|
|
plug PhilomenaWeb.CanaryMapPlug, create: :approve
|
|
|
|
|
|
|
|
plug :load_and_authorize_resource,
|
|
|
|
model: Comment,
|
|
|
|
id_name: "comment_id",
|
|
|
|
persisted: true,
|
|
|
|
preload: [:user]
|
|
|
|
|
|
|
|
def create(conn, _params) do
|
|
|
|
comment = conn.assigns.comment
|
|
|
|
|
|
|
|
{:ok, _comment} = Comments.approve_comment(comment, conn.assigns.current_user)
|
|
|
|
|
|
|
|
UserStatistics.inc_stat(comment.user, :comments_posted)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_flash(:info, "Comment has been approved.")
|
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}")
|
2022-03-22 22:23:30 +01:00
|
|
|
end
|
|
|
|
|
2024-06-23 16:42:29 +02:00
|
|
|
defp log_details(_action, comment) do
|
2022-03-22 22:23:30 +01:00
|
|
|
%{
|
|
|
|
body: "Approved comment on image >>#{comment.image_id}",
|
2024-04-29 02:55:27 +02:00
|
|
|
subject_path: ~p"/images/#{comment.image_id}" <> "#comment_#{comment.id}"
|
2022-03-22 22:23:30 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|