예제 #1
0
        private async Task ResumeExternalSharingDialog(IDialogContext context, IAwaitable <ExternalSharingQuery> result)
        {
            try
            {
                var    resultFromExtrnalSharing = await result;
                string _strURL                         = resultFromExtrnalSharing.SiteCollectionURL;
                string _strUserID                      = resultFromExtrnalSharing.SPOExternalUserID;
                bool   _isPermissionGranted            = false;
                bool   _isSiteCollectionSharingEnabled = false;
                bool   _isTenantSharingEnabled         = false;

                try
                {
                    SharePointPrimary obj = new SharePointPrimary(_strURL);

                    List <string> lstSiteCollectionAdmins = new List <string>();
                    lstSiteCollectionAdmins = obj.GetSiteCollectionAdmins();
                    string strSiteCollectionAdmins = string.Empty;

                    foreach (var eachAdmin in lstSiteCollectionAdmins)
                    {
                        strSiteCollectionAdmins += eachAdmin + "; ";
                    }

                    _isTenantSharingEnabled = obj.IsTenantExternalSharingEnabled();
                    if (_isTenantSharingEnabled)
                    {
                        _isSiteCollectionSharingEnabled = obj.IsSiteCollectionExternalSharingEnabled(_strURL);
                        if (_isSiteCollectionSharingEnabled)
                        {
                            _isPermissionGranted = obj.HasAccessGrantedToExternalUser(_strURL, _strUserID);

                            if (_isPermissionGranted)
                            {
                                await context.PostAsync($"Access granted \U00002705 An email is sent to '{_strUserID}' ");

                                //context.Done("External Access granted.");
                                context.Done("Done");
                            }
                            else
                            {
                                await context.PostAsync("Permission could not be granted. Please try again later.");

                                //context.Done("External Access could not be granted.");
                                context.Done("Not Done");
                            }
                        }
                        else
                        {
                            await context.PostAsync($"Access could not be granted as External Sharing is disabled for this Site Collection.");

                            await context.PostAsync($"Please reach out to one of the Site Collection Adminstrators listed below:" +
                                                    "\r\r" + strSiteCollectionAdmins);

                            //context.Done("Access could not be granted. External Sharing is disabled for this Site Collection.");
                            context.Done("Not Done");
                        }
                    }
                    else
                    {
                        await context.PostAsync($"Access could not be granted as External Sharing is disabled at our Tenant level. ");

                        await context.PostAsync($"Please reach out to one of the Site Collection Adminstrators listed below:" +
                                                "\r\r" + strSiteCollectionAdmins);

                        //context.Done("Access could not be granted. External Sharing is disabled at our Tenant level.");
                        context.Done("Not Done");
                    }
                }
                catch (Exception)
                {
                    context.Fail(new Exception("Unable to grant permission to user \U0001F641 . Please try again later."));
                }
            }
            catch (TooManyAttemptsException)
            {
                await context.PostAsync("Sorry \U0001F641 , I am unable to understand you. Let us try again.");
            }
        }
        private async Task ResumeSiteQuotaDialog(IDialogContext context, IAwaitable <SiteQuotaChangeQuery> result)
        {
            try
            {
                var    resultFromSiteQuotaChange = await result;
                string _strURL    = resultFromSiteQuotaChange.SiteCollectionURL;
                string _strUserID = resultFromSiteQuotaChange.SPOUserID;
                //int _intNewQuota = Convert.ToInt32(resultFromSiteQuotaChange.NewStorageQuota);
                int _intNewQuota = 1;

                if (!string.IsNullOrEmpty(_strURL) && !string.IsNullOrEmpty(_strUserID) && (_intNewQuota != 0))
                {
                    try
                    {
                        SharePointPrimary obj      = new SharePointPrimary(_strURL);
                        bool isSiteCollectionAdmin = obj.IsSiteCollectionAdmin(_strUserID);
                        if (isSiteCollectionAdmin)
                        {
                            bool isStorageUpdated = obj.IsSiteCollectionStorageQuotaUpdated(_strURL, _intNewQuota);
                            //context.Done("Storage Quota Updated.");
                            if (isStorageUpdated)
                            {
                                await context.PostAsync($"The Storage Quota for the Site Collection '{_strURL}' is being updated. Please refresh it after sometime.");

                                context.Done("Done");
                            }
                            else
                            {
                                await context.PostAsync("Storage quota could not be updated \U0001F641 . Please try again later.");

                                context.Done("Not Done");
                            }
                        }
                        else
                        {
                            List <string> lstSiteCollectionAdmins = new List <string>();
                            lstSiteCollectionAdmins = obj.GetSiteCollectionAdmins();
                            string strSiteCollectionAdmins = string.Empty;

                            foreach (var eachAdmin in lstSiteCollectionAdmins)
                            {
                                strSiteCollectionAdmins += eachAdmin + ";";
                            }

                            await context.PostAsync($"I just found out that you are not authorized to update the Storage Quota of the Site Collection '{_strURL}'");

                            await context.PostAsync($"Please reach out to one of the Site Collection Adminstrators listed below:" +
                                                    "\r\r" + strSiteCollectionAdmins);

                            context.Done("Not Done");
                        }
                    }
                    catch (Exception)
                    {
                        context.Fail(new TooManyAttemptsException("Unable to update Storage Quota \U0001F641 . Please try again later."));
                    }
                }
            }
            catch (TooManyAttemptsException)
            {
                await context.PostAsync("Sorry \U0001F641 , I am unable to understand you. Let us try again.");
            }
        }