MastoAPI Accounts: Add fetching by nickname.
This is to make it easier for the frontends to handle domain.com/users/nickname urls.
This commit is contained in:
parent
2c8deecdd2
commit
3474066f6d
|
@ -19,3 +19,7 @@ Adding the parameter `with_muted=true` to the timeline queries will also return
|
||||||
Has these additional fields under the `pleroma` object:
|
Has these additional fields under the `pleroma` object:
|
||||||
|
|
||||||
- `local`: true if the post was made on the local instance.
|
- `local`: true if the post was made on the local instance.
|
||||||
|
|
||||||
|
## Accounts
|
||||||
|
|
||||||
|
- `/api/v1/accounts/:id`: The `id` parameter can also be the `nickname` of the user. This only works in this endpoint, not the deeper nested ones for following etc.
|
||||||
|
|
|
@ -131,8 +131,8 @@ def verify_credentials(%{assigns: %{user: user}} = conn, _) do
|
||||||
json(conn, account)
|
json(conn, account)
|
||||||
end
|
end
|
||||||
|
|
||||||
def user(%{assigns: %{user: for_user}} = conn, %{"id" => id}) do
|
def user(%{assigns: %{user: for_user}} = conn, %{"id" => nickname_or_id}) do
|
||||||
with %User{} = user <- Repo.get(User, id),
|
with %User{} = user <- User.get_cached_by_nickname_or_id(nickname_or_id),
|
||||||
true <- User.auth_active?(user) || user.id == for_user.id || User.superuser?(for_user) do
|
true <- User.auth_active?(user) || user.id == for_user.id || User.superuser?(for_user) do
|
||||||
account = AccountView.render("account.json", %{user: user, for: for_user})
|
account = AccountView.render("account.json", %{user: user, for: for_user})
|
||||||
json(conn, account)
|
json(conn, account)
|
||||||
|
|
|
@ -1064,6 +1064,17 @@ test "account fetching", %{conn: conn} do
|
||||||
assert %{"error" => "Can't find user"} = json_response(conn, 404)
|
assert %{"error" => "Can't find user"} = json_response(conn, 404)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "account fetching also works nickname", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/accounts/#{user.nickname}")
|
||||||
|
|
||||||
|
assert %{"id" => id} = json_response(conn, 200)
|
||||||
|
assert id == user.id
|
||||||
|
end
|
||||||
|
|
||||||
test "media upload", %{conn: conn} do
|
test "media upload", %{conn: conn} do
|
||||||
file = %Plug.Upload{
|
file = %Plug.Upload{
|
||||||
content_type: "image/jpg",
|
content_type: "image/jpg",
|
||||||
|
@ -1950,7 +1961,7 @@ test "submit a report with statuses and comment", %{
|
||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "accound_id is required", %{
|
test "account_id is required", %{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
reporter: reporter,
|
reporter: reporter,
|
||||||
activity: activity
|
activity: activity
|
||||||
|
|
Loading…
Reference in a new issue