[IMP] auth_signup,portal: create portal user using template user
Purpose of this commit is to standardize portal user creation when creating new portal users (when 'Free sign up (B2C)' option activated). It copies the portal user template. The same behavior now applies when converting a partner into portal user using the portal wizard. This commit is related to task ID 31399 .
This commit is contained in:
committed by
Thibault Delavallée
parent
e3afd5508c
commit
7cee389e78
@@ -76,19 +76,24 @@ class ResUsers(models.Model):
|
||||
|
||||
@api.model
|
||||
def _signup_create_user(self, values):
|
||||
""" create a new user from the template user """
|
||||
get_param = self.env['ir.config_parameter'].sudo().get_param
|
||||
template_user_id = literal_eval(get_param('base.template_portal_user_id', 'False'))
|
||||
template_user = self.browse(template_user_id)
|
||||
assert template_user.exists(), 'Signup: invalid template user'
|
||||
""" signup a new user using the template user """
|
||||
|
||||
# check that uninvited users may sign up
|
||||
if 'partner_id' not in values:
|
||||
if get_param('auth_signup.invitation_scope', 'b2b') != 'b2c':
|
||||
if self.env['ir.config_parameter'].sudo().get_param('auth_signup.invitation_scope', 'b2b') != 'b2c':
|
||||
raise SignupError(_('Signup is not allowed for uninvited users'))
|
||||
return self._create_user_from_template(values)
|
||||
|
||||
assert values.get('login'), "Signup: no login given for new user"
|
||||
assert values.get('partner_id') or values.get('name'), "Signup: no name or partner given for new user"
|
||||
def _create_user_from_template(self, values):
|
||||
template_user_id = literal_eval(self.env['ir.config_parameter'].sudo().get_param('base.template_portal_user_id', 'False'))
|
||||
template_user = self.browse(template_user_id)
|
||||
if template_user.exists():
|
||||
raise ValueError(_('Signup: invalid template user'))
|
||||
|
||||
if not values.get('login'):
|
||||
raise ValueError(_('Signup: no login given for new user'))
|
||||
if not values.get('partner_id') or not values.get('name'):
|
||||
raise ValueError(_('Signup: no name or partner given for new user'))
|
||||
|
||||
# create a copy of the template user (attached to a specific partner_id if given)
|
||||
values['active'] = True
|
||||
|
||||
@@ -160,13 +160,12 @@ class PortalWizardUser(models.TransientModel):
|
||||
:returns record of res.users
|
||||
"""
|
||||
company_id = self.env.context.get('company_id')
|
||||
return self.env['res.users'].with_context(no_reset_password=True).create({
|
||||
return self.env['res.users'].with_context(no_reset_password=True)._create_user_from_template({
|
||||
'email': extract_email(self.email),
|
||||
'login': extract_email(self.email),
|
||||
'partner_id': self.partner_id.id,
|
||||
'company_id': company_id,
|
||||
'company_ids': [(6, 0, [company_id])],
|
||||
'groups_id': [(6, 0, [])],
|
||||
})
|
||||
|
||||
@api.multi
|
||||
|
||||
Reference in New Issue
Block a user