From 7583d07d3a1e17808424b910e0dffe95a60bce87 Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 25 Mar 2026 13:32:47 +0100 Subject: [PATCH] Change avatar and account header description limit and expose it in API (#38384) --- app/models/concerns/account/avatar.rb | 3 ++- app/models/concerns/account/header.rb | 3 ++- app/serializers/rest/instance_serializer.rb | 2 ++ spec/requests/api/v2/instance_spec.rb | 9 ++++++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/account/avatar.rb b/app/models/concerns/account/avatar.rb index 1b561fc770..bcc48791d5 100644 --- a/app/models/concerns/account/avatar.rb +++ b/app/models/concerns/account/avatar.rb @@ -3,6 +3,7 @@ module Account::Avatar extend ActiveSupport::Concern + MAX_DESCRIPTION_LENGTH = 150 AVATAR_IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze AVATAR_LIMIT = 8.megabytes AVATAR_DIMENSIONS = [400, 400].freeze @@ -25,7 +26,7 @@ module Account::Avatar validates_attachment_size :avatar, less_than: AVATAR_LIMIT remotable_attachment :avatar, AVATAR_LIMIT, suppress_errors: false - validates :avatar_description, length: { maximum: MediaAttachment::MAX_DESCRIPTION_LENGTH }, if: -> { local? && will_save_change_to_avatar_description? } + validates :avatar_description, length: { maximum: MAX_DESCRIPTION_LENGTH }, if: -> { local? && will_save_change_to_avatar_description? } end def avatar_original_url diff --git a/app/models/concerns/account/header.rb b/app/models/concerns/account/header.rb index 75d3c04542..a3715c211b 100644 --- a/app/models/concerns/account/header.rb +++ b/app/models/concerns/account/header.rb @@ -3,6 +3,7 @@ module Account::Header extend ActiveSupport::Concern + MAX_DESCRIPTION_LENGTH = 150 HEADER_IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze HEADER_LIMIT = 8.megabytes HEADER_DIMENSIONS = [1500, 500].freeze @@ -26,7 +27,7 @@ module Account::Header validates_attachment_size :header, less_than: HEADER_LIMIT remotable_attachment :header, HEADER_LIMIT, suppress_errors: false - validates :header_description, length: { maximum: MediaAttachment::MAX_DESCRIPTION_LENGTH }, if: -> { local? && will_save_change_to_header_description? } + validates :header_description, length: { maximum: MAX_DESCRIPTION_LENGTH }, if: -> { local? && will_save_change_to_header_description? } end def header_original_url diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index 625cd3ad8c..52d7f2b363 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -71,6 +71,8 @@ class REST::InstanceSerializer < ActiveModel::Serializer accounts: { max_display_name_length: Account::DISPLAY_NAME_LENGTH_LIMIT, max_note_length: Account::NOTE_LENGTH_LIMIT, + max_avatar_description_length: Account::Avatar::MAX_DESCRIPTION_LENGTH, + max_header_description_length: Account::Header::MAX_DESCRIPTION_LENGTH, max_featured_tags: FeaturedTag::LIMIT, max_pinned_statuses: StatusPinValidator::PIN_LIMIT, max_profile_fields: Account::DEFAULT_FIELDS_SIZE, diff --git a/spec/requests/api/v2/instance_spec.rb b/spec/requests/api/v2/instance_spec.rb index 39e7105f09..d9d5df1bea 100644 --- a/spec/requests/api/v2/instance_spec.rb +++ b/spec/requests/api/v2/instance_spec.rb @@ -66,8 +66,15 @@ RSpec.describe 'Instances' do include( configuration: include( accounts: include( + max_display_name_length: Account::DISPLAY_NAME_LENGTH_LIMIT, + max_note_length: Account::NOTE_LENGTH_LIMIT, + max_avatar_description_length: Account::Avatar::MAX_DESCRIPTION_LENGTH, + max_header_description_length: Account::Header::MAX_DESCRIPTION_LENGTH, max_featured_tags: FeaturedTag::LIMIT, - max_pinned_statuses: StatusPinValidator::PIN_LIMIT + max_pinned_statuses: StatusPinValidator::PIN_LIMIT, + max_profile_fields: Account::DEFAULT_FIELDS_SIZE, + profile_field_name_limit: Account::Field::MAX_CHARACTERS_LOCAL, + profile_field_value_limit: Account::Field::MAX_CHARACTERS_LOCAL ), statuses: include( max_characters: StatusLengthValidator::MAX_CHARS,