Merge branch 'instance-contact-account' into 'develop'
Add contact account to InstanceView See merge request soapbox-pub/rebased!201
This commit is contained in:
commit
fc93cce682
3 changed files with 38 additions and 3 deletions
|
@ -566,6 +566,12 @@
|
||||||
"Cool instance"
|
"Cool instance"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
%{
|
||||||
|
key: :contact_username,
|
||||||
|
type: :string,
|
||||||
|
description: "Instance owner username",
|
||||||
|
suggestions: ["admin"]
|
||||||
|
},
|
||||||
%{
|
%{
|
||||||
key: :limit,
|
key: :limit,
|
||||||
type: :integer,
|
type: :integer,
|
||||||
|
|
|
@ -6,7 +6,9 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
||||||
use Pleroma.Web, :view
|
use Pleroma.Web, :view
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.MRF
|
alias Pleroma.Web.ActivityPub.MRF
|
||||||
|
alias Pleroma.Web.MastodonAPI
|
||||||
|
|
||||||
@mastodon_api_level "2.7.2"
|
@mastodon_api_level "2.7.2"
|
||||||
|
|
||||||
|
@ -31,6 +33,7 @@ def render("show.json", _) do
|
||||||
registrations: Keyword.get(instance, :registrations_open),
|
registrations: Keyword.get(instance, :registrations_open),
|
||||||
approval_required: Keyword.get(instance, :account_approval_required),
|
approval_required: Keyword.get(instance, :account_approval_required),
|
||||||
configuration: configuration(),
|
configuration: configuration(),
|
||||||
|
contact_account: contact_account(Keyword.get(instance, :contact_username)),
|
||||||
rules: render(__MODULE__, "rules.json"),
|
rules: render(__MODULE__, "rules.json"),
|
||||||
# Extra (not present in Mastodon):
|
# Extra (not present in Mastodon):
|
||||||
max_toot_chars: Keyword.get(instance, :limit),
|
max_toot_chars: Keyword.get(instance, :limit),
|
||||||
|
@ -74,7 +77,7 @@ def render("show2.json", _) do
|
||||||
},
|
},
|
||||||
contact: %{
|
contact: %{
|
||||||
email: Keyword.get(instance, :email),
|
email: Keyword.get(instance, :email),
|
||||||
account: nil
|
account: contact_account(Keyword.get(instance, :contact_username))
|
||||||
},
|
},
|
||||||
rules: render(__MODULE__, "rules.json"),
|
rules: render(__MODULE__, "rules.json"),
|
||||||
# Extra (not present in Mastodon):
|
# Extra (not present in Mastodon):
|
||||||
|
@ -250,4 +253,20 @@ defp pleroma_configuration2(instance) do
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp contact_account(nil), do: nil
|
||||||
|
|
||||||
|
defp contact_account("@" <> username) do
|
||||||
|
contact_account(username)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp contact_account(username) do
|
||||||
|
user = User.get_cached_by_nickname(username)
|
||||||
|
|
||||||
|
if user do
|
||||||
|
MastodonAPI.AccountView.render("show.json", %{user: user, for: nil})
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -139,9 +139,19 @@ test "get oauth_consumer_strategies", %{conn: conn} do
|
||||||
assert result["pleroma"]["oauth_consumer_strategies"] == ["keycloak"]
|
assert result["pleroma"]["oauth_consumer_strategies"] == ["keycloak"]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get instance information v2", %{conn: conn} do
|
test "get instance contact information", %{conn: conn} do
|
||||||
clear_config([:auth, :oauth_consumer_strategies], [])
|
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
|
||||||
assert get(conn, "/api/v2/instance")
|
assert get(conn, "/api/v2/instance")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue