Author: yusaku
Date: Wed Jan 30 01:51:18 2013
New Revision: 1440244
URL: http://svn.apache.org/viewvc?rev=1440244&view=rev
Log:
AMBARI-1297. Edit User: if "old password" is not specified and "new password"
is specified, password update silently fails. (Jaimin Jetly via yusaku)
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-web/app/models/authentication.js
incubator/ambari/trunk/ambari-web/app/models/form.js
incubator/ambari/trunk/ambari-web/app/models/user.js
incubator/ambari/trunk/ambari-web/app/templates/main/admin/user/create.hbs
incubator/ambari/trunk/ambari-web/app/templates/main/admin/user/edit.hbs
Modified: incubator/ambari/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1440244&r1=1440243&r2=1440244&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Wed Jan 30 01:51:18 2013
@@ -188,6 +188,10 @@ Trunk (unreleased changes):
BUG FIXES
+ AMBARI-1297. Edit User: if "old password" is not specified and "new
+ password" is specified, password update silently fails. (Jaimin Jetly via
+ yusaku)
+
AMBARI-1282. Admin user can lose its own admin privilege. (Jaimin Jetly
via yusaku)
Modified: incubator/ambari/trunk/ambari-web/app/models/authentication.js
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/models/authentication.js?rev=1440244&r1=1440243&r2=1440244&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/models/authentication.js (original)
+++ incubator/ambari/trunk/ambari-web/app/models/authentication.js Wed Jan 30
01:51:18 2013
@@ -47,7 +47,6 @@ App.Authentication.FIXTURES = [
App.AuthenticationForm = App.Form.extend({
testResult:false,
- isObjectNew:false,
fieldsOptions:[
{ name:"method", displayName:"", isRequired:false, displayType:"select",
values:[
@@ -104,6 +103,6 @@ App.AuthenticationForm = App.Form.extend
}.property('testResult'),
testConfigurationClass:function () {
return this.get('testResult') ? "text-success" : "text-error";
- }.property('testConfigurationMessage'),
+ }.property('testConfigurationMessage')
})
;
\ No newline at end of file
Modified: incubator/ambari/trunk/ambari-web/app/models/form.js
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/models/form.js?rev=1440244&r1=1440243&r2=1440244&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/models/form.js (original)
+++ incubator/ambari/trunk/ambari-web/app/models/form.js Wed Jan 30 01:51:18
2013
@@ -71,14 +71,6 @@ App.Form = Em.View.extend({
return isValid;
},
- isObjectNew:function () {
- var object = this.get('object');
- if(object instanceof App.User){
- return false;
- }
- return !(object instanceof DS.Model && object.get('id'));
- }.property("object"),
-
updateValues:function () {
var object = this.get('object');
if (object instanceof Em.Object) {
@@ -97,36 +89,6 @@ App.Form = Em.View.extend({
});
},
- /**
- * need to refactor for integration
- * @return {Boolean}
- */
- save:function () {
- var object = this.get('object');
- var formValues = {};
- $.each(this.get('fields'), function () {
- formValues[this.get('name')] = this.get('value');
- });
- if (!this.get('isObjectNew')) {
- $.each(formValues, function (k, v) {
- object.set(k, v);
- });
- }
- else {
- if (this.get('className')) {
- App.store.createRecord(this.get('className'), formValues);
- }
- else {
- console.log("Please define class name for your form " +
this.constructor);
- }
- }
-
- //App.store.commit();
- this.set('result', 1);
-
- return true;
- },
-
visibleFields:function () {
var fields = this.get('fields');
var visible = [];
@@ -150,16 +112,7 @@ App.Form = Em.View.extend({
}
return text;
- }.property('result'),
-
- saveButtonText:function () {
- return Em.I18n.t(this.get('i18nprefix') + (this.get('isObjectNew') ?
"create" : "save"));
- }.property('isObjectNew')
-
-// not recommended
-// cancelButtonText:function () {
-// return Em.I18n.t(this.get('i18nprefix') + 'cancel').property();
-// }
+ }.property('result')
});
App.FormField = Em.Object.extend({ // try to realize this as view
Modified: incubator/ambari/trunk/ambari-web/app/models/user.js
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/models/user.js?rev=1440244&r1=1440243&r2=1440244&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/models/user.js (original)
+++ incubator/ambari/trunk/ambari-web/app/models/user.js Wed Jan 30 01:51:18
2013
@@ -49,7 +49,7 @@ App.EditUserForm = App.Form.extend({
fieldsOptions:[
{ name:"userName", displayName:"Username" },
- { name:"old_password", displayName:"Current Password",
displayType:"password", isRequired: function(){ return
this.get('form.isObjectNew'); }.property('form.isObjectNew') },
+ { name:"old_password", displayName:"Current Password",
displayType:"password", isRequired: false },
{ name:"new_password", displayName:"New Password", displayType:"password",
isRequired: false },
{ name:"admin", displayName:"Admin", displayType:"checkbox",
isRequired:false },
{ name:"roles", displayName:"Role", isRequired:false, isHidden:true },
@@ -57,48 +57,46 @@ App.EditUserForm = App.Form.extend({
],
fields:[],
disableUsername:function () {
- var field = this.getField("userName");
- if (field) field.set("disabled", this.get('isObjectNew') ? false :
"disabled");
- }.observes('isObjectNew'),
+ this.getField("userName").set("disabled", "disabled");
+ }.observes('object'),
disableAdminCheckbox:function () {
- if (!this.get('isObjectNew')) {
- var object = this.get('object');
- var field = this.getField("admin");
- if (field) {
- field.set("disabled", (object.get('userName') ==
App.get('router').getLoginName()) ? "disabled" : false);
- }
+ var object = this.get('object');
+ if (object) {
+ this.getField("admin").set("disabled", (object.get('userName') ==
App.get('router').getLoginName()) ? "disabled" : false);
}
- }.observes('isObjectNew'),
+ }.observes('object'),
isValid:function () {
var isValid = this._super();
thisForm = this;
- var passField = this.get('field.password');
- var passRetype = this.get('field.passwordRetype');
+ var newPass = this.get('field.new_password');
+ var oldPass = this.get('field.old_password');
- if (!validator.empty(passField.get('value'))) {
- if (passField.get('value') != passRetype.get('value')) {
- passRetype.set('errorMessage', "Passwords are different");
+ if (!validator.empty(newPass.get('value')) &&
validator.empty(oldPass.get('value'))) {
+ oldPass.set('errorMessage', "This is required");
isValid = false;
- }
}
- if (isValid && this.get('isObjectNew')) {
- var users = App.User.find();
- var userNameField = this.getField('userName');
- var userName = userNameField.get('value');
+ return isValid;
+ },
- users.forEach(function (user) {
- if (userName == user.get('userName')) {
- userNameField.set('errorMessage', 'User with the same name is
already exists');
- return isValid = false;
- }
- });
- }
+ save: function () {
+ var object = this.get('object');
+ var formValues = {};
+ $.each(this.get('fields'), function () {
+ formValues[this.get('name')] = this.get('value');
+ });
+
+ $.each(formValues, function (k, v) {
+ object.set(k, v);
+ });
- return isValid;
+ //App.store.commit();
+ this.set('result', 1);
+
+ return true;
}
});
App.CreateUserForm = App.Form.extend({
@@ -109,25 +107,12 @@ App.CreateUserForm = App.Form.extend({
fieldsOptions:[
{ name:"userName", displayName:"Username", toLowerCase: function(){var v =
this.get('value'); this.set('value', v.toLowerCase())}.observes('value') },
- { name:"password", displayName:"Password", displayType:"password",
isRequired: function(){ return this.get('form.isObjectNew');
}.property('form.isObjectNew') },
- { name:"passwordRetype", displayName:"Retype Password",
displayType:"password", validator:"passwordRetype", isRequired: false },
+ { name:"password", displayName:"Password", displayType:"password",
isRequired: true },
+ { name:"passwordRetype", displayName:"Retype Password",
displayType:"password", validator:"passwordRetype", isRequired: true },
{ name:"admin", displayName:"Admin", displayType:"checkbox",
isRequired:false },
{ name:"roles", displayName:"Role", isRequired:false, isHidden:true }
],
fields:[],
- disableUsername:function () {
- var field = this.getField("userName");
- if (field) field.set("disabled", this.get('isObjectNew') ? false :
"disabled");
- }.observes('isObjectNew'),
- disableAdminCheckbox:function () {
- if (!this.get('isObjectNew')) {
- var object = this.get('object');
- var field = this.getField("admin");
- if (field) {
- field.set("disabled", (object.get('userName') ==
App.get('router').getLoginName()) ? "disabled" : false);
- }
- }
- }.observes('isObjectNew'),
isValid:function () {
var isValid = this._super();
@@ -142,20 +127,38 @@ App.CreateUserForm = App.Form.extend({
}
}
- if (isValid && this.get('isObjectNew')) {
+ if (isValid) {
var users = App.User.find();
var userNameField = this.getField('userName');
var userName = userNameField.get('value');
-
- users.forEach(function (user) {
- if (userName == user.get('userName')) {
+ if (users.mapProperty('userName').contains(userName)) {
userNameField.set('errorMessage', 'User with the same name is
already exists');
return isValid = false;
}
- });
}
return isValid;
+ },
+
+ save: function () {
+
+ var object = this.get('object');
+ var formValues = {};
+ $.each(this.get('fields'), function () {
+ formValues[this.get('name')] = this.get('value');
+ });
+
+ if (this.get('className')) {
+ App.store.createRecord(this.get('className'), formValues);
+ }
+ else {
+ console.log("Please define class name for your form " +
this.constructor);
+ }
+
+ //App.store.commit();
+ this.set('result', 1);
+
+ return true;
}
});
App.User.FIXTURES = [];
Modified:
incubator/ambari/trunk/ambari-web/app/templates/main/admin/user/create.hbs
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/templates/main/admin/user/create.hbs?rev=1440244&r1=1440243&r2=1440244&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/templates/main/admin/user/create.hbs
(original)
+++ incubator/ambari/trunk/ambari-web/app/templates/main/admin/user/create.hbs
Wed Jan 30 01:51:18 2013
@@ -32,7 +32,7 @@
<div class="controls">
<button type="submit" class="btn" {{action gotoUsers}}>{{t
form.cancel}}</button>
<button type="submit"
- class="btn btn-primary" {{action create
target="view"}}>{{view.userForm.saveButtonText}}</button>
+ class="btn btn-primary" {{action create
target="view"}}>Create</button>
</div>
</div>
</form>
Modified:
incubator/ambari/trunk/ambari-web/app/templates/main/admin/user/edit.hbs
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/templates/main/admin/user/edit.hbs?rev=1440244&r1=1440243&r2=1440244&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/templates/main/admin/user/edit.hbs
(original)
+++ incubator/ambari/trunk/ambari-web/app/templates/main/admin/user/edit.hbs
Wed Jan 30 01:51:18 2013
@@ -32,7 +32,7 @@
<div class="controls">
<button type="submit" class="btn" {{action gotoUsers}}>{{t
form.cancel}}</button>
<button type="submit"
- class="btn btn-primary" {{action edit
target="view"}}>{{view.userForm.saveButtonText}}</button>
+ class="btn btn-primary" {{action edit
target="view"}}>Save</button>
</div>
</div>
</form>
\ No newline at end of file