[IMP] base: only recompute share field on users when users are added/removed from group "Employee"

Note: The change in `base_security.xml` is needed as xmlid must exists
when adding/removing users from group to determine the value of `share`
field.

Also add a test to reassure @odony the function fields are correctly
recomputed for removed m2m entries (see http://git.io/vCqAG for context)
This commit is contained in:
Christophe Simonis
2015-10-09 16:57:18 +02:00
parent 5bb9be5522
commit 80bb106463
3 changed files with 25 additions and 3 deletions
+8 -2
View File
@@ -162,6 +162,12 @@ class res_users(osv.osv):
res[user.id] = not self.has_group(cr, user.id, 'base.group_user')
return res
def _store_trigger_share_res_groups(self, cr, uid, ids, context=None):
group_user = self.pool['ir.model.data'].xmlid_to_object(cr, SUPERUSER_ID, 'base.group_user', context=context)
if group_user and group_user.id in ids:
return group_user.users.ids
return []
def _get_users_from_group(self, cr, uid, ids, context=None):
result = set()
groups = self.pool['res.groups'].browse(cr, uid, ids, context=context)
@@ -197,8 +203,8 @@ class res_users(osv.osv):
'company_ids':fields.many2many('res.company','res_company_users_rel','user_id','cid','Companies'),
'share': fields.function(_is_share, string='Share User', type='boolean',
store={
'res.users': (lambda self, cr, uid, ids, c={}: ids, None, 50),
'res.groups': (_get_users_from_group, None, 50),
'res.users': (lambda self, cr, uid, ids, c={}: ids, ['groups_id'], 50),
'res.groups': (_store_trigger_share_res_groups, ['users'], 50),
}, help="External user with limited access, created only for the purpose of sharing data."),
}
@@ -23,7 +23,6 @@
<record model="res.groups" id="group_user">
<field name="name">Employee</field>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
<record model="res.groups" id="group_light_multi_company">
@@ -44,6 +43,7 @@
</record>
<record model="res.groups" id="group_user">
<field name="implied_ids" eval="[(4, ref('group_no_one'))]"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
<record id="group_sale_salesman" model="res.groups">
+16
View File
@@ -166,6 +166,22 @@ class TestORM(common.TransactionCase):
['date'], ['date:month', 'date:day'], lazy=False)
self.assertEqual(len(rg), len(all_partners))
def test_m2m_store_trigger(self):
group_user = self.env.ref('base.group_user')
user = self.env['res.users'].create({
'name': 'test',
'login': 'test_m2m_store_trigger',
'groups_id': [(6, 0, [])],
})
self.assertTrue(user.share)
group_user.write({'users': [(4, user.id)]})
self.assertFalse(user.share)
group_user.write({'users': [(3, user.id)]})
self.assertTrue(user.share)
class TestInherits(common.TransactionCase):
""" test the behavior of the orm for models that use _inherits;