1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 17:42:49 -05:00

overwrite existing users on import

This commit is contained in:
Kyle Spearrin
2019-05-06 21:31:20 -04:00
parent afdf29da78
commit 0c760cf9e1
4 changed files with 24 additions and 3 deletions

View File

@ -1143,7 +1143,8 @@ namespace Bit.Core.Services
Guid importingUserId,
IEnumerable<ImportedGroup> groups,
IEnumerable<ImportedOrganizationUser> newUsers,
IEnumerable<string> removeUserExternalIds)
IEnumerable<string> removeUserExternalIds,
bool overwriteExisting)
{
var organization = await GetOrgById(organizationId);
if(organization == null)
@ -1181,6 +1182,23 @@ namespace Bit.Core.Services
}
}
if(overwriteExisting)
{
// Remove existing external users that are not in new user set
foreach(var user in existingExternalUsers)
{
if(!newUsersSet.Contains(user.ExternalId) &&
existingExternalUsersIdDict.ContainsKey(user.ExternalId))
{
await _organizationUserRepository.DeleteAsync(new OrganizationUser
{
Id = user.Id
});
existingExternalUsersIdDict.Remove(user.ExternalId);
}
}
}
if(newUsers?.Any() ?? false)
{
// Marry existing users