AdminAPI: Allow filtering reports by rule_id
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
b354d70e85
commit
0ecd6ba35e
|
@ -1191,6 +1191,15 @@ defp restrict_filtered(query, %{blocking_user: %User{} = user}) do
|
||||||
|
|
||||||
defp restrict_filtered(query, _), do: query
|
defp restrict_filtered(query, _), do: query
|
||||||
|
|
||||||
|
defp restrict_rule(query, %{rule_id: rule_id}) do
|
||||||
|
from(
|
||||||
|
activity in query,
|
||||||
|
where: fragment("(?)->'rules' \\? (?)", activity.data, ^rule_id)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict_rule(query, _), do: query
|
||||||
|
|
||||||
defp exclude_poll_votes(query, %{include_poll_votes: true}), do: query
|
defp exclude_poll_votes(query, %{include_poll_votes: true}), do: query
|
||||||
|
|
||||||
defp exclude_poll_votes(query, _) do
|
defp exclude_poll_votes(query, _) do
|
||||||
|
@ -1353,6 +1362,7 @@ def fetch_activities_query(recipients, opts \\ %{}) do
|
||||||
|> restrict_instance(opts)
|
|> restrict_instance(opts)
|
||||||
|> restrict_announce_object_actor(opts)
|
|> restrict_announce_object_actor(opts)
|
||||||
|> restrict_filtered(opts)
|
|> restrict_filtered(opts)
|
||||||
|
|> restrict_rule(opts)
|
||||||
|> Activity.restrict_deactivated_users()
|
|> Activity.restrict_deactivated_users()
|
||||||
|> exclude_poll_votes(opts)
|
|> exclude_poll_votes(opts)
|
||||||
|> exclude_chat_messages(opts)
|
|> exclude_chat_messages(opts)
|
||||||
|
|
|
@ -30,6 +30,12 @@ def index_operation do
|
||||||
report_state(),
|
report_state(),
|
||||||
"Filter by report state"
|
"Filter by report state"
|
||||||
),
|
),
|
||||||
|
Operation.parameter(
|
||||||
|
:rule_id,
|
||||||
|
:query,
|
||||||
|
%Schema{type: :string},
|
||||||
|
"Filter by selected rule id"
|
||||||
|
),
|
||||||
Operation.parameter(
|
Operation.parameter(
|
||||||
:limit,
|
:limit,
|
||||||
:query,
|
:query,
|
||||||
|
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|
||||||
alias Pleroma.ModerationLog
|
alias Pleroma.ModerationLog
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.ReportNote
|
alias Pleroma.ReportNote
|
||||||
|
alias Pleroma.Rule
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
|
@ -313,6 +314,34 @@ test "returns 403 when requested by anonymous" do
|
||||||
"error" => "Invalid credentials."
|
"error" => "Invalid credentials."
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "returns reports with specified role_id", %{conn: conn} do
|
||||||
|
[reporter, target_user] = insert_pair(:user)
|
||||||
|
|
||||||
|
%{id: rule_id} = Rule.create(%{text: "Example rule"})
|
||||||
|
|
||||||
|
rule_id = to_string(rule_id)
|
||||||
|
|
||||||
|
{:ok, %{id: report_id}} =
|
||||||
|
CommonAPI.report(reporter, %{
|
||||||
|
account_id: target_user.id,
|
||||||
|
comment: "",
|
||||||
|
rule_ids: [rule_id]
|
||||||
|
})
|
||||||
|
|
||||||
|
{:ok, _report} =
|
||||||
|
CommonAPI.report(reporter, %{
|
||||||
|
account_id: target_user.id,
|
||||||
|
comment: ""
|
||||||
|
})
|
||||||
|
|
||||||
|
response =
|
||||||
|
conn
|
||||||
|
|> get("/api/pleroma/admin/reports?rule_id=#{rule_id}")
|
||||||
|
|> json_response_and_validate_schema(:ok)
|
||||||
|
|
||||||
|
assert %{"reports" => [%{"id" => ^report_id}]} = response
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "POST /api/pleroma/admin/reports/:id/notes" do
|
describe "POST /api/pleroma/admin/reports/:id/notes" do
|
||||||
|
|
|
@ -176,15 +176,17 @@ test "renders included rules" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
%{id: id, text: text} = Rule.create(%{text: "Example rule"})
|
%{id: rule_id, text: text} = Rule.create(%{text: "Example rule"})
|
||||||
|
|
||||||
|
rule_id = to_string(rule_id)
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, activity} =
|
||||||
CommonAPI.report(user, %{
|
CommonAPI.report(user, %{
|
||||||
account_id: other_user.id,
|
account_id: other_user.id,
|
||||||
rule_ids: [id]
|
rule_ids: [rule_id]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert %{rules: [%{id: ^id, text: ^text}]} =
|
assert %{rules: [%{id: ^rule_id, text: ^text}]} =
|
||||||
ReportView.render("show.json", Report.extract_report_info(activity))
|
ReportView.render("show.json", Report.extract_report_info(activity))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,6 +52,8 @@ test "submit a report with rule_ids", %{
|
||||||
} do
|
} do
|
||||||
%{id: rule_id} = Rule.create(%{text: "There are no rules"})
|
%{id: rule_id} = Rule.create(%{text: "There are no rules"})
|
||||||
|
|
||||||
|
rule_id = to_string(rule_id)
|
||||||
|
|
||||||
assert %{"action_taken" => false, "id" => id} =
|
assert %{"action_taken" => false, "id" => id} =
|
||||||
conn
|
conn
|
||||||
|> put_req_header("content-type", "application/json")
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|
Loading…
Reference in New Issue