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

46 lines
1.1 KiB
Elixir
Raw Permalink Normal View History

2019-12-04 14:25:10 +01:00
defmodule PhilomenaWeb.Profile.ReportController do
use PhilomenaWeb, :controller
alias PhilomenaWeb.ReportController
alias PhilomenaWeb.ReportView
alias Philomena.Users.User
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: User,
id_name: "profile_id",
id_field: "slug",
persisted: true
2019-12-04 14:25:10 +01:00
def new(conn, _params) do
user = conn.assigns.user
action = Routes.profile_report_path(conn, :create, user)
2020-01-11 05:20:19 +01:00
2019-12-04 14:25:10 +01:00
changeset =
%Report{reportable_type: "User", reportable_id: user.id}
|> Reports.change_report()
conn
|> put_view(ReportView)
2020-01-11 05:20:19 +01:00
|> render("new.html",
title: "Reporting User",
reportable: user,
changeset: changeset,
action: action
)
2019-12-04 14:25:10 +01:00
end
def create(conn, params) do
user = conn.assigns.user
action = Routes.profile_report_path(conn, :create, user)
ReportController.create(conn, action, user, "User", params)
end
2019-12-16 20:24:38 +01:00
end