Remove brand_color2 from users_settings (#18473)

* Remove brand_color2 from users_settings

* Remove occurences of brand_color2
This commit is contained in:
Fernando Valverde 2022-09-21 11:21:29 -06:00 committed by GitHub
parent 828d568443
commit bebd1d459c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 20 additions and 39 deletions

View file

@ -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],

View file

@ -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

View file

@ -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

View file

@ -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<Symbol, Hash<Symbol, Object>>] the profile

View file

@ -2,7 +2,6 @@
<div class="grid gap-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 @@
<div class="crayons-field">
<% 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 %>

View file

@ -0,0 +1,7 @@
class RemoveBrandColor2FromSettings < ActiveRecord::Migration[7.0]
def change
safety_assured do
remove_column :users_settings, :brand_color2
end
end
end

View file

@ -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

View file

@ -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

View file

@ -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