Allow system manager to change other users password

Also, update gateway membership type if sync_with_gateway is true
This commit is contained in:
Anand Doshi 2011-09-09 13:41:36 +05:30
parent 1c3443cab6
commit 389de000d9
3 changed files with 69 additions and 19 deletions

View File

@ -53,6 +53,15 @@ class DocType:
pr.role = r pr.role = r
pr.parentfield = 'userroles' pr.parentfield = 'userroles'
pr.save(1) pr.save(1)
# Update Membership Type at Gateway
if cint(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
if 'System Manager' in role_list : membership_type = 'Administrator'
else : membership_type = 'Member'
import server_tools.gateway_utils
server_tools.gateway_utils.update_membership_type(cstr(arg['usr']), membership_type)
sql("delete from __SessionCache where user=%s", cstr(arg['usr'])) sql("delete from __SessionCache where user=%s", cstr(arg['usr']))
# Save profile # Save profile

View File

@ -322,7 +322,7 @@ MemberProfile = function(parent, uid, member_item) {
// show securty settings // show securty settings
this.set_security = function() { this.set_security = function() {
var d = new wn.widgets.Dialog({ var sd = new wn.widgets.Dialog({
title: 'Set User Security', title: 'Set User Security',
width: 500, width: 500,
fields: [ fields: [
@ -362,30 +362,72 @@ MemberProfile = function(parent, uid, member_item) {
} }
] ]
}); });
d.onshow = function() {
d.set_values({ me.sec_dialog = sd
sd.onshow = function() {
me.sec_dialog.set_values({
restrict_ip: me.profile.restrict_ip || '', restrict_ip: me.profile.restrict_ip || '',
login_before: me.profile.login_before || '', login_before: me.profile.login_before || '',
login_after: me.profile.login_after || '', login_after: me.profile.login_after || '',
new_password: '' new_password: ''
}) });
} };
d.fields_dict.update.input.onclick = function() { sd.fields_dict.update.input.onclick = function() {
var btn = this; var btn = this;
this.set_working(); this.set_working();
var args = d.get_values(); var args = me.sec_dialog.get_values();
args.user = me.profile.name; args.user = me.profile.name;
$c_page('home', 'my_company', 'update_security', JSON.stringify(args), function(r,rt) {
if(r.exc) { if (args.new_password) {
msgprint(r.exc); var pass_d = new wn.widgets.Dialog({
title: 'Your Password',
width: 300,
fields: [
{
label: 'Please Enter Your Password',
description: "Your password is required to update the concerned user's password",
fieldtype: 'Password',
fieldname: 'sys_admin_pwd',
reqd: 1
},
{
label: 'Continue',
fieldtype: 'Button',
fieldname: 'continue'
}
]
});
pass_d.fields_dict.continue.input.onclick = function() {
btn.pwd_dialog.hide();
args.sys_admin_pwd = btn.pwd_dialog.get_values().sys_admin_pwd;
btn.set_working();
me.update_security(args);
btn.done_working(); btn.done_working();
return;
} }
$.extend(me.profile, d.get_values());
d.hide(); pass_d.show();
}); btn.pwd_dialog = pass_d;
} btn.done_working();
d.show(); } else {
btn.done_working();
me.update_security(args);
}
};
sd.show();
}
this.update_security = function(args) {
$c_page('home', 'my_company', 'update_security', JSON.stringify(args), function(r,rt) {
if(r.exc) {
msgprint(r.exc);
return;
}
me.sec_dialog.hide();
$.extend(me.profile, me.sec_dialog.get_values());
});
} }
// delete user // delete user

View File

@ -140,8 +140,7 @@ def update_security(args=''):
if 'new_password' in args: if 'new_password' in args:
if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')): if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')):
import server_tools.gateway_utils import server_tools.gateway_utils
webnotes.msgprint(server_tools.gateway_utils.change_password('', args['new_password'])['message']) webnotes.msgprint(server_tools.gateway_utils.change_password('', args['new_password'], args['user'], args['sys_admin_pwd'])['message'])
else: else:
webnotes.conn.sql("update tabProfile set password=password(%s) where name=%s", (args['new_password'], args['user'])) webnotes.conn.sql("update tabProfile set password=password(%s) where name=%s", (args['new_password'], args['user']))
else: webnotes.msgprint('Settings Updated')
webnotes.msgprint('Settings Updated')