mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
Fix/f4e multiple sponsorships (#1838)
* Use sponosorship from validate to redeem * Update tests * Format
This commit is contained in:
@ -68,14 +68,16 @@ namespace Bit.Api.Controllers
|
||||
[SelfHosted(NotSelfHostedOnly = true)]
|
||||
public async Task<bool> PreValidateSponsorshipToken([FromQuery] string sponsorshipToken)
|
||||
{
|
||||
return await _organizationsSponsorshipService.ValidateRedemptionTokenAsync(sponsorshipToken, (await CurrentUser).Email);
|
||||
return (await _organizationsSponsorshipService.ValidateRedemptionTokenAsync(sponsorshipToken, (await CurrentUser).Email)).valid;
|
||||
}
|
||||
|
||||
[HttpPost("redeem")]
|
||||
[SelfHosted(NotSelfHostedOnly = true)]
|
||||
public async Task RedeemSponsorship([FromQuery] string sponsorshipToken, [FromBody] OrganizationSponsorshipRedeemRequestModel model)
|
||||
{
|
||||
if (!await _organizationsSponsorshipService.ValidateRedemptionTokenAsync(sponsorshipToken, (await CurrentUser).Email))
|
||||
var (valid, sponsorship) = await _organizationsSponsorshipService.ValidateRedemptionTokenAsync(sponsorshipToken, (await CurrentUser).Email);
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
throw new BadRequestException("Failed to parse sponsorship token.");
|
||||
}
|
||||
@ -86,8 +88,7 @@ namespace Bit.Api.Controllers
|
||||
}
|
||||
|
||||
await _organizationsSponsorshipService.SetUpSponsorshipAsync(
|
||||
await _organizationSponsorshipRepository
|
||||
.GetByOfferedToEmailAsync((await CurrentUser).Email),
|
||||
sponsorship,
|
||||
// Check org to sponsor's product type
|
||||
await _organizationRepository.GetByIdAsync(model.SponsoredOrganizationId));
|
||||
}
|
||||
|
Reference in New Issue
Block a user