From 217621a9e17532c50701b72140027f2473270406 Mon Sep 17 00:00:00 2001 From: Eliot Partridge Date: Sun, 3 Dec 2023 20:56:32 -0500 Subject: [PATCH] Hide Queue staff link if user can't approve images (#200) --- lib/philomena/images.ex | 14 +++++++++----- lib/philomena_web/plugs/admin_counters_plug.ex | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/philomena/images.ex b/lib/philomena/images.ex index 4239f877..fe2e0ac2 100644 --- a/lib/philomena/images.ex +++ b/lib/philomena/images.ex @@ -210,11 +210,15 @@ defmodule Philomena.Images do defp maybe_suggest_user_verification(_user), do: false - def count_pending_approvals() do - Image - |> where(hidden_from_users: false) - |> where(approved: false) - |> Repo.aggregate(:count) + def count_pending_approvals(user) do + if Canada.Can.can?(user, :approve, %Image{}) do + Image + |> where(hidden_from_users: false) + |> where(approved: false) + |> Repo.aggregate(:count) + else + nil + end end def feature_image(featurer, %Image{} = image) do diff --git a/lib/philomena_web/plugs/admin_counters_plug.ex b/lib/philomena_web/plugs/admin_counters_plug.ex index e2da61a9..9e01a559 100644 --- a/lib/philomena_web/plugs/admin_counters_plug.ex +++ b/lib/philomena_web/plugs/admin_counters_plug.ex @@ -32,7 +32,7 @@ defmodule PhilomenaWeb.AdminCountersPlug do defp maybe_assign_admin_metrics(conn, _user, false), do: conn defp maybe_assign_admin_metrics(conn, user, true) do - pending_approvals = Images.count_pending_approvals() + pending_approvals = Images.count_pending_approvals(user) duplicate_reports = DuplicateReports.count_duplicate_reports(user) reports = Reports.count_reports(user) artist_links = ArtistLinks.count_artist_links(user)