You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2013/04/27 05:02:18 UTC

svn commit: r1476472 - in /incubator/ambari/trunk: CHANGES.txt ambari-web/app/messages.js ambari-web/app/utils/validator.js ambari-web/app/views/common/configs/services_config.js

Author: yusaku
Date: Sat Apr 27 03:02:18 2013
New Revision: 1476472

URL: http://svn.apache.org/r1476472
Log:
AMBARI-2027. Add validation checks for Add Property on custom site configs. (yusaku)

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/ambari-web/app/messages.js
    incubator/ambari/trunk/ambari-web/app/utils/validator.js
    incubator/ambari/trunk/ambari-web/app/views/common/configs/services_config.js

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1476472&r1=1476471&r2=1476472&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Sat Apr 27 03:02:18 2013
@@ -269,6 +269,9 @@ Trunk (unreleased changes):
 
  IMPROVEMENTS
 
+ AMBARI-2027. Add validation checks for Add Property on custom site configs.
+ (yusaku)
+
  AMBARI-2017. Admin Misc page tweaks. (yusaku)
 
  AMBARI-2022. Service Component metric collection API takes over a minute

Modified: incubator/ambari/trunk/ambari-web/app/messages.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/messages.js?rev=1476472&r1=1476471&r2=1476472&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/messages.js (original)
+++ incubator/ambari/trunk/ambari-web/app/messages.js Sat Apr 27 03:02:18 2013
@@ -508,6 +508,7 @@ Em.I18n.translations = {
   'form.item.placeholders.typePassword':'Type password',
 
   'form.validator.invalidIp':'Please enter valid ip address',
+  'form.validator.configKey':'Invalid Key. Only alphanumerics, hyphens, underscores, and periods are allowed.',
 
   'admin.advanced.title':'Advanced',
   'admin.advanced.caution':'This section is for advanced user only.<br/>Proceed with caution.',

Modified: incubator/ambari/trunk/ambari-web/app/utils/validator.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/utils/validator.js?rev=1476472&r1=1476471&r2=1476472&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/utils/validator.js (original)
+++ incubator/ambari/trunk/ambari-web/app/utils/validator.js Sat Apr 27 03:02:18 2013
@@ -96,6 +96,16 @@ module.exports = {
     return usernameRegex.test(value);
   },
 
+  /**
+   * validate key of configurations
+   * @param value
+   * @return {Boolean}
+   */
+  isValidConfigKey: function(value) {
+    var configKeyRegex = /^[0-9a-z_\-\.]+$/i;
+    return configKeyRegex.test(value);
+  },
+
   empty:function (e) {
     switch (e) {
       case "":

Modified: incubator/ambari/trunk/ambari-web/app/views/common/configs/services_config.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/views/common/configs/services_config.js?rev=1476472&r1=1476471&r2=1476472&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/views/common/configs/services_config.js (original)
+++ incubator/ambari/trunk/ambari-web/app/views/common/configs/services_config.js Sat Apr 27 03:02:18 2013
@@ -180,7 +180,7 @@ App.ServiceConfigsByCategoryView = Ember
     return category.indexOf("Advanced") != -1;
   },
   showAddPropertyWindow: function (event) {
-
+    var serviceConfigNames = this.get('categoryConfigs').mapProperty('name');
     var serviceConfigObj = Ember.Object.create({
       name: '',
       value: '',
@@ -190,21 +190,28 @@ App.ServiceConfigsByCategoryView = Ember
       isKeyError:false,
       errorMessage:"",
       observeAddPropertyValue:function(){
-        if(this.get("name").trim() != ""){
-          var configMappingProperty = App.config.configMapping.all().findProperty('name', serviceConfigObj.get('name'));
-          if(configMappingProperty==null){
-            this.set("isKeyError", false);
-            this.set("errorMessage", "");
-          }else{
+        var name = this.get('name');
+        if(name.trim() != ""){
+          if(validator.isValidConfigKey(name)){
+            var configMappingProperty = App.config.configMapping.all().findProperty('name', name);
+            if((configMappingProperty == null) && (!serviceConfigNames.contains(name))){
+              this.set("isKeyError", false);
+              this.set("errorMessage", "");
+            } else {
+              this.set("isKeyError", true);
+              this.set("errorMessage", Em.I18n.t('services.service.config.addPropertyWindow.error.derivedKey'));
+            }
+          } else {
             this.set("isKeyError", true);
-            this.set("errorMessage", Em.I18n.t('services.service.config.addPropertyWindow.error.derivedKey'));
+            this.set("errorMessage", Em.I18n.t('form.validator.configKey'));
           }
-        }else{
+        } else {
           this.set("isKeyError", true);
           this.set("errorMessage", Em.I18n.t('services.service.config.addPropertyWindow.errorMessage'));
         }
       }.observes("name")
     });
+    serviceConfigObj.observeAddPropertyValue();
 
     var category = this.get('category');
     serviceConfigObj.displayType = "advanced";
@@ -230,23 +237,12 @@ App.ServiceConfigsByCategoryView = Ember
          * For the first entrance use this if (serviceConfigObj.name.trim() != "")
          */
         if (!serviceConfigObj.isKeyError) {
-          if (serviceConfigObj.name.trim() != "") {
-            var configMappingProperty = App.config.configMapping.all().findProperty('name', serviceConfigObj.get('name'));
-            if (configMappingProperty == null) {
-              serviceConfigObj.displayName = serviceConfigObj.name;
-              serviceConfigObj.id = 'site property';
-              serviceConfigObj.serviceName = serviceName;
-              var serviceConfigProperty = App.ServiceConfigProperty.create(serviceConfigObj);
-              self.get('serviceConfigs').pushObject(serviceConfigProperty);
-              this.hide();
-            } else {
-              serviceConfigObj.set("isKeyError", true);
-              serviceConfigObj.set("errorMessage", Em.I18n.t('services.service.config.addPropertyWindow.error.derivedKey'));
-            }
-          } else {
-            serviceConfigObj.set("isKeyError", true);
-            serviceConfigObj.set("errorMessage", Em.I18n.t('services.service.config.addPropertyWindow.errorMessage'));
-          }
+          serviceConfigObj.displayName = serviceConfigObj.name;
+          serviceConfigObj.id = 'site property';
+          serviceConfigObj.serviceName = serviceName;
+          var serviceConfigProperty = App.ServiceConfigProperty.create(serviceConfigObj);
+          self.get('serviceConfigs').pushObject(serviceConfigProperty);
+          this.hide();
         }
       },
       onSecondary: function () {