feat: validate and store the size choice in redmine_tonalmine (T6)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
module RedmineTonalmine
|
module RedmineTonalmine
|
||||||
# Validates appearance hashes ({mode, contrast, palette, seed, css}) coming from users and from
|
# Validates appearance hashes ({mode, contrast, size, palette, seed, css}) coming from users and from
|
||||||
# the Display settings form. Any part may be missing: it then falls back to the default.
|
# the Display settings form. Any part may be missing: it then falls back to the default.
|
||||||
module Appearance
|
module Appearance
|
||||||
MODES = %w[auto light dark].freeze
|
MODES = %w[auto light dark].freeze
|
||||||
CONTRASTS = %w[standard medium high].freeze
|
CONTRASTS = %w[standard medium high].freeze
|
||||||
|
SIZES = %w[compact normal large].freeze
|
||||||
# Ids must match PALETTES in tonalmine/javascripts/theme.js (tools/palettes checks this).
|
# Ids must match PALETTES in tonalmine/javascripts/theme.js (tools/palettes checks this).
|
||||||
PALETTES = %w[purple blue green orange].freeze
|
PALETTES = %w[purple blue green orange].freeze
|
||||||
KEYS = %w[mode contrast palette seed css].freeze
|
KEYS = %w[mode contrast size palette seed css].freeze
|
||||||
MAX_CSS = 32.kilobytes
|
MAX_CSS = 32.kilobytes
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
@@ -21,6 +22,7 @@ module RedmineTonalmine
|
|||||||
end
|
end
|
||||||
errors << 'invalid mode' if prefs['mode'] && !MODES.include?(prefs['mode'])
|
errors << 'invalid mode' if prefs['mode'] && !MODES.include?(prefs['mode'])
|
||||||
errors << 'invalid contrast' if prefs['contrast'] && !CONTRASTS.include?(prefs['contrast'])
|
errors << 'invalid contrast' if prefs['contrast'] && !CONTRASTS.include?(prefs['contrast'])
|
||||||
|
errors << 'invalid size' if prefs['size'] && !SIZES.include?(prefs['size'])
|
||||||
errors.concat(custom_errors(prefs))
|
errors.concat(custom_errors(prefs))
|
||||||
errors
|
errors
|
||||||
end
|
end
|
||||||
@@ -30,6 +32,7 @@ module RedmineTonalmine
|
|||||||
prefs = normalize(hash)
|
prefs = normalize(hash)
|
||||||
prefs.delete('mode') unless MODES.include?(prefs['mode'])
|
prefs.delete('mode') unless MODES.include?(prefs['mode'])
|
||||||
prefs.delete('contrast') unless CONTRASTS.include?(prefs['contrast'])
|
prefs.delete('contrast') unless CONTRASTS.include?(prefs['contrast'])
|
||||||
|
prefs.delete('size') unless SIZES.include?(prefs['size'])
|
||||||
prefs = prefs.except('palette', 'seed', 'css') if custom_errors(prefs).any?
|
prefs = prefs.except('palette', 'seed', 'css') if custom_errors(prefs).any?
|
||||||
prefs.compact
|
prefs.compact
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user