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 json_response: 3
] ]
require Logger
plug(Pleroma.Web.ApiSpec.CastAndValidate) plug(Pleroma.Web.ApiSpec.CastAndValidate)
plug( plug(

View File

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