Instance rules: Use render_many

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2022-02-07 23:41:41 +01:00
parent 432599311d
commit 384f8bfa78
2 changed files with 11 additions and 10 deletions

View file

@ -14,8 +14,6 @@ defmodule Pleroma.Web.AdminAPI.RuleController do
json_response: 3
]
require Logger
plug(Pleroma.Web.ApiSpec.CastAndValidate)
plug(

View file

@ -40,7 +40,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
background_image: Pleroma.Web.Endpoint.url() <> Keyword.get(instance, :background_image),
shout_limit: Config.get([:shout, :limit]),
description_limit: Keyword.get(instance, :description_limit),
rules: rules(),
rules: render(__MODULE__, "rules.json"),
pleroma: %{
metadata: %{
account_activation_required: Keyword.get(instance, :account_activation_required),
@ -59,7 +59,16 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
end
def render("rules.json", _) do
rules()
Pleroma.Rule.query()
|> Pleroma.Repo.all()
|> render_many(__MODULE__, "rule.json", as: :rule)
end
def render("rule.json", %{rule: rule}) do
%{
id: rule.id,
text: rule.text
}
end
def features do
@ -142,10 +151,4 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
value_length: Config.get([:instance, :account_field_value_length])
}
end
def rules do
Pleroma.Rule.query()
|> Pleroma.Repo.all()
|> Enum.map(&%{id: &1.id, text: &1.text})
end
end