1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05:00

collection user refactor

This commit is contained in:
Kyle Spearrin
2017-05-11 14:52:35 -04:00
parent d7f9977382
commit 21d1cd6adc
43 changed files with 318 additions and 504 deletions

View File

@ -17,20 +17,17 @@ namespace Bit.Api.Controllers
public class CollectionsController : Controller
{
private readonly ICollectionRepository _collectionRepository;
private readonly ICollectionUserRepository _collectionUserRepository;
private readonly ICollectionService _collectionService;
private readonly IUserService _userService;
private readonly CurrentContext _currentContext;
public CollectionsController(
ICollectionRepository collectionRepository,
ICollectionUserRepository collectionUserRepository,
ICollectionService collectionService,
IUserService userService,
CurrentContext currentContext)
{
_collectionRepository = collectionRepository;
_collectionUserRepository = collectionUserRepository;
_collectionService = collectionService;
_userService = userService;
_currentContext = currentContext;
@ -82,6 +79,24 @@ namespace Bit.Api.Controllers
return new ListResponseModel<CollectionResponseModel>(responses);
}
[HttpGet("{id}/users")]
public async Task<ListResponseModel<CollectionUserResponseModel>> GetUsers(string orgId, string id)
{
var idGuid = new Guid(id);
var collection = await _collectionRepository.GetByIdAsync(idGuid);
if(collection == null || !_currentContext.OrganizationAdmin(collection.OrganizationId))
{
throw new NotFoundException();
}
var collectionUsers = await _collectionRepository.GetManyUserDetailsByIdAsync(collection.OrganizationId,
collection.Id);
var responses = collectionUsers.Select(c => new CollectionUserResponseModel(c));
return new ListResponseModel<CollectionUserResponseModel>(responses);
}
[HttpPost("")]
public async Task<CollectionResponseModel> Post(string orgId, [FromBody]CollectionRequestModel model)
{
@ -123,5 +138,18 @@ namespace Bit.Api.Controllers
await _collectionRepository.DeleteAsync(collection);
}
[HttpDelete("{id}/user/{orgUserId}")]
[HttpPost("{id}/delete-user/{orgUserId}")]
public async Task Delete(string orgId, string id, string orgUserId)
{
var collection = await _collectionRepository.GetByIdAsync(new Guid(id));
if(collection == null || !_currentContext.OrganizationAdmin(collection.OrganizationId))
{
throw new NotFoundException();
}
await _collectionRepository.DeleteUserAsync(collection.Id, new Guid(orgUserId));
}
}
}