diff --git a/lib/philomena_web/controllers/conversation/report_controller.ex b/lib/philomena_web/controllers/conversation/report_controller.ex new file mode 100644 index 00000000..97a0d38c --- /dev/null +++ b/lib/philomena_web/controllers/conversation/report_controller.ex @@ -0,0 +1,34 @@ +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 + plug :load_and_authorize_resource, model: Conversation, id_name: "conversation_id", id_field: "slug", persisted: true, preload: [:from, :to] + + def new(conn, _params) do + conversation = conn.assigns.conversation + action = Routes.conversation_report_path(conn, :create, conversation) + changeset = + %Report{reportable_type: "Conversation", reportable_id: conversation.id} + |> Reports.change_report() + + conn + |> put_view(ReportView) + |> render("new.html", reportable: conversation, changeset: changeset, action: action) + 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 +end \ No newline at end of file diff --git a/lib/philomena_web/router.ex b/lib/philomena_web/router.ex index 78686a42..5c958018 100644 --- a/lib/philomena_web/router.ex +++ b/lib/philomena_web/router.ex @@ -91,6 +91,7 @@ defmodule PhilomenaWeb.Router do end resources "/notifications", NotificationController, only: [:index, :delete] resources "/conversations", ConversationController, only: [:index, :show, :new, :create] do + resources "/reports", Conversation.ReportController, only: [:new, :create] resources "/messages", Conversation.MessageController, only: [:create] end resources "/images", ImageController, only: [] do diff --git a/lib/philomena_web/templates/conversation/show.html.slime b/lib/philomena_web/templates/conversation/show.html.slime index 3863e07a..dc979864 100644 --- a/lib/philomena_web/templates/conversation/show.html.slime +++ b/lib/philomena_web/templates/conversation/show.html.slime @@ -13,6 +13,7 @@ h1 = @conversation.title => render PhilomenaWeb.UserAttributionView, "_user.html", object: %{user: other}, conn: @conn .block__header--sub.block__header--light = pagination + = link "Report conversation", to: Routes.conversation_report_path(@conn, :new, @conversation) = for {message, body} <- @messages do = render PhilomenaWeb.MessageView, "_message.html", message: message, body: body, conn: @conn diff --git a/lib/philomena_web/templates/message/_message.html.slime b/lib/philomena_web/templates/message/_message.html.slime index 6e3ed41a..e22258d7 100644 --- a/lib/philomena_web/templates/message/_message.html.slime +++ b/lib/philomena_web/templates/message/_message.html.slime @@ -10,8 +10,6 @@ article.block.communication = render PhilomenaWeb.UserAttributionView, "_user_title.html", object: %{user: @message.from}, conn: @conn - br - .communication__body__text == @body