forked from AkkomaGang/akkoma
Add support for bot field in update_credentials
This commit is contained in:
parent
436bb0cd12
commit
b63646169d
4 changed files with 72 additions and 0 deletions
|
@ -40,6 +40,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Mastodon API: Support for `include_types` in `/api/v1/notifications`.
|
- Mastodon API: Support for `include_types` in `/api/v1/notifications`.
|
||||||
- Mastodon API: Added `/api/v1/notifications/:id/dismiss` endpoint.
|
- Mastodon API: Added `/api/v1/notifications/:id/dismiss` endpoint.
|
||||||
- Mastodon API: Add support for filtering replies in public and home timelines
|
- Mastodon API: Add support for filtering replies in public and home timelines
|
||||||
|
- Mastodon API: Support for `bot` field in `/api/v1/accounts/update_credentials`
|
||||||
- Admin API: endpoints for create/update/delete OAuth Apps.
|
- Admin API: endpoints for create/update/delete OAuth Apps.
|
||||||
- Admin API: endpoint for status view.
|
- Admin API: endpoint for status view.
|
||||||
- OTP: Add command to reload emoji packs
|
- OTP: Add command to reload emoji packs
|
||||||
|
|
|
@ -465,6 +465,7 @@ def update_changeset(struct, params \\ %{}) do
|
||||||
|> validate_format(:nickname, local_nickname_regex())
|
|> validate_format(:nickname, local_nickname_regex())
|
||||||
|> validate_length(:bio, max: bio_limit)
|
|> validate_length(:bio, max: bio_limit)
|
||||||
|> validate_length(:name, min: 1, max: name_limit)
|
|> validate_length(:name, min: 1, max: name_limit)
|
||||||
|
|> validate_inclusion(:actor_type, ["Person", "Service"])
|
||||||
|> put_fields()
|
|> put_fields()
|
||||||
|> put_emoji()
|
|> put_emoji()
|
||||||
|> put_change_if_present(:bio, &{:ok, parse_bio(&1, struct)})
|
|> put_change_if_present(:bio, &{:ok, parse_bio(&1, struct)})
|
||||||
|
|
|
@ -177,6 +177,9 @@ def update_credentials(%{assigns: %{user: user}, body_params: params} = conn, _p
|
||||||
|> Maps.put_if_present(:pleroma_settings_store, params[:pleroma_settings_store])
|
|> Maps.put_if_present(:pleroma_settings_store, params[:pleroma_settings_store])
|
||||||
|> Maps.put_if_present(:default_scope, params[:default_scope])
|
|> Maps.put_if_present(:default_scope, params[:default_scope])
|
||||||
|> Maps.put_if_present(:default_scope, params["source"]["privacy"])
|
|> Maps.put_if_present(:default_scope, params["source"]["privacy"])
|
||||||
|
|> Maps.put_if_present(:actor_type, params[:bot], fn bot ->
|
||||||
|
if bot, do: {:ok, "Service"}, else: {:ok, "Person"}
|
||||||
|
end)
|
||||||
|> Maps.put_if_present(:actor_type, params[:actor_type])
|
|> Maps.put_if_present(:actor_type, params[:actor_type])
|
||||||
|
|
||||||
changeset = User.update_changeset(user, user_params)
|
changeset = User.update_changeset(user, user_params)
|
||||||
|
|
|
@ -400,4 +400,71 @@ test "update fields when invalid request", %{conn: conn} do
|
||||||
|> json_response_and_validate_schema(403)
|
|> json_response_and_validate_schema(403)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "Mark account as bot" do
|
||||||
|
setup do: oauth_access(["write:accounts"])
|
||||||
|
setup :request_content_type
|
||||||
|
|
||||||
|
test "changing actor_type to Service makes account a bot", %{conn: conn} do
|
||||||
|
account =
|
||||||
|
conn
|
||||||
|
|> patch("/api/v1/accounts/update_credentials", %{actor_type: "Service"})
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert account["bot"]
|
||||||
|
assert account["source"]["pleroma"]["actor_type"] == "Service"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "changing actor_type to Person makes account a human", %{conn: conn} do
|
||||||
|
account =
|
||||||
|
conn
|
||||||
|
|> patch("/api/v1/accounts/update_credentials", %{actor_type: "Person"})
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
refute account["bot"]
|
||||||
|
assert account["source"]["pleroma"]["actor_type"] == "Person"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "changing actor_type to Application causes error", %{conn: conn} do
|
||||||
|
response =
|
||||||
|
conn
|
||||||
|
|> patch("/api/v1/accounts/update_credentials", %{actor_type: "Application"})
|
||||||
|
|> json_response_and_validate_schema(403)
|
||||||
|
|
||||||
|
assert %{"error" => "Invalid request"} == response
|
||||||
|
end
|
||||||
|
|
||||||
|
test "changing bot field to true changes actor_type to Service", %{conn: conn} do
|
||||||
|
account =
|
||||||
|
conn
|
||||||
|
|> patch("/api/v1/accounts/update_credentials", %{bot: "true"})
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert account["bot"]
|
||||||
|
assert account["source"]["pleroma"]["actor_type"] == "Service"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "changing bot field to false changes actor_type to Person", %{conn: conn} do
|
||||||
|
account =
|
||||||
|
conn
|
||||||
|
|> patch("/api/v1/accounts/update_credentials", %{bot: "false"})
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
refute account["bot"]
|
||||||
|
assert account["source"]["pleroma"]["actor_type"] == "Person"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "actor_type field has a higher priority than bot", %{conn: conn} do
|
||||||
|
account =
|
||||||
|
conn
|
||||||
|
|> patch("/api/v1/accounts/update_credentials", %{
|
||||||
|
actor_type: "Person",
|
||||||
|
bot: "true"
|
||||||
|
})
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
refute account["bot"]
|
||||||
|
assert account["source"]["pleroma"]["actor_type"] == "Person"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue