示例#1
0
 def write(self, vals):
     for key in vals:
         if is_boolean_group(key) or is_selection_groups(key):
             self.env['ir.config_parameter'].sudo().set_param(
                 IR_CONFIG_NAME, '0')
             break
     return super(ResUsers, self).write(vals)
示例#2
0
 def write(self, vals):
     write_res = super(Users, self).write(vals)
     sel_groups = [vals[k] for k in vals if is_selection_groups(k) and vals[k]]
     if vals.get('groups_id'):
         # form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]}
         user_group_ids = [command[1] for command in vals['groups_id'] if command[0] == 4]
         user_group_ids += [id for command in vals['groups_id'] if command[0] == 6 for id in command[2]]
         self.env['mail.channel'].search([('group_ids', 'in', user_group_ids)])._subscribe_users()
     elif sel_groups:
         self.env['mail.channel'].search([('group_ids', 'in', sel_groups)])._subscribe_users()
     return write_res
示例#3
0
    def write(self, vals):
        log_portal_access = 'groups_id' in vals and not self._context.get(
            'mail_create_nolog') and not self._context.get('mail_notrack')
        user_portal_access_dict = {
            user.id: user.has_group('base.group_portal')
            for user in self
        } if log_portal_access else {}

        write_res = super(Users, self).write(vals)

        # log a portal status change (manual tracking)
        if log_portal_access:
            for user in self:
                user_has_group = user.has_group('base.group_portal')
                portal_access_changed = user_has_group != user_portal_access_dict[
                    user.id]
                if portal_access_changed:
                    body = user._get_portal_access_update_body(user_has_group)
                    user.partner_id.message_post(body=body,
                                                 message_type='notification',
                                                 subtype_xmlid='mail.mt_note')

        if 'active' in vals and not vals['active']:
            self._unsubscribe_from_non_public_channels()
        sel_groups = [
            vals[k] for k in vals if is_selection_groups(k) and vals[k]
        ]
        if vals.get('groups_id'):
            # form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]}
            user_group_ids = [
                command[1] for command in vals['groups_id'] if command[0] == 4
            ]
            user_group_ids += [
                id for command in vals['groups_id'] if command[0] == 6
                for id in command[2]
            ]
            self.env['mail.channel'].search([
                ('group_ids', 'in', user_group_ids)
            ])._subscribe_users_automatically()
        elif sel_groups:
            self.env['mail.channel'].search([
                ('group_ids', 'in', sel_groups)
            ])._subscribe_users_automatically()
        return write_res
示例#4
0
    def test_selection_groups(self):
        # create 3 groups that should be in a selection
        app = self.env['ir.module.category'].create({'name': 'Foo'})
        group1, group2, group0 = self.env['res.groups'].create([{
            'name':
            name,
            'category_id':
            app.id
        } for name in ('User', 'Manager', 'Visitor')])
        # THIS PART IS NECESSARY TO REPRODUCE AN ISSUE: group1.id < group2.id < group0.id
        self.assertLess(group1.id, group2.id)
        self.assertLess(group2.id, group0.id)
        # implication order is group0 < group1 < group2
        group2.implied_ids = group1
        group1.implied_ids = group0
        groups = group0 + group1 + group2

        # determine the name of the field corresponding to groups
        fname = next(name for name in self.env['res.users'].fields_get()
                     if is_selection_groups(name)
                     and group0.id in get_selection_groups(name))
        self.assertCountEqual(get_selection_groups(fname), groups.ids)

        # create a user
        user = self.env['res.users'].create({'name': 'foo', 'login': '******'})

        # put user in group0, and check field value
        user.write({fname: group0.id})
        self.assertEqual(user.groups_id & groups, group0)
        self.assertEqual(user.read([fname])[0][fname], group0.id)

        # put user in group1, and check field value
        user.write({fname: group1.id})
        self.assertEqual(user.groups_id & groups, group0 + group1)
        self.assertEqual(user.read([fname])[0][fname], group1.id)

        # put user in group2, and check field value
        user.write({fname: group2.id})
        self.assertEqual(user.groups_id & groups, groups)
        self.assertEqual(user.read([fname])[0][fname], group2.id)