2022-03-24 17:31:57 +01:00
|
|
|
defmodule PhilomenaWeb.Conversation.Message.ApproveController do
|
2022-03-22 22:23:30 +01:00
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
2022-03-24 17:31:57 +01:00
|
|
|
alias Philomena.Conversations.Message
|
2022-03-22 22:23:30 +01:00
|
|
|
alias Philomena.Conversations
|
|
|
|
|
|
|
|
plug PhilomenaWeb.CanaryMapPlug, create: :approve
|
|
|
|
|
|
|
|
plug :load_and_authorize_resource,
|
2022-03-24 17:31:57 +01:00
|
|
|
model: Message,
|
|
|
|
id_name: "message_id",
|
|
|
|
persisted: true,
|
|
|
|
preload: [:conversation]
|
2022-03-22 22:23:30 +01:00
|
|
|
|
|
|
|
def create(conn, _params) do
|
|
|
|
message = conn.assigns.message
|
|
|
|
|
2022-03-24 19:04:25 +01:00
|
|
|
{:ok, _message} =
|
2024-07-15 00:56:23 +02:00
|
|
|
Conversations.approve_message(message, conn.assigns.current_user)
|
2022-03-22 22:23:30 +01:00
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_flash(:info, "Conversation message approved.")
|
2024-06-23 16:42:29 +02:00
|
|
|
|> moderation_log(details: &log_details/2, data: message)
|
2022-03-22 22:23:30 +01:00
|
|
|
|> redirect(to: "/")
|
|
|
|
end
|
|
|
|
|
2024-06-23 16:42:29 +02:00
|
|
|
defp log_details(_action, message) do
|
2022-03-22 22:23:30 +01:00
|
|
|
%{
|
|
|
|
body: "Approved private message in conversation ##{message.conversation_id}",
|
|
|
|
subject_path: "/"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|