IR_MODEL, ORM : A model without write access will appear as readonly for the client.\nir_model.check is modified to not raise exception if asked to.

bzr revid: bch-3a158ff8d5710cfcbd610b966d078396e2df65fd
This commit is contained in:
bch 2007-06-01 10:57:34 +00:00
parent e49c51f93c
commit b8286b0e3d
2 changed files with 8 additions and 2 deletions

View File

@ -86,7 +86,7 @@ class ir_model_access(osv.osv):
'perm_create': fields.boolean('Create Access'),
'perm_unlink': fields.boolean('Delete Permission'),
}
def check(self, cr, uid, model_name, mode='read'):
def check(self, cr, uid, model_name, mode='read',raise_exception=True):
assert mode in ['read','write','create','unlink'], 'Invalid access mode for security'
if uid==1:
return True
@ -98,7 +98,10 @@ class ir_model_access(osv.osv):
if r[0][0] == None : return True
if not r[0][0]:
raise osv.except_osv('Access denied !', 'You can not %s this resource !' % mode)
if raise_exception:
raise osv.except_osv('Access denied !', 'You can not %s this resource !' % mode)
else:
return False
return True
check = tools.cache()(check)

View File

@ -1059,11 +1059,14 @@ class orm(object):
res = {}
for parent in self._inherits:
res.update(self.pool.get(parent).fields_get(cr, user, fields, context))
read_access= self.pool.get('ir.model.access').check(cr, user, self._name,'write',raise_exception=False)
for f in self._columns.keys():
res[f] = {'type': self._columns[f]._type}
for arg in ('string','readonly','states','size','required','change_default','translate', 'help', 'select'):
if getattr(self._columns[f], arg):
res[f][arg] = getattr(self._columns[f], arg)
if not read_access:
res[f]['readonly']= True
for arg in ('digits', 'invisible'):
if hasattr(self._columns[f], arg) and getattr(self._columns[f], arg):
res[f][arg] = getattr(self._columns[f], arg)