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

34 lines
873 B
Elixir
Raw Permalink 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.")
|> moderation_log(details: &log_details/3, data: message)
|> redirect(to: "/")
end
2022-03-24 18:36:49 +01:00
defp log_details(_conn, _action, message) do
2022-03-22 22:23:30 +01:00
%{
body: "Approved private message in conversation ##{message.conversation_id}",
subject_path: "/"
}
end
end