ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexantone...@apache.org
Subject ambari git commit: AMBARI-13567. Kerb: credential dialog should not allow empty princ/pwd
Date Tue, 27 Oct 2015 12:44:27 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 4a6234ae3 -> 8ee493f83


AMBARI-13567. Kerb: credential dialog should not allow empty princ/pwd


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8ee493f8
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8ee493f8
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8ee493f8

Branch: refs/heads/branch-2.1
Commit: 8ee493f83f78c1f6c1014b739cda43efd509afbc
Parents: 4a6234a
Author: Alex Antonenko <hiveww@gmail.com>
Authored: Tue Oct 27 14:29:47 2015 +0200
Committer: Alex Antonenko <hiveww@gmail.com>
Committed: Tue Oct 27 14:44:22 2015 +0200

----------------------------------------------------------------------
 .../common/form/manage_credentilas_form.hbs     | 10 ++++
 .../common/form/manage_credentials_form_view.js | 51 ++++++++++++++++++--
 .../form/manage_kdc_credentials_form_test.js    | 24 +++++++++
 3 files changed, 82 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8ee493f8/ambari-web/app/templates/common/form/manage_credentilas_form.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/common/form/manage_credentilas_form.hbs b/ambari-web/app/templates/common/form/manage_credentilas_form.hbs
index 71f44ee..26ded49 100644
--- a/ambari-web/app/templates/common/form/manage_credentilas_form.hbs
+++ b/ambari-web/app/templates/common/form/manage_credentilas_form.hbs
@@ -24,12 +24,22 @@
     <label class="control-label">{{t popup.invalid.KDC.admin.principal}}</label>
     <div class="controls">
       {{view Ember.TextField valueBinding="view.principal" class="form-control"}}
+      {{#if view.principalError}}
+        <p class="mtm text-error">
+          {{view.principalError}}
+        </p>
+      {{/if}}
     </div>
   </div>
   <div class="control-group">
     <label class="control-label">{{t popup.invalid.KDC.admin.password}}</label>
     <div class="controls">
       {{view Ember.TextField type="password" valueBinding="view.password" class="form-control"}}
+      {{#if view.passwordError}}
+        <p class="mtm text-error">
+          {{view.passwordError}}
+        </p>
+      {{/if}}
     </div>
   </div>
 </form>

http://git-wip-us.apache.org/repos/asf/ambari/blob/8ee493f8/ambari-web/app/views/common/form/manage_credentials_form_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/form/manage_credentials_form_view.js b/ambari-web/app/views/common/form/manage_credentials_form_view.js
index 3327d0d..685051d 100644
--- a/ambari-web/app/views/common/form/manage_credentials_form_view.js
+++ b/ambari-web/app/views/common/form/manage_credentials_form_view.js
@@ -75,9 +75,54 @@ App.ManageCredentialsFormView = Em.View.extend({
    */
   actionStatus: false,
 
-  isSubmitDisabled: function() {
-    return Em.isEmpty(this.get('principal')) || Em.isEmpty(this.get('password'));
-  }.property('principal', 'password'),
+  /**
+   * Validation message error regarding principal name.
+   * When value is <code>false</code> error is hidden.
+   *
+   * @type {boolean|string}
+   */
+  passwordError: false,
+
+  /**
+   * Validation message error regarding principal name field.
+   * When value is <code>false</code> error is hidden.
+   *
+   * @type {boolean|string}
+   */
+  principalError: false,
+
+  isSubmitDisabled: true,
+
+  principalNameObserver: function() {
+    this.set('isPrincipalDirty', true);
+    if (Em.isEmpty(this.get('principal'))) {
+      this.set('principalError', Em.I18n.t('admin.users.editError.requiredField'));
+    } else if (/\s+/.test(this.get('principal'))) {
+      this.set('principalError', Em.I18n.t('host.spacesValidation'));
+    } else {
+      this.set('principalError', false);
+    }
+    this.toggleSubmitState();
+  }.observes('principal'),
+
+  passwordObserver: function() {
+    this.set('isPasswordDirty', true);
+    if (Em.isEmpty(this.get('password'))) {
+      this.set('passwordError', Em.I18n.t('admin.users.editError.requiredField'));
+    } else {
+      this.set('passwordError', false);
+    }
+    this.toggleSubmitState();
+  }.observes('password'),
+
+  /**
+   * Toggle submit disable state only when principal and password fields were modified.
+   */
+  toggleSubmitState: function() {
+    if (this.get('isPrincipalDirty') && this.get('isPasswordDirty')) {
+      this.set('isSubmitDisabled', !!this.get('principalError') || !!this.get('passwordError'));
+    }
+  },
 
   /**
    * Returns storage type used to save credentials e.g. <b>persistent</b>, <b>temporary</b>
(default)

http://git-wip-us.apache.org/repos/asf/ambari/blob/8ee493f8/ambari-web/test/views/common/form/manage_kdc_credentials_form_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/form/manage_kdc_credentials_form_test.js b/ambari-web/test/views/common/form/manage_kdc_credentials_form_test.js
index 1cba71c..76b6763 100644
--- a/ambari-web/test/views/common/form/manage_kdc_credentials_form_test.js
+++ b/ambari-web/test/views/common/form/manage_kdc_credentials_form_test.js
@@ -102,6 +102,30 @@ describe('#App.ManageCredentialsFormView', function() {
     });
   });
 
+  describe('fields validation', function() {
+    it('should flow validation', function() {
+      var t = Em.I18n.t;
+      assert.isTrue(view.get('isSubmitDisabled'), 'submit disabled on initial state');
+      view.set('principal', ' a');
+      assert.equal(view.get('principalError'), t('host.spacesValidation'), 'principal contains
spaces, appropriate message shown');
+      assert.isTrue(view.get('isPrincipalDirty'), 'principal name modified');
+      assert.isTrue(view.get('isSubmitDisabled'), 'submit disabled because principal not
valid');
+      view.set('principal', '');
+      assert.equal(view.get('principalError'), t('admin.users.editError.requiredField'),
'principal is empty, appropriate message shown');
+      view.set('principal', 'some_name');
+      assert.isFalse(view.get('principalError'), 'principal name valid no message shown');
+      assert.isTrue(view.get('isSubmitDisabled'), 'submit disabled because password field
not modified');
+      view.set('password', '1');
+      view.set('password', '');
+      assert.equal(view.get('passwordError'), t('admin.users.editError.requiredField'), 'password
is empty, appropriate message shown');
+      assert.isTrue(view.get('isPasswordDirty'), 'password modified');
+      assert.isTrue(view.get('isSubmitDisabled'), 'submit disabled because password field
is empty');
+      view.set('password', 'some_pass');
+      assert.isFalse(view.get('passwordError'), 'password valid no message shown');
+      assert.isFalse(view.get('isSubmitDisabled'), 'submit enabled all fields are valid');
+    });
+  });
+
   describe('#removeKDCCredentials', function() {
     it('should show confirmation popup', function() {
       var popup = view.removeKDCCredentials().popup;


Mime
View raw message