Foren

How to configure "Dockbar" based on "Roles"?

Rupesh Chotai, geändert vor 12 Jahren.

How to configure "Dockbar" based on "Roles"?

Regular Member Beiträge: 163 Beitrittsdatum: 23.03.11 Neueste Beiträge
Hi,
I am using liferay6x Jboss bundle.
My requirement is to confiure dockbar based on roles.
For eg:
1. Admin has full access to all options of dockbar.
2. Dept Head of the compnay can create user, modify but cant delete. Also can update content.
3. Employee of the company can update the content of the page. No addition of users, deletion etc
4. Guest can ONLY see pages. So no dockbar is displayed. I have done this in portal_normal.vm in my theme as shown below :


#if ($permissionChecker.isOmniadmin())
#dockbar()
#end

But then, other roles i.e. Employee/Dept Head also cant see the dockbar. How to configure dockbar based on roles?

Thank you for the reply in advance.
thumbnail
Corné Aussems, geändert vor 12 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Liferay Legend Beiträge: 1313 Beitrittsdatum: 03.10.06 Neueste Beiträge
RolePermissionUtil is being exposed through this variable
$rolePermission
Rupesh Chotai, geändert vor 12 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Regular Member Beiträge: 163 Beitrittsdatum: 23.03.11 Neueste Beiträge
Hi Corne,
Can you please elaborate more on this?
We are looking for how to use this variable and where to configure it? what are possible values it can contains? etc.

Thanks for your co-operation in this matter.
thumbnail
Corné Aussems, geändert vor 12 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Liferay Legend Beiträge: 1313 Beitrittsdatum: 03.10.06 Neueste Beiträge
I was setting you on the wrong foot;

You can configure the permissions within the control panel;

Choose your desired role and from action choose permissions


[url=http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Using+Liferay's+Permission+System+from+a+portlet]http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Using+Liferay's+Permission+System+from+a+portlet

http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Permissioning+Explained
Rupesh Chotai, geändert vor 12 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Regular Member Beiträge: 163 Beitrittsdatum: 23.03.11 Neueste Beiträge
Hi Corne,
Thanks for the reply. However, setting permission in the control panel will make dockbar visible to all of the logged-in customer. As I mentioned my requirement is to show dockbar for 3-4 roles and hide the dock bar for guest/general customer.

Can you please suggest how to achieve this in Liferay 6?
Rupesh Chotai, geändert vor 12 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Regular Member Beiträge: 163 Beitrittsdatum: 23.03.11 Neueste Beiträge
Hi All,
Problem is solved.
In the portal_normal.vm file of the new theme, I have added the condition as below:


#if ( $is_signed_in )     
    #set ($rService = $serviceLocator.findService("com.liferay.portal.service.RoleService"))
    #set ($usrRoles = $rService.getUserRoles( $user_id )) 
    #foreach( $usrRole in $usrRoles )
       #if ( $usrRole.getName() == "Administrator" || $usrRole.getName() == "Content-Admin" || $usrRole.getName() == "Content-Editor")
          #dockbar()
       #end
    #end
#end


So this will check if logged in user is Admin or Content Editor or Content Admin, then show dockbar, for rest of the user, hide the dock bar.

Cheers.
thumbnail
Corné Aussems, geändert vor 12 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Liferay Legend Beiträge: 1313 Beitrittsdatum: 03.10.06 Neueste Beiträge
I hope one of your users has not all roles because then he would see 3 dockbars ;)




#if ( $is_signed_in )     
#set ($rService = $serviceLocator.findService("com.liferay.portal.service.RoleService"))
#set ($usrRoles = $rService.getUserRoles( $user_id )) 
     
#set ($hasPermission = false)

#foreach( $usrRole in $usrRoles )
        #if ( $usrRole.getName() == "Administrator" || $usrRole.getName() == "Content-Admin" || $usrRole.getName() == "Content-Editor")
           #set ($hasPermission = true)
        #end
     #end
#end

#if($hasPermission == true)
  #dockbar()
#end
Rupesh Chotai, geändert vor 12 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Regular Member Beiträge: 163 Beitrittsdatum: 23.03.11 Neueste Beiträge
Hi Corne,
Thanks for the better code snippet. It will solve the condition of multiple dock bar.
I appreciate you kind co-operation.emoticon

~Rupesh
Brian Cohen, geändert vor 11 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Junior Member Beiträge: 25 Beitrittsdatum: 04.05.12 Neueste Beiträge
So this code works great.
However, this also removes the "sign out" link, so users cannot actually sign out!
I tried adding the "Sign In" portlet, but there is no sign out link on that either?

Any idea how to code it to leave the sign out link available, but the rest of the Dockbar not there?
thumbnail
Corné Aussems, geändert vor 11 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Liferay Legend Beiträge: 1313 Beitrittsdatum: 03.10.06 Neueste Beiträge
You may create a link that points to /c/portal/logout anywere and even from the navigation making it only accesible for users (not guest)
thumbnail
Enrique Valdes Lacasa, geändert vor 9 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Junior Member Beiträge: 92 Beitrittsdatum: 29.07.14 Neueste Beiträge
Thanks for the code snippet! quite interesting... Although, I have a problem when running it in my theme in Liferay 6.2 CE ga2. It didn't work when I used the RoleService: the list of $usrRoles only has the roles stored in it if the user is an Administrator. If not, this List is empty like this [].

Although, I used the script console available in the Control Panel and when I used the RoleLocalServiceUtil instead, it worked. The script that I ran was (being 10805 the user Id of the user whose roles I need):

import com.liferay.portal.service.RoleLocalServiceUtil;
import com.liferay.portal.model.Role;

List<role> lista = RoleLocalServiceUtil.getUserRoles(10805);
for(role in lista){
println(role.getName());
}</role>



What I am going to do then, is creating a JSP hook for it and check the roles like that. But I wanted to use this theme solution you posted since it seemed so fast and easy to do...
thumbnail
Prakash Khanchandani, geändert vor 9 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Expert Beiträge: 329 Beitrittsdatum: 10.02.11 Neueste Beiträge
Enrique Valdes Lacasa:
This script worked fine, displaying all the user roles even if he is not an Administrator. So the velocity calls did not work well for the RoleServiceUtil.


It did not work well in theme is because it was not meant to be. In the script in control-panel you are using RoleLocalServiceUtil and in theme you are using RoleServiceUtil.

LocalService directly fetches from the database while Service layer checks for permission before doing that.

Hope this helps.
thumbnail
Enrique Valdes Lacasa, geändert vor 9 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Junior Member Beiträge: 92 Beitrittsdatum: 29.07.14 Neueste Beiträge
Thanks for the help Prakash! So in the snippet provided by Corné I wrote:

#set ($rService = $serviceLocator.findService("com.liferay.portal.service.RoleLocalService"));

instead of RoleService and it worked! It seems reasonable to do a RoleService call using permissions checkings in the theme, rather than use RoleLocalService and fetch the database directly without any checks. My question here is...so how would I make the RoleService call work? Would it be editing the permissions of the Portal authenticated users to allow the RoleService call somehow? I would like to learn more about how to do service calls appropriately.

Thanks again!
thumbnail
Enrique Valdes Lacasa, geändert vor 9 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Junior Member Beiträge: 92 Beitrittsdatum: 29.07.14 Neueste Beiträge
By the way, if it helps someone, I finished implementing the hook for this. Too bad I didn't read Prakash comment earlier.

I am posting the implementation of the hook below to only display the dockbar for Administrators, Site Administrators and Site Owners. Something I noticed is that I wasn't able to get all the roles together for the users using the getUserRoles method...and it only returned the Regular roles. That's why I did a getUserGroupRoles call too and then merged both lists. Any suggestions to improve it will be appreciated.

long userId = themeDisplay.getUser().getUserId();
long siteId = themeDisplay.getLayout().getGroupId();

List<role> regularRoles = RoleLocalServiceUtil.getUserRoles(userId);
List<role> siteRoles = RoleLocalServiceUtil.getUserGroupRoles(userId, siteId);

List<role> rolesList = new ArrayList<role>();
rolesList.addAll(siteRoles);
rolesList.addAll(regularRoles);

boolean showDockbar = false;

for(Role role: rolesList){
  if(role.getName().equals("Administrator") || role.getName().equals("Site Administrator") ||
       role.getName().equals("Site Owner") ){
    showDockbar = true;
  }
}

if(showDockbar) {
  // wrap the logic of /html/portlet/dockbar/view.jsp in here
}
</role></role></role></role>
thumbnail
Corné Aussems, geändert vor 12 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Liferay Legend Beiträge: 1313 Beitrittsdatum: 03.10.06 Neueste Beiträge
My example was for your requirements preventing some roles to be able to have some Actions
thumbnail
Prakash Khanchandani, geändert vor 9 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Expert Beiträge: 329 Beitrittsdatum: 10.02.11 Neueste Beiträge
If you are only doing for three system roles like Administrator, Site-administrator and Site-owner you need not fetch all the roles for that User you can simply use permissionChecker variable. This variable is also available in theme templates.

So instead of:
Enrique Valdes Lacasa:

if(role.getName().equals("Administrator") || role.getName().equals("Site Administrator") ||
       role.getName().equals("Site Owner") ){



You can use:
long siteId = themeDisplay.getLayout().getGroupId();

if(permissionChecker.isOmniadmin()
    || permissionChecker.isGroupOwner(siteId)
     || permissionChecker.isGroupAdmin(siteId)) { ...


Hope this helps.
thumbnail
Enrique Valdes Lacasa, geändert vor 9 Jahren.

RE: How to configure "Dockbar" based on "Roles"?

Junior Member Beiträge: 92 Beitrittsdatum: 29.07.14 Neueste Beiträge
Great suggestion, thanks! I didn't know that the permissionChecker was capable of this. I don't usually think about the Permissions API when developing in Liferay...but they seem so powerful emoticon I will consider them more often.