[MERGE] forward port of branch saas-6 up to d613843

This commit is contained in:
Christophe Simonis
2016-02-02 18:37:34 +01:00
3 changed files with 65 additions and 1 deletions
+15 -1
View File
@@ -13,6 +13,7 @@ from openerp import api
from openerp import SUPERUSER_ID, models
from openerp import tools
import openerp.exceptions
from openerp import api
from openerp.osv import fields, osv, expression
from openerp.service.db import check_super
from openerp.tools.translate import _
@@ -537,8 +538,19 @@ class res_users(osv.osv):
'target': 'new',
}
@tools.ormcache('uid', 'group_ext_id')
@api.v7
def has_group(self, cr, uid, group_ext_id):
return self._has_group(cr, uid, group_ext_id)
@api.v8
def has_group(self, group_ext_id):
# use singleton's id if called on a non-empty recordset, otherwise
# context uid
uid = self.id or self.env.uid
return self._has_group(self.env.cr, uid, group_ext_id)
@api.noguess
@tools.ormcache('uid', 'group_ext_id')
def _has_group(self, cr, uid, group_ext_id):
"""Checks whether user belongs to given group.
:param str group_ext_id: external ID (XML ID) of the group.
@@ -553,6 +565,8 @@ class res_users(osv.osv):
(SELECT res_id FROM ir_model_data WHERE module=%s AND name=%s)""",
(uid, module, ext_id))
return bool(cr.fetchone())
# for a few places explicitly clearing the has_group cache
has_group.clear_cache = _has_group.clear_cache
@api.multi
def _is_admin(self):
+1
View File
@@ -22,6 +22,7 @@ import test_res_lang
import test_search
import test_translate
#import test_uninstall
import test_user_has_group
import test_view_validation
import test_views
import test_xmlrpc
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
import openerp.tests
class TestHasGroup(openerp.tests.TransactionCase):
def setUp(self):
super(TestHasGroup, self).setUp()
group0 = self.env['ir.model.data']._update(
'res.groups', 'test_user_has_group',
{'name': 'group0'},
xml_id='group0'
)
self.group0 = 'test_user_has_group.group0'
self.env['ir.model.data']._update(
'res.groups', 'test_user_has_group',
{'name': 'group1'},
xml_id='group1'
)
self.group1 = 'test_user_has_group.group1'
self.test_user = self.env['res.users'].create({
'login': 'testuser',
'partner_id': self.env['res.partner'].create({
'name': "Strawman Test User"
}).id,
'groups_id': [(4, group0, 0)]
})
def test_old_api(self):
Users = self.registry['res.users']
self.assertTrue(
Users.has_group(self.cr, self.test_user.id, self.group0),
"the test user should belong to group0"
)
self.assertFalse(
Users.has_group(self.cr, self.test_user.id, self.group1),
"the test user should *not* belong to group1"
)
def test_new_api(self):
self.assertTrue(
self.test_user.has_group(self.group0),
"the test user should belong to group0",
)
self.assertFalse(
self.test_user.has_group(self.group1),
"the test user shoudl not belong to group1"
)