Saturday 19 May 2012

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

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

This  below code 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.

#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


#if ( $is_signed_in )
   #if ( $user.getScreenName() == "superadmin")
      #dockbar()
   #end
#end

LogOut:

#if ($show_sign_out)
   <a title="Sign Out" href="$sign_out_url" style="float:right;">$sign_out_text</a>
#end

16 comments:

  1. Hello, where would you add this?

    ReplyDelete
  2. I second the first comment, where do you add this code?

    ReplyDelete
  3. Inside the portal_normal.vm file of your theme.

    ReplyDelete
    Replies
    1. Thanks...It work fine for me..

      But my requirement is to display name (who ever logged in) . It should display as "Logged as NAME".

      Delete
    2. Hi Sujeet you can get the user name by using $user.getFullName() in your portal_normal.vm
      you can use as below
      #set ($user_full_name = $user.getFullName())

      and wherever you want to display the name in theme you can display it by simply writing $user_full_name

      Delete
  4. good one.Sign out shows.but its not working.

    ReplyDelete
    Replies
    1. Could you let me know what exactly issue you are facing because same solution working fine for me.

      Delete
    2. i just copy the signout code into portal_normal.vm.
      it shows the "sign out".but not link.

      Delete
    3. other code hides the dockbar for me.so i lost sign out.
      but i need sign out option.help me

      Delete
    4. Now its working...thanks for your time

      Delete
    5. may i ask you one thing..
      In social office theme profile picture is included in the my public pages.But i need this in the portal home page.
      am trying replace the
      a href="$current_user_profile_url"><img src="$current_user_profile_portrait_url" alt="$current_user_name"

      But missing $current_user_profile_url error occured.what is the reason?u have any idea?

      Delete
    6. try following value in image src :
      <%= themeDisplay.getPathImage()%>/user_portrait?img_id=<%=id %>

      hope this will resolve the issue you are facing.

      Delete
    7. no vir..it shos only link $current_user_name"

      Delete
  5. thank you for this code, works a treat for the OEM DELL open manage network manager. Perfect!

    ReplyDelete