Apply, suggestions, use strings for actual Mastodon API compatibility

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2022-05-30 12:30:03 +02:00
commit b354d70e85
11 changed files with 38 additions and 15 deletions

View file

@ -37,6 +37,8 @@ defmodule Pleroma.Rule do
def get(id), do: Repo.get(__MODULE__, id)
def exists?(id), do: not is_nil(get(id))
def create(params) do
{:ok, rule} =
%Rule{}

View file

@ -10,8 +10,8 @@ defmodule Pleroma.Web.AdminAPI.ReportView do
alias Pleroma.User
alias Pleroma.Web.AdminAPI
alias Pleroma.Web.AdminAPI.Report
alias Pleroma.Web.AdminAPI.RuleView
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MastodonAPI.InstanceView
alias Pleroma.Web.MastodonAPI.StatusView
defdelegate merge_account_views(user), to: AdminAPI.AccountView
@ -80,8 +80,10 @@ defmodule Pleroma.Web.AdminAPI.ReportView do
end
defp rules(rule_ids) do
rule_ids
|> Rule.get()
|> render_many(InstanceView, "rule.json", as: :rule)
rules =
rule_ids
|> Rule.get()
render(RuleView, "index.json", rules: rules)
end
end

View file

@ -13,7 +13,7 @@ defmodule Pleroma.Web.AdminAPI.RuleView do
def render("show.json", %{rule: rule} = _opts) do
%{
id: rule.id,
id: to_string(rule.id),
priority: rule.priority,
text: rule.text
}

View file

@ -175,7 +175,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.ReportOperation do
items: %Schema{
type: :object,
properties: %{
id: %Schema{type: :integer},
id: %Schema{type: :string},
text: %Schema{type: :string}
}
}

View file

@ -103,10 +103,9 @@ defmodule Pleroma.Web.ApiSpec.Admin.RuleOperation do
%Schema{
type: :object,
properties: %{
id: %Schema{type: :integer},
id: %Schema{type: :string},
priority: %Schema{type: :integer},
text: %Schema{type: :string},
created_at: %Schema{type: :string, format: :"date-time"}
text: %Schema{type: :string}
}
}
end

View file

@ -191,7 +191,7 @@ defmodule Pleroma.Web.ApiSpec.InstanceOperation do
items: %Schema{
type: :object,
properties: %{
id: %Schema{type: :integer},
id: %Schema{type: :string},
text: %Schema{type: :string}
}
}

View file

@ -57,7 +57,7 @@ defmodule Pleroma.Web.ApiSpec.ReportOperation do
rule_ids: %Schema{
type: :array,
nullable: true,
items: %Schema{type: :number},
items: %Schema{type: :string},
description: "Array of rules"
}
},
@ -67,7 +67,7 @@ defmodule Pleroma.Web.ApiSpec.ReportOperation do
"status_ids" => ["1337"],
"comment" => "bad status!",
"forward" => "false",
"rule_ids" => [3]
"rule_ids" => ["3"]
}
}
end

View file

@ -533,8 +533,7 @@ defmodule Pleroma.Web.CommonAPI do
defp get_report_rules(rule_ids) do
rule_ids
|> Rule.get()
|> Enum.map(& &1.id)
|> Enum.filter(&Rule.exists?/1)
end
def update_report_state(activity_ids, state) when is_list(activity_ids) do

View file

@ -66,7 +66,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
def render("rule.json", %{rule: rule}) do
%{
id: rule.id,
id: to_string(rule.id),
text: rule.text
}
end