mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 00:22:50 -05:00
renaming subvault => collection
This commit is contained in:
@ -17,7 +17,7 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
private readonly ICipherRepository _cipherRepository;
|
||||
private readonly IFolderRepository _folderRepository;
|
||||
private readonly ISubvaultCipherRepository _subvaultCipherRepository;
|
||||
private readonly ICollectionCipherRepository _collectionCipherRepository;
|
||||
private readonly ICipherService _cipherService;
|
||||
private readonly IUserService _userService;
|
||||
private readonly CurrentContext _currentContext;
|
||||
@ -25,14 +25,14 @@ namespace Bit.Api.Controllers
|
||||
public CiphersController(
|
||||
ICipherRepository cipherRepository,
|
||||
IFolderRepository folderRepository,
|
||||
ISubvaultCipherRepository subvaultCipherRepository,
|
||||
ICollectionCipherRepository collectionCipherRepository,
|
||||
ICipherService cipherService,
|
||||
IUserService userService,
|
||||
CurrentContext currentContext)
|
||||
{
|
||||
_cipherRepository = cipherRepository;
|
||||
_folderRepository = folderRepository;
|
||||
_subvaultCipherRepository = subvaultCipherRepository;
|
||||
_collectionCipherRepository = collectionCipherRepository;
|
||||
_cipherService = cipherService;
|
||||
_userService = userService;
|
||||
_currentContext = currentContext;
|
||||
@ -62,8 +62,8 @@ namespace Bit.Api.Controllers
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var subvaultCiphers = await _subvaultCipherRepository.GetManyByUserIdCipherIdAsync(userId, cipherId);
|
||||
return new CipherFullDetailsResponseModel(cipher, subvaultCiphers);
|
||||
var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdCipherIdAsync(userId, cipherId);
|
||||
return new CipherFullDetailsResponseModel(cipher, collectionCiphers);
|
||||
}
|
||||
|
||||
[HttpGet("")]
|
||||
@ -91,20 +91,20 @@ namespace Bit.Api.Controllers
|
||||
}
|
||||
|
||||
[HttpGet("details")]
|
||||
public async Task<ListResponseModel<CipherDetailsResponseModel>> GetSubvaults()
|
||||
public async Task<ListResponseModel<CipherDetailsResponseModel>> GetCollections()
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var ciphers = await _cipherRepository.GetManyByUserIdHasSubvaultsAsync(userId);
|
||||
var ciphers = await _cipherRepository.GetManyByUserIdHasCollectionsAsync(userId);
|
||||
|
||||
var subvaultCiphers = await _subvaultCipherRepository.GetManyByUserIdAsync(userId);
|
||||
var subvaultCiphersGroupDict = subvaultCiphers.GroupBy(s => s.CipherId).ToDictionary(s => s.Key);
|
||||
var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(userId);
|
||||
var collectionCiphersGroupDict = collectionCiphers.GroupBy(s => s.CipherId).ToDictionary(s => s.Key);
|
||||
|
||||
var responses = ciphers.Select(c => new CipherDetailsResponseModel(c, subvaultCiphersGroupDict));
|
||||
var responses = ciphers.Select(c => new CipherDetailsResponseModel(c, collectionCiphersGroupDict));
|
||||
return new ListResponseModel<CipherDetailsResponseModel>(responses);
|
||||
}
|
||||
|
||||
[HttpGet("organization-details")]
|
||||
public async Task<ListResponseModel<CipherMiniDetailsResponseModel>> GetOrganizationSubvaults(string organizationId)
|
||||
public async Task<ListResponseModel<CipherMiniDetailsResponseModel>> GetOrganizationCollections(string organizationId)
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var orgIdGuid = new Guid(organizationId);
|
||||
@ -115,10 +115,10 @@ namespace Bit.Api.Controllers
|
||||
|
||||
var ciphers = await _cipherRepository.GetManyByOrganizationIdAsync(orgIdGuid);
|
||||
|
||||
var subvaultCiphers = await _subvaultCipherRepository.GetManyByOrganizationIdAsync(orgIdGuid);
|
||||
var subvaultCiphersGroupDict = subvaultCiphers.GroupBy(s => s.CipherId).ToDictionary(s => s.Key);
|
||||
var collectionCiphers = await _collectionCipherRepository.GetManyByOrganizationIdAsync(orgIdGuid);
|
||||
var collectionCiphersGroupDict = collectionCiphers.GroupBy(s => s.CipherId).ToDictionary(s => s.Key);
|
||||
|
||||
var responses = ciphers.Select(c => new CipherMiniDetailsResponseModel(c, subvaultCiphersGroupDict));
|
||||
var responses = ciphers.Select(c => new CipherMiniDetailsResponseModel(c, collectionCiphersGroupDict));
|
||||
return new ListResponseModel<CipherMiniDetailsResponseModel>(responses);
|
||||
}
|
||||
|
||||
@ -179,12 +179,12 @@ namespace Bit.Api.Controllers
|
||||
}
|
||||
|
||||
await _cipherService.ShareAsync(model.Cipher.ToCipher(cipher), new Guid(model.Cipher.OrganizationId),
|
||||
model.SubvaultIds.Select(s => new Guid(s)), userId);
|
||||
model.CollectionIds.Select(s => new Guid(s)), userId);
|
||||
}
|
||||
|
||||
[HttpPut("{id}/subvaults")]
|
||||
[HttpPost("{id}/subvaults")]
|
||||
public async Task PutSubvaults(string id, [FromBody]CipherSubvaultsRequestModel model)
|
||||
[HttpPut("{id}/collections")]
|
||||
[HttpPost("{id}/collections")]
|
||||
public async Task PutCollections(string id, [FromBody]CipherCollectionsRequestModel model)
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
|
||||
@ -194,12 +194,12 @@ namespace Bit.Api.Controllers
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
await _cipherService.SaveSubvaultsAsync(cipher, model.SubvaultIds.Select(s => new Guid(s)), userId, false);
|
||||
await _cipherService.SaveCollectionsAsync(cipher, model.CollectionIds.Select(s => new Guid(s)), userId, false);
|
||||
}
|
||||
|
||||
[HttpPut("{id}/subvaults-admin")]
|
||||
[HttpPost("{id}/subvaults-admin")]
|
||||
public async Task PutSubvaultsAdmin(string id, [FromBody]CipherSubvaultsRequestModel model)
|
||||
[HttpPut("{id}/collections-admin")]
|
||||
[HttpPost("{id}/collections-admin")]
|
||||
public async Task PutCollectionsAdmin(string id, [FromBody]CipherCollectionsRequestModel model)
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id));
|
||||
@ -209,7 +209,7 @@ namespace Bit.Api.Controllers
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
await _cipherService.SaveSubvaultsAsync(cipher, model.SubvaultIds.Select(s => new Guid(s)), userId, true);
|
||||
await _cipherService.SaveCollectionsAsync(cipher, model.CollectionIds.Select(s => new Guid(s)), userId, true);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
|
@ -18,7 +18,7 @@ namespace Bit.Api.Controllers
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
private readonly IOrganizationService _organizationService;
|
||||
private readonly ISubvaultRepository _subvaultRepository;
|
||||
private readonly ICollectionRepository _collectionRepository;
|
||||
private readonly IUserService _userService;
|
||||
private readonly CurrentContext _currentContext;
|
||||
|
||||
@ -26,14 +26,14 @@ namespace Bit.Api.Controllers
|
||||
IOrganizationRepository organizationRepository,
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
IOrganizationService organizationService,
|
||||
ISubvaultRepository subvaultRepository,
|
||||
ICollectionRepository collectionRepository,
|
||||
IUserService userService,
|
||||
CurrentContext currentContext)
|
||||
{
|
||||
_organizationRepository = organizationRepository;
|
||||
_organizationUserRepository = organizationUserRepository;
|
||||
_organizationService = organizationService;
|
||||
_subvaultRepository = subvaultRepository;
|
||||
_collectionRepository = collectionRepository;
|
||||
_userService = userService;
|
||||
_currentContext = currentContext;
|
||||
}
|
||||
@ -75,7 +75,7 @@ namespace Bit.Api.Controllers
|
||||
|
||||
var userId = _userService.GetProperUserId(User);
|
||||
var result = await _organizationService.InviteUserAsync(orgGuidId, userId.Value, model.Email, model.Type.Value,
|
||||
model.AccessAllSubvaults, model.Subvaults?.Select(s => s.ToSubvaultUser()));
|
||||
model.AccessAllCollections, model.Collections?.Select(s => s.ToCollectionUser()));
|
||||
}
|
||||
|
||||
[HttpPut("{id}/reinvite")]
|
||||
@ -132,7 +132,7 @@ namespace Bit.Api.Controllers
|
||||
|
||||
var userId = _userService.GetProperUserId(User);
|
||||
await _organizationService.SaveUserAsync(model.ToOrganizationUser(organizationUser), userId.Value,
|
||||
model.Subvaults?.Select(s => s.ToSubvaultUser()));
|
||||
model.Collections?.Select(s => s.ToCollectionUser()));
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
|
@ -11,59 +11,59 @@ using Bit.Core;
|
||||
|
||||
namespace Bit.Api.Controllers
|
||||
{
|
||||
[Route("organizations/{orgId}/subvaultUsers")]
|
||||
[Route("organizations/{orgId}/collectionUsers")]
|
||||
[Authorize("Application")]
|
||||
public class SubvaultUsersController : Controller
|
||||
public class CollectionUsersController : Controller
|
||||
{
|
||||
private readonly ISubvaultRepository _subvaultRepository;
|
||||
private readonly ISubvaultUserRepository _subvaultUserRepository;
|
||||
private readonly ICollectionRepository _collectionRepository;
|
||||
private readonly ICollectionUserRepository _collectionUserRepository;
|
||||
private readonly IUserService _userService;
|
||||
private readonly CurrentContext _currentContext;
|
||||
|
||||
public SubvaultUsersController(
|
||||
ISubvaultRepository subvaultRepository,
|
||||
ISubvaultUserRepository subvaultUserRepository,
|
||||
public CollectionUsersController(
|
||||
ICollectionRepository collectionRepository,
|
||||
ICollectionUserRepository collectionUserRepository,
|
||||
IUserService userService,
|
||||
CurrentContext currentContext)
|
||||
{
|
||||
_subvaultRepository = subvaultRepository;
|
||||
_subvaultUserRepository = subvaultUserRepository;
|
||||
_collectionRepository = collectionRepository;
|
||||
_collectionUserRepository = collectionUserRepository;
|
||||
_userService = userService;
|
||||
_currentContext = currentContext;
|
||||
}
|
||||
|
||||
[HttpGet("{subvaultId}")]
|
||||
public async Task<ListResponseModel<SubvaultUserResponseModel>> GetBySubvault(string orgId, string subvaultId)
|
||||
[HttpGet("{collectionId}")]
|
||||
public async Task<ListResponseModel<CollectionUserResponseModel>> GetByCollection(string orgId, string collectionId)
|
||||
{
|
||||
var subvaultIdGuid = new Guid(subvaultId);
|
||||
var subvault = await _subvaultRepository.GetByIdAsync(subvaultIdGuid);
|
||||
if(subvault == null || !_currentContext.OrganizationAdmin(subvault.OrganizationId))
|
||||
var collectionIdGuid = new Guid(collectionId);
|
||||
var collection = await _collectionRepository.GetByIdAsync(collectionIdGuid);
|
||||
if(collection == null || !_currentContext.OrganizationAdmin(collection.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var subvaultUsers = await _subvaultUserRepository.GetManyDetailsBySubvaultIdAsync(subvaultIdGuid);
|
||||
var responses = subvaultUsers.Select(s => new SubvaultUserResponseModel(s));
|
||||
return new ListResponseModel<SubvaultUserResponseModel>(responses);
|
||||
var collectionUsers = await _collectionUserRepository.GetManyDetailsByCollectionIdAsync(collectionIdGuid);
|
||||
var responses = collectionUsers.Select(s => new CollectionUserResponseModel(s));
|
||||
return new ListResponseModel<CollectionUserResponseModel>(responses);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[HttpPost("{id}/delete")]
|
||||
public async Task Delete(string orgId, string id)
|
||||
{
|
||||
var user = await _subvaultUserRepository.GetByIdAsync(new Guid(id));
|
||||
var user = await _collectionUserRepository.GetByIdAsync(new Guid(id));
|
||||
if(user == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var subvault = await _subvaultRepository.GetByIdAsync(user.SubvaultId);
|
||||
if(subvault == null || !_currentContext.OrganizationAdmin(subvault.OrganizationId))
|
||||
var collection = await _collectionRepository.GetByIdAsync(user.CollectionId);
|
||||
if(collection == null || !_currentContext.OrganizationAdmin(collection.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
await _subvaultUserRepository.DeleteAsync(user);
|
||||
await _collectionUserRepository.DeleteAsync(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,41 +11,41 @@ using Bit.Core;
|
||||
|
||||
namespace Bit.Api.Controllers
|
||||
{
|
||||
[Route("organizations/{orgId}/subvaults")]
|
||||
[Route("organizations/{orgId}/collections")]
|
||||
[Authorize("Application")]
|
||||
public class SubvaultsController : Controller
|
||||
public class CollectionsController : Controller
|
||||
{
|
||||
private readonly ISubvaultRepository _subvaultRepository;
|
||||
private readonly ISubvaultService _subvaultService;
|
||||
private readonly ICollectionRepository _collectionRepository;
|
||||
private readonly ICollectionService _collectionService;
|
||||
private readonly IUserService _userService;
|
||||
private readonly CurrentContext _currentContext;
|
||||
|
||||
public SubvaultsController(
|
||||
ISubvaultRepository subvaultRepository,
|
||||
ISubvaultService subvaultService,
|
||||
public CollectionsController(
|
||||
ICollectionRepository collectionRepository,
|
||||
ICollectionService collectionService,
|
||||
IUserService userService,
|
||||
CurrentContext currentContext)
|
||||
{
|
||||
_subvaultRepository = subvaultRepository;
|
||||
_subvaultService = subvaultService;
|
||||
_collectionRepository = collectionRepository;
|
||||
_collectionService = collectionService;
|
||||
_userService = userService;
|
||||
_currentContext = currentContext;
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<SubvaultResponseModel> Get(string orgId, string id)
|
||||
public async Task<CollectionResponseModel> Get(string orgId, string id)
|
||||
{
|
||||
var subvault = await _subvaultRepository.GetByIdAsync(new Guid(id));
|
||||
if(subvault == null || !_currentContext.OrganizationAdmin(subvault.OrganizationId))
|
||||
var collection = await _collectionRepository.GetByIdAsync(new Guid(id));
|
||||
if(collection == null || !_currentContext.OrganizationAdmin(collection.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
return new SubvaultResponseModel(subvault);
|
||||
return new CollectionResponseModel(collection);
|
||||
}
|
||||
|
||||
[HttpGet("")]
|
||||
public async Task<ListResponseModel<SubvaultResponseModel>> Get(string orgId)
|
||||
public async Task<ListResponseModel<CollectionResponseModel>> Get(string orgId)
|
||||
{
|
||||
var orgIdGuid = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
@ -53,21 +53,21 @@ namespace Bit.Api.Controllers
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var subvaults = await _subvaultRepository.GetManyByOrganizationIdAsync(orgIdGuid);
|
||||
var responses = subvaults.Select(s => new SubvaultResponseModel(s));
|
||||
return new ListResponseModel<SubvaultResponseModel>(responses);
|
||||
var collections = await _collectionRepository.GetManyByOrganizationIdAsync(orgIdGuid);
|
||||
var responses = collections.Select(s => new CollectionResponseModel(s));
|
||||
return new ListResponseModel<CollectionResponseModel>(responses);
|
||||
}
|
||||
|
||||
[HttpGet("~/subvaults")]
|
||||
public async Task<ListResponseModel<SubvaultResponseModel>> GetUser()
|
||||
[HttpGet("~/collections")]
|
||||
public async Task<ListResponseModel<CollectionResponseModel>> GetUser()
|
||||
{
|
||||
var subvaults = await _subvaultRepository.GetManyByUserIdAsync(_userService.GetProperUserId(User).Value);
|
||||
var responses = subvaults.Select(s => new SubvaultResponseModel(s));
|
||||
return new ListResponseModel<SubvaultResponseModel>(responses);
|
||||
var collections = await _collectionRepository.GetManyByUserIdAsync(_userService.GetProperUserId(User).Value);
|
||||
var responses = collections.Select(s => new CollectionResponseModel(s));
|
||||
return new ListResponseModel<CollectionResponseModel>(responses);
|
||||
}
|
||||
|
||||
[HttpPost("")]
|
||||
public async Task<SubvaultResponseModel> Post(string orgId, [FromBody]SubvaultRequestModel model)
|
||||
public async Task<CollectionResponseModel> Post(string orgId, [FromBody]CollectionRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(orgId);
|
||||
if(!_currentContext.OrganizationAdmin(orgIdGuid))
|
||||
@ -75,36 +75,36 @@ namespace Bit.Api.Controllers
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var subvault = model.ToSubvault(orgIdGuid);
|
||||
await _subvaultService.SaveAsync(subvault);
|
||||
return new SubvaultResponseModel(subvault);
|
||||
var collection = model.ToCollection(orgIdGuid);
|
||||
await _collectionService.SaveAsync(collection);
|
||||
return new CollectionResponseModel(collection);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
[HttpPost("{id}")]
|
||||
public async Task<SubvaultResponseModel> Put(string orgId, string id, [FromBody]SubvaultRequestModel model)
|
||||
public async Task<CollectionResponseModel> Put(string orgId, string id, [FromBody]CollectionRequestModel model)
|
||||
{
|
||||
var subvault = await _subvaultRepository.GetByIdAsync(new Guid(id));
|
||||
if(subvault == null || !_currentContext.OrganizationAdmin(subvault.OrganizationId))
|
||||
var collection = await _collectionRepository.GetByIdAsync(new Guid(id));
|
||||
if(collection == null || !_currentContext.OrganizationAdmin(collection.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
await _subvaultService.SaveAsync(model.ToSubvault(subvault));
|
||||
return new SubvaultResponseModel(subvault);
|
||||
await _collectionService.SaveAsync(model.ToCollection(collection));
|
||||
return new CollectionResponseModel(collection);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[HttpPost("{id}/delete")]
|
||||
public async Task Delete(string orgId, string id)
|
||||
{
|
||||
var subvault = await _subvaultRepository.GetByIdAsync(new Guid(id));
|
||||
if(subvault == null || !_currentContext.OrganizationAdmin(subvault.OrganizationId))
|
||||
var collection = await _collectionRepository.GetByIdAsync(new Guid(id));
|
||||
if(collection == null || !_currentContext.OrganizationAdmin(collection.OrganizationId))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
await _subvaultRepository.DeleteAsync(subvault);
|
||||
await _collectionRepository.DeleteAsync(collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user