[FIX] website: safely access menu recordset

Introduced with 7fb016f9966b
[0] access could crash, recordset could be empty after `filtered`.

Step to reproduce:
  - Add admin group to website top level menu (Website > Debug > Menu)
  - Try to access frontend as non admin

opw-2573763
task-2574346

closes odoo/odoo#72535

X-original-commit: 759d920d799d332220d86467d83aeb9334b61ce2
Signed-off-by: Romain Derie <rdeodoo@users.noreply.github.com>
This commit is contained in:
Romain Derie
2021-06-22 12:45:31 +00:00
parent 75887ed16a
commit 2bce982731
+4 -1
View File
@@ -159,9 +159,12 @@ class Website(models.Model):
# don't add child menu if parent is forbidden
if menu.parent_id and menu.parent_id in menus:
menu.parent_id._cache['child_id'] += (menu.id,)
# prefetch every website.page and ir.ui.view at once
menus.mapped('is_visible')
website.menu_id = menus and menus.filtered(lambda m: not m.parent_id)[0].id or False
top_menus = menus.filtered(lambda m: not m.parent_id)
website.menu_id = top_menus and top_menus[0].id or False
# self.env.uid for ir.rule groups on menu
@tools.ormcache('self.env.uid', 'self.id')