tags:

views:

14

answers:

1

Hi. How can I check whether a specified group has a certain permission for an item? I know that there are methods like DoesUserHavePermissions() on item, but what about groups?

A: 

Untested code, but something like this.

This works for both groups and users and also for everything with permissions (items, lists, webs etc.)

public static bool DoesPrincipalHavePermission(ISecurableObject @object, SPPrincipal principal, SPRoleDefinition role)
{
      var assignment = @object.RoleAssignments.GetAssignmentByPrincipal(principal);
      if (assignment == null || assignment.RoleDefinitionBindings.Count < 1)
           return false;

      foreach (SPRoleDefinition r in assignment.RoleDefinitionBindings)
      {
          if (r.BasePermissions == role.BasePermissions)
              return true;
      }

      return false;
}
JWL_