mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 23:52:50 -05:00
Fix/f4e multiple sponsorships (#1838)
* Use sponosorship from validate to redeem * Update tests * Format
This commit is contained in:
@ -10,6 +10,5 @@ namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<OrganizationSponsorship> GetBySponsoringOrganizationUserIdAsync(Guid sponsoringOrganizationUserId);
|
||||
Task<OrganizationSponsorship> GetBySponsoredOrganizationIdAsync(Guid sponsoredOrganizationId);
|
||||
Task<OrganizationSponsorship> GetByOfferedToEmailAsync(string email);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace Bit.Core.Services
|
||||
{
|
||||
public interface IOrganizationSponsorshipService
|
||||
{
|
||||
Task<bool> ValidateRedemptionTokenAsync(string encryptedToken, string currentUserEmail);
|
||||
Task<(bool valid, OrganizationSponsorship sponsorship)> ValidateRedemptionTokenAsync(string encryptedToken, string currentUserEmail);
|
||||
Task OfferSponsorshipAsync(Organization sponsoringOrg, OrganizationUser sponsoringOrgUser,
|
||||
PlanSponsorshipType sponsorshipType, string sponsoredEmail, string friendlyName, string sponsoringUserEmail);
|
||||
Task ResendSponsorshipOfferAsync(Organization sponsoringOrg, OrganizationUser sponsoringOrgUser,
|
||||
|
@ -37,11 +37,11 @@ namespace Bit.Core.Services
|
||||
_dataProtector = dataProtectionProvider.CreateProtector("OrganizationSponsorshipServiceDataProtector");
|
||||
}
|
||||
|
||||
public async Task<bool> ValidateRedemptionTokenAsync(string encryptedToken, string sponsoredUserEmail)
|
||||
public async Task<(bool valid, OrganizationSponsorship sponsorship)> ValidateRedemptionTokenAsync(string encryptedToken, string sponsoredUserEmail)
|
||||
{
|
||||
if (!encryptedToken.StartsWith(TokenClearTextPrefix) || sponsoredUserEmail == null)
|
||||
{
|
||||
return false;
|
||||
return (false, null);
|
||||
}
|
||||
|
||||
var decryptedToken = _dataProtector.Unprotect(encryptedToken[TokenClearTextPrefix.Length..]);
|
||||
@ -49,7 +49,7 @@ namespace Bit.Core.Services
|
||||
|
||||
if (dataParts.Length != 3)
|
||||
{
|
||||
return false;
|
||||
return (false, null);
|
||||
}
|
||||
|
||||
if (dataParts[0].Equals(FamiliesForEnterpriseTokenName))
|
||||
@ -57,7 +57,7 @@ namespace Bit.Core.Services
|
||||
if (!Guid.TryParse(dataParts[1], out Guid sponsorshipId) ||
|
||||
!Enum.TryParse<PlanSponsorshipType>(dataParts[2], true, out var sponsorshipType))
|
||||
{
|
||||
return false;
|
||||
return (false, null);
|
||||
}
|
||||
|
||||
var sponsorship = await _organizationSponsorshipRepository.GetByIdAsync(sponsorshipId);
|
||||
@ -65,13 +65,13 @@ namespace Bit.Core.Services
|
||||
sponsorship.PlanSponsorshipType != sponsorshipType ||
|
||||
sponsorship.OfferedToEmail != sponsoredUserEmail)
|
||||
{
|
||||
return false;
|
||||
return (false, sponsorship);
|
||||
}
|
||||
|
||||
return true;
|
||||
return (true, sponsorship);
|
||||
}
|
||||
|
||||
return false;
|
||||
return (false, null);
|
||||
}
|
||||
|
||||
private string RedemptionToken(Guid sponsorshipId, PlanSponsorshipType sponsorshipType) =>
|
||||
|
Reference in New Issue
Block a user