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
* `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.
|> 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, [
: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,
:fields,
:hide_followers
])
- |> validate_fields()
+ |> validate_fields(remote?)
end
def profile_update(info, params) 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)
"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)
ap_enabled: true,
source_data: data,
banner: banner,
+ fields: fields,
locked: locked
},
avatar: avatar,
|> 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(%{
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"}