mirror of
https://github.com/bitwarden/server.git
synced 2025-05-22 12:04:27 -05:00
adjusted subvaults api
This commit is contained in:
parent
9fe28419a1
commit
7bff121eeb
@ -10,7 +10,7 @@ using Bit.Core.Services;
|
|||||||
|
|
||||||
namespace Bit.Api.Controllers
|
namespace Bit.Api.Controllers
|
||||||
{
|
{
|
||||||
[Route("subvaults")]
|
[Route("organizations/{orgId}/subvaults")]
|
||||||
[Authorize("Application")]
|
[Authorize("Application")]
|
||||||
public class SubvaultsController : Controller
|
public class SubvaultsController : Controller
|
||||||
{
|
{
|
||||||
@ -26,7 +26,7 @@ namespace Bit.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public async Task<SubvaultResponseModel> Get(string id)
|
public async Task<SubvaultResponseModel> Get(string orgId, string id)
|
||||||
{
|
{
|
||||||
var userId = _userService.GetProperUserId(User).Value;
|
var userId = _userService.GetProperUserId(User).Value;
|
||||||
var subvault = await _subvaultRepository.GetByIdAdminUserIdAsync(new Guid(id), userId);
|
var subvault = await _subvaultRepository.GetByIdAdminUserIdAsync(new Guid(id), userId);
|
||||||
@ -38,7 +38,7 @@ namespace Bit.Api.Controllers
|
|||||||
return new SubvaultResponseModel(subvault);
|
return new SubvaultResponseModel(subvault);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("")]
|
[HttpGet("~/subvaults")]
|
||||||
public async Task<ListResponseModel<SubvaultResponseModel>> Get()
|
public async Task<ListResponseModel<SubvaultResponseModel>> Get()
|
||||||
{
|
{
|
||||||
var subvaults = await _subvaultRepository.GetManyByUserIdAsync(_userService.GetProperUserId(User).Value);
|
var subvaults = await _subvaultRepository.GetManyByUserIdAsync(_userService.GetProperUserId(User).Value);
|
||||||
@ -46,27 +46,27 @@ namespace Bit.Api.Controllers
|
|||||||
return new ListResponseModel<SubvaultResponseModel>(responses);
|
return new ListResponseModel<SubvaultResponseModel>(responses);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("organization/{organizationId}")]
|
[HttpGet("")]
|
||||||
public async Task<ListResponseModel<SubvaultResponseModel>> GetByOrganization(string organizationId)
|
public async Task<ListResponseModel<SubvaultResponseModel>> GetByOrganization(string orgId)
|
||||||
{
|
{
|
||||||
var subvaults = await _subvaultRepository.GetManyByOrganizationIdAdminUserIdAsync(new Guid(organizationId),
|
var subvaults = await _subvaultRepository.GetManyByOrganizationIdAdminUserIdAsync(new Guid(orgId),
|
||||||
_userService.GetProperUserId(User).Value);
|
_userService.GetProperUserId(User).Value);
|
||||||
var responses = subvaults.Select(s => new SubvaultResponseModel(s));
|
var responses = subvaults.Select(s => new SubvaultResponseModel(s));
|
||||||
return new ListResponseModel<SubvaultResponseModel>(responses);
|
return new ListResponseModel<SubvaultResponseModel>(responses);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("")]
|
[HttpPost("")]
|
||||||
public async Task<SubvaultResponseModel> Post([FromBody]SubvaultCreateRequestModel model)
|
public async Task<SubvaultResponseModel> Post(string orgId, [FromBody]SubvaultRequestModel model)
|
||||||
{
|
{
|
||||||
// TODO: permission check
|
// TODO: permission check
|
||||||
var subvault = model.ToSubvault();
|
var subvault = model.ToSubvault(new Guid(orgId));
|
||||||
await _subvaultRepository.CreateAsync(subvault);
|
await _subvaultRepository.CreateAsync(subvault);
|
||||||
return new SubvaultResponseModel(subvault);
|
return new SubvaultResponseModel(subvault);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[HttpPost("{id}")]
|
[HttpPost("{id}")]
|
||||||
public async Task<SubvaultResponseModel> Put(string id, [FromBody]SubvaultUpdateRequestModel model)
|
public async Task<SubvaultResponseModel> Put(string orgId, string id, [FromBody]SubvaultRequestModel model)
|
||||||
{
|
{
|
||||||
var subvault = await _subvaultRepository.GetByIdAdminUserIdAsync(new Guid(id),
|
var subvault = await _subvaultRepository.GetByIdAdminUserIdAsync(new Guid(id),
|
||||||
_userService.GetProperUserId(User).Value);
|
_userService.GetProperUserId(User).Value);
|
||||||
@ -81,7 +81,7 @@ namespace Bit.Api.Controllers
|
|||||||
|
|
||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
[HttpPost("{id}/delete")]
|
[HttpPost("{id}/delete")]
|
||||||
public async Task Delete(string id)
|
public async Task Delete(string orgId, string id)
|
||||||
{
|
{
|
||||||
var subvault = await _subvaultRepository.GetByIdAdminUserIdAsync(new Guid(id),
|
var subvault = await _subvaultRepository.GetByIdAdminUserIdAsync(new Guid(id),
|
||||||
_userService.GetProperUserId(User).Value);
|
_userService.GetProperUserId(User).Value);
|
||||||
|
@ -6,26 +6,21 @@ using Newtonsoft.Json;
|
|||||||
|
|
||||||
namespace Bit.Core.Models.Api
|
namespace Bit.Core.Models.Api
|
||||||
{
|
{
|
||||||
public class SubvaultCreateRequestModel : SubvaultUpdateRequestModel
|
public class SubvaultRequestModel
|
||||||
{
|
|
||||||
public string OrganizationId { get; set; }
|
|
||||||
|
|
||||||
public Subvault ToSubvault()
|
|
||||||
{
|
|
||||||
return ToSubvault(new Subvault
|
|
||||||
{
|
|
||||||
OrganizationId = new Guid(OrganizationId)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SubvaultUpdateRequestModel
|
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
[EncryptedString]
|
[EncryptedString]
|
||||||
[StringLength(300)]
|
[StringLength(300)]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public Subvault ToSubvault(Guid orgId)
|
||||||
|
{
|
||||||
|
return ToSubvault(new Subvault
|
||||||
|
{
|
||||||
|
OrganizationId = orgId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public Subvault ToSubvault(Subvault existingSubvault)
|
public Subvault ToSubvault(Subvault existingSubvault)
|
||||||
{
|
{
|
||||||
existingSubvault.Name = Name;
|
existingSubvault.Name = Name;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user