From 2123281f7c24620f81dde503b83674cb3824a8cd Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 29 Apr 2024 05:02:47 -0400 Subject: [PATCH] Move `Account` limits to constants (#30087) --- app/models/account.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index 2bf00b2be59..3efa7d88bd7 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -71,6 +71,9 @@ class Account < ApplicationRecord MENTION_RE = %r{(? { local? && will_save_change_to_username? && actor_type != 'Application' } + validates :username, format: { with: /\A[a-z0-9_]+\z/i }, length: { maximum: USERNAME_LENGTH_LIMIT }, 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 :note, note_length: { maximum: 500 }, if: -> { local? && will_save_change_to_note? } + validates :display_name, length: { maximum: DISPLAY_NAME_LENGTH_LIMIT }, if: -> { local? && will_save_change_to_display_name? } + validates :note, note_length: { maximum: NOTE_LENGTH_LIMIT }, if: -> { local? && will_save_change_to_note? } validates :fields, length: { maximum: DEFAULT_FIELDS_SIZE }, if: -> { local? && will_save_change_to_fields? } validates :uri, absence: true, if: :local?, on: :create validates :inbox_url, absence: true, if: :local?, on: :create