Ejemplo n.º 1
0
        public async Task ConnectSiteCollectionToGroupAsync(ConnectSiteToGroupOptions siteGroupConnectOptions, CreationOptions creationOptions = null)
        {
            if (siteGroupConnectOptions == null)
            {
                throw new ArgumentNullException(nameof(siteGroupConnectOptions));
            }

            await SiteCollectionCreator.ConnectGroupToSiteAsync(context, siteGroupConnectOptions, creationOptions).ConfigureAwait(true);
        }
Ejemplo n.º 2
0
        internal static async Task <PnPContext> ConnectGroupToSiteAsync(PnPContext contextIn, ConnectSiteToGroupOptions siteToGroupify, CreationOptions creationOptions)
        {
            using (var context = await GetContextForGroupConnectAsync(contextIn, siteToGroupify.Url).ConfigureAwait(false))
            {
                // Provide default creation options as input
                creationOptions = await EnsureCreationOptionsAsync(context, creationOptions).ConfigureAwait(false);

                // If we're using application permissions we use Microsoft Graph to create the site
                if (creationOptions.UsingApplicationPermissions.Value)
                {
                    throw new NotSupportedException("Group connecting sites using application permissions is not supported");
                }
                else
                {
                    var creationOptionsValues           = new List <string>();
                    Dictionary <string, object> payload = new Dictionary <string, object>
                    {
                        { "displayName", siteToGroupify.DisplayName },
                        { "alias", siteToGroupify.Alias },
                        { "isPublic", siteToGroupify.IsPublic }
                    };

                    var optionalParams = new Dictionary <string, object>
                    {
                        { "Description", siteToGroupify.Description ?? "" }
                    };

                    // Sensitivity labels have replaced classification (see https://docs.microsoft.com/en-us/microsoft-365/compliance/sensitivity-labels-teams-groups-sites?view=o365-worldwide#classic-azure-ad-group-classification)
                    // once enabled. Therefore we prefer setting a sensitivity label id over classification when specified. Also note that for setting sensitivity labels on
                    // group connected sites one needs to have at least one Azure AD P1 license. See https://docs.microsoft.com/en-us/azure/active-directory/enterprise-users/groups-assign-sensitivity-labels
                    if (siteToGroupify.SensitivityLabelId != Guid.Empty)
                    {
                        creationOptionsValues.Add($"SensitivityLabel:{siteToGroupify.SensitivityLabelId}");
                    }
                    else
                    {
                        optionalParams.Add("Classification", siteToGroupify.Classification ?? "");
                    }

                    if (siteToGroupify.Language != Language.Default)
                    {
                        creationOptionsValues.Add($"SPSiteLanguage:{(int)siteToGroupify.Language}");
                    }
                    if (!string.IsNullOrEmpty(siteToGroupify.SiteAlias))
                    {
                        creationOptionsValues.Add($"SiteAlias:{siteToGroupify.SiteAlias}");
                    }
                    creationOptionsValues.Add($"HubSiteId:{siteToGroupify.HubSiteId}");

                    if (siteToGroupify.Owners != null && siteToGroupify.Owners.Length > 0)
                    {
                        optionalParams.Add("Owners", siteToGroupify.Owners);
                    }
                    if (siteToGroupify.PreferredDataLocation.HasValue)
                    {
                        optionalParams.Add("PreferredDataLocation", siteToGroupify.PreferredDataLocation.Value.ToString());
                    }

                    if (creationOptionsValues.Any())
                    {
                        var creationOptionsValuesBody = new
                        {
                            __metadata = new { type = "Collection(Edm.String)" },
                            results    = creationOptionsValues
                        }.AsExpando();
                        optionalParams.Add("CreationOptions", creationOptionsValuesBody);
                    }

                    payload.Add("optionalParams", optionalParams);

                    SiteCreationOptions siteCreationOptions = new SiteCreationOptions()
                    {
                        UsingApplicationPermissions = creationOptions.UsingApplicationPermissions,
                        MaxStatusChecks             = creationOptions.MaxStatusChecks,
                        WaitAfterStatusCheck        = creationOptions.WaitAfterStatusCheck,
                    };

                    // Delegated permissions can use the SharePoint endpoints for site collection creation
                    return(await CreateSiteUsingSpoRestImplementationAsync(context, SiteCreationModel.GroupSiteManagerCreateGroupForSite, payload, siteCreationOptions).ConfigureAwait(false));
                }
            }
        }
Ejemplo n.º 3
0
 public void ConnectSiteCollectionToGroup(ConnectSiteToGroupOptions siteGroupConnectOptions, CreationOptions creationOptions = null)
 {
     ConnectSiteCollectionToGroupAsync(siteGroupConnectOptions, creationOptions).GetAwaiter().GetResult();
 }