Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: improve Group creation by adding support for additional parameters for SharePoint sites #1026

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions src/lib/PnP.Framework/Graph/UnifiedGroupsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,15 @@ public static string GetUnifiedGroupSiteUrl(string groupId, string accessToken,
/// <param name="preferredDataLocation">Defines the codes of geographies in which there is Office 365 presence. Used for multi-geo enabled tenants. List with available geographies is available at https://docs.microsoft.com/office365/enterprise/multi-geo-add-group-with-pdl#geo-location-codes.</param>
/// <param name="assignedLabels">AIP Labels which should be applied to the group (does not work for App-Only)</param>
/// <param name="welcomeEmailDisabled">Option to prevent sending of default welcome emails to new members.</param>
/// <param name="siteAlias">The SharePoint site URL alias, if not specified mailNickName will be used</param>
/// <param name="lcid">The LCID or default language of the SharePoint site</param>
/// <param name="hubSiteId">The HubSiteId of the SharePoint site</param>
/// <param name="siteDesignId">The SiteDesignId to be applied to SharePoint site</param>
/// <returns>The just created Office 365 Group</returns>
public static UnifiedGroupEntity CreateUnifiedGroup(string displayName, string description, string mailNickname,
string accessToken, string[] owners = null, string[] members = null, Stream groupLogo = null,
bool isPrivate = false, bool createTeam = false, int retryCount = 10, int delay = 500, AzureEnvironment azureEnvironment = AzureEnvironment.Production,
Enums.Office365Geography? preferredDataLocation = null, Guid[] assignedLabels = null, bool welcomeEmailDisabled = false)
Enums.Office365Geography? preferredDataLocation = null, Guid[] assignedLabels = null, bool welcomeEmailDisabled = false, string siteAlias = "", uint lcid = 0, Guid hubSiteId = new Guid(), Guid siteDesignId = new Guid())
{
UnifiedGroupEntity result = null;

Expand All @@ -141,7 +145,7 @@ public static UnifiedGroupEntity CreateUnifiedGroup(string displayName, string d
}

var labels = new List<AssignedLabel>();
if(assignedLabels != null)
if (assignedLabels != null)
{
foreach (var label in assignedLabels)
{
Expand All @@ -154,7 +158,7 @@ public static UnifiedGroupEntity CreateUnifiedGroup(string displayName, string d
}
}
}


try
{
Expand All @@ -174,7 +178,7 @@ public static UnifiedGroupEntity CreateUnifiedGroup(string displayName, string d
MailEnabled = true,
SecurityEnabled = false,
Visibility = isPrivate == true ? "Private" : "Public",
GroupTypes = new List<string> { "Unified" }
GroupTypes = new List<string> { "Unified" },
};

if (labels.Any())
Expand Down Expand Up @@ -207,13 +211,36 @@ public static UnifiedGroupEntity CreateUnifiedGroup(string displayName, string d

if (welcomeEmailDisabled)
{
if (newGroup.AdditionalData == null)
{
newGroup.AdditionalData = new Dictionary<string, object>();
}
newGroup.AdditionalData ??= new Dictionary<string, object>();
newGroup.AdditionalData.Add("resourceBehaviorOptions", new string[] { "WelcomeEmailDisabled" });
}

List<string> siteCreationOptions = new()
{
$"HubSiteId:{hubSiteId}"
};

if (!string.IsNullOrEmpty(siteAlias))
{
siteAlias = UrlUtility.RemoveUnallowedCharacters(siteAlias);
siteAlias = UrlUtility.ReplaceAccentedCharactersWithLatin(siteAlias);

siteCreationOptions.Add($"SiteAlias:{siteAlias}");
}
if (lcid != 0)
{
siteCreationOptions.Add($"SPSiteLanguage:{(int)lcid}");
}

if (siteDesignId != Guid.Empty)
{
siteCreationOptions.Add($"implicit_formula_292aa8a00786498a87a5ca52d9f4214a_{siteDesignId.ToString("D").ToLower()}");
}

newGroup.AdditionalData ??= new Dictionary<string, object>();

newGroup.AdditionalData.Add("creationOptions", siteCreationOptions.ToArray());

Microsoft.Graph.Group addedGroup = null;
string modernSiteUrl = null;

Expand Down
6 changes: 5 additions & 1 deletion src/lib/PnP.Framework/Sites/SiteCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,11 @@ public static async Task<ClientContext> CreateTeamSiteViaGraphAsync(ClientContex
delay: retryDelay,
azureEnvironment: azureEnvironment,
preferredDataLocation: siteCollectionCreationInformation.PreferredDataLocation,
assignedLabels: new Guid[] { sensitivityLabelId });
assignedLabels: new Guid[] { sensitivityLabelId },
siteAlias: siteCollectionCreationInformation.SiteAlias,
lcid: siteCollectionCreationInformation.Lcid,
hubSiteId: siteCollectionCreationInformation.HubSiteId,
siteDesignId: siteCollectionCreationInformation.SiteDesignId.HasValue ? siteCollectionCreationInformation.SiteDesignId.Value : Guid.Empty);

if (group != null && !string.IsNullOrEmpty(group.SiteUrl))
{
Expand Down
Loading