[FIX] website: hide menu if related to an unpublished page
Before this commit, if there was a menu entry linked to an unpublished website.page, the menu would be shown. For restricted users, they would land on a 403 forbidden. Now, we dont show website.page's menu if user can't access it. This closes #21328
This commit is contained in:
@@ -807,6 +807,14 @@ class Menu(models.Model):
|
||||
child_id = fields.One2many('website.menu', 'parent_id', string='Child Menus')
|
||||
parent_left = fields.Integer('Parent Left', index=True)
|
||||
parent_right = fields.Integer('Parent Rigth', index=True)
|
||||
is_visible = fields.Boolean(compute='_compute_visible', string='Is Visible')
|
||||
|
||||
@api.one
|
||||
def _compute_visible(self):
|
||||
visible = True
|
||||
if self.page_id and not self.page_id.sudo().is_visible and not self.user_has_groups('base.group_user'):
|
||||
visible = False
|
||||
self.is_visible = visible
|
||||
|
||||
@api.model
|
||||
def clean_url(self):
|
||||
|
||||
@@ -67,14 +67,14 @@
|
||||
|
||||
<!-- Layout -->
|
||||
<template id="submenu" name="Submenu">
|
||||
<li t-if="not submenu.child_id" t-att-class="
|
||||
<li t-if="submenu.is_visible and not submenu.child_id.filtered(lambda menu: menu.is_visible)" t-att-class="
|
||||
'active' if submenu.clean_url() and unslug_url(request.httprequest.path) == unslug_url(submenu.clean_url()) else None
|
||||
">
|
||||
<a t-att-href="submenu.clean_url()" t-ignore="true" t-att-target="'_blank' if submenu.new_window else None">
|
||||
<span t-field="submenu.name"/>
|
||||
</a>
|
||||
</li>
|
||||
<li t-if="submenu.child_id" t-attf-class="dropdown #{
|
||||
<li t-if="submenu.is_visible and submenu.child_id.filtered(lambda menu: menu.is_visible)" t-attf-class="dropdown #{
|
||||
(submenu.clean_url() and submenu.clean_url() != '/' and any([request.httprequest.path == child.url for child in submenu.child_id if child.url]) or
|
||||
(submenu.clean_url() and request.httprequest.path == submenu.clean_url())) and 'active'
|
||||
}">
|
||||
|
||||
Reference in New Issue
Block a user