public bool ContainsPrincipal(SPUser user, out SPPermissionCollection permissionGroups)
        {
            bool result = false;

            if (user.Groups == null)
            {
                user.LoadProperty("Groups");
            }

            var roleDefs = new SPPermissionCollection();

            for (int i = 0; i < _list.Count; i++)
            {
                var spp = _list[i];
                if ((spp.Type == PrincipalType.User && spp.LoginName.Equals(user.LoginName)) ||
                    (spp.Type == PrincipalType.SecurityGroup || spp.Type == PrincipalType.SharePointGroup &&
                     user.Groups.ContainsGroupByLoginName(spp.LoginName)))
                {
                    result = true;
                    roleDefs._list.Add(spp);
                }
            }
            permissionGroups = roleDefs;
            return(result);
        }
        public static SPPermissionCollection ResolvePermissions(SPSecurable securable)
        {
            var roleAss = securable.SecObj.RoleAssignments;

            if (!roleAss.AreItemsAvailable)
            {
                CTX.Lae(roleAss, true, col => col.Include(
                            ass => ass.Member, ass => ass.RoleDefinitionBindings.Include(
                                d => d.Name, d => d.Description)));
            }

            var permCol = new SPPermissionCollection(roleAss.Count);

            foreach (var ass in roleAss)
            {
                permCol._list.Add(SPPermission.ResolvePermission(ass, securable));
            }
            return(permCol);
        }
        //public SPPermissionCollection GetUserPermissions(string userId)
        //{
        //    if (this.CanSetPermissions)
        //    {
        //        var user = new SPUser(userId, true);
        //        if (this.Permissions == null)
        //            this.GetPermissions();

        //        if (this.Permissions)
        //    }
        //    else
        //        return null;
        //}

        #endregion

        #region GET PERMISSIONS

        public SPPermissionCollection GetPermissions()
        {
            if (!SecObj.IsPropertyReady(x => x.RoleAssignments))
            {
                CTX.Lae(SecObj, true, s => s.RoleAssignments);
            }

            Type secType     = SecObj.GetType();
            var  genMeth     = ExpressionMethod.MakeGenericMethod(secType);
            var  expressions = genMeth.Invoke(this, new object[1] {
                new string[2] {
                    NameProperty, IdProperty
                }
            });

            var specLae = typeof(CTX).GetMethod("SpecialLae", BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(SecObj.GetType());

            specLae.Invoke(null, new object[3] {
                SecObj, true, expressions
            });

            Permissions = SPPermissionCollection.ResolvePermissions(this);
            return(Permissions);
        }
 public bool ContainsPrincipal(User user, out SPPermissionCollection permissionGroups) =>
 this.ContainsPrincipal((SPUser)user, out permissionGroups);
Beispiel #5
0
 public SPPermissionCollection GetPermissions()
 {
     Permissions = _web.RoleAssignments;
     return(Permissions);
 }
 public SPPermissionCollection GetPermissions()
 {
     Permissions = _file.ListItemAllFields.RoleAssignments;
     return(Permissions);
 }