feat(spam): Introduce checking new accounts, events & comments for spam with the help of Akismet
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -5,11 +5,13 @@ defmodule Mobilizon.GraphQL.API.Reports do
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.{Admin, Users}
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Activity}
|
||||
alias Mobilizon.Reports, as: ReportsAction
|
||||
alias Mobilizon.Reports.{Note, Report, ReportStatus}
|
||||
alias Mobilizon.Service.Akismet
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Activity}
|
||||
import Mobilizon.Web.Gettext, only: [dgettext: 2]
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
Create a report/flag on an actor, and optionally on an event or on comments.
|
||||
@@ -20,18 +22,48 @@ defmodule Mobilizon.GraphQL.API.Reports do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Update the state of a report
|
||||
Update the status of a report
|
||||
"""
|
||||
@spec update_report_status(Actor.t(), Report.t(), atom()) ::
|
||||
@spec update_report_status(Actor.t(), Report.t(), atom(), atom() | nil) ::
|
||||
{:ok, Report.t()} | {:error, Ecto.Changeset.t() | String.t()}
|
||||
def update_report_status(%Actor{} = actor, %Report{} = report, state) do
|
||||
if ReportStatus.valid_value?(state) do
|
||||
with {:ok, %Report{} = report} <- ReportsAction.update_report(report, %{"status" => state}) do
|
||||
Admin.log_action(actor, "update", report)
|
||||
def update_report_status(
|
||||
%Actor{} = actor,
|
||||
%Report{status: old_status} = report,
|
||||
status,
|
||||
antispam_feedback \\ nil
|
||||
) do
|
||||
if ReportStatus.valid_value?(status) do
|
||||
with {:ok, %Report{} = report} <-
|
||||
ReportsAction.update_report(report, %{
|
||||
"status" => status,
|
||||
"antispam_feedback" => antispam_feedback
|
||||
}) do
|
||||
if old_status != status do
|
||||
Admin.log_action(actor, "update", report)
|
||||
end
|
||||
|
||||
antispam_response =
|
||||
case antispam_feedback do
|
||||
:ham ->
|
||||
Logger.debug("Reporting a report details as ham")
|
||||
Akismet.report_ham(report)
|
||||
|
||||
:spam ->
|
||||
Logger.debug("Reporting a report details as spam")
|
||||
Akismet.report_spam(report)
|
||||
|
||||
_ ->
|
||||
:ok
|
||||
end
|
||||
|
||||
if antispam_response != :ok do
|
||||
Logger.warn("Antispam response has been #{inspect(antispam_response)}")
|
||||
end
|
||||
|
||||
{:ok, report}
|
||||
end
|
||||
else
|
||||
{:error, "Unsupported state"}
|
||||
{:error, dgettext("errors", "Unsupported status for a report")}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -58,7 +90,11 @@ defmodule Mobilizon.GraphQL.API.Reports do
|
||||
{:ok, note}
|
||||
end
|
||||
else
|
||||
{:error, "You need to be a moderator or an administrator to create a note on a report"}
|
||||
{:error,
|
||||
dgettext(
|
||||
"errors",
|
||||
"You need to be a moderator or an administrator to create a note on a report"
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -81,10 +117,14 @@ defmodule Mobilizon.GraphQL.API.Reports do
|
||||
{:ok, note}
|
||||
end
|
||||
else
|
||||
{:error, "You need to be a moderator or an administrator to create a note on a report"}
|
||||
{:error,
|
||||
dgettext(
|
||||
"errors",
|
||||
"You need to be a moderator or an administrator to create a note on a report"
|
||||
)}
|
||||
end
|
||||
else
|
||||
{:error, "You can only remove your own notes"}
|
||||
{:error, dgettext("errors", "You can only remove your own notes")}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user