Skip to content

A platform for community discussion. Free, open, simple.

FIX: ensure theme variables are unique when adding an upload

Régis Hanolfa608f2bb4e2
diff --git a/app/assets/javascripts/admin/controllers/modals/admin-add-upload.js.es6 b/app/assets/javascripts/admin/controllers/modals/admin-add-upload.js.es6
index 7bbdaa3de57..2eb6993b2fe 100644
--- a/app/assets/javascripts/admin/controllers/modals/admin-add-upload.js.es6
+++ b/app/assets/javascripts/admin/controllers/modals/admin-add-upload.js.es6
@@ -3,6 +3,8 @@ import { ajax } from 'discourse/lib/ajax';
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
import { popupAjaxError } from 'discourse/lib/ajax-error';
+const THEME_FIELD_VARIABLE_TYPE_IDS = [2, 3, 4];
+
export default Ember.Controller.extend(ModalFunctionality, {
adminCustomizeThemesShow: Ember.inject.controller(),
@@ -14,9 +16,11 @@ export default Ember.Controller.extend(ModalFunctionality, {
enabled: Em.computed.and('nameValid', 'fileSelected'),
disabled: Em.computed.not('enabled'),
- @computed('name')
- nameValid(name) {
- return name && name.match(/^[a-z_][a-z0-9_-]*$/i);
+ @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);
},
@observes('name')
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index b5d2236856a..52bf9d24691 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -3099,7 +3099,7 @@ en:
add_upload: "Add Upload"
upload_file_tip: "Choose an asset to upload (png, woff2, etc...)"
variable_name: "SCSS var name:"
- variable_name_invalid: "Invalid variable name. Only alphanumeric allowed. Must start with a letter."
+ variable_name_invalid: "Invalid variable name. Only alphanumeric allowed. Must start with a letter. Must be unique."
upload: "Upload"
child_themes_check: "Theme includes other child themes"
css_html: "Custom CSS/HTML"