mirror of
https://github.com/bitwarden/server.git
synced 2024-12-22 16:57:36 +01:00
overwrite existing users on import
This commit is contained in:
parent
afdf29da78
commit
0c760cf9e1
@ -376,7 +376,8 @@ namespace Bit.Api.Controllers
|
||||
userId.Value,
|
||||
model.Groups.Select(g => g.ToImportedGroup(orgIdGuid)),
|
||||
model.Users.Where(u => !u.Deleted).Select(u => u.ToImportedOrganizationUser()),
|
||||
model.Users.Where(u => u.Deleted).Select(u => u.ExternalId));
|
||||
model.Users.Where(u => u.Deleted).Select(u => u.ExternalId),
|
||||
model.OverwriteExisting);
|
||||
}
|
||||
|
||||
[HttpPost("{id}/api-key")]
|
||||
|
@ -10,6 +10,7 @@ namespace Bit.Core.Models.Api
|
||||
{
|
||||
public Group[] Groups { get; set; }
|
||||
public User[] Users { get; set; }
|
||||
public bool OverwriteExisting { get; set; }
|
||||
|
||||
public class Group
|
||||
{
|
||||
|
@ -42,7 +42,8 @@ namespace Bit.Core.Services
|
||||
Task<OrganizationLicense> GenerateLicenseAsync(Guid organizationId, Guid installationId);
|
||||
Task<OrganizationLicense> GenerateLicenseAsync(Organization organization, Guid installationId);
|
||||
Task ImportAsync(Guid organizationId, Guid importingUserId, IEnumerable<ImportedGroup> groups,
|
||||
IEnumerable<ImportedOrganizationUser> newUsers, IEnumerable<string> removeUserExternalIds);
|
||||
IEnumerable<ImportedOrganizationUser> newUsers, IEnumerable<string> removeUserExternalIds,
|
||||
bool overwriteExisting);
|
||||
Task RotateApiKeyAsync(Organization organization);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user