# Local user validations
with_options if: :local? do
- validates :username, format: { with: /\A[a-z0-9_]+\z/i }, uniqueness: { scope: :domain, case_sensitive: false }, length: { maximum: 30 }
+ validates :username, format: { with: /\A[a-z0-9_]+\z/i }, uniqueness: { scope: :domain, case_sensitive: false }, length: { maximum: 30 }, unreserved: true
validates :display_name, length: { maximum: 30 }
validates :note, length: { maximum: 160 }
end
--- /dev/null
+# frozen_string_literal: true
+
+class UnreservedValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ return if value.nil?
+ record.errors.add(attribute, I18n.t('accounts.reserved_username')) if reserved_username?(value)
+ end
+
+ private
+
+ def reserved_username?(value)
+ return false unless Setting.reserved_usernames
+ Setting.reserved_usernames.include?(value.downcase)
+ end
+end
posts: Posts
remote_follow: Remote follow
unfollow: Unfollow
+ reserved_username: The username is reserved
activitypub:
activity:
announce:
# For more information, see docs/Running-Mastodon/Administration-guide.md
#
defaults: &defaults
- site_title: 'Mastodon'
+ site_title: Mastodon
site_description: ''
site_extended_description: ''
site_contact_username: ''
interactions:
must_be_follower: false
must_be_following: false
+ reserved_usernames:
+ - admin
+ - support
+ - help
+ - root
+ - webmaster
+ - administrator
development:
<<: *defaults
expect(account_2).to model_have_error_on_field(:username)
end
+ it 'is invalid if the username is reserved' do
+ account = Fabricate.build(:account, username: 'support')
+ account.valid?
+ expect(account).to model_have_error_on_field(:username)
+ end
+
context 'when is local' do
it 'is invalid if the username doesn\'t only contains letters, numbers and underscores' do
account = Fabricate.build(:account, username: 'the-doctor')