From 785e2f939980803c70a1e61c8eb6c0a2d7401d2d Mon Sep 17 00:00:00 2001
From: Matt Jankowski <matt@jankowski.online>
Date: Tue, 20 Feb 2024 04:18:05 -0500
Subject: [PATCH] Add scope `providing_styles` to `UserRole` (#29286)

---
 app/controllers/custom_css_controller.rb | 2 +-
 app/models/user_role.rb                  | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/app/controllers/custom_css_controller.rb b/app/controllers/custom_css_controller.rb
index 62f8e0d77..eb6417698 100644
--- a/app/controllers/custom_css_controller.rb
+++ b/app/controllers/custom_css_controller.rb
@@ -16,6 +16,6 @@ class CustomCssController < ActionController::Base # rubocop:disable Rails/Appli
   helper_method :custom_css_styles
 
   def set_user_roles
-    @user_roles = UserRole.where(highlighted: true).where.not(color: [nil, ''])
+    @user_roles = UserRole.providing_styles
   end
 end
diff --git a/app/models/user_role.rb b/app/models/user_role.rb
index ed64ca053..9115d91c2 100644
--- a/app/models/user_role.rb
+++ b/app/models/user_role.rb
@@ -97,6 +97,9 @@ class UserRole < ApplicationRecord
   before_validation :set_position
 
   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