mirror of
https://github.com/mastodon/mastodon.git
synced 2025-10-05 16:42:47 +00:00
fix: OIDC account creation fails for long display names (#34639)
This commit is contained in:
parent
d2f8a38887
commit
f090fde8a8
|
@ -69,6 +69,7 @@ class Account < ApplicationRecord
|
||||||
MENTION_RE = %r{(?<![=/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]]+([.-]+[[:word:]]+)*)?)}
|
MENTION_RE = %r{(?<![=/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]]+([.-]+[[:word:]]+)*)?)}
|
||||||
URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+}
|
URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+}
|
||||||
USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i
|
USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i
|
||||||
|
DISPLAY_NAME_LENGTH_LIMIT = 30
|
||||||
|
|
||||||
include Attachmentable
|
include Attachmentable
|
||||||
include AccountAssociations
|
include AccountAssociations
|
||||||
|
@ -99,7 +100,7 @@ class Account < ApplicationRecord
|
||||||
# Local user validations
|
# 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 :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_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 :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 :fields, length: { maximum: 4 }, if: -> { local? && will_save_change_to_fields? }
|
||||||
validates :uri, absence: true, if: :local?, on: :create
|
validates :uri, absence: true, if: :local?, on: :create
|
||||||
|
|
|
@ -99,7 +99,7 @@ module Omniauthable
|
||||||
external: true,
|
external: true,
|
||||||
account_attributes: {
|
account_attributes: {
|
||||||
username: ensure_unique_username(ensure_valid_username(auth.uid)),
|
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
|
end
|
||||||
|
@ -121,5 +121,10 @@ module Omniauthable
|
||||||
temp_username = starting_username.gsub(/[^a-z0-9_]+/i, '')
|
temp_username = starting_username.gsub(/[^a-z0-9_]+/i, '')
|
||||||
temp_username.truncate(30, omission: '')
|
temp_username.truncate(30, omission: '')
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user