2023-11-02 01:14:40 +10:00
|
|
|
|
using Bit.Api.AdminConsole.Models.Request;
|
|
|
|
|
|
using Bit.Api.AdminConsole.Models.Response;
|
2023-06-15 14:54:08 -07:00
|
|
|
|
using Bit.Api.Models.Response;
|
[AC-1191] TDE admin approval email (#3044)
* feat: add new command for updating request and emailing user, refs AC-1191
* feat: inject service with organization service collection extensions, refs AC-1191
* feat: add function to send admin approval email to mail services (interface/noop/handlebars), refs AC-1191
* feat: add html/text mail templates and add view model for email data, refs AC-1191
* feat: update org auth request controller to use new command during auth request update, refs AC-1191
* fix: dotnet format, refs AC-1191
* refactor: update user not found error, FirstOrDefault for enum type display name, refs AC-1191
* refactor: update user not found to log error instead of throws, refs AC-1191
* fix: remove whitespace lint errors, refs AC-1191
* refactor: update hardcoded UTC timezone string, refs AC-1191
* refactor: add unit test for new command, refs AC-1191
* refactor: improve enum name fallback and identifier string creation, refs AC-1191
* refactor: add addtional unit tests, refs AC-1191
* refactor: update success test to use more generated params, refs AC-1191
* fix: dotnet format...again, refs AC-1191
* refactor: make UTC display a constant for handlebars mail service, refs AC-1191
* refactor: update displayTypeIdentifer to displayTypeAndIdentifier for clarity, refs AC-1191
2023-07-06 10:03:49 -05:00
|
|
|
|
using Bit.Core.AdminConsole.OrganizationAuth.Interfaces;
|
2023-06-15 14:54:08 -07:00
|
|
|
|
using Bit.Core.Auth.Models.Api.Request.AuthRequest;
|
|
|
|
|
|
using Bit.Core.Auth.Services;
|
|
|
|
|
|
using Bit.Core.Context;
|
|
|
|
|
|
using Bit.Core.Exceptions;
|
|
|
|
|
|
using Bit.Core.Repositories;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
2023-10-27 07:47:44 +10:00
|
|
|
|
namespace Bit.Api.AdminConsole.Controllers;
|
2023-06-15 14:54:08 -07:00
|
|
|
|
|
|
|
|
|
|
[Route("organizations/{orgId}/auth-requests")]
|
|
|
|
|
|
[Authorize("Application")]
|
|
|
|
|
|
public class OrganizationAuthRequestsController : Controller
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IAuthRequestRepository _authRequestRepository;
|
|
|
|
|
|
private readonly ICurrentContext _currentContext;
|
|
|
|
|
|
private readonly IAuthRequestService _authRequestService;
|
[AC-1191] TDE admin approval email (#3044)
* feat: add new command for updating request and emailing user, refs AC-1191
* feat: inject service with organization service collection extensions, refs AC-1191
* feat: add function to send admin approval email to mail services (interface/noop/handlebars), refs AC-1191
* feat: add html/text mail templates and add view model for email data, refs AC-1191
* feat: update org auth request controller to use new command during auth request update, refs AC-1191
* fix: dotnet format, refs AC-1191
* refactor: update user not found error, FirstOrDefault for enum type display name, refs AC-1191
* refactor: update user not found to log error instead of throws, refs AC-1191
* fix: remove whitespace lint errors, refs AC-1191
* refactor: update hardcoded UTC timezone string, refs AC-1191
* refactor: add unit test for new command, refs AC-1191
* refactor: improve enum name fallback and identifier string creation, refs AC-1191
* refactor: add addtional unit tests, refs AC-1191
* refactor: update success test to use more generated params, refs AC-1191
* fix: dotnet format...again, refs AC-1191
* refactor: make UTC display a constant for handlebars mail service, refs AC-1191
* refactor: update displayTypeIdentifer to displayTypeAndIdentifier for clarity, refs AC-1191
2023-07-06 10:03:49 -05:00
|
|
|
|
private readonly IUpdateOrganizationAuthRequestCommand _updateOrganizationAuthRequestCommand;
|
2023-06-15 14:54:08 -07:00
|
|
|
|
|
|
|
|
|
|
public OrganizationAuthRequestsController(IAuthRequestRepository authRequestRepository,
|
[AC-1191] TDE admin approval email (#3044)
* feat: add new command for updating request and emailing user, refs AC-1191
* feat: inject service with organization service collection extensions, refs AC-1191
* feat: add function to send admin approval email to mail services (interface/noop/handlebars), refs AC-1191
* feat: add html/text mail templates and add view model for email data, refs AC-1191
* feat: update org auth request controller to use new command during auth request update, refs AC-1191
* fix: dotnet format, refs AC-1191
* refactor: update user not found error, FirstOrDefault for enum type display name, refs AC-1191
* refactor: update user not found to log error instead of throws, refs AC-1191
* fix: remove whitespace lint errors, refs AC-1191
* refactor: update hardcoded UTC timezone string, refs AC-1191
* refactor: add unit test for new command, refs AC-1191
* refactor: improve enum name fallback and identifier string creation, refs AC-1191
* refactor: add addtional unit tests, refs AC-1191
* refactor: update success test to use more generated params, refs AC-1191
* fix: dotnet format...again, refs AC-1191
* refactor: make UTC display a constant for handlebars mail service, refs AC-1191
* refactor: update displayTypeIdentifer to displayTypeAndIdentifier for clarity, refs AC-1191
2023-07-06 10:03:49 -05:00
|
|
|
|
ICurrentContext currentContext, IAuthRequestService authRequestService,
|
|
|
|
|
|
IUpdateOrganizationAuthRequestCommand updateOrganizationAuthRequestCommand)
|
2023-06-15 14:54:08 -07:00
|
|
|
|
{
|
|
|
|
|
|
_authRequestRepository = authRequestRepository;
|
|
|
|
|
|
_currentContext = currentContext;
|
|
|
|
|
|
_authRequestService = authRequestService;
|
[AC-1191] TDE admin approval email (#3044)
* feat: add new command for updating request and emailing user, refs AC-1191
* feat: inject service with organization service collection extensions, refs AC-1191
* feat: add function to send admin approval email to mail services (interface/noop/handlebars), refs AC-1191
* feat: add html/text mail templates and add view model for email data, refs AC-1191
* feat: update org auth request controller to use new command during auth request update, refs AC-1191
* fix: dotnet format, refs AC-1191
* refactor: update user not found error, FirstOrDefault for enum type display name, refs AC-1191
* refactor: update user not found to log error instead of throws, refs AC-1191
* fix: remove whitespace lint errors, refs AC-1191
* refactor: update hardcoded UTC timezone string, refs AC-1191
* refactor: add unit test for new command, refs AC-1191
* refactor: improve enum name fallback and identifier string creation, refs AC-1191
* refactor: add addtional unit tests, refs AC-1191
* refactor: update success test to use more generated params, refs AC-1191
* fix: dotnet format...again, refs AC-1191
* refactor: make UTC display a constant for handlebars mail service, refs AC-1191
* refactor: update displayTypeIdentifer to displayTypeAndIdentifier for clarity, refs AC-1191
2023-07-06 10:03:49 -05:00
|
|
|
|
_updateOrganizationAuthRequestCommand = updateOrganizationAuthRequestCommand;
|
2023-06-15 14:54:08 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("")]
|
|
|
|
|
|
public async Task<ListResponseModel<PendingOrganizationAuthRequestResponseModel>> GetPendingRequests(Guid orgId)
|
|
|
|
|
|
{
|
|
|
|
|
|
await ValidateAdminRequest(orgId);
|
|
|
|
|
|
|
|
|
|
|
|
var authRequests = await _authRequestRepository.GetManyPendingByOrganizationIdAsync(orgId);
|
|
|
|
|
|
var responses = authRequests
|
|
|
|
|
|
.Select(a => new PendingOrganizationAuthRequestResponseModel(a))
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
return new ListResponseModel<PendingOrganizationAuthRequestResponseModel>(responses);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost("{requestId}")]
|
|
|
|
|
|
public async Task UpdateAuthRequest(Guid orgId, Guid requestId, [FromBody] AdminAuthRequestUpdateRequestModel model)
|
|
|
|
|
|
{
|
|
|
|
|
|
await ValidateAdminRequest(orgId);
|
|
|
|
|
|
|
|
|
|
|
|
var authRequest =
|
|
|
|
|
|
(await _authRequestRepository.GetManyAdminApprovalRequestsByManyIdsAsync(orgId, new[] { requestId })).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
|
|
if (authRequest == null || authRequest.OrganizationId != orgId)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotFoundException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
[AC-1191] TDE admin approval email (#3044)
* feat: add new command for updating request and emailing user, refs AC-1191
* feat: inject service with organization service collection extensions, refs AC-1191
* feat: add function to send admin approval email to mail services (interface/noop/handlebars), refs AC-1191
* feat: add html/text mail templates and add view model for email data, refs AC-1191
* feat: update org auth request controller to use new command during auth request update, refs AC-1191
* fix: dotnet format, refs AC-1191
* refactor: update user not found error, FirstOrDefault for enum type display name, refs AC-1191
* refactor: update user not found to log error instead of throws, refs AC-1191
* fix: remove whitespace lint errors, refs AC-1191
* refactor: update hardcoded UTC timezone string, refs AC-1191
* refactor: add unit test for new command, refs AC-1191
* refactor: improve enum name fallback and identifier string creation, refs AC-1191
* refactor: add addtional unit tests, refs AC-1191
* refactor: update success test to use more generated params, refs AC-1191
* fix: dotnet format...again, refs AC-1191
* refactor: make UTC display a constant for handlebars mail service, refs AC-1191
* refactor: update displayTypeIdentifer to displayTypeAndIdentifier for clarity, refs AC-1191
2023-07-06 10:03:49 -05:00
|
|
|
|
await _updateOrganizationAuthRequestCommand.UpdateAsync(authRequest.Id, authRequest.UserId, model.RequestApproved, model.EncryptedUserKey);
|
2023-06-15 14:54:08 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost("deny")]
|
|
|
|
|
|
public async Task BulkDenyRequests(Guid orgId, [FromBody] BulkDenyAdminAuthRequestRequestModel model)
|
|
|
|
|
|
{
|
|
|
|
|
|
await ValidateAdminRequest(orgId);
|
|
|
|
|
|
|
|
|
|
|
|
var authRequests = await _authRequestRepository.GetManyAdminApprovalRequestsByManyIdsAsync(orgId, model.Ids);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var authRequest in authRequests)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _authRequestService.UpdateAuthRequestAsync(authRequest.Id, authRequest.UserId,
|
|
|
|
|
|
new AuthRequestUpdateRequestModel { RequestApproved = false, });
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-26 20:56:52 -05:00
|
|
|
|
[HttpPost("")]
|
|
|
|
|
|
public async Task UpdateManyAuthRequests(Guid orgId, [FromBody] IEnumerable<OrganizationAuthRequestUpdateManyRequestModel> model)
|
|
|
|
|
|
{
|
|
|
|
|
|
await ValidateAdminRequest(orgId);
|
|
|
|
|
|
await _updateOrganizationAuthRequestCommand.UpdateAsync(orgId, model.Select(x => x.ToOrganizationAuthRequestUpdate()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task ValidateAdminRequest(Guid orgId)
|
2023-06-15 14:54:08 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (!await _currentContext.ManageResetPassword(orgId))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new UnauthorizedAccessException();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
[AC-1191] TDE admin approval email (#3044)
* feat: add new command for updating request and emailing user, refs AC-1191
* feat: inject service with organization service collection extensions, refs AC-1191
* feat: add function to send admin approval email to mail services (interface/noop/handlebars), refs AC-1191
* feat: add html/text mail templates and add view model for email data, refs AC-1191
* feat: update org auth request controller to use new command during auth request update, refs AC-1191
* fix: dotnet format, refs AC-1191
* refactor: update user not found error, FirstOrDefault for enum type display name, refs AC-1191
* refactor: update user not found to log error instead of throws, refs AC-1191
* fix: remove whitespace lint errors, refs AC-1191
* refactor: update hardcoded UTC timezone string, refs AC-1191
* refactor: add unit test for new command, refs AC-1191
* refactor: improve enum name fallback and identifier string creation, refs AC-1191
* refactor: add addtional unit tests, refs AC-1191
* refactor: update success test to use more generated params, refs AC-1191
* fix: dotnet format...again, refs AC-1191
* refactor: make UTC display a constant for handlebars mail service, refs AC-1191
* refactor: update displayTypeIdentifer to displayTypeAndIdentifier for clarity, refs AC-1191
2023-07-06 10:03:49 -05:00
|
|
|
|
|