mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
permission checks
This commit is contained in:
parent
7c6a189dab
commit
cb4c956079
6 changed files with 59 additions and 39 deletions
|
@ -102,9 +102,13 @@ defmodule Philomena.DnpEntries do
|
|||
DnpEntry.changeset(dnp_entry, %{})
|
||||
end
|
||||
|
||||
def count_dnp_entries() do
|
||||
DnpEntry
|
||||
|> where([dnp], dnp.aasm_state in ["requested", "claimed", "acknowledged"])
|
||||
|> Repo.aggregate(:count, :id)
|
||||
def count_dnp_entries(user) do
|
||||
if Canada.Can.can?(user, :manage, DnpEntry) do
|
||||
DnpEntry
|
||||
|> where([dnp], dnp.aasm_state in ["requested", "claimed", "acknowledged"])
|
||||
|> Repo.aggregate(:count, :id)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -115,9 +115,13 @@ defmodule Philomena.DuplicateReports do
|
|||
DuplicateReport.changeset(duplicate_report, %{})
|
||||
end
|
||||
|
||||
def count_duplicate_reports() do
|
||||
DuplicateReport
|
||||
|> where(state: "open")
|
||||
|> Repo.aggregate(:count, :id)
|
||||
def count_duplicate_reports(user) do
|
||||
if Canada.Can.can?(user, :manage, DuplicateReport) do
|
||||
DuplicateReport
|
||||
|> where(state: "open")
|
||||
|> Repo.aggregate(:count, :id)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -117,9 +117,13 @@ defmodule Philomena.Reports do
|
|||
report
|
||||
end
|
||||
|
||||
def count_reports() do
|
||||
Report
|
||||
|> where(open: true)
|
||||
|> Repo.aggregate(:count, :id)
|
||||
def count_reports(user) do
|
||||
if Canada.Can.can?(user, :manage, Report) do
|
||||
Report
|
||||
|> where(open: true)
|
||||
|> Repo.aggregate(:count, :id)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -105,9 +105,13 @@ defmodule Philomena.UserLinks do
|
|||
UserLink.changeset(user_link, %{})
|
||||
end
|
||||
|
||||
def count_user_links() do
|
||||
UserLink
|
||||
|> where(aasm_state: "unverified")
|
||||
|> Repo.aggregate(:count, :id)
|
||||
def count_user_links(user) do
|
||||
if Canada.Can.can?(user, :edit, UserLink) do
|
||||
UserLink
|
||||
|> where(aasm_state: "unverified")
|
||||
|> Repo.aggregate(:count, :id)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,15 +26,15 @@ defmodule PhilomenaWeb.AdminCountersPlug do
|
|||
def call(conn, _opts) do
|
||||
user = conn.assigns.current_user
|
||||
|
||||
maybe_assign_admin_metrics(conn, staff?(user))
|
||||
maybe_assign_admin_metrics(conn, user, staff?(user))
|
||||
end
|
||||
|
||||
defp maybe_assign_admin_metrics(conn, false), do: conn
|
||||
defp maybe_assign_admin_metrics(conn, true) do
|
||||
duplicate_reports = DuplicateReports.count_duplicate_reports()
|
||||
reports = Reports.count_reports()
|
||||
user_links = UserLinks.count_user_links()
|
||||
dnps = DnpEntries.count_dnp_entries()
|
||||
defp maybe_assign_admin_metrics(conn, _user, false), do: conn
|
||||
defp maybe_assign_admin_metrics(conn, user, true) do
|
||||
duplicate_reports = DuplicateReports.count_duplicate_reports(user)
|
||||
reports = Reports.count_reports(user)
|
||||
user_links = UserLinks.count_user_links(user)
|
||||
dnps = DnpEntries.count_dnp_entries(user)
|
||||
|
||||
conn
|
||||
|> assign(:duplicate_report_count, duplicate_reports)
|
||||
|
|
|
@ -35,22 +35,26 @@
|
|||
= link to: "#", class: "header__link" do
|
||||
i.fa.fa-fw.fa-sticky-note
|
||||
| Mod Notes
|
||||
= link to: "#", class: "header__link", title: "Duplicates" do
|
||||
=<> "D"
|
||||
span.header__counter__admin
|
||||
= @duplicate_report_count
|
||||
= link to: "#", class: "header__link", title: "Reports" do
|
||||
=<> "R"
|
||||
span.header__counter__admin
|
||||
= @report_count
|
||||
= link to: "#", class: "header__link", title: "User Links" do
|
||||
=<> "L"
|
||||
span.header__counter__admin
|
||||
= @user_link_count
|
||||
= link to: "#", class: "header__link", title: "DNP Requests" do
|
||||
=<> "S"
|
||||
span.header__counter__admin
|
||||
= @dnp_entry_count
|
||||
= if @duplicate_report_count do
|
||||
= link to: "#", class: "header__link", title: "Duplicates" do
|
||||
=<> "D"
|
||||
span.header__counter__admin
|
||||
= @duplicate_report_count
|
||||
= if @report_count do
|
||||
= link to: "#", class: "header__link", title: "Reports" do
|
||||
=<> "R"
|
||||
span.header__counter__admin
|
||||
= @report_count
|
||||
= if @user_link_count do
|
||||
= link to: "#", class: "header__link", title: "User Links" do
|
||||
=<> "L"
|
||||
span.header__counter__admin
|
||||
= @user_link_count
|
||||
= if @dnp_entry_count do
|
||||
= link to: "#", class: "header__link", title: "DNP Requests" do
|
||||
=<> "S"
|
||||
span.header__counter__admin
|
||||
= @dnp_entry_count
|
||||
.dropdown.hide-mobile
|
||||
a.header__link title="Bans"
|
||||
=<> "B"
|
||||
|
|
Loading…
Reference in a new issue