Beispiel #1
0
 public DeadAccountEntity(e.Permission p)
 {
     this.DeadAccount      = p.LoginName;
     this.Object           = p.SecurableObjectFx;
     this.Group            = p.Group;
     this.PermissionLevels = p.PermissionLevels;
 }
Beispiel #2
0
        private void SetPermissionsForListItem(string loginName, e.Permission p, SPListItem listItem)
        {
            using (SPSite esite = new SPSite(listItem.ParentList.ParentWeb.Site.ID))
            {
                using (SPWeb eweb = esite.OpenWeb(listItem.ParentList.ParentWeb.ID))
                {
                    SPList     elist     = eweb.Lists[listItem.ParentList.ID];
                    SPListItem elistItem = elist.GetItemById(listItem.ID);

                    eweb.AllowUnsafeUpdates = true;
                    SPUser user = eweb.EnsureUser(loginName);

                    if (p.SharePointGroup == null)
                    {
                        SPRoleAssignment ra = new SPRoleAssignment(user);

                        foreach (string level in p.PermissionLevels.Split(';'))
                        {
                            if (level == "Limited Access")
                            {
                                SkippedPermissions = true;
                            }
                            else
                            {
                                ra.RoleDefinitionBindings.Add(eweb.RoleDefinitions[level.Trim()]);
                            }
                        }

                        if (ra.RoleDefinitionBindings.Count > 0)
                        {
                            elistItem.RoleAssignments.Add(ra);
                        }
                    }
                    else
                    {
                        eweb.Groups[p.SharePointGroup.Name].AddUser(user);
                    }

                    eweb.AllowUnsafeUpdates = false;
                    eweb.Update();
                }
            }
        }