mirror of
https://github.com/bitwarden/server
synced 2025-12-30 07:03:42 +00:00
Add sponsorship validation to upcoming invoice webhook
This commit is contained in:
@@ -53,7 +53,7 @@ namespace Bit.Core.Services
|
||||
Task SendFamiliesForEnterpriseOfferEmailAsync(string email, string organizationName, string token);
|
||||
Task SendFamiliesForEnterpriseRedeemedEmailsAsync(string familyUserEmail, string sponsorEmail, string sponsorOrgName);
|
||||
Task SendFamiliesForEnterpriseReconfirmationRequiredEmailAsync(string email);
|
||||
Task SendFamiliesForEnterpriseSponsorshipRevertingEmailAsync(string email);
|
||||
Task SendFamiliesForEnterpriseSponsorshipRevertingEmailAsync(string email, string familyOrgName);
|
||||
Task SendFamiliesForEnterpriseSponsorshipEndingEmailAsync(string email);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -801,7 +801,7 @@ namespace Bit.Core.Services
|
||||
var message = CreateDefaultMessage("A User Has Redeemeed Your Sponsorship", email);
|
||||
var model = new FamiliesForEnterpriseRedeemedToOrgUserViewModel
|
||||
{
|
||||
OrganizationName = organizationName,
|
||||
OrganizationName = CoreHelpers.SanitizeForEmail(organizationName, false),
|
||||
};
|
||||
await AddMessageContentAsync(message, "FamiliesForEnterprise.FamiliesForEnterpriseRedeemedToOrgUser", model);
|
||||
message.Category = "FamilyForEnterpriseRedeemedToOrgUser";
|
||||
@@ -821,13 +821,13 @@ namespace Bit.Core.Services
|
||||
await _mailDeliveryService.SendEmailAsync(message);
|
||||
}
|
||||
|
||||
public async Task SendFamiliesForEnterpriseSponsorshipRevertingEmailAsync(string email)
|
||||
public async Task SendFamiliesForEnterpriseSponsorshipRevertingEmailAsync(string email, string familyOrgName)
|
||||
{
|
||||
// TODO: Complete emails
|
||||
var message = CreateDefaultMessage("A Family Organization Sponsorship Is Reverting", email);
|
||||
var message = CreateDefaultMessage($"{familyOrgName} Organization Sponsorship Is No Longer Valid", email);
|
||||
var model = new FamiliesForEnterpriseSponsorshipRevertingViewModel
|
||||
{
|
||||
|
||||
OrganizationName = CoreHelpers.SanitizeForEmail(familyOrgName, false),
|
||||
};
|
||||
await AddMessageContentAsync(message, "FamiliesForEnterprise.FamiliesForEnterpriseSponsorshipReverting", model);
|
||||
message.Category = "FamiliesForEnterpriseSponsorshipReverting";
|
||||
|
||||
@@ -133,38 +133,30 @@ namespace Bit.Core.Services
|
||||
|
||||
if (existingSponsorship == null)
|
||||
{
|
||||
// TODO: null safe this method
|
||||
await RemoveSponsorshipAsync(sponsoredOrganization, null);
|
||||
// TODO on fail, mark org as disabled.
|
||||
return false;
|
||||
}
|
||||
|
||||
var validated = true;
|
||||
if (existingSponsorship.SponsoringOrganizationId == null || existingSponsorship.SponsoringOrganizationUserId == null)
|
||||
if (existingSponsorship.SponsoringOrganizationId == null || existingSponsorship.SponsoringOrganizationUserId == null || existingSponsorship.PlanSponsorshipType == null)
|
||||
{
|
||||
await RemoveSponsorshipAsync(sponsoredOrganization, existingSponsorship);
|
||||
validated = false;
|
||||
return false;
|
||||
}
|
||||
var sponsoredPlan = Utilities.StaticStore.GetSponsoredPlan(existingSponsorship.PlanSponsorshipType.Value);
|
||||
|
||||
var sponsoringOrganization = await _organizationRepository
|
||||
.GetByIdAsync(existingSponsorship.SponsoringOrganizationId.Value);
|
||||
if (!sponsoringOrganization.Enabled)
|
||||
if (sponsoringOrganization == null)
|
||||
{
|
||||
await RemoveSponsorshipAsync(sponsoredOrganization, existingSponsorship);
|
||||
validated = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!validated && existingSponsorship.SponsoredOrganizationId != null)
|
||||
var sponsoringOrgPlan = Utilities.StaticStore.GetPlan(sponsoringOrganization.PlanType);
|
||||
if (!sponsoringOrganization.Enabled || sponsoredPlan.SponsoringProductType != sponsoringOrgPlan.Product)
|
||||
{
|
||||
existingSponsorship.TimesRenewedWithoutValidation += 1;
|
||||
existingSponsorship.SponsorshipLapsedDate ??= DateTime.UtcNow;
|
||||
|
||||
await _organizationSponsorshipRepository.UpsertAsync(existingSponsorship);
|
||||
if (existingSponsorship.TimesRenewedWithoutValidation >= 6)
|
||||
{
|
||||
sponsoredOrganization.Enabled = false;
|
||||
await _organizationRepository.UpsertAsync(sponsoredOrganization);
|
||||
}
|
||||
await RemoveSponsorshipAsync(sponsoredOrganization, existingSponsorship);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -175,6 +167,10 @@ namespace Bit.Core.Services
|
||||
await _paymentService.RemoveOrganizationSponsorshipAsync(sponsoredOrganization, sponsorship);
|
||||
await _organizationRepository.UpsertAsync(sponsoredOrganization);
|
||||
|
||||
await _mailService.SendFamiliesForEnterpriseSponsorshipRevertingEmailAsync(
|
||||
sponsoredOrganization.BillingEmailAddress(),
|
||||
sponsoredOrganization.Name);
|
||||
|
||||
if (sponsorship == null)
|
||||
{
|
||||
return;
|
||||
@@ -197,6 +193,5 @@ namespace Bit.Core.Services
|
||||
await _organizationSponsorshipRepository.UpsertAsync(sponsorship);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,9 @@ namespace Bit.Core.Services
|
||||
private async Task ChangeOrganizationSponsorship(Organization org, OrganizationSponsorship sponsorship, bool applySponsorship)
|
||||
{
|
||||
var existingPlan = Utilities.StaticStore.GetPlan(org.PlanType);
|
||||
var sponsoredPlan = Utilities.StaticStore.GetSponsoredPlan(sponsorship.PlanSponsorshipType.Value);
|
||||
var sponsoredPlan = sponsorship != null ?
|
||||
Utilities.StaticStore.GetSponsoredPlan(sponsorship.PlanSponsorshipType.Value) :
|
||||
null;
|
||||
var subscriptionUpdate = new SponsorOrganizationSubscriptionUpdate(existingPlan, sponsoredPlan, applySponsorship);
|
||||
|
||||
await FinalizeSubscriptionChangeAsync(org, subscriptionUpdate, DateTime.UtcNow);
|
||||
|
||||
@@ -216,7 +216,7 @@ namespace Bit.Core.Services
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task SendFamiliesForEnterpriseSponsorshipRevertingEmailAsync(string email)
|
||||
public Task SendFamiliesForEnterpriseSponsorshipRevertingEmailAsync(string email, string familyOrgName)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user