philomena/lib/philomena_web/controllers/conversation/report_controller.ex

47 lines
1.3 KiB
Elixir
Raw Permalink Normal View History

2019-12-04 14:19:33 +01:00
defmodule PhilomenaWeb.Conversation.ReportController do
use PhilomenaWeb, :controller
alias PhilomenaWeb.ReportController
alias PhilomenaWeb.ReportView
alias Philomena.Conversations.Conversation
alias Philomena.Reports.Report
alias Philomena.Reports
plug PhilomenaWeb.FilterBannedUsersPlug
plug PhilomenaWeb.UserAttributionPlug
plug PhilomenaWeb.CaptchaPlug when action in [:create]
plug PhilomenaWeb.CanaryMapPlug, new: :show, create: :show
2020-01-11 05:20:19 +01:00
plug :load_and_authorize_resource,
model: Conversation,
id_name: "conversation_id",
id_field: "slug",
persisted: true,
preload: [:from, :to]
2019-12-04 14:19:33 +01:00
def new(conn, _params) do
conversation = conn.assigns.conversation
action = Routes.conversation_report_path(conn, :create, conversation)
2020-01-11 05:20:19 +01:00
2019-12-04 14:19:33 +01:00
changeset =
%Report{reportable_type: "Conversation", reportable_id: conversation.id}
|> Reports.change_report()
conn
|> put_view(ReportView)
2020-01-11 05:20:19 +01:00
|> render("new.html",
title: "Reporting Conversation",
reportable: conversation,
changeset: changeset,
action: action
)
2019-12-04 14:19:33 +01:00
end
def create(conn, params) do
conversation = conn.assigns.conversation
action = Routes.conversation_report_path(conn, :create, conversation)
ReportController.create(conn, action, conversation, "Conversation", params)
end
2019-12-16 20:24:38 +01:00
end