Skip to content

Commit

Permalink
Merge pull request #96 from NoxOrg/bugfix/not-all-users-are-added-to-…
Browse files Browse the repository at this point in the history
…projects

- fixed issue with some users not added to projects
  • Loading branch information
jan-schutte authored Sep 20, 2023
2 parents 61a5fac + f1011ce commit 4d2a163
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.Graph.Client;
using Microsoft.VisualStudio.Services.WebApi;
using Nox.Cli.Abstractions;
Expand Down Expand Up @@ -122,29 +123,34 @@ private async Task<bool> AddTeamMembers(INoxWorkflowContext ctx)
ctx.SetErrorMessage($"Unable to find the default project Team' that should automatically have been created with the project");
return false;
}

var usersInGraph = _graphClient.ListUsersAsync(new string[] {"aad"}).Result;

var members = _members!.Split(',').ToList();

var allUsers = new List<GraphUser>();

var usersInGraph = await _graphClient.ListUsersAsync(new string[] {"aad"});
allUsers.AddRange(usersInGraph.GraphUsers);

while (usersInGraph.ContinuationToken is not null)
{
foreach (var user in usersInGraph.GraphUsers.OrderBy(u => u.DisplayName))
usersInGraph = await _graphClient.ListUsersAsync(new string[] {"aad"}, continuationToken: usersInGraph.ContinuationToken.FirstOrDefault());
allUsers.AddRange(usersInGraph.GraphUsers);
}

foreach (var member in members)
{
var developer = allUsers.FirstOrDefault(gu => gu.PrincipalName.Equals(member, StringComparison.OrdinalIgnoreCase));
if (developer != null)
{
var developer = members!.FirstOrDefault(d => d.Equals(user.PrincipalName, StringComparison.OrdinalIgnoreCase));

if (developer != null)
var isUserInGroup = await _graphClient.CheckMembershipExistenceAsync(developer.Descriptor, graphGroup.Descriptor);
if (!isUserInGroup)
{
var isUserInGroup = await _graphClient.CheckMembershipExistenceAsync(user.Descriptor, graphGroup.Descriptor);
if (!isUserInGroup)
{
var membership = await _graphClient.AddMembershipAsync(user.Descriptor, graphGroup.Descriptor);
}
var membership = await _graphClient.AddMembershipAsync(developer.Descriptor, graphGroup.Descriptor);
}
}
usersInGraph = await _graphClient.ListUsersAsync(new string[] {"aad"}, continuationToken: usersInGraph.ContinuationToken.FirstOrDefault());
}



return true;

}
Expand Down
2 changes: 1 addition & 1 deletion src/Nox.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Nox.Cli": {
"commandName": "Project",
"commandLineArgs": "test workflow",
"workingDirectory": "/home/jan/demo/CliDemo",
"workingDirectory": "/home/jan/demo/NoxCliDemoProject",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down

0 comments on commit 4d2a163

Please sign in to comment.