Check Current User Permissions…

I had a requirement to security trim some functionality in SharePoint to some user roles. Basically I wanted to display some controls / options in the Ribbon control to the users if they have “Design” permission level.

One thing to understand here is, SharePoint Security Groups has a group named, Designer. Checking is the current user in the Designer group will not be accurate. Because there can be new groups get created with the same permission set but with a different name. Also SharePoint allows you to add direct permission to users. (Not adding to a Group but directly give required permissions to the user itself).

So as a solution we have to check the current users Permission Levels contains “Design” permission level.

Following is a code segment that can be used to full fill the above requirement.

// Retrieve all user roles assigned for the current user for the current web. 
SPRoleDefinitionBindingCollection userRoles = 

// Retrieve all role definitions in the current web. 
SPRoleDefinitionCollection roleDefinitions = 
SPRoleDefinition roleDefinition = roleDefinitions[PERMISSION_LEVEL_DESIGN];

// Check current user permissions and the required permissions. 
if (!userRoles.Contains(roleDefinition))
    // Hide the controls from ribbon for the non designer users.

Simple Smile

Leave a Reply

Your email address will not be published. Required fields are marked *