Пример #1
0
        //public static string GetGroupUrl(this SPClient.Group group)
        //{
        //    return null;
        //}

        public static string GetSettingsUrl(this SPClient.Group group)
        {
            // <sitecollection|web>/_layouts/userdisp.aspx?ID=10

            Uri ctxUrl = new Uri(group.Context.Url.ToLower());

            return(string.Format("{0}/_layouts/userdisp.aspx?ID={1}", ctxUrl.GetServerUrl(), group.Id));
        }
Пример #2
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post")] AddUserToGroupRequest request, TraceWriter log)
        {
            string siteUrl = request.SiteURL;

            try
            {
                if (string.IsNullOrWhiteSpace(request.SiteURL))
                {
                    throw new ArgumentException("Parameter cannot be null", "SiteURL");
                }
                if (string.IsNullOrWhiteSpace(request.Title))
                {
                    throw new ArgumentException("Parameter cannot be null", "Title");
                }

                var clientContext = await ConnectADAL.GetClientContext(siteUrl, log);


                var web  = clientContext.Web;
                var user = web.EnsureUser(request.Title);
                Microsoft.SharePoint.Client.Group siteGroup = null;

                switch (request.AssociatedGroup)
                {
                case AssociatedGroup.Member:
                {
                    siteGroup = web.AssociatedMemberGroup;
                }
                break;

                case AssociatedGroup.Owner:
                {
                    siteGroup = web.AssociatedOwnerGroup;
                }
                break;

                case AssociatedGroup.Visitor:
                {
                    siteGroup = web.AssociatedVisitorGroup;
                }
                break;
                }


                if (siteGroup != null)
                {
                    web.Context.Load(siteGroup);
                    web.Context.Load(user);
                    web.Context.ExecuteQueryRetry();

                    siteGroup.Users.AddUser(user);
                    web.Context.ExecuteQueryRetry();

                    return(await Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new ObjectContent <AddUserToGroupResponse>(new AddUserToGroupResponse {
                            UserAdded = true
                        }, new JsonMediaTypeFormatter())
                    }));
                }
                else
                {
                    return(await Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new ObjectContent <AddUserToGroupResponse>(new AddUserToGroupResponse {
                            UserAdded = false
                        }, new JsonMediaTypeFormatter())
                    }));
                }
            }
            catch (Exception e)
            {
                log.Error($"Error: {e.Message }\n\n{e.StackTrace}");
                return(await Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ObjectContent <AddUserToGroupResponse>(new AddUserToGroupResponse {
                        UserAdded = false
                    }, new JsonMediaTypeFormatter())
                }));
            }
        }
Пример #3
0
        private void SilverlightOM()
        {
            admintab.Visibility      = Visibility.Collapsed;
            teamtab.Visibility       = Visibility.Collapsed;
            myideas.Visibility       = Visibility.Visible;
            financetab.Visibility    = Visibility.Collapsed;
            btn_siteadmin.Visibility = Visibility.Collapsed;


            ClientContext   client          = ClientContext.Current;
            GroupCollection groupCollection = client.Web.SiteGroups;

            Microsoft.SharePoint.Client.Group adminGroup = groupCollection.GetById(40);
            User           currentUser = client.Web.CurrentUser;
            UserCollection userCol     = adminGroup.Users;

            client.Load(currentUser);
            client.Load(userCol);

            client.ExecuteQueryAsync((s, ee) =>
            {
                foreach (User groupUser in userCol)
                {
                    if (groupUser.LoginName.Equals(currentUser.LoginName))
                    {
                        Dispatcher.BeginInvoke(() =>
                        {
                            teamtab.Visibility       = Visibility.Visible;
                            admintab.Visibility      = Visibility.Visible;
                            financetab.Visibility    = Visibility.Visible;
                            btn_siteadmin.Visibility = Visibility.Visible;
                        }

                                               );
                    }
                }
            },



                                     (s, ee) =>
            {
                Console.WriteLine(ee.Message);
            });

            Microsoft.SharePoint.Client.Group financeGroup = groupCollection.GetById(39);

            UserCollection userCol2 = financeGroup.Users;

            client.Load(currentUser);

            client.Load(userCol2);



            client.ExecuteQueryAsync((ss, eee) =>
            {
                foreach (User groupUser in userCol2)
                {
                    if (groupUser.LoginName.Equals(currentUser.LoginName))
                    {
                        Dispatcher.BeginInvoke(() =>
                        {
                            financetab.Visibility    = Visibility.Visible;
                            btn_siteadmin.Visibility = Visibility.Collapsed;
                        }

                                               );
                    }
                }
            },



                                     (ss, eee) =>
            {
                Console.WriteLine(eee.Message);
            });
            Microsoft.SharePoint.Client.Group employeeGroup = groupCollection.GetById(37);
            UserCollection userCol3 = employeeGroup.Users;

            client.Load(currentUser);
            client.Load(userCol3);



            client.ExecuteQueryAsync((sss, eeee) =>
            {
                foreach (User groupUser in userCol3)
                {
                    if (groupUser.LoginName.Equals(currentUser.LoginName))
                    {
                        Dispatcher.BeginInvoke(() =>
                        {
                            teamtab.Visibility       = Visibility.Visible;
                            btn_siteadmin.Visibility = Visibility.Collapsed;
                        }

                                               );
                    }
                }
            },



                                     (sss, eeee) =>
            {
                Console.WriteLine(eeee.Message);
            });

            Microsoft.SharePoint.Client.Group ownersGroup = groupCollection.GetById(6);
            UserCollection userCol4 = ownersGroup.Users;

            client.Load(currentUser);

            client.Load(userCol4);


            client.ExecuteQueryAsync((ssss, eeeee) =>
            {
                foreach (User groupUser in userCol4)
                {
                    if (groupUser.LoginName.Equals(currentUser.LoginName))
                    {
                        Dispatcher.BeginInvoke(() =>
                        {
                            teamtab.Visibility       = Visibility.Visible;
                            admintab.Visibility      = Visibility.Visible;
                            financetab.Visibility    = Visibility.Visible;
                            btn_siteadmin.Visibility = Visibility.Visible;
                        }

                                               );
                    }
                }
            },



                                     (ssss, eeeee) =>
            {
                Console.WriteLine(eeeee.Message);
            });
        }
Пример #4
0
 /// <summary>
 /// Event to handle a group
 /// </summary>
 /// <param name="group">Group</param>
 public virtual void OnGroupRunning(SP.Group group)
 {
 }