From ca9cb3a50edac2d4d725e85b4e4361d33c8f3358 Mon Sep 17 00:00:00 2001 From: mdashlw Date: Sat, 4 May 2024 20:00:55 +0300 Subject: [PATCH] feat: add "retained" column to tag changes table (#246) * feat: add "retained" column to tag changes table * Update lib/philomena_web/views/tag_change_view.ex Co-authored-by: liamwhite --------- Co-authored-by: liamwhite --- .../templates/tag_change/index.html.slime | 5 +++++ lib/philomena_web/views/tag_change_view.ex | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/philomena_web/templates/tag_change/index.html.slime b/lib/philomena_web/templates/tag_change/index.html.slime index 36f0630e..a5f6b64b 100644 --- a/lib/philomena_web/templates/tag_change/index.html.slime +++ b/lib/philomena_web/templates/tag_change/index.html.slime @@ -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?" diff --git a/lib/philomena_web/views/tag_change_view.ex b/lib/philomena_web/views/tag_change_view.ex index e821ca93..6db71454 100644 --- a/lib/philomena_web/views/tag_change_view.ex +++ b/lib/philomena_web/views/tag_change_view.ex @@ -15,4 +15,14 @@ defmodule PhilomenaWeb.TagChangeView do def reverts_tag_changes?(conn), do: can?(conn, :revert, Philomena.TagChanges.TagChange) + + def tag_change_retained(%{image: image, added: added, tag: %{id: tag_id}}) do + added == Enum.any?(image.tags, &(&1.id == tag_id)) + end + + def tag_change_retained(%{image: image, added: added, tag_name_cache: tag_name}) do + added == Enum.any?(image.tags, &(&1.name == tag_name)) + end + + def tag_change_retained(_), do: false end