Skip to content

Commit

Permalink
Add team members after team creation; Only add delegated user when ow…
Browse files Browse the repository at this point in the history
…ner is not specified
  • Loading branch information
damsleth committed Aug 17, 2023
1 parent ccee58d commit 8aba935
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/Commands/Utilities/TeamsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,33 +195,6 @@ public static async Task<Team> NewTeamAsync(string accessToken, PnPConnection co
}
if (group != null)
{
// Construct a list of all owners and members to add
var teamOwnersAndMembers = new List<TeamChannelMember>();
if (owners != null && owners.Length > 0)
{
foreach (var owner in owners)
{
teamOwnersAndMembers.Add(new TeamChannelMember { Roles = new List<string> { "owner" }, UserIdentifier = $"https://{connection.GraphEndPoint}/v1.0/users('{owner}')" });
}
}

if (members != null && members.Length > 0)
{
foreach (var member in members)
{
teamOwnersAndMembers.Add(new TeamChannelMember { Roles = new List<string>(), UserIdentifier = $"https://{connection.GraphEndPoint}/v1.0/users('{member}')" });
}
}

if (teamOwnersAndMembers.Count > 0)
{
var ownersAndMembers = BatchUtility.Chunk(teamOwnersAndMembers, 200);
foreach (var chunk in ownersAndMembers)
{
await GraphHelper.PostAsync(connection, $"v1.0/teams/{group.Id}/members/add", new { values = chunk.ToList() }, accessToken);
}
}

Team team = teamCI.ToTeam(group.Visibility.Value);
var retry = true;
var iteration = 0;
Expand Down Expand Up @@ -251,7 +224,34 @@ public static async Task<Team> NewTeamAsync(string accessToken, PnPConnection co
{
retry = false;
}
}
}

// Construct a list of all owners and members to add
var teamOwnersAndMembers = new List<TeamChannelMember>();
if (owners != null && owners.Length > 0)
{
foreach (var owner in owners)
{
teamOwnersAndMembers.Add(new TeamChannelMember { Roles = new List<string> { "owner" }, UserIdentifier = $"https://{connection.GraphEndPoint}/v1.0/users('{owner}')" });
}
}

if (members != null && members.Length > 0)
{
foreach (var member in members)
{
teamOwnersAndMembers.Add(new TeamChannelMember { Roles = new List<string>(), UserIdentifier = $"https://{connection.GraphEndPoint}/v1.0/users('{member}')" });
}
}

if (teamOwnersAndMembers.Count > 0)
{
var ownersAndMembers = BatchUtility.Chunk(teamOwnersAndMembers, 200);
foreach (var chunk in ownersAndMembers)
{
await GraphHelper.PostAsync(connection, $"v1.0/teams/{group.Id}/members/add", new { values = chunk.ToList() }, accessToken);
}
}
}
return returnTeam;
}
Expand Down Expand Up @@ -293,7 +293,7 @@ private static async Task<Group> CreateGroupAsync(string accessToken, PnPConnect
}

// Check if by now we've identified a user Id to become the owner
if (!string.IsNullOrEmpty(ownerId))
if (string.IsNullOrEmpty(ownerId))
{
var contextSettings = connection.Context.GetContextSettings();

Expand Down

0 comments on commit 8aba935

Please sign in to comment.