开发者

Programmatically check permissions for a sharepoint group

开发者 https://www.devze.com 2023-01-05 04:25 出处:网络
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?U

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

精彩评论

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