[MERGE] res.user: fix the call to create_user:

Corrected the dictionary values passed to res_users.create()
from tuples (id,name) to ids and from list of ids to tuples
(6,0,ids) (accounting for the discrepancy between read/write
values).
Added a call to that mathod from a yml test.

bzr revid: vmt@openerp.com-20110523111953-umzk6kow40wxh607
This commit is contained in:
Vo Minh Thu 2011-05-23 13:19:53 +02:00
commit 00fc2c908f
4 changed files with 33 additions and 12 deletions

View File

@ -94,6 +94,7 @@
'test/bug_lp541545.xml',
'test/test_osv_expression.yml',
'test/test_ir_rule.yml', # <-- These tests modify/add/delete ir_rules.
'test/test_config_users.yml'
],
'installable': True,
'active': True,

View File

@ -127,6 +127,8 @@ class users(osv.osv):
def send_welcome_email(self, cr, uid, id, context=None):
logger= netsvc.Logger()
user = self.pool.get('res.users').read(cr, uid, id, context=context)
if not user.get('email'):
return False
if not tools.config.get('smtp_server'):
logger.notifyChannel('mails', netsvc.LOG_WARNING,
_('"smtp_server" needs to be set to send mails to users'))
@ -136,8 +138,6 @@ class users(osv.osv):
_('"email_from" needs to be set to send welcome mails '
'to users'))
return False
if not user.get('email'):
return False
return tools.email_send(email_from=None, email_to=[user['email']],
subject=self.get_welcome_mail_subject(
@ -206,6 +206,9 @@ class users(osv.osv):
raise osv.except_osv(_('Operation Canceled'), _('Please use the change password wizard (in User Preferences or User menu) to change your own password.'))
self.write(cr, uid, id, {'password': value})
def _get_password(self, cr, uid, ids, arg, karg, context=None):
return dict.fromkeys(ids, '')
_columns = {
'name': fields.char('User Name', size=64, required=True, select=True,
help="The new user's real name, used for searching"
@ -213,7 +216,7 @@ class users(osv.osv):
'login': fields.char('Login', size=64, required=True,
help="Used to log into the system"),
'password': fields.char('Password', size=64, invisible=True, help="Keep empty if you don't want the user to be able to connect on the system."),
'new_password': fields.function(lambda *a:'', method=True, type='char', size=64,
'new_password': fields.function(_get_password, method=True, type='char', size=64,
fnct_inv=_set_new_password,
string='Change password', help="Only specify a value if you want to change the user password. "
"This user will have to logout and login again!"),
@ -263,7 +266,6 @@ class users(osv.osv):
if 'password' in o and ( 'id' not in o or o['id'] != uid ):
o['password'] = '********'
return o
result = super(users, self).read(cr, uid, ids, fields, context, load)
canwrite = self.pool.get('ir.model.access').check(cr, uid, 'res.users', 'write', raise_exception=False)
if not canwrite:
@ -535,15 +537,19 @@ class config_users(osv.osv_memory):
'email': base_data['email'],
'partner_id': partner_id,},
context)
user_data = dict(
base_data,
signature=self._generate_signature(
cr, base_data['name'], base_data['email'], context=context),
address_id=address,
)
# Change the read many2one values from (id,name) to id, and
# the one2many from ids to (6,0,ids).
base_data.update({'menu_id' : base_data.get('menu_id') and base_data['menu_id'][0],
'company_id' : base_data.get('company_id') and base_data['company_id'][0],
'action_id' : base_data.get('action_id') and base_data['action_id'][0],
'signature' : self._generate_signature(cr, base_data['name'], base_data['email'], context=context),
'address_id' : address,
'groups_id' : [(6,0, base_data.get('groups_id',[]))],
})
new_user = self.pool.get('res.users').create(
cr, uid, user_data, context)
cr, uid, base_data, context)
self.send_welcome_email(cr, uid, new_user, context=context)
def execute(self, cr, uid, ids, context=None):
'Do nothing on execution, just launch the next action/todo'
pass

View File

@ -0,0 +1,11 @@
-
I Create "test" user using configuration wizard.
-
!python {model: res.config.users}: |
defaults = {
'name' : 'test1',
'login' : 'test1',
'password' : 'test',
}
wizard_id = self.create(cr, uid, defaults)
self.action_add(cr, uid, [wizard_id], context)

View File

@ -3532,7 +3532,10 @@ class orm(orm_template):
#
def create(self, cr, user, vals, context=None):
"""
Create new record with specified value
Create a new record for the model.
The values for the new record are initialized using the ``vals``
argument, and if necessary the result of ``default_get()``.
:param cr: database cursor
:param user: current user id