Skip to content
Snippets Groups Projects
Commit 11911fe0 authored by Denis Ledoux's avatar Denis Ledoux
Browse files

[FIX] portal: portal access management for partners having users

When the partner already had a user,
checking `in_portal` of this partner and applying
the wizard raised the fact there was already a duplicated
user for this email, even if there wasn't.

This is because the system relied on the fact
the field `user_id` of the `portal.wizard.user`
was automatically filled with the partner user if
there was one, but it was not the case:
This `user_id` field is a simple many2one field,
not computed, and the assignation was done nowhere
when the partner already had a user.

The assignation should be done in the `onchange_portal_id` method
of the `portal.wizard` model, like the other fields
`partner_id`, `email` and `in_portal`,
but if we do it know, as the `user_id` field is not
in the view (not even in `invisible`), the
web client will ignore it even if returned by
this `onchange_portal_id` method. It was therefore pointless
to solve this issue by adding the correct `user_id`
in the `user_ids` returned by this onchange method.

We could add `user_id` in invisible in the view,
but existing databases with the current view
will not benefit of the bug fix without updating the according view.

This revision therefore replaces `wizard.user_id` by
`wizard.partner_ids.user_ids[0]` everywhere where it's needed to
know if the partner already has a user or not.

Besides, it takes care about the fact his user could
be disabled (`active` False).

opw-659339
parent 7a3ad6ba
No related branches found
No related tags found
No related merge requests found
...@@ -94,8 +94,8 @@ class wizard_user(osv.osv_memory): ...@@ -94,8 +94,8 @@ class wizard_user(osv.osv_memory):
error_emails = [] error_emails = []
error_user = [] error_user = []
ctx = dict(context or {}, active_test=False) ctx = dict(context or {}, active_test=False)
for wizard_user in self.browse(cr, SUPERUSER_ID, ids, context): for wizard_user in self.browse(cr, SUPERUSER_ID, ids, ctx):
if wizard_user.in_portal and not wizard_user.user_id: if wizard_user.in_portal and not wizard_user.partner_id.user_ids:
email = extract_email(wizard_user.email) email = extract_email(wizard_user.email)
if not email: if not email:
error_empty.append(wizard_user.partner_id) error_empty.append(wizard_user.partner_id)
...@@ -127,15 +127,19 @@ class wizard_user(osv.osv_memory): ...@@ -127,15 +127,19 @@ class wizard_user(osv.osv_memory):
if error_msg: if error_msg:
raise UserError( "\n\n".join(error_msg)) raise UserError( "\n\n".join(error_msg))
for wizard_user in self.browse(cr, SUPERUSER_ID, ids, context): for wizard_user in self.browse(cr, SUPERUSER_ID, ids, dict(context, active_test=False)):
portal = wizard_user.wizard_id.portal_id portal = wizard_user.wizard_id.portal_id
user = wizard_user.partner_id.user_ids and wizard_user.partner_id.user_ids[0] or False
if wizard_user.partner_id.email != wizard_user.email: if wizard_user.partner_id.email != wizard_user.email:
wizard_user.partner_id.write({'email': wizard_user.email}) wizard_user.partner_id.write({'email': wizard_user.email})
if wizard_user.in_portal: if wizard_user.in_portal:
user_id = False
# create a user if necessary, and make sure it is in the portal group # create a user if necessary, and make sure it is in the portal group
if not wizard_user.user_id: if not user:
user = self._create_user(cr, SUPERUSER_ID, wizard_user.id, context) user_id = self._create_user(cr, SUPERUSER_ID, wizard_user.id, context)
wizard_user.write({'user_id': user}) else:
user_id = user.id
wizard_user.write({'user_id': user_id})
if (not wizard_user.user_id.active) or (portal not in wizard_user.user_id.groups_id): if (not wizard_user.user_id.active) or (portal not in wizard_user.user_id.groups_id):
wizard_user.user_id.write({'active': True, 'groups_id': [(4, portal.id)]}) wizard_user.user_id.write({'active': True, 'groups_id': [(4, portal.id)]})
# prepare for the signup process # prepare for the signup process
...@@ -144,12 +148,12 @@ class wizard_user(osv.osv_memory): ...@@ -144,12 +148,12 @@ class wizard_user(osv.osv_memory):
wizard_user.refresh() wizard_user.refresh()
else: else:
# remove the user (if it exists) from the portal group # remove the user (if it exists) from the portal group
if wizard_user.user_id and (portal in wizard_user.user_id.groups_id): if user and (portal in user.groups_id):
# if user belongs to portal only, deactivate it # if user belongs to portal only, deactivate it
if len(wizard_user.user_id.groups_id) <= 1: if len(user.groups_id) <= 1:
wizard_user.user_id.write({'groups_id': [(3, portal.id)], 'active': False}) user.write({'groups_id': [(3, portal.id)], 'active': False})
else: else:
wizard_user.user_id.write({'groups_id': [(3, portal.id)]}) user.write({'groups_id': [(3, portal.id)]})
def _create_user(self, cr, uid, ids, context=None): def _create_user(self, cr, uid, ids, context=None):
""" create a new user for wizard_user.partner_id """ create a new user for wizard_user.partner_id
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment