1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-04 20:50:21 -05:00

Add feature flag to CreateAdminInitiatedSponsorshipHandler

This commit is contained in:
Jonas Hendrickx 2025-03-26 10:49:54 +01:00
parent bbb109cba8
commit f6ec513443
No known key found for this signature in database
GPG Key ID: C4B27F601CE4317D
3 changed files with 11 additions and 2 deletions

View File

@ -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";

View File

@ -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);
}

View File

@ -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.
/// </summary>
public class CreateAdminInitiatedSponsorshipHandler(
ICurrentContext currentContext) : BaseCreateSponsorshipHandler
ICurrentContext currentContext,
IFeatureService featureService) : BaseCreateSponsorshipHandler
{
public override async Task<OrganizationSponsorship> 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 =
[