mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
[AC-1593] Auto-Grant SM access to org owner when they add SM (#3349)
* Auto grant SM access to org owner * Thomas' feedback
This commit is contained in:
@ -320,8 +320,16 @@ public class OrganizationsController : Controller
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var result = await _upgradeOrganizationPlanCommand.UpgradePlanAsync(orgIdGuid, model.ToOrganizationUpgrade());
|
||||
return new PaymentResponseModel { Success = result.Item1, PaymentIntentClientSecret = result.Item2 };
|
||||
var (success, paymentIntentClientSecret) = await _upgradeOrganizationPlanCommand.UpgradePlanAsync(orgIdGuid, model.ToOrganizationUpgrade());
|
||||
|
||||
if (model.UseSecretsManager && success)
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
|
||||
await TryGrantOwnerAccessToSecretsManagerAsync(orgIdGuid, userId);
|
||||
}
|
||||
|
||||
return new PaymentResponseModel { Success = success, PaymentIntentClientSecret = paymentIntentClientSecret };
|
||||
}
|
||||
|
||||
[HttpPost("{id}/subscription")]
|
||||
@ -374,6 +382,9 @@ public class OrganizationsController : Controller
|
||||
model.AdditionalServiceAccounts);
|
||||
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
|
||||
await TryGrantOwnerAccessToSecretsManagerAsync(organization.Id, userId);
|
||||
|
||||
var organizationDetails = await _organizationUserRepository.GetDetailsByUserAsync(userId, organization.Id,
|
||||
OrganizationUserStatusType.Confirmed);
|
||||
|
||||
@ -786,4 +797,15 @@ public class OrganizationsController : Controller
|
||||
await _organizationService.UpdateAsync(model.ToOrganization(organization));
|
||||
return new OrganizationResponseModel(organization);
|
||||
}
|
||||
|
||||
private async Task TryGrantOwnerAccessToSecretsManagerAsync(Guid organizationId, Guid userId)
|
||||
{
|
||||
var organizationUser = await _organizationUserRepository.GetByOrganizationAsync(organizationId, userId);
|
||||
|
||||
if (organizationUser != null)
|
||||
{
|
||||
organizationUser.AccessSecretsManager = true;
|
||||
await _organizationUserRepository.ReplaceAsync(organizationUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user