Add create/delete field access
review398002
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Add create/delete field access
|
||||
* Add dynamic size limit on the One2Many, Many2Many and Char
|
||||
* Replace __tryton__.py by tryton.cfg
|
||||
* Allow to use Reference field in One2Many & Many2Many
|
||||
|
||||
+11
-2
@@ -391,6 +391,8 @@ class ModelFieldAccess(ModelSQL, ModelView):
|
||||
group = fields.Many2One('res.group', 'Group', ondelete='CASCADE')
|
||||
perm_read = fields.Boolean('Read Access')
|
||||
perm_write = fields.Boolean('Write Access')
|
||||
perm_create = fields.Boolean('Create Access')
|
||||
perm_delete = fields.Boolean('Delete Access')
|
||||
description = fields.Text('Description')
|
||||
|
||||
def __init__(self):
|
||||
@@ -413,6 +415,12 @@ class ModelFieldAccess(ModelSQL, ModelView):
|
||||
def default_perm_write(self):
|
||||
return False
|
||||
|
||||
def default_perm_create(self):
|
||||
return True
|
||||
|
||||
def default_perm_delete(self):
|
||||
return True
|
||||
|
||||
@Cache('ir_model_field_access.check')
|
||||
def check(self, model_name, fields, mode='read', raise_exception=True,
|
||||
access=False):
|
||||
@@ -421,13 +429,14 @@ class ModelFieldAccess(ModelSQL, ModelView):
|
||||
|
||||
:param model_name: the model name
|
||||
:param fields: a list of fields
|
||||
:param mode: 'read' or 'write'
|
||||
:param mode: 'read', 'write', 'create' or 'delete'
|
||||
:param raise_exception: raise an exception if the test failed
|
||||
:param access: return a dictionary with access right instead of boolean
|
||||
|
||||
:return: a boolean
|
||||
'''
|
||||
assert mode in ('read', 'write'), 'Invalid access mode'
|
||||
assert mode in ('read', 'write', 'create', 'delete'), \
|
||||
'Invalid access mode'
|
||||
if Transaction().user == 0:
|
||||
if access:
|
||||
return dict((x, True) for x in fields)
|
||||
|
||||
@@ -181,6 +181,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<tree string="Field Access">
|
||||
<field name="perm_read"/>
|
||||
<field name="perm_write"/>
|
||||
<field name="perm_create"/>
|
||||
<field name="perm_delete"/>
|
||||
<field name="field"/>
|
||||
<field name="group"/>
|
||||
</tree>
|
||||
@@ -203,6 +205,10 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="perm_read"/>
|
||||
<label name="perm_write"/>
|
||||
<field name="perm_write"/>
|
||||
<label name="perm_create"/>
|
||||
<field name="perm_create"/>
|
||||
<label name="perm_delete"/>
|
||||
<field name="perm_delete"/>
|
||||
<separator name="description" colspan="4"/>
|
||||
<field name="description" colspan="4"/>
|
||||
</form>
|
||||
|
||||
@@ -450,6 +450,10 @@ class Model(WarningErrorMixin, URLMixin):
|
||||
|
||||
fwrite_accesses = field_access_obj.check(self._name, fields_names or
|
||||
self._columns.keys(), 'write', access=True)
|
||||
fcreate_accesses = field_access_obj.check(self._name, fields_names or
|
||||
self._columns.keys(), 'create', access=True)
|
||||
fdelete_accesses = field_access_obj.check(self._name, fields_names or
|
||||
self._columns.keys(), 'delete', access=True)
|
||||
for field in (x for x in self._columns.keys()
|
||||
if ((not fields_names) or x in fields_names)):
|
||||
res[field] = {
|
||||
@@ -547,6 +551,8 @@ class Model(WarningErrorMixin, URLMixin):
|
||||
res[field]['relation'] = relation
|
||||
res[field]['domain'] = copy.copy(self._columns[field].domain)
|
||||
res[field]['context'] = copy.copy(self._columns[field].context)
|
||||
res[field]['create'] = fcreate_accesses.get(field, True)
|
||||
res[field]['delete'] = fdelete_accesses.get(field, True)
|
||||
if res[field]['type'] == 'one2many' \
|
||||
and hasattr(self._columns[field], 'field'):
|
||||
res[field]['relation_field'] = copy.copy(
|
||||
|
||||
Reference in New Issue
Block a user