2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-10-03 17:21:20 +08:00

can't prevent edits to remote color schemes

This commit is contained in:
OsamaSayegh 2025-10-02 17:21:49 +03:00
parent a06e40fd05
commit b8ea221ade
No known key found for this signature in database
GPG key ID: 060E5AC82223685F
2 changed files with 0 additions and 29 deletions

View file

@ -8,19 +8,10 @@ class ColorSchemeColor < ActiveRecord::Base
belongs_to :color_scheme, -> { unscope(where: :remote_copy) }

validates :hex, format: { with: /\A([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\z/ }
validate :no_edits_for_remote_copies, on: :update

def hex_with_hash
"##{hex}"
end

private

def no_edits_for_remote_copies
if color_scheme&.remote_copy && will_save_change_to_hex?
errors.add(:base, I18n.t("color_schemes.errors.cannot_edit_remote_copies"))
end
end
end

# == Schema Information

View file

@ -26,24 +26,4 @@ RSpec.describe ColorSchemeColor do
"555 666",
].each { |hex| test_invalid_hex(hex) }
end

describe "#no_edits_for_remote_copies" do
it "prevents editing colors of remote copies" do
remote_copy =
Fabricate(
:color_scheme,
remote_copy: true,
color_scheme_colors: [
Fabricate(:color_scheme_color, name: "primary", hex: "998877"),
Fabricate(:color_scheme_color, name: "secondary", hex: "553322"),
],
)
color = remote_copy.color_scheme_colors.first
color.hex = "111111"
expect(color.valid?).to eq(false)
expect(color.errors.full_messages).to include(
I18n.t("color_schemes.errors.cannot_edit_remote_copies"),
)
end
end
end