Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
443 Zobrazení

I see group_ids in website.menu but seems not work as portal and public user has access to website.menu model already

is there any solution to hide a website menu based on custom group?


Avatar
Zrušit
Nejlepší odpověď

Hi,


You can achieve it by inheriting the _compute_visible method of website.menu model.


Try any methods.

1- You can use the module,

      * https://apps.odoo.com/apps/modules/17.0/website_menu_restriction


2- By inheriting the website.layout and add the user group.


< template

  id="layout"

  inherit_id="website.layout">

  < xpath expr="//header/t[@t-cache]" position="attributes">

    < attribute name="t-cache" add="website.get_website_user_group_cache_key()"/>

  < /xpath>

< /template>


3- Inherit the website.menu model.


class WebsiteMenu(models.Model):

   _inherit = 'website.menu'



   def _compute_visible(self):

       """Compute menu invisible"""

       super()._compute_visible()

       for menu in self:

           if not menu.is_visible:

               return

           if menu.name == 'Shop' and not self.env.user.user_has_groups(

                   'base.group_user'):

               menu.is_visible = False


Hope it helps

Avatar
Zrušit
Nejlepší odpověď

Go to Website -> Configuration -> Menus, open the menu item in question and set Visible Groups to the groups you want it available for:


Results in 

(not logged in)

(logged in)


Note: This hides the menu item only as asked. /blog is still accessible.

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
5
srp 25
9978
2
čvc 25
1027
4
čvn 25
1173
1
čvn 25
1485
1
kvě 25
1374