From 86d4e026547567a3b4d361580e2ab2e383a118b7 Mon Sep 17 00:00:00 2001 From: kfchen Date: Fri, 15 Dec 2023 11:51:43 +0200 Subject: [PATCH] Include timezone option for the site creation #1265 --- .../SharePoint/SiteManagerTests.cs | 64 +++++++++++++++++++ .../Core/Internal/SiteCollectionCreator.cs | 6 ++ .../Options/CommonNoGroupSiteOptions.cs | 8 ++- 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/sdk/PnP.Core.Admin.Test/SharePoint/SiteManagerTests.cs b/src/sdk/PnP.Core.Admin.Test/SharePoint/SiteManagerTests.cs index 024b9f3612..8a8c2cd26b 100644 --- a/src/sdk/PnP.Core.Admin.Test/SharePoint/SiteManagerTests.cs +++ b/src/sdk/PnP.Core.Admin.Test/SharePoint/SiteManagerTests.cs @@ -1167,6 +1167,70 @@ await context.GetSiteCollectionManager().SetSiteCollectionAdminsAsync( } } + [TestMethod] + public async Task SetSiteCollectionWithTimeZome_Async() + { + //Time zone object to test with + var selectedTimeZone = TimeZone.UTCPLUS0200_JERUSALEM; + + //TestCommon.Instance.Mocking = false; + TestCommon.Instance.UseApplicationPermissions = false; + + CommunicationSiteOptions communicationSiteToCreate = null; + + // Create the site collection + try + { + using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite)) + { + // Persist the used site url as we need to have the same url when we run an offline test + Uri siteUrl; + if (!TestCommon.Instance.Mocking) + { + siteUrl = new Uri($"https://{context.Uri.DnsSafeHost}/sites/pnpcoresdktestcommsite{Guid.NewGuid().ToString().Replace("-", "")}"); + Dictionary properties = new Dictionary + { + { "SiteUrl", siteUrl.ToString() } + }; + TestManager.SaveProperties(context, properties); + } + else + { + siteUrl = new Uri(TestManager.GetProperties(context)["SiteUrl"]); + } + + communicationSiteToCreate = new CommunicationSiteOptions(siteUrl, "PnP Core SDK Test") + { + Description = "This is a test site collection", + Language = Language.English, + TimeZone = selectedTimeZone + }; + + SiteCreationOptions siteCreationOptions = new() + { + UsingApplicationPermissions = false + }; + + var siteProperties = context.GetSiteCollectionManager().GetSiteCollectionProperties(context.Uri); + + //Validating time zone set as expected + Assert.IsTrue(siteProperties.TimeZoneId == selectedTimeZone); + + if (context.Mode == TestMode.Record) + { + // Add a little delay between creation and deletion + await Task.Delay(TimeSpan.FromSeconds(15)); + } + } + } + finally + { + TestCommon.Instance.UseApplicationPermissions = false; + using var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite, 1); + await context.GetSiteCollectionManager().DeleteSiteCollectionAsync(communicationSiteToCreate.Url); + } + } + [TestMethod] public async Task SetSiteCollectionAdminsGroupSite() { diff --git a/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Internal/SiteCollectionCreator.cs b/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Internal/SiteCollectionCreator.cs index a4fc59dbd4..81512a92e5 100644 --- a/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Internal/SiteCollectionCreator.cs +++ b/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Internal/SiteCollectionCreator.cs @@ -182,6 +182,12 @@ private static async Task CreateCommonNoGroupSiteAsync(PnPContext co payload["Classification"] = siteToCreate.Classification ?? ""; } + if (siteToCreate.TimeZone.HasValue) + { + payload.Add("TimeZoneId", (int)siteToCreate.TimeZone.Value); + } + + return await CreateSiteUsingSpoRestImplementationAsync(context, SiteCreationModel.SPSiteManagerCreate, payload, creationOptions).ConfigureAwait(false); } diff --git a/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Public/Options/CommonNoGroupSiteOptions.cs b/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Public/Options/CommonNoGroupSiteOptions.cs index 267dd33761..d0206276d3 100644 --- a/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Public/Options/CommonNoGroupSiteOptions.cs +++ b/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Public/Options/CommonNoGroupSiteOptions.cs @@ -72,7 +72,11 @@ public CommonNoGroupSiteOptions(Uri url, string title) /// /// The Sensitivity label to use. See https://www.youtube.com/watch?v=NxvUXBiPFcw for more information. /// - public Guid SensitivityLabelId { get; set; } - + public Guid SensitivityLabelId { get; set; } + + /// + /// The time zone to use for the site. + /// + public TimeZone? TimeZone { get; set; } } }