开发者

Programmatically check permissions for a sharepoint group

How can I check whether a specified group has a certain permission for an item? I know that there are methods like DoesUserHavePermissi开发者_StackOverflow中文版ons() on item, but what about groups?


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜