mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
Image hide reason changing
This commit is contained in:
parent
d35b7a2b0e
commit
7cee5f38ee
5 changed files with 49 additions and 1 deletions
|
@ -334,6 +334,12 @@ defmodule Philomena.Images do
|
|||
|> internal_hide_image(image)
|
||||
end
|
||||
|
||||
def update_hide_reason(%Image{} = image, attrs) do
|
||||
image
|
||||
|> Image.hide_reason_changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def merge_image(%Image{} = image, duplicate_of_image) do
|
||||
result =
|
||||
Image.merge_changeset(image, duplicate_of_image)
|
||||
|
|
|
@ -202,6 +202,12 @@ defmodule Philomena.Images.Image do
|
|||
|> validate_required([:deletion_reason, :deleter_id])
|
||||
end
|
||||
|
||||
def hide_reason_changeset(image, attrs) do
|
||||
image
|
||||
|> cast(attrs, [:deletion_reason])
|
||||
|> validate_required([:deletion_reason])
|
||||
end
|
||||
|
||||
def merge_changeset(image, duplicate_of_image) do
|
||||
change(image)
|
||||
|> put_change(:duplicate_id, duplicate_of_image.id)
|
||||
|
|
|
@ -11,6 +11,7 @@ defmodule PhilomenaWeb.Image.DeleteController do
|
|||
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :hide, delete: :hide
|
||||
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
||||
plug :verify_deleted when action in [:update]
|
||||
|
||||
def create(conn, %{"image" => image_params}) do
|
||||
image = conn.assigns.image
|
||||
|
@ -31,6 +32,35 @@ defmodule PhilomenaWeb.Image.DeleteController do
|
|||
end
|
||||
end
|
||||
|
||||
def update(conn, %{"image" => image_params}) do
|
||||
image = conn.assigns.image
|
||||
|
||||
case Images.update_hide_reason(image, image_params) do
|
||||
{:ok, image} ->
|
||||
Images.reindex_image(image)
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Hide reason updated.")
|
||||
|> redirect(to: Routes.image_path(conn, :show, image))
|
||||
|
||||
{:error, _changeset} ->
|
||||
conn
|
||||
|> put_flash(:error, "Couldn't update hide reason.")
|
||||
|> redirect(to: Routes.image_path(conn, :show, image))
|
||||
end
|
||||
end
|
||||
|
||||
defp verify_deleted(conn, _opts) do
|
||||
case conn.assigns.image.hidden_from_users do
|
||||
true ->
|
||||
conn
|
||||
_false ->
|
||||
conn
|
||||
|> put_flash(:error, "Cannot change hide reason on a non-hidden image!")
|
||||
|> redirect(to: Routes.image_path(conn, :show, conn.assigns.image))
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, _params) do
|
||||
image = conn.assigns.image
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ defmodule PhilomenaWeb.Router do
|
|||
resources "/delete", Image.Comment.DeleteController, only: [:create], singleton: true
|
||||
end
|
||||
|
||||
resources "/delete", Image.DeleteController, only: [:create, :delete], singleton: true
|
||||
resources "/delete", Image.DeleteController, only: [:create, :delete, :update], singleton: true
|
||||
|
||||
resources "/tamper", Image.TamperController, only: [:create], singleton: true
|
||||
resources "/hash", Image.HashController, only: [:delete], singleton: true
|
||||
|
|
|
@ -90,6 +90,12 @@
|
|||
.field.field--inline
|
||||
= text_input f, :deletion_reason, class: "input input--wide", placeholder: "Rule violation", required: true
|
||||
= submit "Delete", class: "button button--state-danger button--separate-left"
|
||||
- else
|
||||
= form_for @changeset, Routes.image_delete_path(@conn, :update, @image), [method: "put"], fn f ->
|
||||
= label f, :deletion_reason, "Deletion reason (cannot be empty)"
|
||||
.field.field--inline
|
||||
= text_input f, :deletion_reason, class: "input input--wide", placeholder: "Rule violation", required: true
|
||||
= submit "Change hide reason", class: "button button--state-danger button--separate-left"
|
||||
|
||||
.flex.flex--spaced-out.flex--wrap
|
||||
= if not @image.hidden_from_users do
|
||||
|
|
Loading…
Reference in a new issue