From b5f09c599b0fcaf06168f729a49fbc75af75c1d0 Mon Sep 17 00:00:00 2001 From: Alex Morask <144709477+amorask-bitwarden@users.noreply.github.com> Date: Wed, 24 Jul 2024 09:04:04 -0400 Subject: [PATCH] Added SM standalone check to public members controller (#4179) --- .../Public/Controllers/MembersController.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Api/AdminConsole/Public/Controllers/MembersController.cs b/src/Api/AdminConsole/Public/Controllers/MembersController.cs index 1ecec686a6..8258f4b546 100644 --- a/src/Api/AdminConsole/Public/Controllers/MembersController.cs +++ b/src/Api/AdminConsole/Public/Controllers/MembersController.cs @@ -24,6 +24,8 @@ public class MembersController : Controller private readonly IUpdateOrganizationUserCommand _updateOrganizationUserCommand; private readonly IUpdateOrganizationUserGroupsCommand _updateOrganizationUserGroupsCommand; private readonly IApplicationCacheService _applicationCacheService; + private readonly IPaymentService _paymentService; + private readonly IOrganizationRepository _organizationRepository; public MembersController( IOrganizationUserRepository organizationUserRepository, @@ -33,7 +35,9 @@ public class MembersController : Controller ICurrentContext currentContext, IUpdateOrganizationUserCommand updateOrganizationUserCommand, IUpdateOrganizationUserGroupsCommand updateOrganizationUserGroupsCommand, - IApplicationCacheService applicationCacheService) + IApplicationCacheService applicationCacheService, + IPaymentService paymentService, + IOrganizationRepository organizationRepository) { _organizationUserRepository = organizationUserRepository; _groupRepository = groupRepository; @@ -43,6 +47,8 @@ public class MembersController : Controller _updateOrganizationUserCommand = updateOrganizationUserCommand; _updateOrganizationUserGroupsCommand = updateOrganizationUserGroupsCommand; _applicationCacheService = applicationCacheService; + _paymentService = paymentService; + _organizationRepository = organizationRepository; } /// @@ -124,8 +130,19 @@ public class MembersController : Controller [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] public async Task Post([FromBody] MemberCreateRequestModel model) { + var hasStandaloneSecretsManager = false; + + var organization = await _organizationRepository.GetByIdAsync(_currentContext.OrganizationId!.Value); + + if (organization != null) + { + hasStandaloneSecretsManager = await _paymentService.HasSecretsManagerStandalone(organization); + } + var invite = model.ToOrganizationUserInvite(); + invite.AccessSecretsManager = hasStandaloneSecretsManager; + var user = await _organizationService.InviteUserAsync(_currentContext.OrganizationId.Value, null, systemUser: null, invite, model.ExternalId); var response = new MemberResponseModel(user, invite.Collections);