FIX: ensure theme variables are unique when adding an upload

This commit is contained in:
Régis Hanol 2018-03-28 18:57:11 +02:00
parent 31d0998506
commit fa608f2bb4
2 changed files with 8 additions and 4 deletions

View File

@ -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')

View File

@ -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"