forked from AkkomaGang/akkoma
proper error codes for error in adminFE
This commit is contained in:
parent
f928267773
commit
c5863438ba
4 changed files with 50 additions and 43 deletions
|
@ -488,35 +488,39 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
||||||
|
|
||||||
### Change the user's email, password, display and settings-related fields
|
### Change the user's email, password, display and settings-related fields
|
||||||
|
|
||||||
- Params:
|
* Params:
|
||||||
- `email`
|
* `email`
|
||||||
- `password`
|
* `password`
|
||||||
- `name`
|
* `name`
|
||||||
- `bio`
|
* `bio`
|
||||||
- `avatar`
|
* `avatar`
|
||||||
- `locked`
|
* `locked`
|
||||||
- `no_rich_text`
|
* `no_rich_text`
|
||||||
- `default_scope`
|
* `default_scope`
|
||||||
- `banner`
|
* `banner`
|
||||||
- `hide_follows`
|
* `hide_follows`
|
||||||
- `hide_followers`
|
* `hide_followers`
|
||||||
- `hide_followers_count`
|
* `hide_followers_count`
|
||||||
- `hide_follows_count`
|
* `hide_follows_count`
|
||||||
- `hide_favorites`
|
* `hide_favorites`
|
||||||
- `allow_following_move`
|
* `allow_following_move`
|
||||||
- `background`
|
* `background`
|
||||||
- `show_role`
|
* `show_role`
|
||||||
- `skip_thread_containment`
|
* `skip_thread_containment`
|
||||||
- `fields`
|
* `fields`
|
||||||
- `discoverable`
|
* `discoverable`
|
||||||
- `actor_type`
|
* `actor_type`
|
||||||
|
|
||||||
- Response:
|
* Responses:
|
||||||
|
|
||||||
|
Status: 200
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{"status": "success"}
|
{"status": "success"}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Status: 400
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{"errors":
|
{"errors":
|
||||||
{"actor_type": "is invalid"},
|
{"actor_type": "is invalid"},
|
||||||
|
@ -525,8 +529,10 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Status: 404
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{"error": "Unable to update user."}
|
{"error": "Not found"}
|
||||||
```
|
```
|
||||||
|
|
||||||
## `GET /api/pleroma/admin/reports`
|
## `GET /api/pleroma/admin/reports`
|
||||||
|
|
|
@ -111,8 +111,7 @@ def user_delete(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames})
|
||||||
action: "delete"
|
action: "delete"
|
||||||
})
|
})
|
||||||
|
|
||||||
conn
|
json(conn, nicknames)
|
||||||
|> json(nicknames)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_follow(%{assigns: %{user: admin}} = conn, %{
|
def user_follow(%{assigns: %{user: admin}} = conn, %{
|
||||||
|
@ -131,8 +130,7 @@ def user_follow(%{assigns: %{user: admin}} = conn, %{
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
conn
|
json(conn, "ok")
|
||||||
|> json("ok")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_unfollow(%{assigns: %{user: admin}} = conn, %{
|
def user_unfollow(%{assigns: %{user: admin}} = conn, %{
|
||||||
|
@ -151,8 +149,7 @@ def user_unfollow(%{assigns: %{user: admin}} = conn, %{
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
conn
|
json(conn, "ok")
|
||||||
|> json("ok")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def users_create(%{assigns: %{user: admin}} = conn, %{"users" => users}) do
|
def users_create(%{assigns: %{user: admin}} = conn, %{"users" => users}) do
|
||||||
|
@ -191,8 +188,7 @@ def users_create(%{assigns: %{user: admin}} = conn, %{"users" => users}) do
|
||||||
action: "create"
|
action: "create"
|
||||||
})
|
})
|
||||||
|
|
||||||
conn
|
json(conn, res)
|
||||||
|> json(res)
|
|
||||||
|
|
||||||
{:error, id, changeset, _} ->
|
{:error, id, changeset, _} ->
|
||||||
res =
|
res =
|
||||||
|
@ -363,8 +359,8 @@ defp maybe_parse_filters(filters) do
|
||||||
filters
|
filters
|
||||||
|> String.split(",")
|
|> String.split(",")
|
||||||
|> Enum.filter(&Enum.member?(@filters, &1))
|
|> Enum.filter(&Enum.member?(@filters, &1))
|
||||||
|> Enum.map(&String.to_atom(&1))
|
|> Enum.map(&String.to_atom/1)
|
||||||
|> Enum.into(%{}, &{&1, true})
|
|> Map.new(&{&1, true})
|
||||||
end
|
end
|
||||||
|
|
||||||
def right_add_multiple(%{assigns: %{user: admin}} = conn, %{
|
def right_add_multiple(%{assigns: %{user: admin}} = conn, %{
|
||||||
|
@ -568,10 +564,10 @@ def update_user_credentials(
|
||||||
{:error, changeset} ->
|
{:error, changeset} ->
|
||||||
errors = Map.new(changeset.errors, fn {key, {error, _}} -> {key, error} end)
|
errors = Map.new(changeset.errors, fn {key, {error, _}} -> {key, error} end)
|
||||||
|
|
||||||
json(conn, %{errors: errors})
|
{:errors, errors}
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
json(conn, %{error: "Unable to update user."})
|
{:error, :not_found}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -616,7 +612,7 @@ defp configurable_from_database do
|
||||||
def reload_emoji(conn, _params) do
|
def reload_emoji(conn, _params) do
|
||||||
Pleroma.Emoji.reload()
|
Pleroma.Emoji.reload()
|
||||||
|
|
||||||
conn |> json("ok")
|
json(conn, "ok")
|
||||||
end
|
end
|
||||||
|
|
||||||
def confirm_email(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames}) do
|
def confirm_email(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames}) do
|
||||||
|
@ -630,7 +626,7 @@ def confirm_email(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames}
|
||||||
action: "confirm_email"
|
action: "confirm_email"
|
||||||
})
|
})
|
||||||
|
|
||||||
conn |> json("")
|
json(conn, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
def resend_confirmation_email(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames}) do
|
def resend_confirmation_email(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames}) do
|
||||||
|
@ -644,14 +640,13 @@ def resend_confirmation_email(%{assigns: %{user: admin}} = conn, %{"nicknames" =
|
||||||
action: "resend_confirmation_email"
|
action: "resend_confirmation_email"
|
||||||
})
|
})
|
||||||
|
|
||||||
conn |> json("")
|
json(conn, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
def stats(conn, _) do
|
def stats(conn, _) do
|
||||||
count = Stats.get_status_visibility_count()
|
count = Stats.get_status_visibility_count()
|
||||||
|
|
||||||
conn
|
json(conn, %{"status_visibility" => count})
|
||||||
|> json(%{"status_visibility" => count})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp page_params(params) do
|
defp page_params(params) do
|
||||||
|
|
|
@ -17,6 +17,12 @@ def call(conn, {:error, reason}) do
|
||||||
|> json(%{error: reason})
|
|> json(%{error: reason})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def call(conn, {:errors, errors}) do
|
||||||
|
conn
|
||||||
|
|> put_status(:bad_request)
|
||||||
|
|> json(%{errors: errors})
|
||||||
|
end
|
||||||
|
|
||||||
def call(conn, {:param_cast, _}) do
|
def call(conn, {:param_cast, _}) do
|
||||||
conn
|
conn
|
||||||
|> put_status(:bad_request)
|
|> put_status(:bad_request)
|
||||||
|
|
|
@ -1599,14 +1599,14 @@ test "changes actor type from permitted list", %{conn: conn, user: user} do
|
||||||
assert patch(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials", %{
|
assert patch(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials", %{
|
||||||
"actor_type" => "Application"
|
"actor_type" => "Application"
|
||||||
})
|
})
|
||||||
|> json_response(200) == %{"errors" => %{"actor_type" => "is invalid"}}
|
|> json_response(400) == %{"errors" => %{"actor_type" => "is invalid"}}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update non existing user", %{conn: conn} do
|
test "update non existing user", %{conn: conn} do
|
||||||
assert patch(conn, "/api/pleroma/admin/users/non-existing/credentials", %{
|
assert patch(conn, "/api/pleroma/admin/users/non-existing/credentials", %{
|
||||||
"password" => "new_password"
|
"password" => "new_password"
|
||||||
})
|
})
|
||||||
|> json_response(200) == %{"error" => "Unable to update user."}
|
|> json_response(404) == %{"error" => "Not found"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue