Skip to content

Commit

Permalink
Merge pull request #3351 from damsleth/fix-new-team-with-mngd-id
Browse files Browse the repository at this point in the history
Make New-PnPTeamsTeam work with Managed Identity
  • Loading branch information
KoenZomers authored Sep 2, 2023
2 parents 3a6bb1c + e4b3bc6 commit 0f2d560
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed `New-PnPTeamsTeam` cmdlet, it will now throw error if it fails to teamify a Microsoft 365 group. [#3310](https://github.com/pnp/powershell/pull/3310)
- Fixed `Connect-PnPOnline` cmdlet throwing host not reachable errors. [#3337](https://github.com/pnp/powershell/pull/3337)
- Fixed `Set-PnPTerm` cmdlet throwing object reference error when only the term Id is specified. [#3341](https://github.com/pnp/powershell/pull/3341)
- Fixed `New-PnPTeamsTeam` cmdlet throwing an error when specifying members [#3351](https://github.com/pnp/powershell/pull/3351)
- Fixed `New-PnPTeamsTeam` cmdlet not working well with a managed identity [#3351](https://github.com/pnp/powershell/pull/3351)

### Changed

Expand All @@ -47,6 +49,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Contributors

- Carl Joakim Damsleth [damsleth]
- Rodel Pacurib [ryder-cayden]
- [CatSchneider]
- [msjennywu]
Expand Down
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 0f2d560

Please sign in to comment.