fix: OIDC account creation fails for long display names (#34639)

This commit is contained in:
Marcel Hellkamp 2025-05-12 17:51:53 +02:00 committed by Claire
parent d2f8a38887
commit f090fde8a8
2 changed files with 8 additions and 2 deletions

View File

@ -69,6 +69,7 @@ class Account < ApplicationRecord
MENTION_RE = %r{(?<![=/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]]+([.-]+[[:word:]]+)*)?)}
URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+}
USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i
DISPLAY_NAME_LENGTH_LIMIT = 30
include Attachmentable
include AccountAssociations
@ -99,7 +100,7 @@ class Account < ApplicationRecord
# Local user validations
validates :username, format: { with: /\A[a-z0-9_]+\z/i }, length: { maximum: 30 }, if: -> { local? && will_save_change_to_username? && actor_type != 'Application' }
validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? && actor_type != 'Application' }
validates :display_name, length: { maximum: 30 }, if: -> { local? && will_save_change_to_display_name? }
validates :display_name, length: { maximum: DISPLAY_NAME_LENGTH_LIMIT }, if: -> { local? && will_save_change_to_display_name? }
validates :note, note_length: { maximum: 500 }, if: -> { local? && will_save_change_to_note? }
validates :fields, length: { maximum: 4 }, if: -> { local? && will_save_change_to_fields? }
validates :uri, absence: true, if: :local?, on: :create

View File

@ -99,7 +99,7 @@ module Omniauthable
external: true,
account_attributes: {
username: ensure_unique_username(ensure_valid_username(auth.uid)),
display_name: auth.info.full_name || auth.info.name || [auth.info.first_name, auth.info.last_name].join(' '),
display_name: display_name_from_auth(auth),
},
}
end
@ -121,5 +121,10 @@ module Omniauthable
temp_username = starting_username.gsub(/[^a-z0-9_]+/i, '')
temp_username.truncate(30, omission: '')
end
def display_name_from_auth(auth)
display_name = auth.info.full_name || auth.info.name || [auth.info.first_name, auth.info.last_name].join(' ')
display_name.truncate(Account::DISPLAY_NAME_LENGTH_LIMIT, omission: '')
end
end
end