Skip to content

Commit

Permalink
[IMP] ir_ui_view: Log warning on incorrect 'groups' attribute
Browse files Browse the repository at this point in the history
Purpose
=======

They are a lot of places where we set an attribute 'groups' on a view element and:

- The group doesn't exist anymore
- The group xmlid is not correct
- The group xmlid exists but the modularity is not respected (example: group_stock_user
  used in a view in the 'product' module).

Where it happens, nothing warns the user or the developer. The element is just never
rendered.

Specification
=============

In the method _check_xml, log a warning if a 'groups' attribute is set and if
a group doesn't not exist at that moment.
  • Loading branch information
tivisse committed Oct 2, 2018
1 parent eaba05b commit b2b9545
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions odoo/addons/base/models/ir_ui_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ def _valid_inheritance(self, arch):
self.raise_view_error(message, self.id)
return True

def _check_groups_validity(self, view, view_name):
for node in view.xpath('//*[@groups]'):
for group in node.get('groups').replace('!', '').split(','):
if not self.env.ref(group.strip(), raise_if_not_found=False):
_logger.warning("The group %s defined in view %s does not exist!", group, view_name)

@api.constrains('arch_db')
def _check_xml(self):
# Sanity checks: the view should not break anything upon rendering!
Expand All @@ -332,6 +338,7 @@ def _check_xml(self):
view_arch_utf8 = view_def['arch']
if view.type != 'qweb':
view_doc = etree.fromstring(view_arch_utf8)
self._check_groups_validity(view_doc, view.name)
# verify that all fields used are valid, etc.
self.postprocess_and_fields(view.model, view_doc, view.id)
# RNG-based validation is not possible anymore with 7.0 forms
Expand Down

0 comments on commit b2b9545

Please sign in to comment.