Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Hide Dockbar based on role in Liferay 7
Durga prasada Rao Kasina, modified 8 Years ago.
New Member
Posts: 21
Join Date: 7/26/12
Recent Posts
I wanted to hide Dockbar based on role in Liferay 7. when i searched in internet i got the below code but it is in velocity
<#if ( $is_signed_in ) >
<# $rService = $serviceLocator.findService("com.liferay.portal.service.RoleService")>
<# $usrRoles = $rService.getUserRoles( $user_id )>
<# list( $usrRoles as $usrRole )>
<#if ( $usrRole.getName() == "Administrator" || $usrRole.getName() == "Content-Admin" || $usrRole.getName() == "Content-Editor") >
#dockbar()
</#if>
</# list>
</#if>
Can any body pls. let me know the code snippet for freemarker.
<#if ( $is_signed_in ) >
<# $rService = $serviceLocator.findService("com.liferay.portal.service.RoleService")>
<# $usrRoles = $rService.getUserRoles( $user_id )>
<# list( $usrRoles as $usrRole )>
<#if ( $usrRole.getName() == "Administrator" || $usrRole.getName() == "Content-Admin" || $usrRole.getName() == "Content-Editor") >
#dockbar()
</#if>
</# list>
</#if>
Can any body pls. let me know the code snippet for freemarker.
Sure. Each and every customer ask us to remove the dockbar for normal users. I wonder for many years now why there is no permission for that ...
<#if is_signed_in>
<#assign roles = user.getRoles()
showcontrolmenu = false
/>
<#list roles as role>
<#if role.getName() == "Administrator" || role.getName() == "Other Role" >
<#assign showcontrolmenu = true />
<#break>
<!--#if-->
<!--#list-->
<#if showcontrolmenu>
@liferay.control_menu
<!--#if-->
<!--#if-->
Jose Francisco Pertuz Perez, modified 7 Years ago.
New Member
Posts: 11
Join Date: 8/11/14
Recent Posts
Thank you Christoph Rabel
Hi @Christoph, I think it is necessary a more effort. In your proposal you're looking for regular roles only, but this is not enough. I could have to check other types as site or organizational roles. It is not simple to perform this check using a frontend language (freemarker or velocity).
There is another complexity. The "has-control-menu" css class which is injected into body tag. If you remove @liferay.control_menu macro only, you will find a white bar on the top of the side and this is not a desiderable setting. I think we have to walk on two different ways: write a new theme contributor component and add some controls into frontend template.
First step: add my new theme contributor component
Second step: modify template (freemarker in this example)
1) init_custom.ftl, I have added this lines:
1) portal_normal.ftl, I have added showcontrolmenu variable checking:
I am working on LF CE GA 6 (7.0.5).
Enrico
There is another complexity. The "has-control-menu" css class which is injected into body tag. If you remove @liferay.control_menu macro only, you will find a white bar on the top of the side and this is not a desiderable setting. I think we have to walk on two different ways: write a new theme contributor component and add some controls into frontend template.
First step: add my new theme contributor component
@Component(
immediate = true,
property = {"type=" + TemplateContextContributor.TYPE_THEME},
service = TemplateContextContributor.class
)
public class MyProductNavigationControlMenuTemplateContextContributor implements TemplateContextContributor {
private static final String ADMIN_PATTERN_ROLE = "administrator";
private static final Log _log = LogFactoryUtil.getLog(MyProductNavigationControlMenuTemplateContextContributor.class);
@Override
public void prepare(Map<string, object> contextObjects, HttpServletRequest request) {
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
//Check some roles
if ( !themeDisplay.isSignedIn() || hasAdminRegularRole(request) || hasAdminSiteRole(request, themeDisplay) || ...)
{
return;
}
String cssClass = GetterUtil.getString(contextObjects.get("bodyCssClass"));
//Add a new class to set if a user cannot access to control panel menu
contextObjects.put("bodyCssClass", cssClass + " delete-control-menu");
}
[...]
</string,>
Second step: modify template (freemarker in this example)
1) init_custom.ftl, I have added this lines:
[...]
<#if css_class?lower_case?contains("delete-control-menu")>
<#assign
css_class = css_class?replace("has-control-menu", "")
showcontrolmenu = false
/>
<#else>
<#assign showcontrolmenu = true />
<!--#if-->
[...]
1) portal_normal.ftl, I have added showcontrolmenu variable checking:
[...]
<@liferay_ui["quick-access"] contentId="#main-content" />
<@liferay_util["include"] page=body_top_include />
<#if showcontrolmenu>
<@liferay.control_menu/>
<!--#if-->
[...]
I am working on LF CE GA 6 (7.0.5).
Enrico
Hi Enrico!
Can I have the jar?
Hi
I can able to set the permistion for Regular Roles but it's not working for Site Role.
Please help. how to add site roles permistion as well
-------------------------------------------------------------------------------------
<#if is_signed_in>
<#assign roles = user.getRoles()
showcontrolmenu = false />
<#list roles as role>
<#if role.getName() == "Administrator" || role.getName() == "Site Administrator" >
<#assign showcontrolmenu = true />
<#break>
</#if>
</#list>
<#if showcontrolmenu>
<@liferay.control_menu />
</#if>
</#if>
-------------------------------------------------------------------------------------
I can able to set the permistion for Regular Roles but it's not working for Site Role.
Please help. how to add site roles permistion as well
-------------------------------------------------------------------------------------
<#if is_signed_in>
<#assign roles = user.getRoles()
showcontrolmenu = false />
<#list roles as role>
<#if role.getName() == "Administrator" || role.getName() == "Site Administrator" >
<#assign showcontrolmenu = true />
<#break>
</#if>
</#list>
<#if showcontrolmenu>
<@liferay.control_menu />
</#if>
</#if>
-------------------------------------------------------------------------------------
You could use UserGroupRoleLocalServiceUtil:
https://community.liferay.com/de/forums/-/message_boards/message/12032442
https://community.liferay.com/de/forums/-/message_boards/message/12032442
Thank you for reply
Adding to this interesting topic. Wiping out the dockbar for site members and guest users has been a terrible thing for me to have to correct. Our users are never signed out and always need a dockbar regardless of if they are not an admin; however the dockbar contained our branding, access to our help site and a list of applications like a hub for all our organizations other web apps. It's just gone now for 80% of our users which is ridiculous.
So it's not correct that non-admins and other users like site visitors don't need a dockbar. I've had to create my own "fake dockbar" containing all the stuff that was there in 7.0 and do a lot of jiggery pokery that has taken MONTHS to get right. When we make these suggestions in discussions about taking things away from users can we understand that doing so impacts other people please? It should be a configurable option not just taken away from site members like it has been.
The result is that 7.1+ now has a dockbar only for site and portal admins, so we've had our branding and global dockbar links wiped out.
So it's not correct that non-admins and other users like site visitors don't need a dockbar. I've had to create my own "fake dockbar" containing all the stuff that was there in 7.0 and do a lot of jiggery pokery that has taken MONTHS to get right. When we make these suggestions in discussions about taking things away from users can we understand that doing so impacts other people please? It should be a configurable option not just taken away from site members like it has been.
The result is that 7.1+ now has a dockbar only for site and portal admins, so we've had our branding and global dockbar links wiped out.
And what stopped you from giving all users the permission to see the dockbar? Liferay took nothing away here, it just added "You need a permission now to see the dockbar".
Lack of documentation and communication.
On the actual topic of detecting if the user is an admin or member of the site ... this is CRAZY difficult in a theme portal_normal and I've already given up a few times.
Lee Jordan:
Luckily, in the mean time, there's an answer here. (You're aware of that thread, I know. I'm just crossreferencing for people coming along this post later)
On the actual topic of detecting if the user is an admin or member of the site ... this is CRAZY difficult in a theme portal_normal and I've already given up a few times.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™