콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
582 화면

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?


아바타
취소
베스트 답변

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

아바타
취소
베스트 답변

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.

아바타
취소
관련 게시물 답글 화면 활동
5
8월 25
10066
2
7월 25
1087
4
6월 25
1242
1
6월 25
1570
1
5월 25
1419