掲示板

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

13年前 に Rupesh Chotai によって更新されました。

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

Regular Member 投稿: 163 参加年月日: 11/03/23 最新の投稿
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
13年前 に Corné Aussems によって更新されました。

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

Liferay Legend 投稿: 1313 参加年月日: 06/10/03 最新の投稿
RolePermissionUtil is being exposed through this variable
$rolePermission
13年前 に Rupesh Chotai によって更新されました。

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

Regular Member 投稿: 163 参加年月日: 11/03/23 最新の投稿
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
13年前 に Corné Aussems によって更新されました。

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

Liferay Legend 投稿: 1313 参加年月日: 06/10/03 最新の投稿
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

添付ファイル:

13年前 に Rupesh Chotai によって更新されました。

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

Regular Member 投稿: 163 参加年月日: 11/03/23 最新の投稿
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?
13年前 に Rupesh Chotai によって更新されました。

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

Regular Member 投稿: 163 参加年月日: 11/03/23 最新の投稿
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
13年前 に Corné Aussems によって更新されました。

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

Liferay Legend 投稿: 1313 参加年月日: 06/10/03 最新の投稿
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
13年前 に Rupesh Chotai によって更新されました。

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

Regular Member 投稿: 163 参加年月日: 11/03/23 最新の投稿
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
11年前 に Brian Cohen によって更新されました。

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

Junior Member 投稿: 25 参加年月日: 12/05/04 最新の投稿
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
11年前 に Corné Aussems によって更新されました。

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

Liferay Legend 投稿: 1313 参加年月日: 06/10/03 最新の投稿
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
9年前 に Enrique Valdes Lacasa によって更新されました。

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

Junior Member 投稿: 92 参加年月日: 14/07/29 最新の投稿
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
9年前 に Prakash Khanchandani によって更新されました。

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

Expert 投稿: 329 参加年月日: 11/02/10 最新の投稿
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
9年前 に Enrique Valdes Lacasa によって更新されました。

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

Junior Member 投稿: 92 参加年月日: 14/07/29 最新の投稿
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
9年前 に Enrique Valdes Lacasa によって更新されました。

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

Junior Member 投稿: 92 参加年月日: 14/07/29 最新の投稿
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
13年前 に Corné Aussems によって更新されました。

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

Liferay Legend 投稿: 1313 参加年月日: 06/10/03 最新の投稿
My example was for your requirements preventing some roles to be able to have some Actions
thumbnail
9年前 に Prakash Khanchandani によって更新されました。

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

Expert 投稿: 329 参加年月日: 11/02/10 最新の投稿
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
9年前 に Enrique Valdes Lacasa によって更新されました。

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

Junior Member 投稿: 92 参加年月日: 14/07/29 最新の投稿
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.