Skip to content

Commit

Permalink
feat: add "retained" column to tag changes table (#246)
Browse files Browse the repository at this point in the history
* feat: add "retained" column to tag changes table

* Update lib/philomena_web/views/tag_change_view.ex

Co-authored-by: liamwhite <[email protected]>

---------

Co-authored-by: liamwhite <[email protected]>
  • Loading branch information
mdashlw and liamwhite authored May 4, 2024
1 parent eba094f commit ca9cb3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/philomena_web/templates/tag_change/index.html.slime
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
th Action
th Timestamp
th User
th Retained?
= if reverts_tag_changes?(@conn) do
th Moderation

Expand Down Expand Up @@ -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?"
Expand Down
10 changes: 10 additions & 0 deletions lib/philomena_web/views/tag_change_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ca9cb3a

Please sign in to comment.