mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-18 17:23:27 +00:00
recursively build out member groups
This commit is contained in:
@@ -18,11 +18,11 @@ namespace Bit.Core.Models
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public HashSet<string> Members { get; set; } = new HashSet<string>();
|
public HashSet<string> Members { get; set; } = new HashSet<string>();
|
||||||
public List<GroupEntry> GroupMembers { get; set; } = new List<GroupEntry>();
|
public List<GroupEntry> GroupMembers { get; set; } = new List<GroupEntry>();
|
||||||
public List<UserEntry> UserMembers { get; set; } = new List<UserEntry>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UserEntry : Entry
|
public class UserEntry : Entry
|
||||||
{
|
{
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
|
public List<GroupEntry> Groups { get; set; } = new List<GroupEntry>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,12 +168,12 @@ namespace Bit.Core.Utilities
|
|||||||
users = await SyncUsersAsync();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@@ -186,12 +186,16 @@ namespace Bit.Core.Utilities
|
|||||||
|
|
||||||
if(users != null)
|
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)
|
private static DateTime? ParseDate(ResultPropertyCollection collection, string dateKey)
|
||||||
|
|||||||
Reference in New Issue
Block a user