Merge branch 'instance-contact-account' into 'develop'

Add contact account to InstanceView

See merge request pleroma/pleroma!3960
This commit is contained in:
tusooa 2024-03-10 13:14:19 +00:00
commit df7a8d4efe
4 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1 @@
Add contact account to InstanceView

View File

@ -574,6 +574,12 @@
"https://status.pleroma.example.org"
]
},
%{
key: :contact_username,
type: :string,
description: "Instance owner username",
suggestions: ["admin"]
},
%{
key: :limit,
type: :integer,

View File

@ -28,6 +28,7 @@ def render("show.json", _) do
|> to_string,
registrations: Keyword.get(instance, :registrations_open),
approval_required: Keyword.get(instance, :account_approval_required),
contact_account: contact_account(Keyword.get(instance, :contact_username)),
configuration: configuration(),
# Extra (not present in Mastodon):
max_toot_chars: Keyword.get(instance, :limit),
@ -68,7 +69,7 @@ def render("show2.json", _) do
},
contact: %{
email: Keyword.get(instance, :email),
account: nil
account: contact_account(Keyword.get(instance, :contact_username))
},
# Extra (not present in Mastodon):
pleroma: pleroma_configuration2(instance)
@ -170,6 +171,22 @@ defp fields_limits do
}
end
defp contact_account(nil), do: nil
defp contact_account("@" <> username) do
contact_account(username)
end
defp contact_account(username) do
user = Pleroma.User.get_cached_by_nickname(username)
if user do
Pleroma.Web.MastodonAPI.AccountView.render("show.json", %{user: user, for: nil})
else
nil
end
end
defp configuration do
%{
accounts: %{

View File

@ -107,6 +107,18 @@ test "instance languages", %{conn: conn} do
|> json_response_and_validate_schema(200)
end
test "get instance contact information", %{conn: conn} do
user = insert(:user, %{local: true})
clear_config([:instance, :contact_username], user.nickname)
conn = get(conn, "/api/v1/instance")
assert result = json_response_and_validate_schema(conn, 200)
assert result["contact_account"]["id"] == user.id
end
test "get instance information v2", %{conn: conn} do
clear_config([:auth, :oauth_consumer_strategies], [])