Apply, suggestions, use strings for actual Mastodon API compatibility
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
5c383ada8a
commit
b354d70e85
|
@ -37,6 +37,8 @@ def get(ids) when is_list(ids) do
|
||||||
|
|
||||||
def get(id), do: Repo.get(__MODULE__, id)
|
def get(id), do: Repo.get(__MODULE__, id)
|
||||||
|
|
||||||
|
def exists?(id), do: not is_nil(get(id))
|
||||||
|
|
||||||
def create(params) do
|
def create(params) do
|
||||||
{:ok, rule} =
|
{:ok, rule} =
|
||||||
%Rule{}
|
%Rule{}
|
||||||
|
|
|
@ -10,8 +10,8 @@ defmodule Pleroma.Web.AdminAPI.ReportView do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.AdminAPI
|
alias Pleroma.Web.AdminAPI
|
||||||
alias Pleroma.Web.AdminAPI.Report
|
alias Pleroma.Web.AdminAPI.Report
|
||||||
|
alias Pleroma.Web.AdminAPI.RuleView
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
alias Pleroma.Web.MastodonAPI.InstanceView
|
|
||||||
alias Pleroma.Web.MastodonAPI.StatusView
|
alias Pleroma.Web.MastodonAPI.StatusView
|
||||||
|
|
||||||
defdelegate merge_account_views(user), to: AdminAPI.AccountView
|
defdelegate merge_account_views(user), to: AdminAPI.AccountView
|
||||||
|
@ -80,8 +80,10 @@ defp rules(nil) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp rules(rule_ids) do
|
defp rules(rule_ids) do
|
||||||
rule_ids
|
rules =
|
||||||
|> Rule.get()
|
rule_ids
|
||||||
|> render_many(InstanceView, "rule.json", as: :rule)
|
|> Rule.get()
|
||||||
|
|
||||||
|
render(RuleView, "index.json", rules: rules)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,7 @@ def render("index.json", %{rules: rules} = _opts) do
|
||||||
|
|
||||||
def render("show.json", %{rule: rule} = _opts) do
|
def render("show.json", %{rule: rule} = _opts) do
|
||||||
%{
|
%{
|
||||||
id: rule.id,
|
id: to_string(rule.id),
|
||||||
priority: rule.priority,
|
priority: rule.priority,
|
||||||
text: rule.text
|
text: rule.text
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,7 +175,7 @@ defp report do
|
||||||
items: %Schema{
|
items: %Schema{
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: %{
|
properties: %{
|
||||||
id: %Schema{type: :integer},
|
id: %Schema{type: :string},
|
||||||
text: %Schema{type: :string}
|
text: %Schema{type: :string}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,10 +103,9 @@ defp rule do
|
||||||
%Schema{
|
%Schema{
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: %{
|
properties: %{
|
||||||
id: %Schema{type: :integer},
|
id: %Schema{type: :string},
|
||||||
priority: %Schema{type: :integer},
|
priority: %Schema{type: :integer},
|
||||||
text: %Schema{type: :string},
|
text: %Schema{type: :string}
|
||||||
created_at: %Schema{type: :string, format: :"date-time"}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -191,7 +191,7 @@ defp array_of_rules do
|
||||||
items: %Schema{
|
items: %Schema{
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: %{
|
properties: %{
|
||||||
id: %Schema{type: :integer},
|
id: %Schema{type: :string},
|
||||||
text: %Schema{type: :string}
|
text: %Schema{type: :string}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ defp create_request do
|
||||||
rule_ids: %Schema{
|
rule_ids: %Schema{
|
||||||
type: :array,
|
type: :array,
|
||||||
nullable: true,
|
nullable: true,
|
||||||
items: %Schema{type: :number},
|
items: %Schema{type: :string},
|
||||||
description: "Array of rules"
|
description: "Array of rules"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -67,7 +67,7 @@ defp create_request do
|
||||||
"status_ids" => ["1337"],
|
"status_ids" => ["1337"],
|
||||||
"comment" => "bad status!",
|
"comment" => "bad status!",
|
||||||
"forward" => "false",
|
"forward" => "false",
|
||||||
"rule_ids" => [3]
|
"rule_ids" => ["3"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -533,8 +533,7 @@ defp get_report_rules(nil) do
|
||||||
|
|
||||||
defp get_report_rules(rule_ids) do
|
defp get_report_rules(rule_ids) do
|
||||||
rule_ids
|
rule_ids
|
||||||
|> Rule.get()
|
|> Enum.filter(&Rule.exists?/1)
|
||||||
|> Enum.map(& &1.id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_report_state(activity_ids, state) when is_list(activity_ids) do
|
def update_report_state(activity_ids, state) when is_list(activity_ids) do
|
||||||
|
|
|
@ -66,7 +66,7 @@ def render("rules.json", _) do
|
||||||
|
|
||||||
def render("rule.json", %{rule: rule}) do
|
def render("rule.json", %{rule: rule}) do
|
||||||
%{
|
%{
|
||||||
id: rule.id,
|
id: to_string(rule.id),
|
||||||
text: rule.text
|
text: rule.text
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,6 +27,10 @@ test "sorts rules by priority", %{conn: conn} do
|
||||||
%{id: id2} = Rule.create(%{text: "Second rule", priority: 2})
|
%{id: id2} = Rule.create(%{text: "Second rule", priority: 2})
|
||||||
%{id: id3} = Rule.create(%{text: "Third rule", priority: 1})
|
%{id: id3} = Rule.create(%{text: "Third rule", priority: 1})
|
||||||
|
|
||||||
|
id1 = to_string(id1)
|
||||||
|
id2 = to_string(id2)
|
||||||
|
id3 = to_string(id3)
|
||||||
|
|
||||||
response =
|
response =
|
||||||
conn
|
conn
|
||||||
|> get("/api/pleroma/admin/rules")
|
|> get("/api/pleroma/admin/rules")
|
||||||
|
|
|
@ -65,6 +65,23 @@ test "submit a report with rule_ids", %{
|
||||||
assert %Activity{data: %{"rules" => [^rule_id]}} = Activity.get_report(id)
|
assert %Activity{data: %{"rules" => [^rule_id]}} = Activity.get_report(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "rules field is empty if provided wrong rule id", %{
|
||||||
|
conn: conn,
|
||||||
|
target_user: target_user
|
||||||
|
} do
|
||||||
|
assert %{"id" => id} =
|
||||||
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/v1/reports", %{
|
||||||
|
"account_id" => target_user.id,
|
||||||
|
"forward" => "false",
|
||||||
|
"rule_ids" => ["-1"]
|
||||||
|
})
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert %Activity{data: %{"rules" => []}} = Activity.get_report(id)
|
||||||
|
end
|
||||||
|
|
||||||
test "account_id is required", %{
|
test "account_id is required", %{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
activity: activity
|
activity: activity
|
||||||
|
|
Loading…
Reference in New Issue