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

Make New-PnPTeamsTeam work with Managed Identity #3351

Merged
merged 2 commits into from
Sep 2, 2023
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
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
Loading