re-add mod scratchpad by blatantly copy-pasting

This commit is contained in:
Luna D 2019-12-22 17:17:20 -05:00
parent c14d0b6f34
commit 7caafd976e
No known key found for this signature in database
GPG key ID: D0F46C94720BAA4B
9 changed files with 84 additions and 3 deletions

View file

@ -106,6 +106,12 @@ defmodule Philomena.Users do
|> Repo.update() |> Repo.update()
end end
def update_scratchpad(%User{} = user, attrs) do
user
|> User.scratchpad_changeset(attrs)
|> Repo.update()
end
def watch_tag(%User{} = user, tag) do def watch_tag(%User{} = user, tag) do
watched_tag_ids = Enum.uniq([tag.id | user.watched_tag_ids]) watched_tag_ids = Enum.uniq([tag.id | user.watched_tag_ids])

View file

@ -222,6 +222,11 @@ defmodule Philomena.Users.User do
|> validate_format(:personal_title, ~r/\A((?!site|admin|moderator|assistant|developer|\p{C}).)*\z/iu) |> validate_format(:personal_title, ~r/\A((?!site|admin|moderator|assistant|developer|\p{C}).)*\z/iu)
end end
def scratchpad_changeset(user, attrs) do
user
|> cast(attrs, [:scratchpad])
end
def avatar_changeset(user, attrs) do def avatar_changeset(user, attrs) do
user user
|> cast(attrs, [ |> cast(attrs, [

View file

@ -0,0 +1,29 @@
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)
render(conn, "edit.html", title: "Editing Moderation Scratchpad", changeset: changeset, user: conn.assigns.user)
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.")
|> redirect(to: Routes.profile_path(conn, :show, user))
{:error, changeset} ->
render(conn, "edit.html", changeset: changeset)
end
end
end

View file

@ -110,6 +110,9 @@ defmodule PhilomenaWeb.ProfileController do
about_me = about_me =
Renderer.render_one(%{body: user.description || ""}, conn) Renderer.render_one(%{body: user.description || ""}, conn)
scratchpad =
Renderer.render_one(%{body: user.scratchpad || ""}, conn)
commission_information = commission_information =
commission_info(user.commission, conn) commission_info(user.commission, conn)
@ -145,6 +148,7 @@ defmodule PhilomenaWeb.ProfileController do
statistics: statistics, statistics: statistics,
watcher_counts: watcher_counts, watcher_counts: watcher_counts,
about_me: about_me, about_me: about_me,
scratchpad: scratchpad,
tags: tags, tags: tags,
bans: bans, bans: bans,
layout_class: "layout--medium", layout_class: "layout--medium",

View file

@ -159,6 +159,7 @@ defmodule PhilomenaWeb.Router do
resources "/reports", Profile.Commission.ReportController, only: [:new, :create] resources "/reports", Profile.Commission.ReportController, only: [:new, :create]
end end
resources "/description", Profile.DescriptionController, only: [:edit, :update], singleton: true resources "/description", Profile.DescriptionController, only: [:edit, :update], singleton: true
resources "/scratchpad", Profile.ScratchpadController, only: [:edit, :update], singleton: true
resources "/user_links", Profile.UserLinkController resources "/user_links", Profile.UserLinkController
resources "/awards", Profile.AwardController, except: [:index, :show] resources "/awards", Profile.AwardController, except: [:index, :show]
@ -286,7 +287,6 @@ defmodule PhilomenaWeb.Router do
resources "/sources", Image.SourceController, only: [:update], singleton: true resources "/sources", Image.SourceController, only: [:update], singleton: true
resources "/tag_changes", Image.TagChangeController, only: [:index] resources "/tag_changes", Image.TagChangeController, only: [:index]
resources "/source_changes", Image.SourceChangeController, only: [:index] resources "/source_changes", Image.SourceChangeController, only: [:index]
resources "/description", Image.DescriptionController, only: [:update], singleton: true
resources "/navigate", Image.NavigateController, only: [:index] resources "/navigate", Image.NavigateController, only: [:index]
resources "/reports", Image.ReportController, only: [:new, :create] resources "/reports", Image.ReportController, only: [:new, :create]
resources "/reporting", Image.ReportingController, only: [:show], singleton: true resources "/reporting", Image.ReportingController, only: [:show], singleton: true

View file

@ -0,0 +1,29 @@
h1 Updating Moderation Scratchpad
= form_for @changeset, Routes.profile_scratchpad_path(@conn, :update, @user), [method: "put"], fn f ->
= if @changeset.action do
.alert.alert-danger
p Oops, something went wrong! Please check the errors below.
.block
.block__header.block__header--js-tabbed
a.selected href="#" data-click-tab="write"
i.fas.fa-edit>
' Scratchpad
a href="#" data-click-tab="preview"
i.fa.fa-eye>
' Preview
.block__tab.communication-edit__tab.selected data-tab="write"
= render PhilomenaWeb.TextileView, "_help.html", conn: @conn
= render PhilomenaWeb.TextileView, "_toolbar.html", conn: @conn
.field
= textarea f, :scratchpad, class: "input input--wide input--text js-preview-input js-toolbar-input", placeholder: "God I sure could go for some dragon dick"
= error_tag f, :scratchpad
.block__tab.communication-edit__tab.hidden data-tab="preview"
' [Loading preview...]
.block__content.communication-edit__actions
=> submit "Update", class: "button"

View file

@ -124,6 +124,11 @@
tr tr
td == body td == body
td = pretty_time(mod_note.created_at) td = pretty_time(mod_note.created_at)
= if can_index_user?(@conn) do
.block
a.block__header--single-item href=Routes.profile_scratchpad_path(@conn, :edit, @user) Moderation Scratchpad
.block__content.profile-about
== @scratchpad
.column-layout__main .column-layout__main
= render PhilomenaWeb.ProfileView, "_statistics.html", user: @user, statistics: @statistics, conn: @conn = render PhilomenaWeb.ProfileView, "_statistics.html", user: @user, statistics: @statistics, conn: @conn

View file

@ -0,0 +1,3 @@
defmodule PhilomenaWeb.Profile.ScratchpadView do
use PhilomenaWeb, :view
end