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.
- From the Persona Bar, navigate to Settings > SQL Console.
- Run the following queries to find the necessary information:
- 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 - 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 - 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
- First, you'll run the following query to find the MenuID based on the MenuName:
- 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.
- 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 - You will get one of two responses:
- 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:
- 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.
- 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:
- Run the following query, inserting the PortalID, RoleID, and MenuID from the previous steps where appropriate:
- 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 - Clear the server cache.
Testing
You can test that this script has been completed successfully by:
- Re-run the script from Step 3 to ensure that HasAccess is set to "No"
- Log into a user account with the role you've removed the item for.
- Try to access the Persona Bar menu item that you've hidden above.
Comments
0 comments
Please sign in to leave a comment.