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()
end
def update_scratchpad(%User{} = user, attrs) do
user
|> User.scratchpad_changeset(attrs)
|> Repo.update()
end
def watch_tag(%User{} = user, tag) do
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)
end
def scratchpad_changeset(user, attrs) do
user
|> cast(attrs, [:scratchpad])
end
def avatar_changeset(user, attrs) do
user
|> 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

@ -108,7 +108,10 @@ defmodule PhilomenaWeb.ProfileController do
|> Enum.filter(&Canada.Can.can?(current_user, :show, &1.topic))
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_info(user.commission, conn)
@ -145,6 +148,7 @@ defmodule PhilomenaWeb.ProfileController do
statistics: statistics,
watcher_counts: watcher_counts,
about_me: about_me,
scratchpad: scratchpad,
tags: tags,
bans: bans,
layout_class: "layout--medium",

View file

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

View file

@ -8,4 +8,4 @@
' Want to
=> link "add some info about yourself?", to: "#"
- true ->
- 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
td == body
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
= 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