Forráskód Böngészése

AMBARI-15869. Name in create Alert Notification should be restricted to use only alphanumerics, hyphens, spaces and underscores (alexantonenko)

Alex Antonenko 9 éve
szülő
commit
6db7fa262b

+ 6 - 0
ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js

@@ -483,6 +483,9 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
             } else if (newName && newName !== this.get('currentName') && self.get('alertNotifications').mapProperty('name').contains(newName)) {
               this.set('nameError', true);
               errorMessage = Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.existed');
+            } else if (newName && !validator.isValidAlertNotificationName(newName)){
+              this.set('nameError', true);
+              errorMessage = Em.I18n.t('form.validator.alertNotificationName');
             } else {
               this.set('nameError', false);
             }
@@ -494,6 +497,9 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
             } else if (newName && self.get('alertNotifications').mapProperty('name').contains(newName)) {
               this.set('nameError', true);
               errorMessage = Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.existed');
+            } else if (newName && !validator.isValidAlertNotificationName(newName)){
+              this.set('nameError', true);
+              errorMessage = Em.I18n.t('form.validator.alertNotificationName');
             } else {
               this.set('nameError', false);
             }

+ 1 - 0
ambari-web/app/messages.js

@@ -987,6 +987,7 @@ Em.I18n.translations = {
   'form.validator.configKey':'Invalid Key. Only alphanumerics, hyphens, underscores, asterisks and periods are allowed.',
   'form.validator.configGroupName':'Invalid Group Name. Only alphanumerics, hyphens, spaces and underscores are allowed.',
   'form.validator.alertGroupName':'Invalid Alert Group Name. Only alphanumerics, hyphens, spaces and underscores are allowed.',
+  'form.validator.alertNotificationName':'Invalid Alert Notification Name. Only alphanumerics, hyphens, spaces and underscores are allowed.',
   'form.validator.configKey.specific':'"{0}" is invalid Key. Only alphanumerics, hyphens, underscores, asterisks and periods are allowed.',
   'form.validator.error.trailingSpaces': 'Cannot contain trailing whitespace',
 

+ 10 - 0
ambari-web/app/utils/validator.js

@@ -198,6 +198,16 @@ module.exports = {
     return configKeyRegex.test(value);
   },
 
+  /**
+   * validate alert notification name
+   * @param value
+   * @return {Boolean}
+   */
+  isValidAlertNotificationName: function(value) {
+    var configKeyRegex = /^[\s0-9a-z_\-]+$/i;
+    return configKeyRegex.test(value);
+  },
+  
   /**
    * validate alert group name
    * @param value

+ 7 - 0
ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js

@@ -674,6 +674,13 @@ describe('App.ManageAlertNotificationsController', function () {
           view.set('controller.inputFields.name.value', 'test');
           expect(view.get('controller.inputFields.name.errorMsg')).to.equal('');
         });
+        
+        it('should check inputFields.name.value (5)', function () {
+         view.set('isEdit', true);
+         view.set('controller.inputFields.name.errorMsg', 'error');
+         view.set('controller.inputFields.name.value', 'test%');
+         expect(view.get('controller.inputFields.name.errorMsg')).to.equal(Em.I18n.t('form.validator.alertNotificationName'));
+       });
 
       });