Skip to content

Commit

Permalink
Feature: improve Group creation by adding support for additional para…
Browse files Browse the repository at this point in the history
…meters for SharePoint sites
  • Loading branch information
Gautam Sheth committed Jun 7, 2024
1 parent 6de4e40 commit f8439ac
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
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

0 comments on commit f8439ac

Please sign in to comment.