2020-05-21 15:43:56 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-05-21 15:43:56 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.AdminAPI.ReportController do
|
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
|
|
|
import Pleroma.Web.ControllerHelper, only: [json_response: 3]
|
|
|
|
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.ModerationLog
|
|
|
|
alias Pleroma.ReportNote
|
|
|
|
alias Pleroma.Web.ActivityPub.Utils
|
|
|
|
alias Pleroma.Web.AdminAPI
|
|
|
|
alias Pleroma.Web.AdminAPI.Report
|
|
|
|
alias Pleroma.Web.CommonAPI
|
2020-06-24 10:07:47 +00:00
|
|
|
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
2020-05-21 15:43:56 +00:00
|
|
|
|
|
|
|
require Logger
|
|
|
|
|
2020-06-03 15:10:11 +00:00
|
|
|
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
2021-02-17 18:37:23 +00:00
|
|
|
plug(OAuthScopesPlug, %{scopes: ["admin:read:reports"]} when action in [:index, :show])
|
2020-05-21 15:43:56 +00:00
|
|
|
|
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
2021-02-17 18:37:23 +00:00
|
|
|
%{scopes: ["admin:write:reports"]}
|
2020-05-21 15:43:56 +00:00
|
|
|
when action in [:update, :notes_create, :notes_delete]
|
|
|
|
)
|
|
|
|
|
|
|
|
action_fallback(AdminAPI.FallbackController)
|
|
|
|
|
2020-06-03 15:10:11 +00:00
|
|
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.ReportOperation
|
2020-05-21 15:43:56 +00:00
|
|
|
|
2020-06-03 15:10:11 +00:00
|
|
|
def index(conn, params) do
|
|
|
|
reports = Utils.get_reports(params, params.page, params.page_size)
|
2020-05-21 15:43:56 +00:00
|
|
|
|
|
|
|
render(conn, "index.json", reports: reports)
|
|
|
|
end
|
|
|
|
|
2020-06-03 15:10:11 +00:00
|
|
|
def show(conn, %{id: id}) do
|
2020-11-02 18:19:44 +00:00
|
|
|
with %Activity{} = report <- Activity.get_report(id) do
|
2020-05-21 15:43:56 +00:00
|
|
|
render(conn, "show.json", Report.extract_report_info(report))
|
|
|
|
else
|
|
|
|
_ -> {:error, :not_found}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Pleroma.Web.AdminAPI.ReportController: dialyzer errors
lib/pleroma/web/admin_api/controllers/report_controller.ex:48:no_return
Function update/2 has no local return.
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/report_controller.ex:70:call
The function call will not succeed.
Pleroma.Web.ControllerHelper.json_response(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:reports => _, _ => _},
_ => _
},
:bad_request,
_result :: [any()]
)
will never return since the 1st arguments differ
from the success typing arguments:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{binary(), binary()}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{binary(), binary()}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | 1..1_114_111,
any()
)
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/report_controller.ex:72:call
The function call will not succeed.
Pleroma.Web.ControllerHelper.json_response(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:reports => _, _ => _},
_ => _
},
:no_content,
<<>>
)
will never return since the 1st arguments differ
from the success typing arguments:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{binary(), binary()}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{binary(), binary()}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | 1..1_114_111,
any()
)
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/report_controller.ex:76:no_return
Function notes_create/2 has no local return.
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/report_controller.ex:89:call
The function call will not succeed.
Pleroma.Web.ControllerHelper.json_response(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:content => _, _ => _},
_ => _
},
:no_content,
<<>>
)
will never return since the 1st arguments differ
from the success typing arguments:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{binary(), binary()}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{binary(), binary()}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | 1..1_114_111,
any()
)
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/report_controller.ex:91:call
The function call will not succeed.
Pleroma.Web.ControllerHelper.json_response(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:content => _, _ => _},
_ => _
},
:bad_request,
<<>>
)
will never return since the 1st arguments differ
from the success typing arguments:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{binary(), binary()}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{binary(), binary()}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | 1..1_114_111,
any()
)
2024-01-28 21:32:50 +00:00
|
|
|
def update(%{assigns: %{user: admin}, body_params: %{"reports" => reports}} = conn, _) do
|
2020-05-21 15:43:56 +00:00
|
|
|
result =
|
2020-06-03 15:10:11 +00:00
|
|
|
Enum.map(reports, fn report ->
|
|
|
|
case CommonAPI.update_report_state(report.id, report.state) do
|
|
|
|
{:ok, activity} ->
|
2020-11-19 19:13:45 +00:00
|
|
|
report = Activity.get_by_id_with_user_actor(activity.id)
|
|
|
|
|
2020-06-03 15:10:11 +00:00
|
|
|
ModerationLog.insert_log(%{
|
|
|
|
action: "report_update",
|
|
|
|
actor: admin,
|
2020-11-19 19:13:45 +00:00
|
|
|
subject: activity,
|
|
|
|
subject_actor: report.user_actor
|
2020-06-03 15:10:11 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
activity
|
|
|
|
|
|
|
|
{:error, message} ->
|
|
|
|
%{id: report.id, error: message}
|
2020-05-21 15:43:56 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2020-06-03 15:10:11 +00:00
|
|
|
if Enum.any?(result, &Map.has_key?(&1, :error)) do
|
|
|
|
json_response(conn, :bad_request, result)
|
|
|
|
else
|
|
|
|
json_response(conn, :no_content, "")
|
2020-05-21 15:43:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Pleroma.Web.AdminAPI.ReportController: dialyzer errors
lib/pleroma/web/admin_api/controllers/report_controller.ex:48:no_return
Function update/2 has no local return.
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/report_controller.ex:70:call
The function call will not succeed.
Pleroma.Web.ControllerHelper.json_response(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:reports => _, _ => _},
_ => _
},
:bad_request,
_result :: [any()]
)
will never return since the 1st arguments differ
from the success typing arguments:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{binary(), binary()}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{binary(), binary()}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | 1..1_114_111,
any()
)
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/report_controller.ex:72:call
The function call will not succeed.
Pleroma.Web.ControllerHelper.json_response(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:reports => _, _ => _},
_ => _
},
:no_content,
<<>>
)
will never return since the 1st arguments differ
from the success typing arguments:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{binary(), binary()}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{binary(), binary()}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | 1..1_114_111,
any()
)
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/report_controller.ex:76:no_return
Function notes_create/2 has no local return.
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/report_controller.ex:89:call
The function call will not succeed.
Pleroma.Web.ControllerHelper.json_response(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:content => _, _ => _},
_ => _
},
:no_content,
<<>>
)
will never return since the 1st arguments differ
from the success typing arguments:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{binary(), binary()}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{binary(), binary()}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | 1..1_114_111,
any()
)
________________________________________________________________________________
lib/pleroma/web/admin_api/controllers/report_controller.ex:91:call
The function call will not succeed.
Pleroma.Web.ControllerHelper.json_response(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:content => _, _ => _},
_ => _
},
:bad_request,
<<>>
)
will never return since the 1st arguments differ
from the success typing arguments:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() =>
binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{binary(), binary()}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{binary(), binary()}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | 1..1_114_111,
any()
)
2024-01-28 21:32:50 +00:00
|
|
|
def notes_create(%{assigns: %{user: user}, body_params: %{"content" => content}} = conn, %{
|
2020-06-03 15:10:11 +00:00
|
|
|
id: report_id
|
2020-05-21 15:43:56 +00:00
|
|
|
}) do
|
2020-11-19 19:13:45 +00:00
|
|
|
with {:ok, _} <- ReportNote.create(user.id, report_id, content),
|
|
|
|
report <- Activity.get_by_id_with_user_actor(report_id) do
|
2020-05-21 15:43:56 +00:00
|
|
|
ModerationLog.insert_log(%{
|
|
|
|
action: "report_note",
|
|
|
|
actor: user,
|
2020-11-19 19:13:45 +00:00
|
|
|
subject: report,
|
|
|
|
subject_actor: report.user_actor,
|
2020-05-21 15:43:56 +00:00
|
|
|
text: content
|
|
|
|
})
|
|
|
|
|
|
|
|
json_response(conn, :no_content, "")
|
|
|
|
else
|
|
|
|
_ -> json_response(conn, :bad_request, "")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def notes_delete(%{assigns: %{user: user}} = conn, %{
|
2020-06-03 15:10:11 +00:00
|
|
|
id: note_id,
|
|
|
|
report_id: report_id
|
2020-05-21 15:43:56 +00:00
|
|
|
}) do
|
2020-11-19 19:13:45 +00:00
|
|
|
with {:ok, note} <- ReportNote.destroy(note_id),
|
|
|
|
report <- Activity.get_by_id_with_user_actor(report_id) do
|
2020-05-21 15:43:56 +00:00
|
|
|
ModerationLog.insert_log(%{
|
|
|
|
action: "report_note_delete",
|
|
|
|
actor: user,
|
2020-11-19 19:13:45 +00:00
|
|
|
subject: report,
|
|
|
|
subject_actor: report.user_actor,
|
2020-05-21 15:43:56 +00:00
|
|
|
text: note.content
|
|
|
|
})
|
|
|
|
|
|
|
|
json_response(conn, :no_content, "")
|
|
|
|
else
|
|
|
|
_ -> json_response(conn, :bad_request, "")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|