feat: add "retained" column to tag changes table

This commit is contained in:
mdashlw 2024-05-02 09:32:44 +03:00
parent 70cde5d4b2
commit 068ed9f565
No known key found for this signature in database
GPG key ID: 0887AF18569DED32
2 changed files with 23 additions and 0 deletions
lib/philomena_web
templates/tag_change
views

View file

@ -19,6 +19,7 @@
th Action
th Timestamp
th User
th Retained?
= if reverts_tag_changes?(@conn) do
th Moderation
@ -62,6 +63,10 @@
' This user is a staff member.
br
' Ask them before reverting their changes.
= if tag_change_retained(tag_change) do
td.success Yes
- else
td.danger No
= 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?"

View file

@ -15,4 +15,22 @@ defmodule PhilomenaWeb.TagChangeView do
def reverts_tag_changes?(conn),
do: can?(conn, :revert, Philomena.TagChanges.TagChange)
def tag_change_retained(%{image: image, added: true, tag: %{id: tag_id}}) do
Enum.any?(image.tags, &(&1.id == tag_id))
end
def tag_change_retained(%{image: image, added: true, tag_name_cache: tag_name}) do
Enum.any?(image.tags, &(&1.name == tag_name))
end
def tag_change_retained(%{image: image, added: false, tag: %{id: tag_id}}) do
not Enum.any?(image.tags, &(&1.id == tag_id))
end
def tag_change_retained(%{image: image, added: false, tag_name_cache: tag_name}) do
not Enum.any?(image.tags, &(&1.name == tag_name))
end
def tag_change_retained(_), do: false
end