bug with field with widget=selection + groups if user has no access right

bzr revid: hda@tinyerp.com-20100429140313-cnizdvh7m48m5cme
This commit is contained in:
HDA (OpenERP) 2010-04-29 19:33:13 +05:30
parent 39388d4b22
commit 7b6827a6b4
1 changed files with 39 additions and 28 deletions

View File

@ -1138,7 +1138,17 @@ class orm_template(object):
if isinstance(s, unicode):
return s.encode('utf8')
return s
def check_group(node):
if node.get('groups'):
groups = node.get('groups').split(',')
readonly = False
access_pool = self.pool.get('ir.model.access')
for group in groups:
readonly = readonly or access_pool.check_groups(cr, user, group)
if not readonly:
node.set('invisible', '1')
del(node.attrib['groups'])
if node.tag in ('field', 'node', 'arrow'):
if node.get('object'):
attrs = {}
@ -1185,15 +1195,20 @@ class orm_template(object):
}
attrs = {'views': views}
if node.get('widget') and node.get('widget') == 'selection':
if 'groups' in node.attrib:
check_group(node)
if node.get('invisible'):
attrs['selection'] = []
# We can not use the 'string' domain has it is defined according to the record !
dom = []
if column._domain and not isinstance(column._domain, (str, unicode)):
dom = column._domain
dom += eval(node.get('domain','[]'), {'uid':user, 'time':time})
context.update(eval(node.get('context','{}')))
attrs['selection'] = self.pool.get(relation).name_search(cr, user, '', dom, context=context,limit=None)
if (node.get('required') and not int(node.get('required'))) or not column.required:
attrs['selection'].append((False,''))
else:
dom = []
if column._domain and not isinstance(column._domain, (str, unicode)):
dom = column._domain
dom += eval(node.get('domain','[]'), {'uid':user, 'time':time})
context.update(eval(node.get('context','{}')))
attrs['selection'] = self.pool.get(relation)._name_search(cr, user, '', dom, context=context,limit=None,name_get_uid=1)
if (node.get('required') and not int(node.get('required'))) or not column.required:
attrs['selection'].append((False,''))
fields[node.get('name')] = attrs
elif node.tag in ('form', 'tree'):
@ -1207,15 +1222,7 @@ class orm_template(object):
fields[node.get(additional_field)] = {}
if 'groups' in node.attrib:
if node.get('groups'):
groups = node.get('groups').split(',')
readonly = False
access_pool = self.pool.get('ir.model.access')
for group in groups:
readonly = readonly or access_pool.check_groups(cr, user, group)
if not readonly:
node.set('invisible', '1')
del(node.attrib['groups'])
check_group(node)
# translate view
if ('lang' in context) and not result:
@ -3649,6 +3656,18 @@ class orm(orm_template):
return [(r['id'], tools.ustr(r[self._rec_name])) for r in self.read(cr, user, ids,
[self._rec_name], context, load='_classic_write')]
def _name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100, name_get_uid=None):
if not args:
args = []
if not context:
context = {}
args = args[:]
if name:
args += [(self._rec_name, operator, name)]
ids = self.search(cr, user, args, limit=limit, context=context)
res = self.name_get(cr, name_get_uid, ids, context)
return res
def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100):
"""
@ -3664,17 +3683,9 @@ class orm(orm_template):
This method is equivalent of search() on name + name_get()
"""
if not args:
args = []
if not context:
context = {}
args = args[:]
if name:
args += [(self._rec_name, operator, name)]
ids = self.search(cr, user, args, limit=limit, context=context)
res = self.name_get(cr, user, ids, context)
return res
return self._name_search(cr, user, name, args, operator, context, limit, user)
def copy_data(self, cr, uid, id, default=None, context=None):
"""
Copy given record's data with all its fields values