mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
add duplicate and deleted handling
This commit is contained in:
parent
5cdc647208
commit
13ad9e964d
3 changed files with 53 additions and 1 deletions
|
@ -12,7 +12,7 @@ defmodule PhilomenaWeb.ImageController do
|
|||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
plug :load_and_authorize_resource, model: Image, only: :show, preload: [:tags, user: [awards: :badge]]
|
||||
plug :load_image
|
||||
|
||||
plug PhilomenaWeb.FilterBannedUsersPlug when action in [:new, :create]
|
||||
plug PhilomenaWeb.UserAttributionPlug when action in [:create]
|
||||
|
@ -135,4 +135,30 @@ defmodule PhilomenaWeb.ImageController do
|
|||
|
||||
{user_galleries, image_galleries}
|
||||
end
|
||||
|
||||
defp load_image(conn, _opts) do
|
||||
id = conn.params["id"]
|
||||
|
||||
image =
|
||||
Image
|
||||
|> where(id: ^id)
|
||||
|> preload([:tags, :deleter, user: [awards: :badge]])
|
||||
|> Repo.one()
|
||||
|
||||
cond do
|
||||
is_nil(image) ->
|
||||
PhilomenaWeb.NotFoundPlug.call(conn)
|
||||
|
||||
not is_nil(image.duplicate_id) and not Canada.Can.can?(conn, :show, image) ->
|
||||
conn
|
||||
|> put_flash(:info, "The image you were looking for has been marked a duplicate of the image below")
|
||||
|> redirect(to: Routes.image_path(conn, :show, image.duplicate_id))
|
||||
|
||||
image.hidden_from_users ->
|
||||
render(conn, "deleted.html", image: image)
|
||||
|
||||
true ->
|
||||
assign(conn, :image, image)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
23
lib/philomena_web/templates/image/deleted.html.slime
Normal file
23
lib/philomena_web/templates/image/deleted.html.slime
Normal file
|
@ -0,0 +1,23 @@
|
|||
.walloftext
|
||||
.block.block--fixed.block--warning
|
||||
h1 This image has been deleted
|
||||
p
|
||||
' Reason:
|
||||
strong
|
||||
= @image.deletion_reason || "Unknown (likely deleted in error). Please contact a moderator."
|
||||
|
||||
= if can?(@conn, :undelete, @image) do
|
||||
p
|
||||
strong> Spoilers!
|
||||
' Done by:
|
||||
strong = deleter(@image)
|
||||
p
|
||||
' If you originally uploaded the file previously located here, please don't re-upload it -
|
||||
=> link "contact us", to: "/pages/contact"
|
||||
' if you feel this was in error and we'll talk! We're only human, and mistakes happen.
|
||||
p
|
||||
' Here's the
|
||||
=> link "tagging guidelines", to: "/pages/tags"
|
||||
' and
|
||||
= link "rules of the site", to: "/pages/rules"
|
||||
' . Other useful links can be found at the bottom of the page.
|
|
@ -144,6 +144,9 @@ defmodule PhilomenaWeb.ImageView do
|
|||
render PhilomenaWeb.TagView, "_tags_row.html", conn: conn, tags: tags
|
||||
end
|
||||
|
||||
def deleter(%{deleter: %{name: name}}), do: name
|
||||
def deleter(_image), do: "System"
|
||||
|
||||
defp thumb_format("svg", _name), do: "png"
|
||||
defp thumb_format(_, :rendered), do: "png"
|
||||
defp thumb_format(format, _name), do: format
|
||||
|
|
Loading…
Reference in a new issue