diff --git a/src/Api/Controllers/LoginsController.cs b/src/Api/Controllers/LoginsController.cs index fcd78a7e29..1d9a363556 100644 --- a/src/Api/Controllers/LoginsController.cs +++ b/src/Api/Controllers/LoginsController.cs @@ -61,6 +61,20 @@ namespace Bit.Api.Controllers return new ListResponseModel(responses); } + [HttpGet("{id}/admin")] + public async Task 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 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 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 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 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)