Beispiel #1
0
        /// <summary>
        /// Nacte uzivatele pro ktere se maji priradit prava
        /// </summary>
        /// <param name="item"></param>
        /// <param name="identifications">muze byt login, jmeno pole ze ktereho se nactou uzivatele a nebo lookup a pak pole ze ktereho se to nacte</param>
        /// <param name="expandUsers"></param>
        /// <returns></returns>
        private static List<SPPrincipal> LoadUsers(SPListItem item, List<string> identifications, bool expandUsers)
        {
            List<SPPrincipal> users = new List<SPPrincipal>();

            foreach (string identification in identifications)
            {
                if (item.ParentList.ContainsFieldIntName(identification)) //je jmeno pole
                {
                    if (item[identification] != null)
                    {
                        var fieldUsers = item.Web.GetSPPrincipals(item[identification]);
                        users.AddRange(fieldUsers);
                    }
                }
                else if (identification.Contains("\\")) //obsahuje login - at uz s claims nebo bez
                {
                    List<SPPrincipal> principals = item.Web.GetSPPrincipals(identification.Split(';')); //bacha aby tady nebylo v claims vice stredniku!!
                    users.AddRange(principals);
                }
                else if (identification.Contains('|')) //Lookupový zápis
                {
                    List<string> fields = identification.Split('|').ToList();
                    string userField = fields.Last();
                    fields.RemoveAt(fields.Count - 1);

                    WebListItemDictionary wild = item.TraverseItemLookups(fields);

                    wild.ProcessItems(item.Web.Site, delegate(SPListItem lookupItem)
                    {
                        if (lookupItem[userField] != null)
                        {
                            List<SPPrincipal> principals = lookupItem.Web.GetSPPrincipals(lookupItem[userField]);
                            if (principals != null)
                            {
                                users.AddRange(principals);
                            }
                        }
                        return null;
                    });
                }
                else
                {
                    //nemelo by diky konfiguraci nikdy nastat
                }
            }

            users = users.Distinct(new SPPrincipalComparer()).ToList();

            return expandUsers ? item.Web.GetSPUsers(users).Cast<SPPrincipal>().ToList() : users;
        }