From bebd1d459c7b24046c97086a0f7dff1d0a1f751d Mon Sep 17 00:00:00 2001 From: Fernando Valverde Date: Wed, 21 Sep 2022 11:21:29 -0600 Subject: [PATCH] Remove brand_color2 from users_settings (#18473) * Remove brand_color2 from users_settings * Remove occurences of brand_color2 --- app/controllers/profiles_controller.rb | 4 +-- app/decorators/user_decorator.rb | 4 +-- app/models/users/setting.rb | 1 - app/services/users/update.rb | 2 +- app/views/shared/_logo_design.html.erb | 3 +- ...22729_remove_brand_color2_from_settings.rb | 7 +++++ db/schema.rb | 3 +- spec/decorators/user_decorator_spec.rb | 29 ++++--------------- spec/services/users/update_spec.rb | 6 ---- 9 files changed, 20 insertions(+), 39 deletions(-) create mode 100644 db/migrate/20220919222729_remove_brand_color2_from_settings.rb diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index d5b412fda..6b94f1b07 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -2,7 +2,7 @@ class ProfilesController < ApplicationController before_action :authenticate_user! ALLOWED_USER_PARAMS = %i[name email username profile_image].freeze - ALLOWED_USERS_SETTING_PARAMS = %i[display_email_on_profile brand_color1 brand_color2].freeze + ALLOWED_USERS_SETTING_PARAMS = %i[display_email_on_profile brand_color1].freeze def update update_result = Users::Update.call(current_user, update_params) @@ -12,7 +12,7 @@ class ProfilesController < ApplicationController else @user = current_user @tab = "profile" - flash[:error] = I18n.t("errors.messages.general", errors: update_result.errors_as_sentence) + flash.now[:error] = I18n.t("errors.messages.general", errors: update_result.errors_as_sentence) render template: "users/edit", locals: { user: update_params[:user], profile: update_params[:profile], diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb index c5b86b6e2..dc85ca40d 100644 --- a/app/decorators/user_decorator.rb +++ b/app/decorators/user_decorator.rb @@ -59,7 +59,7 @@ class UserDecorator < ApplicationDecorator end def enriched_colors - if setting.brand_color1.blank? || setting.brand_color2.blank? + if setting.brand_color1.blank? { bg: assigned_color[:bg], text: assigned_color[:text] @@ -67,7 +67,7 @@ class UserDecorator < ApplicationDecorator else { bg: setting.brand_color1, - text: setting.brand_color2 + text: "#ffffff" } end end diff --git a/app/models/users/setting.rb b/app/models/users/setting.rb index d6902a6f3..be21c85e4 100644 --- a/app/models/users/setting.rb +++ b/app/models/users/setting.rb @@ -21,7 +21,6 @@ module Users _suffix: :feed validates :brand_color1, - :brand_color2, format: { with: HEX_COLOR_REGEXP, message: I18n.t("models.users.setting.invalid_hex") }, allow_nil: true diff --git a/app/services/users/update.rb b/app/services/users/update.rb index 5d71828b2..50e9d4595 100644 --- a/app/services/users/update.rb +++ b/app/services/users/update.rb @@ -6,7 +6,7 @@ module Users CORE_PROFILE_FIELDS = %i[summary].freeze CORE_USER_FIELDS = %i[name username profile_image].freeze - CORE_SETTINGS_FIELDS = %i[brand_color1 brand_color2].freeze + CORE_SETTINGS_FIELDS = %i[brand_color1].freeze # @param user [User] the user whose profile we are updating # @param updated_attributes [Hash>] the profile diff --git a/app/views/shared/_logo_design.html.erb b/app/views/shared/_logo_design.html.erb index 3f9b4187a..ea0a144e9 100644 --- a/app/views/shared/_logo_design.html.erb +++ b/app/views/shared/_logo_design.html.erb @@ -2,7 +2,6 @@
<% if account.class.name == "User" %> <% account.setting.brand_color1 = user_colors(account)[:bg] if account.setting && account.setting.brand_color1.blank? %> - <% account.setting.brand_color2 = user_colors(account)[:text] if account.setting && account.setting.brand_color2.blank? %> <% else %> <% account.bg_color_hex = user_colors(account)[:bg] if account.bg_color_hex.blank? %> <% account.text_color_hex = user_colors(account)[:text] if account.text_color_hex.blank? %> @@ -17,7 +16,7 @@
<% if account.class.name == "User" %> - <% account.setting.brand_color1 = user_colors(account)[:text] if account.setting && account.setting.brand_color2.blank? %> + <% account.setting.brand_color1 = user_colors(account)[:text] if account.setting %> <% else %> <% account.bg_color_hex = user_colors(account)[:text] if account.text_color_hex.blank? %> <% end %> diff --git a/db/migrate/20220919222729_remove_brand_color2_from_settings.rb b/db/migrate/20220919222729_remove_brand_color2_from_settings.rb new file mode 100644 index 000000000..a6b4dd128 --- /dev/null +++ b/db/migrate/20220919222729_remove_brand_color2_from_settings.rb @@ -0,0 +1,7 @@ +class RemoveBrandColor2FromSettings < ActiveRecord::Migration[7.0] + def change + safety_assured do + remove_column :users_settings, :brand_color2 + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 851d8f821..ed5ca4689 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_08_31_091245) do +ActiveRecord::Schema[7.0].define(version: 2022_09_19_222729) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "pg_stat_statements" @@ -1338,7 +1338,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_08_31_091245) do create_table "users_settings", force: :cascade do |t| t.string "brand_color1", default: "#000000" - t.string "brand_color2", default: "#ffffff" t.integer "config_font", default: 0, null: false t.integer "config_homepage_feed", default: 0, null: false t.integer "config_navbar", default: 0, null: false diff --git a/spec/decorators/user_decorator_spec.rb b/spec/decorators/user_decorator_spec.rb index 45a878820..15e21c9ee 100644 --- a/spec/decorators/user_decorator_spec.rb +++ b/spec/decorators/user_decorator_spec.rb @@ -38,22 +38,22 @@ RSpec.describe UserDecorator, type: :decorator do describe "#darker_color" do it "returns a darker version of the assigned color if colors are blank" do - saved_user.setting.update(brand_color1: "", brand_color2: "") + saved_user.setting.update(brand_color1: "") expect(saved_user.decorate.darker_color).to be_present end it "returns a darker version of the color if brand_color1 is present" do - saved_user.setting.update(brand_color1: "#dddddd", brand_color2: "#ffffff") + saved_user.setting.update(brand_color1: "#dddddd") expect(saved_user.decorate.darker_color).to eq("#c2c2c2") end it "returns an adjusted darker version of the color" do - saved_user.setting.update(brand_color1: "#dddddd", brand_color2: "#ffffff") + saved_user.setting.update(brand_color1: "#dddddd") expect(saved_user.decorate.darker_color(0.3)).to eq("#424242") end it "returns an adjusted lighter version of the color if adjustment is over 1.0" do - saved_user.setting.update(brand_color1: "#dddddd", brand_color2: "#ffffff") + saved_user.setting.update(brand_color1: "#dddddd") expect(saved_user.decorate.darker_color(1.1)).to eq("#f3f3f3") end end @@ -65,28 +65,11 @@ RSpec.describe UserDecorator, type: :decorator do expect(saved_user.decorate.enriched_colors[:text]).to be_present end - it "returns assigned colors if brand_color2 is blank" do - saved_user.setting.update(brand_color2: "") + it "returns brand_color1 if present" do + saved_user.setting.update(brand_color1: "#dddddd") expect(saved_user.decorate.enriched_colors[:bg]).to be_present expect(saved_user.decorate.enriched_colors[:text]).to be_present end - - it "returns brand_color1 and assigned brand_color2 if brand_color2 is blank" do - saved_user.setting.update(brand_color1: "#dddddd", brand_color2: "") - expect(saved_user.decorate.enriched_colors[:bg]).to be_present - expect(saved_user.decorate.enriched_colors[:text]).to be_present - end - - it "returns brand_color2 and assigned brand_color1 if brand_color1 is blank" do - saved_user.setting.update(brand_color1: "", brand_color2: "#ffffff") - expect(saved_user.decorate.enriched_colors[:bg]).to be_present - expect(saved_user.decorate.enriched_colors[:text]).to be_present - end - - it "returns brand_color1 and brand_color2 if both are present" do - saved_user.setting.update(brand_color1: "#dddddd", brand_color2: "#fffff3") - expect(saved_user.decorate.enriched_colors).to eq(bg: "#dddddd", text: "#fffff3") - end end describe "#config_body_class" do diff --git a/spec/services/users/update_spec.rb b/spec/services/users/update_spec.rb index 75b531a93..5b2446370 100644 --- a/spec/services/users/update_spec.rb +++ b/spec/services/users/update_spec.rb @@ -145,12 +145,6 @@ RSpec.describe Users::Update, type: :service do end end - it "enqueues resave articles job when changing text_color_hex" do - sidekiq_assert_resave_article_worker(user) do - described_class.call(user, user_settings: { brand_color2: "#12345F" }) - end - end - Authentication::Providers.username_fields.each do |username_field| it "enqueues resave articles job when changing #{username_field}" do sidekiq_assert_resave_article_worker(user) do