Hiding a Persona Bar Menu Item for a Specific Role

Overview

At times, you may want to hide a Persona Bar menu item from a specific role to prevent users in that role from accessing the menu features. Note that permissions must be defined for a role before they can be modified. If you're not sure whether a permission has been set for this particular menu item and role, follow steps 1 through 3 below.

 

Prerequisites

  • You must have access to the SQL Server and a SuperUser account.
  • You must know the role name and the portal it is associated with.
  • The custom role must have permissions defined for the menu item you wish to hide (see steps 1-3 below).

 

Solution

To hide the menu, we'll need to gather some information via SQL queries, then use an update to make the necessary changes. Steps 1-3 gather the RoleID, PortalID, and MenuID, and check whether permissions have been set up. Step 4 executes the change using that information.

  1. From the Persona Bar, navigate to Settings > SQL Console.
  2. Run the following queries to find the necessary information:
    1. First, you'll run the following query to find the MenuID based on the MenuName:
      select p.MenuID
      ,p.ModuleName as MenuName
      ,pp.modulename as ParentMenu
      from personabarmenu p
      left join personabarmenu pp
      on p.parentid =pp.menuid
      order by MenuName
    2. Run the following query to find the PortalID based on the PortalAlias:
      select PortalID
      ,(select top 1 httpalias
      from portalalias pa
      where p.portalid=pa.portalid
      order by case when isprimary=1 then 0 else 1 end, portalaliasid) as PortalAlias
      from portals p
    3. Finally, run this query to find the RoleID based on the RoleName. Make sure the PortalID here matches the PortalID from the previous step:
      select RoleID
      , PortalID
      , RoleName
      , Description
      from Roles
  3. We can now use the information we've gathered to find out whether existing permissions have been set up for this role pertaining to this menu item.
    1. Run the following query, inserting the PortalID, RoleID, and MenuID from the previous steps where appropriate:
      declare @portalid INT = 0    --REPLACE THIS NUMBER WITH YOUR PORTALID
      , @menuid INT = 0 --REPLACE THIS NUMBER WITH YOUR MENUID
      , @roleid INT = 0 --REPLACE THIS NUMBER WITH YOUR ROLEID

      select MenuPermissionID
      , RoleName
      ,(select top 1 httpalias
      from portalalias pa
      where pmp.portalid=pa.portalid
      order by case when isprimary=1 then 0 else 1 end, portalaliasid) as Portal
      , ModuleName as MenuName
      , PermissionName
      , case when AllowAccess=1 then 'Yes' else 'No' end as HasAccess

      from PersonaBarMenuPermission pmp
      left join personabarpermission pp on pp.permissionid=pmp.permissionid
      left join personabarmenu pm on pm.menuid=pmp.menuid
      left join roles on roles.roleid=pmp.roleid
      WHERE 1=1
      AND pmp.RoleID = @roleid
      AND pmp.MenuID = @menuid
      AND pmp.PortalID = @portalid

    2. You will get one of two responses:
      1. If permissions are set up, you will get a result like the following picture. Note that if the View Menu permission has "HasAccess" set to "No," then the role is already restricted from viewing that menu, and no further action needs to be taken. Otherwise, proceed to Step 4:
        mceclip0.png
      2. If permissions are not set up for the role, you will get a message saying "The query did not return any data." If this happens, no permissions for that combination of role, menu, and portal have been set up. Double check to make sure you entered the IDs correctly, and if it continues to return no results, you will need to add permissions for that role. See Mapping custom roles to Persona bar permissions for more information.
  4. We can now run our final query to hide the Persona Bar menu from the role. Note that this permission change will remove all permissions to access that menu item by that role. This includes viewing and editing. Because this is an update script, it will not return any results when run.
    Run the following query, inserting your PortalID, MenuID, and RoleID where appropriate:
    declare @portalid INT = 0    --REPLACE THIS NUMBER WITH YOUR PORTALID
    , @menuid INT = 0 --REPLACE THIS NUMBER WITH YOUR MENUID
    , @roleid INT = 0 --REPLACE THIS NUMBER WITH YOUR ROLEID
    UPDATE PMP
    SET PMP.AllowAccess = 0 --Set value to 0 to hide, set 1 to show
    FROM PersonaBarMenuPermission AS PMP
    WHERE pmp.PortalID = @portalid
    AND pmp.Roleid = @roleid
    AND PMP.MenuID = @menuid
  5. Clear the server cache.

Testing

You can test that this script has been completed successfully by:

  1. Re-run the script from Step 3 to ensure that HasAccess is set to "No"
  2. Log into a user account with the role you've removed the item for.
  3. Try to access the Persona Bar menu item that you've hidden above.

 

Back to top

Comments

0 comments

Please sign in to leave a comment.