Skip to content

Commit

Permalink
Added Sensitivity Labels to Unified Group Creation
Browse files Browse the repository at this point in the history
  • Loading branch information
NikoMix committed Nov 29, 2021
1 parent e72165a commit 20cb026
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/lib/PnP.Framework/Graph/UnifiedGroupsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static string GetUnifiedGroupSiteUrl(string groupId, string accessToken,
/// <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)
bool isPrivate = false, bool createTeam = false, int retryCount = 10, int delay = 500, AzureEnvironment azureEnvironment = AzureEnvironment.Production, Enums.Office365Geography? preferredDataLocation = null, Guid[] assignedLabels = null)
{
UnifiedGroupEntity result = null;

Expand All @@ -137,6 +137,18 @@ public static UnifiedGroupEntity CreateUnifiedGroup(string displayName, string d
throw new ArgumentNullException(nameof(accessToken));
}

var labels = new List<AssignedLabel>();
foreach (var label in assignedLabels)
{
if(label != Guid.Empty)
{
labels.Add(new AssignedLabel
{
LabelId = label.ToString()
});
}
}

try
{
// Use a synchronous model to invoke the asynchronous process
Expand All @@ -156,6 +168,7 @@ public static UnifiedGroupEntity CreateUnifiedGroup(string displayName, string d
SecurityEnabled = false,
Visibility = isPrivate == true ? "Private" : "Public",
GroupTypes = new List<string> { "Unified" },
AssignedLabels = labels
};

if (preferredDataLocation.HasValue)
Expand Down
19 changes: 16 additions & 3 deletions src/lib/PnP.Framework/Sites/SiteCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,18 @@ public static async Task<ClientContext> CreateTeamSiteViaGraphAsync(ClientContex
)
{
ClientContext responseContext = null;



Guid sensitivityLabelId = Guid.Empty;
if (siteCollectionCreationInformation.SensitivityLabelId != Guid.Empty)
{
sensitivityLabelId = siteCollectionCreationInformation.SensitivityLabelId;
}
else if (!string.IsNullOrEmpty(siteCollectionCreationInformation.SensitivityLabel))
{
sensitivityLabelId = await GetSensitivityLabelId(clientContext, siteCollectionCreationInformation.SensitivityLabel);
}

var group = Graph.UnifiedGroupsUtility.CreateUnifiedGroup(
siteCollectionCreationInformation.DisplayName,
siteCollectionCreationInformation.Description,
Expand All @@ -518,8 +529,10 @@ public static async Task<ClientContext> CreateTeamSiteViaGraphAsync(ClientContex
isPrivate: !siteCollectionCreationInformation.IsPublic,
createTeam: false,
retryCount: maxRetryCount,
delay: retryDelay, azureEnvironment: azureEnvironment,
preferredDataLocation: siteCollectionCreationInformation.PreferredDataLocation);
delay: retryDelay,
azureEnvironment: azureEnvironment,
preferredDataLocation: siteCollectionCreationInformation.PreferredDataLocation,
assignedLabels: new Guid[] { sensitivityLabelId });

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

0 comments on commit 20cb026

Please sign in to comment.