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:
parent
a06e40fd05
commit
b8ea221ade
2 changed files with 0 additions and 29 deletions
|
@ -8,19 +8,10 @@ class ColorSchemeColor < ActiveRecord::Base
|
||||||
belongs_to :color_scheme, -> { unscope(where: :remote_copy) }
|
belongs_to :color_scheme, -> { unscope(where: :remote_copy) }
|
||||||
|
|
||||||
validates :hex, format: { with: /\A([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\z/ }
|
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
|
def hex_with_hash
|
||||||
"##{hex}"
|
"##{hex}"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
|
|
|
@ -26,24 +26,4 @@ RSpec.describe ColorSchemeColor do
|
||||||
"555 666",
|
"555 666",
|
||||||
].each { |hex| test_invalid_hex(hex) }
|
].each { |hex| test_invalid_hex(hex) }
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue