From 7ad44e22edee9b07f5a1b2df1efb5b5c7a12afe5 Mon Sep 17 00:00:00 2001
From: Matt Jankowski <matt@jankowski.online>
Date: Tue, 7 Jan 2025 11:28:35 -0500
Subject: [PATCH] Remove role color highlighting from custom css (#33493)

---
 app/controllers/custom_css_controller.rb |  6 -----
 app/models/user_role.rb                  |  3 ---
 app/views/admin/roles/_role.html.haml    |  4 ++--
 app/views/custom_css/show.css.erb        |  6 -----
 spec/requests/custom_css_spec.rb         | 29 ------------------------
 5 files changed, 2 insertions(+), 46 deletions(-)

diff --git a/app/controllers/custom_css_controller.rb b/app/controllers/custom_css_controller.rb
index eb6417698..9f33870bd 100644
--- a/app/controllers/custom_css_controller.rb
+++ b/app/controllers/custom_css_controller.rb
@@ -1,8 +1,6 @@
 # frozen_string_literal: true
 
 class CustomCssController < ActionController::Base # rubocop:disable Rails/ApplicationController
-  before_action :set_user_roles
-
   def show
     expires_in 3.minutes, public: true
     render content_type: 'text/css'
@@ -14,8 +12,4 @@ class CustomCssController < ActionController::Base # rubocop:disable Rails/Appli
     Setting.custom_css
   end
   helper_method :custom_css_styles
-
-  def set_user_roles
-    @user_roles = UserRole.providing_styles
-  end
 end
diff --git a/app/models/user_role.rb b/app/models/user_role.rb
index f9c4c14c4..24cd5983f 100644
--- a/app/models/user_role.rb
+++ b/app/models/user_role.rb
@@ -101,9 +101,6 @@ 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
 
diff --git a/app/views/admin/roles/_role.html.haml b/app/views/admin/roles/_role.html.haml
index 636127354..085bdbd15 100644
--- a/app/views/admin/roles/_role.html.haml
+++ b/app/views/admin/roles/_role.html.haml
@@ -1,7 +1,7 @@
 .announcements-list__item
   - if can?(:update, role)
     = link_to edit_admin_role_path(role), class: 'announcements-list__item__title' do
-      %span.user-role{ class: "user-role-#{role.id}" }
+      %span.user-role
         = material_symbol 'group'
 
         - if role.everyone?
@@ -10,7 +10,7 @@
           = role.name
   - else
     %span.announcements-list__item__title
-      %span.user-role{ class: "user-role-#{role.id}" }
+      %span.user-role
         = material_symbol 'group'
 
         - if role.everyone?
diff --git a/app/views/custom_css/show.css.erb b/app/views/custom_css/show.css.erb
index 78da809ed..d4b24b210 100644
--- a/app/views/custom_css/show.css.erb
+++ b/app/views/custom_css/show.css.erb
@@ -2,9 +2,3 @@
 <%= raw custom_css_styles %>
 
 <%- end %>
-<%- @user_roles.each do |role| %>
-.user-role-<%= role.id %> {
-  --user-role-accent: <%= role.color %>;
-}
-
-<%- end %>
diff --git a/spec/requests/custom_css_spec.rb b/spec/requests/custom_css_spec.rb
index d97da0018..380c32908 100644
--- a/spec/requests/custom_css_spec.rb
+++ b/spec/requests/custom_css_spec.rb
@@ -45,34 +45,5 @@ RSpec.describe 'Custom CSS' do
         CSS
       end
     end
-
-    context 'with highlighted colored UserRole records' do
-      before do
-        _highlighted_colored = Fabricate :user_role, highlighted: true, color: '#336699', id: '123_123_123'
-        _highlighted_no_color = Fabricate :user_role, highlighted: true, color: ''
-        _no_highlight_with_color = Fabricate :user_role, highlighted: false, color: ''
-      end
-
-      it 'returns stylesheet from settings' do
-        get '/custom.css'
-
-        expect(response)
-          .to have_http_status(200)
-          .and have_cacheable_headers
-          .and have_attributes(
-            content_type: match('text/css')
-          )
-        expect(response.body.strip)
-          .to eq(expected_css)
-      end
-
-      def expected_css
-        <<~CSS.strip
-          .user-role-123123123 {
-            --user-role-accent: #336699;
-          }
-        CSS
-      end
-    end
   end
 end