From f6ec5134436ae00a5dd1f15a37c4b36faa8b3bea Mon Sep 17 00:00:00 2001 From: Jonas Hendrickx Date: Wed, 26 Mar 2025 10:49:54 +0100 Subject: [PATCH] Add feature flag to `CreateAdminInitiatedSponsorshipHandler` --- src/Core/Constants.cs | 1 + .../FamiliesForEnterprise/CreateSponsorshipCommand.cs | 3 ++- .../CreateAdminInitiatedSponsorshipHandler.cs | 9 ++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Core/Constants.cs b/src/Core/Constants.cs index 6baa9227e1..412e21f454 100644 --- a/src/Core/Constants.cs +++ b/src/Core/Constants.cs @@ -157,6 +157,7 @@ public static class FeatureFlagKeys public const string PrivateKeyRegeneration = "pm-12241-private-key-regeneration"; public const string AppReviewPrompt = "app-review-prompt"; public const string ResellerManagedOrgAlert = "PM-15814-alert-owners-of-reseller-managed-orgs"; + public const string PM17772_AdminInitiatedSponsorships = "pm-17772-admin-initiated-sponsorships"; public const string Argon2Default = "argon2-default"; public const string UsePricingService = "use-pricing-service"; public const string RecordInstallationLastActivityDate = "installation-last-activity-date"; diff --git a/src/Core/OrganizationFeatures/OrganizationSponsorships/FamiliesForEnterprise/CreateSponsorshipCommand.cs b/src/Core/OrganizationFeatures/OrganizationSponsorships/FamiliesForEnterprise/CreateSponsorshipCommand.cs index a7591d0d45..750ced4854 100644 --- a/src/Core/OrganizationFeatures/OrganizationSponsorships/FamiliesForEnterprise/CreateSponsorshipCommand.cs +++ b/src/Core/OrganizationFeatures/OrganizationSponsorships/FamiliesForEnterprise/CreateSponsorshipCommand.cs @@ -16,13 +16,14 @@ public class CreateSponsorshipCommand : ICreateSponsorshipCommand private readonly BaseCreateSponsorshipHandler _createSponsorshipHandler; public CreateSponsorshipCommand( + IFeatureService featureService, IOrganizationSponsorshipRepository organizationSponsorshipRepository, IUserService userService, ICurrentContext currentContext) { _organizationSponsorshipRepository = organizationSponsorshipRepository; - var adminInitiatedSponsorshipHandler = new CreateAdminInitiatedSponsorshipHandler(currentContext); + var adminInitiatedSponsorshipHandler = new CreateAdminInitiatedSponsorshipHandler(currentContext, featureService); _createSponsorshipHandler = new CreateSponsorshipHandler(userService, organizationSponsorshipRepository); _createSponsorshipHandler.SetNext(adminInitiatedSponsorshipHandler); } diff --git a/src/Core/OrganizationFeatures/OrganizationSponsorships/FamiliesForEnterprise/SponsorshipCreation/CreateAdminInitiatedSponsorshipHandler.cs b/src/Core/OrganizationFeatures/OrganizationSponsorships/FamiliesForEnterprise/SponsorshipCreation/CreateAdminInitiatedSponsorshipHandler.cs index e3d915fbff..f36a3719f1 100644 --- a/src/Core/OrganizationFeatures/OrganizationSponsorships/FamiliesForEnterprise/SponsorshipCreation/CreateAdminInitiatedSponsorshipHandler.cs +++ b/src/Core/OrganizationFeatures/OrganizationSponsorships/FamiliesForEnterprise/SponsorshipCreation/CreateAdminInitiatedSponsorshipHandler.cs @@ -2,6 +2,7 @@ using Bit.Core.Entities; using Bit.Core.Enums; using Bit.Core.Exceptions; +using Bit.Core.Services; namespace Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnterprise.SponsorshipCreation; @@ -10,13 +11,19 @@ namespace Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnte /// sponsorship initiated by organization members with specific permissions to manage members/users. /// public class CreateAdminInitiatedSponsorshipHandler( - ICurrentContext currentContext) : BaseCreateSponsorshipHandler + ICurrentContext currentContext, + IFeatureService featureService) : BaseCreateSponsorshipHandler { public override async Task HandleAsync(CreateSponsorshipRequest request) { var isAdminInitiated = false; if (currentContext.UserId != request.SponsoringMember.UserId) { + if (!featureService.IsEnabled(FeatureFlagKeys.PM17772_AdminInitiatedSponsorships)) + { + throw new BadRequestException("Feature 'pm-17772-admin-initiated-sponsorships' is not enabled."); + } + var organization = currentContext.Organizations.First(x => x.Id == request.SponsoringOrganization.Id); OrganizationUserType[] allowedUserTypes = [