4

I am working with Liferay 7 GA 4. At the left side there is the Liefray menu (Control Panel, Users etc...)

I'd like to remove this menu for the normal user and keep it visible only for the admin.

Any one can help me find how can I do this?

Thanks a lot in advance

Judy1989
  • 327
  • 1
  • 6
  • 18

1 Answers1

5

You need to wrap this code in portal_normal.ftl in your theme.

<@liferay.control_menu />

You can create a theme context contributor to add a value into the model that will determine if the user should or should not get the menu.

the code could be something like this

    Boolean isAdmin = false;
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    try {
        Group group = themeDisplay.getScopeGroup();
        PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
        if (themeDisplay.isSignedIn() && groupPermission.contains(permissionChecker, group,
                ActionKeys.VIEW_SITE_ADMINISTRATION)) {
            isAdmin = true;

        }
    } catch (PortalException e) {
        LOG.warn(e);
    }
    contextObjects.put("is_site_admin", isAdmin);

The key is to use the permission checker.

Miroslav Ligas
  • 1,287
  • 8
  • 22
  • 1
    ...and provide the "Log Out" link somewhere on the page, because that will be gone as well (it's part of the User Personal Bar, which you'd like to disappear) – Olaf Kock Aug 06 '17 at 08:59
  • thank you very much. I will try this solution. I have an other one question; I need to put "My Account" link outside of this menu (which is going to be removed for the normal user) and put it for example at the top right of the page (right next to logout/user-name etc.) Thank you very much in advance. – Judy1989 Aug 08 '17 at 09:13
  • Do you want the whole 'My account' sub menu? – Miroslav Ligas Aug 08 '17 at 09:17
  • look at this will render the whole thing. If the user does not have permissions to other section it should do the right thing. you may need to hide something with the css. alternatively look at the implementation if you can cut out smaller code bits. – Miroslav Ligas Aug 09 '17 at 15:19
  • I used themeDisplay.getURLMyAccount(). It works! When it comes to PermissionChecker: the following is not recognised . And I could not really understand the concept. I had a look on the different methodes of PermissionChecker; I need a ressource, a group etc... I do not know how to get the ressource id of control panel for example, and how to get the roles or the group of user the visitor belongs to etc... – Judy1989 Aug 10 '17 at 07:59
  • 1
    I found the solution: isAdmin = themeDisplay.isSignedIn() && permissionChecker.isOmniAdmin(). Thank you very much. My problem is solved now! – Judy1989 Aug 11 '17 at 09:05
  • The only thing left now is that when the menu is hidden (for the normal user) there would be still space left fot the menu even if the menu is not displayed. I see in scss this line _padding-left: $product-menu-width;_ but I could not find this variable to change it. It has to be removed for the normal user or at least I should add a condition (I would need to read the _isAdmin_ variable somwhow from the java code) – Judy1989 Aug 11 '17 at 11:30
  • there is a class on the *body* tag that controls the padding. remove the open and control panel and it should fix the problem. The : isAdmin = themeDisplay.isSignedIn() && permissionChecker.isOmniAdmin() appraoch is OK if you don't need to deal with lower level admins. – Miroslav Ligas Sep 19 '17 at 13:34
  • I had a bug with variable groupPermission, but I fixed it with GroupPermissionUtil – horelvis Jan 18 '19 at 12:35