Allow local user to have group actor type

https://git.pleroma.social/pleroma/pleroma/-/issues/3205
This commit is contained in:
tusooa 2023-11-05 18:49:31 -05:00
parent 40f170f0a7
commit 7a58ddfa48
No known key found for this signature in database
GPG Key ID: 42AEC43D48433C51
4 changed files with 35 additions and 2 deletions

View File

@ -76,6 +76,14 @@ defmodule Pleroma.Constants do
] ]
) )
const(allowed_user_actor_types,
do: [
"Person",
"Service",
"Group"
]
)
# basic regex, just there to weed out potential mistakes # basic regex, just there to weed out potential mistakes
# https://datatracker.ietf.org/doc/html/rfc2045#section-5.1 # https://datatracker.ietf.org/doc/html/rfc2045#section-5.1
const(mime_regex, const(mime_regex,

View File

@ -39,6 +39,7 @@ defmodule Pleroma.User do
alias Pleroma.Workers.BackgroundWorker alias Pleroma.Workers.BackgroundWorker
require Logger require Logger
require Pleroma.Constants
@type t :: %__MODULE__{} @type t :: %__MODULE__{}
@type account_status :: @type account_status ::
@ -579,7 +580,7 @@ defmodule Pleroma.User 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"]) |> validate_inclusion(:actor_type, Pleroma.Constants.allowed_user_actor_types())
|> 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)})

View File

@ -212,7 +212,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
do: user.follower_count, do: user.follower_count,
else: 0 else: 0
bot = user.actor_type == "Service" bot = is_bot?(user)
emojis = emojis =
Enum.map(user.emoji, fn {shortcode, raw_url} -> Enum.map(user.emoji, fn {shortcode, raw_url} ->
@ -468,4 +468,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
defp image_url(%{"url" => [%{"href" => href} | _]}), do: href defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
defp image_url(_), do: nil defp image_url(_), do: nil
defp is_bot?(user) do
# Because older and/or Mastodon clients may not recognize a Group actor properly,
# and currently the group actor can only boost things, we should let these clients
# think groups are bots.
# See https://git.pleroma.social/pleroma/pleroma-meta/-/issues/14
user.actor_type == "Service" || user.actor_type == "Group"
end
end end

View File

@ -732,4 +732,20 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
assert account["source"]["pleroma"]["actor_type"] == "Person" assert account["source"]["pleroma"]["actor_type"] == "Person"
end end
end end
describe "Mark account as group" do
setup do: oauth_access(["write:accounts"])
setup :request_content_type
test "changing actor_type to Group makes account a Group and enables bot indicator for backward compatibility",
%{conn: conn} do
account =
conn
|> patch("/api/v1/accounts/update_credentials", %{actor_type: "Group"})
|> json_response_and_validate_schema(200)
assert account["bot"]
assert account["source"]["pleroma"]["actor_type"] == "Group"
end
end
end end