2019-12-22 23:17:20 +01:00
|
|
|
defmodule PhilomenaWeb.Profile.ScratchpadController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
|
|
|
alias Philomena.Users.User
|
|
|
|
alias Philomena.Users
|
|
|
|
|
|
|
|
plug PhilomenaWeb.FilterBannedUsersPlug
|
|
|
|
plug PhilomenaWeb.CanaryMapPlug, edit: :index, update: :index
|
|
|
|
plug :load_resource, model: User, id_name: "profile_id", id_field: "slug", persisted: true
|
|
|
|
|
|
|
|
def edit(conn, _params) do
|
|
|
|
changeset = Users.change_user(conn.assigns.user)
|
2020-01-11 05:20:19 +01:00
|
|
|
|
|
|
|
render(conn, "edit.html",
|
|
|
|
title: "Editing Moderation Scratchpad",
|
|
|
|
changeset: changeset,
|
|
|
|
user: conn.assigns.user
|
|
|
|
)
|
2019-12-22 23:17:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def update(conn, %{"user" => user_params}) do
|
|
|
|
user = conn.assigns.user
|
|
|
|
|
|
|
|
case Users.update_scratchpad(user, user_params) do
|
|
|
|
{:ok, _user} ->
|
|
|
|
conn
|
|
|
|
|> put_flash(:info, "Moderation scratchpad successfully updated.")
|
2024-04-29 02:55:27 +02:00
|
|
|
|> redirect(to: ~p"/profiles/#{user}")
|
2019-12-22 23:17:20 +01:00
|
|
|
|
|
|
|
{:error, changeset} ->
|
|
|
|
render(conn, "edit.html", changeset: changeset)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|