diff --git a/lib/philomena_web/controllers/profile/report_controller.ex b/lib/philomena_web/controllers/profile/report_controller.ex new file mode 100644 index 00000000..613d2d24 --- /dev/null +++ b/lib/philomena_web/controllers/profile/report_controller.ex @@ -0,0 +1,34 @@ +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 + plug :load_and_authorize_resource, model: User, id_name: "profile_id", id_field: "slug", persisted: true + + def new(conn, _params) do + user = conn.assigns.user + action = Routes.profile_report_path(conn, :create, user) + changeset = + %Report{reportable_type: "User", reportable_id: user.id} + |> Reports.change_report() + + conn + |> put_view(ReportView) + |> render("new.html", reportable: user, changeset: changeset, action: action) + 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 +end \ No newline at end of file diff --git a/lib/philomena_web/router.ex b/lib/philomena_web/router.ex index 5c958018..31ffcceb 100644 --- a/lib/philomena_web/router.ex +++ b/lib/philomena_web/router.ex @@ -165,7 +165,9 @@ defmodule PhilomenaWeb.Router do resources "/current", CurrentController, only: [:update], singleton: true end resources "/filters", FilterController - resources "/profiles", ProfileController, only: [:show] + resources "/profiles", ProfileController, only: [:show] do + resources "/reports", Profile.ReportController, only: [:new, :create] + end resources "/captchas", CaptchaController, only: [:create] scope "/posts", Post, as: :post do resources "/preview", PreviewController, only: [:create] diff --git a/lib/philomena_web/templates/profile/show.html.slime b/lib/philomena_web/templates/profile/show.html.slime index db448fb6..b6f9ed21 100644 --- a/lib/philomena_web/templates/profile/show.html.slime +++ b/lib/philomena_web/templates/profile/show.html.slime @@ -12,9 +12,9 @@ .profile-top__options ul.profile-top__options__column - li = link("Send message", to: "#") - li = link("Our conversations", to: "#") - li = link("Report this user", to: "#") + li = link("Send message", to: Routes.conversation_path(@conn, :new, recipient: @user.name)) + li = link("Our conversations", to: Routes.conversation_path(@conn, :index, with: @user.id)) + li = link("Report this user", to: Routes.profile_report_path(@conn, :new, @user)) ul.profile-top__options__column li = link("Uploads", to: Routes.search_path(@conn, :index, q: "uploader_id:#{@user.id}"))