From cfd002e3043fb9824b6aa4602b7bc4657cf2a125 Mon Sep 17 00:00:00 2001 From: Adrien Dieudonne <adr@odoo.com> Date: Thu, 1 Sep 2016 20:18:27 +0200 Subject: [PATCH] [IMP] base: Extract check_group function into a method Possibility to inherit _check_group to have groups in attribute In studio, we need to avoid to delete groups node --- odoo/addons/base/ir/ir_ui_view.py | 58 ++++++++++++++++--------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/odoo/addons/base/ir/ir_ui_view.py b/odoo/addons/base/ir/ir_ui_view.py index f907409bff1f..67c755581d32 100644 --- a/odoo/addons/base/ir/ir_ui_view.py +++ b/odoo/addons/base/ir/ir_ui_view.py @@ -646,6 +646,35 @@ actual arch. return dict(view_data, arch=etree.tostring(arch, encoding='utf-8')) + def _apply_group(self, model, node, modifiers, fields): + """Apply group restrictions, may be set at view level or model level:: + * at view level this means the element should be made invisible to + people who are not members + * at model level (exclusively for fields, obviously), this means + the field should be completely removed from the view, as it is + completely unavailable for non-members + + :return: True if field should be included in the result of fields_view_get + """ + Model = self.env[model] + + if node.tag == 'field' and node.get('name') in Model._fields: + field = Model._fields[node.get('name')] + if field.groups and not self.user_has_groups(groups=field.groups): + node.getparent().remove(node) + fields.pop(node.get('name'), None) + # no point processing view-level ``groups`` anymore, return + return False + if node.get('groups'): + can_see = self.user_has_groups(groups=node.get('groups')) + if not can_see: + node.set('invisible', '1') + modifiers['invisible'] = True + if 'attrs' in node.attrib: + del node.attrib['attrs'] # avoid making field visible later + del node.attrib['groups'] + return True + #------------------------------------------------------ # Postprocessing: translation, groups and modifiers #------------------------------------------------------ @@ -673,33 +702,6 @@ actual arch. self.raise_view_error(_('Model not found: %(model)s') % dict(model=model), view_id) Model = self.env[model] - def check_group(node): - """Apply group restrictions, may be set at view level or model level:: - * at view level this means the element should be made invisible to - people who are not members - * at model level (exclusively for fields, obviously), this means - the field should be completely removed from the view, as it is - completely unavailable for non-members - - :return: True if field should be included in the result of fields_view_get - """ - if node.tag == 'field' and node.get('name') in Model._fields: - field = Model._fields[node.get('name')] - if field.groups and not self.user_has_groups(groups=field.groups): - node.getparent().remove(node) - fields.pop(node.get('name'), None) - # no point processing view-level ``groups`` anymore, return - return False - if node.get('groups'): - can_see = self.user_has_groups(groups=node.get('groups')) - if not can_see: - node.set('invisible', '1') - modifiers['invisible'] = True - if 'attrs' in node.attrib: - del node.attrib['attrs'] # avoid making field visible later - del node.attrib['groups'] - return True - if node.tag in ('field', 'node', 'arrow'): if node.get('object'): attrs = {} @@ -748,7 +750,7 @@ actual arch. if node.get(additional_field): fields[node.get(additional_field)] = {} - if not check_group(node): + if not self._apply_group(model, node, modifiers, fields): # node must be removed, no need to proceed further with its children return fields -- GitLab