1
0
mirror of https://github.com/bitwarden/directory-connector synced 2025-12-16 00:04:34 +00:00

recursively build out member groups

This commit is contained in:
Kyle Spearrin
2017-05-12 18:07:11 -04:00
parent a7d9b0db42
commit f3646aa1e6
2 changed files with 11 additions and 7 deletions

View File

@@ -18,11 +18,11 @@ namespace Bit.Core.Models
public string Name { get; set; }
public HashSet<string> Members { get; set; } = new HashSet<string>();
public List<GroupEntry> GroupMembers { get; set; } = new List<GroupEntry>();
public List<UserEntry> UserMembers { get; set; } = new List<UserEntry>();
}
public class UserEntry : Entry
{
public string Email { get; set; }
public List<GroupEntry> Groups { get; set; } = new List<GroupEntry>();
}
}

View File

@@ -168,12 +168,12 @@ namespace Bit.Core.Utilities
users = await SyncUsersAsync();
}
AssociateMembers(ref groups, ref users);
AssociateGroups(groups, users);
}
private static void AssociateMembers(ref List<GroupEntry> groups, ref List<UserEntry> users)
private static void AssociateGroups(List<GroupEntry> groups, List<UserEntry> users)
{
if(groups == null)
if(groups == null || !groups.Any())
{
return;
}
@@ -186,12 +186,16 @@ namespace Bit.Core.Utilities
if(users != null)
{
group.UserMembers = users.Where(u => group.Members.Contains(u.DistinguishedName)).ToList();
var usersInThisGroup = users.Where(u => group.Members.Contains(u.DistinguishedName)).ToList();
foreach(var user in usersInThisGroup)
{
user.Groups.Add(group);
}
}
AssociateGroups(group.GroupMembers, users);
}
}
// TODO: Handle nested group associations with recursion
}
private static DateTime? ParseDate(ResultPropertyCollection collection, string dateKey)