mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 14:17:59 +01:00
feat: add ability for staff to delete tag changes from tag change history
This used to be a thing in Booru on Rails but wasn't added to Philomena for some reason.
This commit is contained in:
parent
a1ab17638a
commit
fe8395da99
3 changed files with 42 additions and 1 deletions
|
@ -2,6 +2,7 @@ defmodule PhilomenaWeb.Image.TagChangeController do
|
||||||
use PhilomenaWeb, :controller
|
use PhilomenaWeb, :controller
|
||||||
|
|
||||||
alias Philomena.Images.Image
|
alias Philomena.Images.Image
|
||||||
|
alias Philomena.TagChanges
|
||||||
alias Philomena.TagChanges.TagChange
|
alias Philomena.TagChanges.TagChange
|
||||||
alias Philomena.Repo
|
alias Philomena.Repo
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
@ -9,6 +10,12 @@ defmodule PhilomenaWeb.Image.TagChangeController do
|
||||||
plug PhilomenaWeb.CanaryMapPlug, index: :show
|
plug PhilomenaWeb.CanaryMapPlug, index: :show
|
||||||
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
||||||
|
|
||||||
|
plug :load_and_authorize_resource,
|
||||||
|
model: TagChange,
|
||||||
|
preload: [:tag],
|
||||||
|
persisted: true,
|
||||||
|
only: [:delete]
|
||||||
|
|
||||||
def index(conn, params) do
|
def index(conn, params) do
|
||||||
image = conn.assigns.image
|
image = conn.assigns.image
|
||||||
|
|
||||||
|
@ -27,6 +34,21 @@ defmodule PhilomenaWeb.Image.TagChangeController do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete(conn, params) do
|
||||||
|
image = conn.assigns.image
|
||||||
|
tag_change = conn.assigns.tag_change
|
||||||
|
|
||||||
|
TagChanges.delete_tag_change(tag_change)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Successfully deleted tag change from history.")
|
||||||
|
|> moderation_log(
|
||||||
|
details: &log_details/3,
|
||||||
|
data: %{image: image, details: tag_change_details(tag_change)}
|
||||||
|
)
|
||||||
|
|> redirect(to: Routes.image_path(conn, :show, image))
|
||||||
|
end
|
||||||
|
|
||||||
defp added_filter(query, %{"added" => "1"}),
|
defp added_filter(query, %{"added" => "1"}),
|
||||||
do: where(query, added: true)
|
do: where(query, added: true)
|
||||||
|
|
||||||
|
@ -35,4 +57,17 @@ defmodule PhilomenaWeb.Image.TagChangeController do
|
||||||
|
|
||||||
defp added_filter(query, _params),
|
defp added_filter(query, _params),
|
||||||
do: query
|
do: query
|
||||||
|
|
||||||
|
defp log_details(conn, _action, %{image: image, details: details}) do
|
||||||
|
%{
|
||||||
|
body: "Deleted tag change (#{details}) from history",
|
||||||
|
subject_path: Routes.image_path(conn, :show, image)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp tag_change_details(%TagChange{added: true, tag: tag}),
|
||||||
|
do: "added tag \"#{tag.name}\""
|
||||||
|
|
||||||
|
defp tag_change_details(%TagChange{added: false, tag: tag}),
|
||||||
|
do: "removed tag \"#{tag.name}\""
|
||||||
end
|
end
|
||||||
|
|
|
@ -470,7 +470,7 @@ defmodule PhilomenaWeb.Router do
|
||||||
|
|
||||||
resources "/tags", Image.TagController, only: [:update], singleton: true
|
resources "/tags", Image.TagController, only: [:update], singleton: true
|
||||||
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, :delete]
|
||||||
resources "/source_changes", Image.SourceChangeController, only: [:index]
|
resources "/source_changes", Image.SourceChangeController, only: [:index]
|
||||||
resources "/description", Image.DescriptionController, only: [:update], singleton: true
|
resources "/description", Image.DescriptionController, only: [:update], singleton: true
|
||||||
resources "/navigate", Image.NavigateController, only: [:index]
|
resources "/navigate", Image.NavigateController, only: [:index]
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
th Action
|
th Action
|
||||||
th Timestamp
|
th Timestamp
|
||||||
th User
|
th User
|
||||||
|
= if reverts_tag_changes?(@conn) do
|
||||||
|
th Moderation
|
||||||
|
|
||||||
tbody
|
tbody
|
||||||
= for tag_change <- @tag_changes do
|
= for tag_change <- @tag_changes do
|
||||||
|
@ -60,6 +62,10 @@
|
||||||
' This user is a staff member.
|
' This user is a staff member.
|
||||||
br
|
br
|
||||||
' Ask them before reverting their changes.
|
' Ask them before reverting their changes.
|
||||||
|
= if reverts_tag_changes?(@conn) do
|
||||||
|
td
|
||||||
|
a href=Routes.image_tag_change_path(@conn, :delete, tag_change.image, tag_change) data-method="delete" data-confirm="Are you really, really sure?"
|
||||||
|
' Delete from history
|
||||||
|
|
||||||
.block__header
|
.block__header
|
||||||
= @pagination
|
= @pagination
|
||||||
|
|
Loading…
Reference in a new issue