mirror of
https://github.com/bitwarden/server.git
synced 2025-01-22 21:51:22 +01:00
org sync fixes
This commit is contained in:
parent
a0ac7242b6
commit
56f9ea0207
@ -230,7 +230,7 @@ namespace Bit.Api.Controllers
|
||||
}
|
||||
|
||||
[HttpPost("{id}/import")]
|
||||
public Task Import(string id, [FromBody]ImportOrganizationUsersRequestModel model)
|
||||
public async Task Import(string id, [FromBody]ImportOrganizationUsersRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
@ -238,7 +238,9 @@ namespace Bit.Api.Controllers
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
return Task.FromResult(0);
|
||||
var userId = _userService.GetProperUserId(User);
|
||||
await _organizationService.ImportAsync(orgIdGuid, userId.Value, model.Groups.Select(g => g.ToGroup(orgIdGuid)),
|
||||
model.Users.Select(u => u.ToKvp()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,5 +29,7 @@ namespace Bit.Core.Services
|
||||
Task SaveUserAsync(OrganizationUser user, Guid savingUserId, IEnumerable<SelectionReadOnly> collections);
|
||||
Task DeleteUserAsync(Guid organizationId, Guid organizationUserId, Guid deletingUserId);
|
||||
Task DeleteUserAsync(Guid organizationId, Guid userId);
|
||||
Task ImportAsync(Guid organizationId, Guid importingUserId, IEnumerable<Group> groups,
|
||||
IEnumerable<KeyValuePair<string, IEnumerable<string>>> users);
|
||||
}
|
||||
}
|
||||
|
@ -921,10 +921,12 @@ namespace Bit.Core.Services
|
||||
var newGroups = groups.Where(g => !existingGroupsDict.ContainsKey(g.ExternalId));
|
||||
var updateGroups = existingGroups.Where(eg => groups.Any(g => g.ExternalId == eg.ExternalId && g.Name != eg.Name));
|
||||
|
||||
var createdGroups = new List<Group>();
|
||||
foreach(var group in newGroups)
|
||||
{
|
||||
group.CreationDate = group.RevisionDate = DateTime.UtcNow;
|
||||
await _groupRepository.CreateAsync(group);
|
||||
createdGroups.Add(group);
|
||||
}
|
||||
|
||||
foreach(var group in updateGroups)
|
||||
@ -935,12 +937,12 @@ namespace Bit.Core.Services
|
||||
}
|
||||
|
||||
// Add the newly created groups to existing groups so that we have a complete list to reference below for users.
|
||||
existingGroups.AddRange(newGroups);
|
||||
existingGroups.AddRange(createdGroups);
|
||||
existingGroupsDict = existingGroups.ToDictionary(g => g.ExternalId);
|
||||
}
|
||||
|
||||
// Users
|
||||
if(users?.Any() ?? false)
|
||||
if(!users?.Any() ?? true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user