Add scope `providing_styles` to `UserRole` (#29286)

main-rebase-security-fix
Matt Jankowski 2024-02-20 04:18:05 -05:00 committed by GitHub
parent 5d9d0d174a
commit 785e2f9399
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -16,6 +16,6 @@ class CustomCssController < ActionController::Base # rubocop:disable Rails/Appli
helper_method :custom_css_styles helper_method :custom_css_styles
def set_user_roles def set_user_roles
@user_roles = UserRole.where(highlighted: true).where.not(color: [nil, '']) @user_roles = UserRole.providing_styles
end end
end end

View File

@ -97,6 +97,9 @@ class UserRole < ApplicationRecord
before_validation :set_position before_validation :set_position
scope :assignable, -> { where.not(id: EVERYONE_ROLE_ID).order(position: :asc) } scope :assignable, -> { where.not(id: EVERYONE_ROLE_ID).order(position: :asc) }
scope :highlighted, -> { where(highlighted: true) }
scope :with_color, -> { where.not(color: [nil, '']) }
scope :providing_styles, -> { highlighted.with_color }
has_many :users, inverse_of: :role, foreign_key: 'role_id', dependent: :nullify has_many :users, inverse_of: :role, foreign_key: 'role_id', dependent: :nullify