Extract CSS_COLORS constant for UserRole regex validation (#33532)

This commit is contained in:
Matt Jankowski 2025-01-10 04:02:48 -05:00 committed by GitHub
parent 846c89b66e
commit 4fb3dc0363
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -42,6 +42,7 @@ class UserRole < ApplicationRecord
NOBODY_POSITION = -1
POSITION_LIMIT = (2**31) - 1
CSS_COLORS = /\A#?(?:[A-F0-9]{3}){1,2}\z/i # CSS-style hex colors
module Flags
NONE = 0
@ -90,7 +91,7 @@ class UserRole < ApplicationRecord
attr_writer :current_account
validates :name, presence: true, unless: :everyone?
validates :color, format: { with: /\A#?(?:[A-F0-9]{3}){1,2}\z/i }, unless: -> { color.blank? }
validates :color, format: { with: CSS_COLORS }, if: :color?
validates :position, numericality: { in: (-POSITION_LIMIT..POSITION_LIMIT) }
validate :validate_permissions_elevation