Hiding/Showing the Control Panel Menu for Specific Users without a custom theme

For so many years we have been using a reverse logic in our theme by hidding the Control Panel Menu from specific Users... something that generated a lot of doubts, even from the most expert Liferay Portal Developers:

- Is possible to do it by Roles and Permissions?

Some thoughts like these come out:

- It should be, since Liferay has a really great granularity system for Roles and Permissions, and we try to review all permissions and roles, removing most of them... and finally we ended up finding that once you give any simple permissions like "the role User can update a Document and Media" the user will be able to see the black header, plus some links agreed on the permissions.

So the majority of us, have been doing basically the same or something similar all this years; we've been applying reverse logic, allowing only specific users to see or not see the Control Panel Menu... some workaround like the code below (or applying the similar logic in a TemplateContextContributor OSGI component) : 

<#if is_signed_in>
  <#assign roles = user.getRoles()
           showcontrolmenu = false />
<#list roles as role>
   <#if role.getName() == "Administrator" || role.getName() == "Marketing" >
       <#assign showcontrolmenu = true />
    <#break>
   </#if>
</#list>

<#if showcontrolmenu>
  <@liferay.control_menu />
</#if>

</#if>

But nowadays we are developing in a new way and we should avoid building themes or any OSGI customisation, if you would like to take advantages of getting all new features updating/upgrading your Liferay Portal version constantly without a big efforts.

Liferay bets and recommends a Portal built using Fragments and/or Client Extensions, is a way much less invasive to the platform and a good solution to avoid breaking changes during the platform updates.

Long story short... thinking about this we have come up with an OOTB solution (which will be available in Liferay Portal 7.4 GA88+):

*** A Configuration to control which users can see the Control Menu by Site Settings ***

You will be able to configure the Control Menu accessing:

  • Site Setting -> Site Settings -> Site Configuration.

  • Activate the "Show Control Menu by Role" option.
  • Select all roles that show be displayed the Control Menu and save it.

{should look like the image below}

Activating this option and selecting the Roles that can see the Control Menu will overwrite the default Roles, it is a much easier way to control hiding or showing to specific users by Site Themeless.