Fórum

how to verify permissions for a layout in 5.2.3

jm mayer, modificado 12 Anos atrás.

how to verify permissions for a layout in 5.2.3

New Member Postagens: 23 Data de Entrada: 28/07/10 Postagens Recentes
I'm having trouble finding documentation on how to programmatically determine if a specific role has access to a layout.
I'm trying to make it slightly less obscure for community admins to add permissions to specific pages. The normal way of doing so is to go through Control Panel -> Communities -> Manage Pages -> click the individual page, click the permissions button, then select the permissions you'd like to have access to the page.

I've managed to correctly set the permissions for pages through my UI, but setting the text I want to display is turning out to be less than the trivial task I thought it would be.

I'll include my code in case someone else has an alternate way of accomplishing it (or spots a bug), they can chime in.

	
public boolean communityUserHasViewPermissions(RenderRequest request) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    Layout currentLayout = themeDisplay.getLayout();
    long currentGroupId = currentLayout.getGroupId();
    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    return permissionChecker.hasPermission(currentGroupId, currentLayout.getClass().getName(), RoleConstants.COMMUNITY_MEMBER, ActionKeys.VIEW);
}