mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
More documentation
This commit is contained in:
parent
c9bcda4e0a
commit
c8410e7957
2 changed files with 69 additions and 11 deletions
|
@ -12,6 +12,31 @@ defmodule Philomena.Reports do
|
|||
alias Philomena.IndexWorker
|
||||
alias Philomena.Polymorphic
|
||||
|
||||
@doc """
|
||||
Returns the current number of open reports.
|
||||
|
||||
If the user is allowed to view reports, returns the current count.
|
||||
If the user is not allowed to view reports, returns `nil`.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> count_reports(%User{})
|
||||
nil
|
||||
|
||||
iex> count_reports(%User{role: "admin"})
|
||||
4
|
||||
|
||||
"""
|
||||
def count_open_reports(user) do
|
||||
if Canada.Can.can?(user, :index, Report) do
|
||||
Report
|
||||
|> where(open: true)
|
||||
|> Repo.aggregate(:count)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of reports.
|
||||
|
||||
|
@ -173,6 +198,15 @@ defmodule Philomena.Reports do
|
|||
Report.changeset(report, %{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
Marks the report as claimed by the given user.
|
||||
|
||||
## Example
|
||||
|
||||
iex> claim_report(%Report{}, %User{})
|
||||
{:ok, %Report{}}
|
||||
|
||||
"""
|
||||
def claim_report(%Report{} = report, user) do
|
||||
report
|
||||
|> Report.claim_changeset(user)
|
||||
|
@ -180,6 +214,15 @@ defmodule Philomena.Reports do
|
|||
|> reindex_after_update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Marks the report as unclaimed.
|
||||
|
||||
## Example
|
||||
|
||||
iex> unclaim_report(%Report{})
|
||||
{:ok, %Report{}}
|
||||
|
||||
"""
|
||||
def unclaim_report(%Report{} = report) do
|
||||
report
|
||||
|> Report.unclaim_changeset()
|
||||
|
@ -187,6 +230,15 @@ defmodule Philomena.Reports do
|
|||
|> reindex_after_update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Marks the report as closed by the given user.
|
||||
|
||||
## Example
|
||||
|
||||
iex> close_report(%Report{}, %User{})
|
||||
{:ok, %Report{}}
|
||||
|
||||
"""
|
||||
def close_report(%Report{} = report, user) do
|
||||
report
|
||||
|> Report.close_changeset(user)
|
||||
|
@ -194,6 +246,15 @@ defmodule Philomena.Reports do
|
|||
|> reindex_after_update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Reindex all reports where the user or admin has `old_name`.
|
||||
|
||||
## Example
|
||||
|
||||
iex> user_name_reindex("Administrator", "Administrator2")
|
||||
{:ok, %Req.Response{}}
|
||||
|
||||
"""
|
||||
def user_name_reindex(old_name, new_name) do
|
||||
data = ReportIndex.user_name_update_by_query(old_name, new_name)
|
||||
|
||||
|
@ -210,18 +271,25 @@ defmodule Philomena.Reports do
|
|||
result
|
||||
end
|
||||
|
||||
@doc """
|
||||
Callback for post-transaction update.
|
||||
|
||||
See `close_report_query/2` for more information and example.
|
||||
"""
|
||||
def reindex_reports(report_ids) do
|
||||
Exq.enqueue(Exq, "indexing", IndexWorker, ["Reports", "id", report_ids])
|
||||
|
||||
report_ids
|
||||
end
|
||||
|
||||
@doc false
|
||||
def reindex_report(%Report{} = report) do
|
||||
Exq.enqueue(Exq, "indexing", IndexWorker, ["Reports", "id", [report.id]])
|
||||
|
||||
report
|
||||
end
|
||||
|
||||
@doc false
|
||||
def perform_reindex(column, condition) do
|
||||
Report
|
||||
|> where([r], field(r, ^column) in ^condition)
|
||||
|
@ -230,14 +298,4 @@ defmodule Philomena.Reports do
|
|||
|> Polymorphic.load_polymorphic(reportable: [reportable_id: :reportable_type])
|
||||
|> Enum.map(&Search.index_document(&1, Report))
|
||||
end
|
||||
|
||||
def count_reports(user) do
|
||||
if Canada.Can.can?(user, :index, Report) do
|
||||
Report
|
||||
|> where(open: true)
|
||||
|> Repo.aggregate(:count, :id)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,7 +34,7 @@ defmodule PhilomenaWeb.AdminCountersPlug do
|
|||
defp maybe_assign_admin_metrics(conn, user, true) do
|
||||
pending_approvals = Images.count_pending_approvals(user)
|
||||
duplicate_reports = DuplicateReports.count_duplicate_reports(user)
|
||||
reports = Reports.count_reports(user)
|
||||
reports = Reports.count_open_reports(user)
|
||||
artist_links = ArtistLinks.count_artist_links(user)
|
||||
dnps = DnpEntries.count_dnp_entries(user)
|
||||
|
||||
|
|
Loading…
Reference in a new issue