mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-31 19:36:44 +01:00
allow users to reveal hidden images, moderators to index deleted images
This commit is contained in:
parent
b423f8f201
commit
8cb3e33714
8 changed files with 93 additions and 12 deletions
|
@ -4,6 +4,8 @@ defmodule Philomena.ImageScope do
|
|||
|> scope(conn, "q", :q)
|
||||
|> scope(conn, "sf", :sf)
|
||||
|> scope(conn, "sd", :sd)
|
||||
|> scope(conn, "del", :del)
|
||||
|> scope(conn, "hidden", :hidden)
|
||||
end
|
||||
|
||||
defp scope(list, conn, key, key_atom) do
|
||||
|
@ -13,4 +15,4 @@ defmodule Philomena.ImageScope do
|
|||
val -> [{key_atom, val} | list]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ defmodule PhilomenaWeb.ImageLoader do
|
|||
|
||||
user = conn.assigns.current_user
|
||||
filter = conn.assigns.compiled_filter
|
||||
filters = create_filters(user, filter)
|
||||
filters = create_filters(conn, user, filter)
|
||||
|
||||
records =
|
||||
Image.search_records(
|
||||
|
@ -50,18 +50,42 @@ defmodule PhilomenaWeb.ImageLoader do
|
|||
{records, tags}
|
||||
end
|
||||
|
||||
defp create_filters(user, filter) do
|
||||
defp create_filters(conn, user, filter) do
|
||||
show_hidden? = Canada.Can.can?(user, :hide, %Image{})
|
||||
del = conn.params["del"]
|
||||
hidden = conn.params["hidden"]
|
||||
|
||||
[
|
||||
filter,
|
||||
%{term: %{hidden_from_users: true}}
|
||||
filter
|
||||
]
|
||||
|> maybe_custom_hide(user)
|
||||
|> maybe_show_deleted(show_hidden?, del)
|
||||
|> maybe_custom_hide(user, hidden)
|
||||
end
|
||||
|
||||
defp maybe_custom_hide(filters, %{id: id}),
|
||||
# Allow moderators to index hidden images
|
||||
|
||||
defp maybe_show_deleted(filters, false, _param),
|
||||
do: [%{term: %{hidden_from_users: true}} | filters]
|
||||
|
||||
defp maybe_show_deleted(filters, true, "1"),
|
||||
do: filters
|
||||
|
||||
defp maybe_show_deleted(filters, true, "only"),
|
||||
do: [%{term: %{hidden_from_users: false}} | filters]
|
||||
|
||||
defp maybe_show_deleted(filters, true, _param),
|
||||
do: [%{term: %{hidden_from_users: true}} | filters]
|
||||
|
||||
# Allow users to reverse the effect of hiding images,
|
||||
# if desired
|
||||
|
||||
defp maybe_custom_hide(filters, %{id: id}, "1"),
|
||||
do: filters
|
||||
|
||||
defp maybe_custom_hide(filters, %{id: id}, _param),
|
||||
do: [%{term: %{hidden_by_user_ids: id}} | filters]
|
||||
|
||||
defp maybe_custom_hide(filters, _user),
|
||||
defp maybe_custom_hide(filters, _user, _param),
|
||||
do: filters
|
||||
|
||||
# TODO: the search parser should try to optimize queries
|
||||
|
@ -99,4 +123,4 @@ defmodule PhilomenaWeb.ImageLoader do
|
|||
[{tag, description, dnp_entries}]
|
||||
end
|
||||
defp render_bodies(tags, _conn), do: tags
|
||||
end
|
||||
end
|
||||
|
|
25
lib/philomena_web/templates/image/_deleted_toggle.html.slime
Normal file
25
lib/philomena_web/templates/image/_deleted_toggle.html.slime
Normal file
|
@ -0,0 +1,25 @@
|
|||
- del = @conn.params["del"]
|
||||
|
||||
= if blank?(del) do
|
||||
a href=@route.(Keyword.put(@params, :del, 1)) title="Include Deleted/Merged Images"
|
||||
i.fa.fa-plus
|
||||
i.fa.fa-exclamation>
|
||||
span.hide-mobile.hide-limited-desktop Show Deleted
|
||||
|
||||
= if del != "only" do
|
||||
a href=@route.(Keyword.put(@params, :del, "only")) title="Only Deleted/Merged Images"
|
||||
i.fa.fa-minus
|
||||
i.fa.fa-check>
|
||||
span.hide-mobile.hide-limited-desktop Only Deleted
|
||||
|
||||
= if del == "only" do
|
||||
a href=@route.(Keyword.put(@params, :del, 1)) title="Include Images Visible to Users"
|
||||
i.fa.fa-plus
|
||||
i.fa.fa-check>
|
||||
span.hide-mobile.hide-limited-desktop Show Non-Deleted
|
||||
|
||||
= if present?(del) do
|
||||
a href=@route.(Keyword.delete(@params, :del)) title="Hide Deleted/Merged Images"
|
||||
i.fa.fa-minus
|
||||
i.fa.fa-exclamation>
|
||||
span.hide-mobile.hide-limited-desktop Hide Deleted
|
|
@ -0,0 +1,9 @@
|
|||
= if present?(@conn.params["hidden"]) do
|
||||
a href=@route.(Keyword.delete(@params, :hidden)) title="Hide Hidden Images"
|
||||
i.fa.fa-eye-slash>
|
||||
span.hide-mobile.hide-limited-desktop Hide Hidden
|
||||
|
||||
- else
|
||||
a href=@route.(Keyword.put(@params, :hidden, "1")) title="Show Hidden Images"
|
||||
i.fa.fa-eye-slash>
|
||||
span.hide-mobile.hide-limited-desktop Show Hidden
|
|
@ -16,6 +16,8 @@ elixir:
|
|||
= pagination
|
||||
|
||||
.flex__right
|
||||
= hidden_toggle @conn, route, params
|
||||
= deleted_toggle @conn, route, params
|
||||
= quick_tag @conn
|
||||
|
||||
= info_row @conn, tags
|
||||
|
|
|
@ -11,15 +11,18 @@ header.header
|
|||
a.header__link.hide-mobile href="/images/new" title="Upload"
|
||||
i.fa.fa-upload
|
||||
|
||||
form.header__search.flex.flex--no-wrap.flex--centered action="/search" method="get"
|
||||
input.input.header__input.header__input--search#q name="q" title="For terms all required, separate with ',' or 'AND'; also supports 'OR' for optional terms and '-' or 'NOT' for negation. Search with a blank query for more options or click the ? for syntax help." value=(assigns[:search_query] || @conn.params["q"]) placeholder="Search" autocapitalize="none"
|
||||
= form_for @conn, Routes.search_path(@conn, :index), [method: "get", class: "header__search flex flex--no-wrap flex--centered"], fn f ->
|
||||
input.input.header__input.header__input--search#q name="q" title="For terms all required, separate with ',' or 'AND'; also supports 'OR' for optional terms and '-' or 'NOT' for negation. Search with a blank query for more options or click the ? for syntax help." value=@conn.params["q"] placeholder="Search" autocapitalize="none"
|
||||
|
||||
= if present?(@conn.params["sf"]) do
|
||||
input type="hidden" name="sf" value=@conn.params["sf"]
|
||||
= if present?(@conn.params["sd"]) do
|
||||
input type="hidden" name="sd" value=@conn.params["sd"]
|
||||
|
||||
button.header__search__button type="submit" title='Search'
|
||||
= if hides_images?(@conn) do
|
||||
= select f, :del, [{"-D", ""}, {"+D", 1}, {"DO", "only"}], name: "del", class: "input header__input", autocomplete: "off"
|
||||
|
||||
button.header__search__button type="submit" title="Search"
|
||||
i.fa-embedded--search
|
||||
a.header__search__button href="/search/reverse" title="Search using an image"
|
||||
i.fa-embedded--camera
|
||||
|
|
|
@ -171,6 +171,19 @@ defmodule PhilomenaWeb.ImageView do
|
|||
def scaled_value(%{scale_large_images: false}), do: "false"
|
||||
def scaled_value(_user), do: "true"
|
||||
|
||||
def hides_images?(conn), do: can?(conn, :hide, %Philomena.Images.Image{})
|
||||
|
||||
def hidden_toggle(%{assigns: %{current_user: nil}}, _route, _params), do: nil
|
||||
def hidden_toggle(%{assigns: %{current_user: user}} = conn, route, params) do
|
||||
render PhilomenaWeb.ImageView, "_hidden_toggle.html", route: route, params: params, conn: conn
|
||||
end
|
||||
|
||||
def deleted_toggle(conn, route, params) do
|
||||
if hides_images?(conn) do
|
||||
render PhilomenaWeb.ImageView, "_deleted_toggle.html", route: route, params: params, conn: conn
|
||||
end
|
||||
end
|
||||
|
||||
defp thumb_format("svg", _name), do: "png"
|
||||
defp thumb_format(_, :rendered), do: "png"
|
||||
defp thumb_format(format, _name), do: format
|
||||
|
|
|
@ -83,6 +83,9 @@ defmodule PhilomenaWeb.LayoutView do
|
|||
def opengraph?(conn),
|
||||
do: !is_nil(conn.assigns[:image]) and conn.assigns.image.__meta__.state == :loaded and is_list(conn.assigns.image.tags)
|
||||
|
||||
def hides_images?(conn),
|
||||
do: can?(conn, :hide, %Philomena.Images.Image{})
|
||||
|
||||
def manages_site_notices?(conn),
|
||||
do: can?(conn, :index, Philomena.SiteNotices.SiteNotice)
|
||||
|
||||
|
|
Loading…
Reference in a new issue