mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: prevent theme uploads from overwriting existing variables
This commit is contained in:
@ -5,6 +5,24 @@ import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
||||
const THEME_FIELD_VARIABLE_TYPE_IDS = [2, 3, 4];
|
||||
|
||||
const SCSS_VARIABLE_NAMES = [
|
||||
// common/foundation/colors.scss
|
||||
"primary", "secondary", "tertiary", "quaternary", "header_background",
|
||||
"header_primary", "highlight", "danger", "success", "love",
|
||||
// common/foundation/math.scss
|
||||
"E", "PI", "LN2", "SQRT2",
|
||||
// common/foundation/variables.scss
|
||||
"small-width", "medium-width", "large-width",
|
||||
"google", "instagram", "facebook", "cas", "twitter", "yahoo", "github",
|
||||
"base-font-size", "base-line-height", "base-font-family",
|
||||
"primary-low", "primary-medium",
|
||||
"secondary-low", "secondary-medium",
|
||||
"tertiary-low", "quaternary-low",
|
||||
"highlight-low", "highlight-medium",
|
||||
"danger-low", "danger-medium",
|
||||
"success-low", "love-low",
|
||||
];
|
||||
|
||||
export default Ember.Controller.extend(ModalFunctionality, {
|
||||
adminCustomizeThemesShow: Ember.inject.controller(),
|
||||
|
||||
@ -19,10 +37,23 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
||||
disabled: Em.computed.not('enabled'),
|
||||
|
||||
@computed('name', 'adminCustomizeThemesShow.model.theme_fields')
|
||||
nameValid(name, themeFields) {
|
||||
return name &&
|
||||
name.match(/^[a-z_][a-z0-9_-]*$/i) &&
|
||||
!themeFields.some(tf => THEME_FIELD_VARIABLE_TYPE_IDS.includes(tf.type_id) && name === tf.name);
|
||||
errorMessage(name, themeFields) {
|
||||
if (name) {
|
||||
if (!name.match(/^[a-z_][a-z0-9_-]*$/i)) {
|
||||
return I18n.t("admin.customize.theme.variable_name_error.invalid_syntax");
|
||||
} else if (SCSS_VARIABLE_NAMES.includes(name.toLowerCase())) {
|
||||
return I18n.t("admin.customize.theme.variable_name_error.no_overwrite");
|
||||
} else if (themeFields.some(tf => THEME_FIELD_VARIABLE_TYPE_IDS.includes(tf.type_id) && name === tf.name)) {
|
||||
return I18n.t("admin.customize.theme.variable_name_error.must_be_unique");
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
@computed('errorMessage')
|
||||
nameValid(errorMessage) {
|
||||
return null === errorMessage;
|
||||
},
|
||||
|
||||
@observes('name')
|
||||
|
Reference in New Issue
Block a user