Add admin dashboard, event reporting, moderation report screens, moderation log
Close #156 and #158 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -22,7 +22,8 @@ defmodule Mobilizon.Admin do
|
||||
def list_action_logs(page \\ nil, limit \\ nil) do
|
||||
from(
|
||||
r in ActionLog,
|
||||
preload: [:actor]
|
||||
preload: [:actor],
|
||||
order_by: [desc: :id]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> Repo.all()
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
import EctoEnum
|
||||
|
||||
defenum(Mobilizon.Admin.ActionLogAction, [
|
||||
"update",
|
||||
"create",
|
||||
"delete"
|
||||
])
|
||||
|
||||
defmodule Mobilizon.Admin.ActionLog do
|
||||
@moduledoc """
|
||||
ActionLog entity schema
|
||||
@@ -5,11 +13,13 @@ defmodule Mobilizon.Admin.ActionLog do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Admin.ActionLogAction
|
||||
|
||||
@timestamps_opts [type: :utc_datetime]
|
||||
@required_attrs [:action, :target_type, :target_id, :changes, :actor_id]
|
||||
|
||||
schema "admin_action_logs" do
|
||||
field(:action, :string)
|
||||
field(:action, ActionLogAction)
|
||||
field(:target_type, :string)
|
||||
field(:target_id, :integer)
|
||||
field(:changes, :map)
|
||||
|
||||
@@ -54,6 +54,21 @@ defmodule Mobilizon.Application do
|
||||
],
|
||||
id: :cache_ics
|
||||
),
|
||||
worker(
|
||||
Cachex,
|
||||
[
|
||||
:statistics,
|
||||
[
|
||||
limit: 10,
|
||||
expiration:
|
||||
expiration(
|
||||
default: :timer.minutes(60),
|
||||
interval: :timer.seconds(60)
|
||||
)
|
||||
]
|
||||
],
|
||||
id: :cache_statistics
|
||||
),
|
||||
worker(
|
||||
Cachex,
|
||||
[
|
||||
|
||||
@@ -42,6 +42,7 @@ defmodule Mobilizon.Events.EventOptions do
|
||||
}
|
||||
|
||||
@primary_key false
|
||||
@derive Jason.Encoder
|
||||
embedded_schema do
|
||||
field(:maximum_attendee_capacity, :integer)
|
||||
field(:remaining_attendee_capacity, :integer)
|
||||
|
||||
@@ -30,16 +30,28 @@ defmodule Mobilizon.Reports do
|
||||
|
||||
"""
|
||||
@spec list_reports(integer(), integer(), atom(), atom()) :: list(Report.t())
|
||||
def list_reports(page \\ nil, limit \\ nil, sort \\ :updated_at, direction \\ :asc) do
|
||||
def list_reports(
|
||||
page \\ nil,
|
||||
limit \\ nil,
|
||||
sort \\ :updated_at,
|
||||
direction \\ :desc,
|
||||
status \\ :open
|
||||
) do
|
||||
from(
|
||||
r in Report,
|
||||
preload: [:reported, :reporter, :manager, :event, :comments, :notes]
|
||||
preload: [:reported, :reporter, :manager, :event, :comments, :notes],
|
||||
where: r.status == ^status
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> sort(sort, direction)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
def count_opened_reports() do
|
||||
query = from(r in Report, where: r.status == ^:open)
|
||||
Repo.aggregate(query, :count, :id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single report.
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ defmodule Mobilizon.Reports.Note do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Reports.Report
|
||||
|
||||
@timestamps_opts [type: :utc_datetime]
|
||||
@attrs [:content, :moderator_id, :report_id]
|
||||
|
||||
@derive {Jason.Encoder, only: [:content]}
|
||||
|
||||
@@ -17,6 +17,8 @@ defmodule Mobilizon.Reports.Report do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Reports.Note
|
||||
|
||||
@timestamps_opts [type: :utc_datetime]
|
||||
|
||||
@derive {Jason.Encoder, only: [:status, :uri]}
|
||||
schema "reports" do
|
||||
field(:content, :string)
|
||||
@@ -48,7 +50,7 @@ defmodule Mobilizon.Reports.Report do
|
||||
def changeset(report, attrs) do
|
||||
report
|
||||
|> cast(attrs, [:content, :status, :uri, :reported_id, :reporter_id, :manager_id, :event_id])
|
||||
|> validate_required([:content, :uri, :reported_id, :reporter_id])
|
||||
|> validate_required([:uri, :reported_id, :reporter_id])
|
||||
end
|
||||
|
||||
def creation_changeset(report, attrs) do
|
||||
|
||||
Reference in New Issue
Block a user