mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-23 06:58:58 +00:00
Add :max_remote_account_fields
config option
This commit is contained in:
parent
f7bbf99caa
commit
e457fcc479
|
@ -256,6 +256,7 @@ config :pleroma, :instance,
|
|||
user_bio_length: 5000,
|
||||
user_name_length: 100,
|
||||
max_account_fields: 4,
|
||||
max_remote_account_fields: 10,
|
||||
account_field_name_length: 255,
|
||||
account_field_value_length: 255,
|
||||
external_user_synchronization: true
|
||||
|
|
|
@ -133,6 +133,7 @@ config :pleroma, Pleroma.Emails.Mailer,
|
|||
* `limit_to_local_content`: Limit unauthenticated users to search for local statutes and users only. Possible values: `:unauthenticated`, `:all` and `false`. The default is `:unauthenticated`.
|
||||
* `dynamic_configuration`: Allow transferring configuration to DB with the subsequent customization from Admin api.
|
||||
* `max_account_fields`: The maximum number of custom fields in the user profile (default: `4`)
|
||||
* `max_remote_account_fields`: The maximum number of custom fields in the remote user profile (default: `10`)
|
||||
* `account_field_name_length`: An account field name maximum length (default: `255`)
|
||||
* `account_field_value_length`: An account field value maximum length (default: `255`)
|
||||
* `external_user_synchronization`: Enabling following/followers counters synchronization for external users.
|
||||
|
|
|
@ -199,12 +199,12 @@ defmodule Pleroma.User do
|
|||
|> validate_length(:name, min: 1, max: name_limit)
|
||||
end
|
||||
|
||||
def upgrade_changeset(struct, params \\ %{}) do
|
||||
def upgrade_changeset(struct, params \\ %{}, remote? \\ false) do
|
||||
bio_limit = Pleroma.Config.get([:instance, :user_bio_length], 5000)
|
||||
name_limit = Pleroma.Config.get([:instance, :user_name_length], 100)
|
||||
|
||||
params = Map.put(params, :last_refreshed_at, NaiveDateTime.utc_now())
|
||||
info_cng = User.Info.user_upgrade(struct.info, params[:info])
|
||||
info_cng = User.Info.user_upgrade(struct.info, params[:info], remote?)
|
||||
|
||||
struct
|
||||
|> cast(params, [
|
||||
|
|
|
@ -256,11 +256,13 @@ defmodule Pleroma.User.Info do
|
|||
:hide_followers,
|
||||
:hide_follows,
|
||||
:follower_count,
|
||||
:fields,
|
||||
:following_count
|
||||
])
|
||||
|> validate_fields(true)
|
||||
end
|
||||
|
||||
def user_upgrade(info, params) do
|
||||
def user_upgrade(info, params, remote? \\ false) do
|
||||
info
|
||||
|> cast(params, [
|
||||
:ap_enabled,
|
||||
|
@ -274,7 +276,7 @@ defmodule Pleroma.User.Info do
|
|||
:fields,
|
||||
:hide_followers
|
||||
])
|
||||
|> validate_fields()
|
||||
|> validate_fields(remote?)
|
||||
end
|
||||
|
||||
def profile_update(info, params) do
|
||||
|
@ -297,8 +299,9 @@ defmodule Pleroma.User.Info do
|
|||
|> validate_fields()
|
||||
end
|
||||
|
||||
def validate_fields(changeset) do
|
||||
limit = Pleroma.Config.get([:instance, :max_account_fields], 0)
|
||||
def validate_fields(changeset, remote? \\ false) do
|
||||
limit_name = if remote?, do: :max_remote_account_fields, else: :max_account_fields
|
||||
limit = Pleroma.Config.get([:instance, limit_name], 0)
|
||||
|
||||
changeset
|
||||
|> validate_length(:fields, max: limit)
|
||||
|
|
|
@ -1016,6 +1016,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
"url" => [%{"href" => data["image"]["url"]}]
|
||||
}
|
||||
|
||||
fields =
|
||||
data
|
||||
|> Map.get("attachment", [])
|
||||
|> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
|
||||
|> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
|
||||
|
||||
locked = data["manuallyApprovesFollowers"] || false
|
||||
data = Transmogrifier.maybe_fix_user_object(data)
|
||||
|
||||
|
@ -1025,6 +1031,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
ap_enabled: true,
|
||||
source_data: data,
|
||||
banner: banner,
|
||||
fields: fields,
|
||||
locked: locked
|
||||
},
|
||||
avatar: avatar,
|
||||
|
|
|
@ -611,7 +611,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
|> Map.put(:info, %{banner: banner, locked: locked, fields: fields})
|
||||
|
||||
actor
|
||||
|> User.upgrade_changeset(update_data)
|
||||
|> User.upgrade_changeset(update_data, true)
|
||||
|> User.update_and_set_cache()
|
||||
|
||||
ActivityPub.update(%{
|
||||
|
|
|
@ -539,6 +539,24 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert User.Info.fields(user.info) == [
|
||||
%{"name" => "foo", "value" => "updated"},
|
||||
%{"name" => "foo1", "value" => "updated"}
|
||||
]
|
||||
|
||||
Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
|
||||
|
||||
update_data =
|
||||
put_in(update_data, ["object", "attachment"], [
|
||||
%{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
|
||||
%{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
|
||||
%{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
|
||||
])
|
||||
|
||||
{:ok, _} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert User.Info.fields(user.info) == [
|
||||
%{"name" => "foo", "value" => "updated"},
|
||||
%{"name" => "foo1", "value" => "updated"}
|
||||
|
|
Loading…
Reference in a new issue