philomena/lib/philomena_web/controllers/conversation/message/approve_controller.ex

34 lines
866 B
Elixir
Raw Normal View History

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} =
Conversations.approve_conversation_message(message, conn.assigns.current_user)
2022-03-22 22:23:30 +01:00
conn
|> put_flash(:info, "Conversation message approved.")
2024-06-06 22:28:35 +02:00
|> moderation_log(details: &log_details/2, data: message)
2022-03-22 22:23:30 +01:00
|> redirect(to: "/")
end
2024-06-06 22:28:35 +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