mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 08:36:29 +00:00
Add :max_remote_account_fields
config option
This commit is contained in:
parent
f7bbf99caa
commit
e457fcc479
7 changed files with 37 additions and 7 deletions
|
@ -256,6 +256,7 @@ config :pleroma, :instance,
|
||||||
user_bio_length: 5000,
|
user_bio_length: 5000,
|
||||||
user_name_length: 100,
|
user_name_length: 100,
|
||||||
max_account_fields: 4,
|
max_account_fields: 4,
|
||||||
|
max_remote_account_fields: 10,
|
||||||
account_field_name_length: 255,
|
account_field_name_length: 255,
|
||||||
account_field_value_length: 255,
|
account_field_value_length: 255,
|
||||||
external_user_synchronization: true
|
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`.
|
* `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.
|
* `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_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_name_length`: An account field name maximum length (default: `255`)
|
||||||
* `account_field_value_length`: An account field value 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.
|
* `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)
|
|> validate_length(:name, min: 1, max: name_limit)
|
||||||
end
|
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)
|
bio_limit = Pleroma.Config.get([:instance, :user_bio_length], 5000)
|
||||||
name_limit = Pleroma.Config.get([:instance, :user_name_length], 100)
|
name_limit = Pleroma.Config.get([:instance, :user_name_length], 100)
|
||||||
|
|
||||||
params = Map.put(params, :last_refreshed_at, NaiveDateTime.utc_now())
|
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
|
struct
|
||||||
|> cast(params, [
|
|> cast(params, [
|
||||||
|
|
|
@ -256,11 +256,13 @@ defmodule Pleroma.User.Info do
|
||||||
:hide_followers,
|
:hide_followers,
|
||||||
:hide_follows,
|
:hide_follows,
|
||||||
:follower_count,
|
:follower_count,
|
||||||
|
:fields,
|
||||||
:following_count
|
:following_count
|
||||||
])
|
])
|
||||||
|
|> validate_fields(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_upgrade(info, params) do
|
def user_upgrade(info, params, remote? \\ false) do
|
||||||
info
|
info
|
||||||
|> cast(params, [
|
|> cast(params, [
|
||||||
:ap_enabled,
|
:ap_enabled,
|
||||||
|
@ -274,7 +276,7 @@ defmodule Pleroma.User.Info do
|
||||||
:fields,
|
:fields,
|
||||||
:hide_followers
|
:hide_followers
|
||||||
])
|
])
|
||||||
|> validate_fields()
|
|> validate_fields(remote?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def profile_update(info, params) do
|
def profile_update(info, params) do
|
||||||
|
@ -297,8 +299,9 @@ defmodule Pleroma.User.Info do
|
||||||
|> validate_fields()
|
|> validate_fields()
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_fields(changeset) do
|
def validate_fields(changeset, remote? \\ false) do
|
||||||
limit = Pleroma.Config.get([:instance, :max_account_fields], 0)
|
limit_name = if remote?, do: :max_remote_account_fields, else: :max_account_fields
|
||||||
|
limit = Pleroma.Config.get([:instance, limit_name], 0)
|
||||||
|
|
||||||
changeset
|
changeset
|
||||||
|> validate_length(:fields, max: limit)
|
|> validate_length(:fields, max: limit)
|
||||||
|
|
|
@ -1016,6 +1016,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
"url" => [%{"href" => data["image"]["url"]}]
|
"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
|
locked = data["manuallyApprovesFollowers"] || false
|
||||||
data = Transmogrifier.maybe_fix_user_object(data)
|
data = Transmogrifier.maybe_fix_user_object(data)
|
||||||
|
|
||||||
|
@ -1025,6 +1031,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
ap_enabled: true,
|
ap_enabled: true,
|
||||||
source_data: data,
|
source_data: data,
|
||||||
banner: banner,
|
banner: banner,
|
||||||
|
fields: fields,
|
||||||
locked: locked
|
locked: locked
|
||||||
},
|
},
|
||||||
avatar: avatar,
|
avatar: avatar,
|
||||||
|
|
|
@ -611,7 +611,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||||
|> Map.put(:info, %{banner: banner, locked: locked, fields: fields})
|
|> Map.put(:info, %{banner: banner, locked: locked, fields: fields})
|
||||||
|
|
||||||
actor
|
actor
|
||||||
|> User.upgrade_changeset(update_data)
|
|> User.upgrade_changeset(update_data, true)
|
||||||
|> User.update_and_set_cache()
|
|> User.update_and_set_cache()
|
||||||
|
|
||||||
ActivityPub.update(%{
|
ActivityPub.update(%{
|
||||||
|
|
|
@ -539,6 +539,24 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
||||||
|
|
||||||
user = User.get_cached_by_ap_id(user.ap_id)
|
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) == [
|
assert User.Info.fields(user.info) == [
|
||||||
%{"name" => "foo", "value" => "updated"},
|
%{"name" => "foo", "value" => "updated"},
|
||||||
%{"name" => "foo1", "value" => "updated"}
|
%{"name" => "foo1", "value" => "updated"}
|
||||||
|
|
Loading…
Reference in a new issue