1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-27 17:47:37 +01:00

restore dep. login admin apis

This commit is contained in:
Kyle Spearrin 2017-09-27 22:04:01 -04:00
parent 825f7b8bb9
commit c135a2a166

View File

@ -61,6 +61,20 @@ namespace Bit.Api.Controllers
return new ListResponseModel<LoginResponseModel>(responses);
}
[HttpGet("{id}/admin")]
public async Task<LoginResponseModel> GetAdmin(string id)
{
var login = await _cipherRepository.GetDetailsByIdAsync(new Guid(id));
if(login == null || !login.OrganizationId.HasValue ||
!_currentContext.OrganizationAdmin(login.OrganizationId.Value))
{
throw new NotFoundException();
}
var response = new LoginResponseModel(login, _globalSettings, login.OrganizationUseTotp);
return response;
}
[HttpPost("")]
public async Task<LoginResponseModel> Post([FromBody]LoginRequestModel model)
{
@ -71,7 +85,23 @@ namespace Bit.Api.Controllers
var response = new LoginResponseModel(login, _globalSettings);
return response;
}
[HttpPost("admin")]
public async Task<LoginResponseModel> PostAdmin([FromBody]LoginRequestModel model)
{
var login = model.ToOrganizationCipher();
if(!_currentContext.OrganizationAdmin(login.OrganizationId.Value))
{
throw new NotFoundException();
}
var userId = _userService.GetProperUserId(User).Value;
await _cipherService.SaveAsync(login, userId, true);
var response = new LoginResponseModel(login, _globalSettings, false);
return response;
}
[HttpPut("{id}")]
[HttpPost("{id}")]
public async Task<LoginResponseModel> Put(string id, [FromBody]LoginRequestModel model)
@ -96,6 +126,26 @@ namespace Bit.Api.Controllers
return response;
}
[HttpPut("{id}/admin")]
[HttpPost("{id}/admin")]
public async Task<LoginResponseModel> PutAdmin(string id, [FromBody]LoginRequestModel model)
{
var userId = _userService.GetProperUserId(User).Value;
var login = await _cipherRepository.GetDetailsByIdAsync(new Guid(id));
if(login == null || !login.OrganizationId.HasValue ||
!_currentContext.OrganizationAdmin(login.OrganizationId.Value))
{
throw new NotFoundException();
}
// object cannot be a descendant of CipherDetails, so let's clone it.
var cipher = Core.Utilities.CoreHelpers.CloneObject(model.ToCipher(login));
await _cipherService.SaveAsync(cipher, userId, true);
var response = new LoginResponseModel(cipher, _globalSettings, login.OrganizationUseTotp);
return response;
}
[HttpDelete("{id}")]
[HttpPost("{id}/delete")]
public async Task Delete(string id)