You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2016/04/25 22:55:41 UTC
ambari git commit: AMBARI-15869. Name in create Alert Notification
should be restricted to use only alphanumerics, hyphens,
spaces and underscores (alexantonenko)
Repository: ambari
Updated Branches:
refs/heads/trunk acfa1c0e7 -> 6db7fa262
AMBARI-15869. Name in create Alert Notification should be restricted to use only alphanumerics, hyphens, spaces and underscores (alexantonenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/6db7fa26
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/6db7fa26
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/6db7fa26
Branch: refs/heads/trunk
Commit: 6db7fa262b757e9b9e255627a005a500d4a18eb5
Parents: acfa1c0
Author: Alex Antonenko <hi...@gmail.com>
Authored: Mon Apr 25 23:55:28 2016 +0300
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Mon Apr 25 23:55:36 2016 +0300
----------------------------------------------------------------------
.../main/alerts/manage_alert_notifications_controller.js | 6 ++++++
ambari-web/app/messages.js | 1 +
ambari-web/app/utils/validator.js | 10 ++++++++++
.../alerts/manage_alert_notifications_controller_test.js | 7 +++++++
4 files changed, 24 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/6db7fa26/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
index 7dd7dea..1de15a6 100644
--- a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
+++ b/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);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/6db7fa26/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 907d9ae..04041aa 100644
--- a/ambari-web/app/messages.js
+++ b/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',
http://git-wip-us.apache.org/repos/asf/ambari/blob/6db7fa26/ambari-web/app/utils/validator.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/validator.js b/ambari-web/app/utils/validator.js
index 6426163..490fec5 100644
--- a/ambari-web/app/utils/validator.js
+++ b/ambari-web/app/utils/validator.js
@@ -199,6 +199,16 @@ module.exports = {
},
/**
+ * 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
* @return {Boolean}
http://git-wip-us.apache.org/repos/asf/ambari/blob/6db7fa26/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
index 837c2f3..a0a4ce4 100644
--- a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
+++ b/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'));
+ });
});