[FIX] website_slides: auto-enroll correctly when editing user

When a user is modified to grant access to new groups, user is
auto-enrolled to all slide courses that have a auto-enroll policy for
any of the new groups.

However, that auto-enrolling process was not working correctly due to
how values to be written to the user are coming. In order to know what
are the actual new groups, values need to be pre-processed, which was
not being done.

This commit fixes the above issue by pre-processing written values
before extracting new groups.

closes odoo/odoo#153634

X-original-commit: e27be4a81c304c2d749b4417d2184cfed07eddf3
Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
This commit is contained in:
Luis González
2024-02-13 10:08:00 +00:00
parent 673f064cba
commit 6b86fe1fdb
+4 -3
View File
@@ -20,9 +20,10 @@ class Users(models.Model):
def write(self, vals):
""" Trigger automatic subscription based on updated user groups """
res = super(Users, self).write(vals)
if vals.get('groups_id'):
added_group_ids = [command[1] for command in vals['groups_id'] if command[0] == 4]
added_group_ids += [id for command in vals['groups_id'] if command[0] == 6 for id in command[2]]
sanitized_vals = self._remove_reified_groups(vals)
if sanitized_vals.get('groups_id'):
added_group_ids = [command[1] for command in sanitized_vals['groups_id'] if command[0] == 4]
added_group_ids += [id for command in sanitized_vals['groups_id'] if command[0] == 6 for id in command[2]]
self.env['slide.channel'].sudo().search([('enroll_group_ids', 'in', added_group_ids)])._action_add_members(self.mapped('partner_id'))
return res