Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
385 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
5
aug. 25
9963
2
jul. 25
1023
4
jun. 25
1158
1
jun. 25
1467
1
mei 25
1373