Merge pull request #14241 from overleaf/msm-skip-subscription-deletion-groups

Temporarily skip subscription deletion for managed groups

GitOrigin-RevId: 6452a156e255fc599bdd25e38edb15659009a15a
This commit is contained in:
Miguel Serrano 2023-08-16 16:26:14 +02:00 committed by Copybot
parent 277fe530ad
commit b8dc589303
2 changed files with 34 additions and 1 deletions

View file

@ -8,6 +8,7 @@ const FeaturesHelper = require('./FeaturesHelper')
const AnalyticsManager = require('../Analytics/AnalyticsManager')
const { DeletedSubscription } = require('../../models/DeletedSubscription')
const logger = require('@overleaf/logger')
const Features = require('../../infrastructure/Features')
/**
* Change the admin of the given subscription.
@ -228,7 +229,18 @@ async function updateSubscriptionFromRecurly(
requesterData
) {
if (recurlySubscription.state === 'expired') {
await deleteSubscription(subscription, requesterData)
const hasManagedUsersFeature =
Features.hasFeature('saas') && subscription?.groupPolicy != null
if (hasManagedUsersFeature) {
// If a payment lapses and if the group is managed, as a temporary measure we need to
// make sure that the group continues as-is and no destructive actions are taken.
logger.warn(
{ subscriptionId: subscription._id },
'expired subscription has managedUsers feature, skipping deletion'
)
} else {
await deleteSubscription(subscription, requesterData)
}
return
}
const updatedPlanCode = recurlySubscription.plan.plan_code

View file

@ -143,6 +143,10 @@ describe('SubscriptionUpdater', function () {
setUserPropertyForUser: sinon.stub(),
}
this.Features = {
hasFeature: sinon.stub().returns(false),
}
this.SubscriptionUpdater = SandboxedModule.require(modulePath, {
requires: {
'../../models/Subscription': {
@ -157,6 +161,7 @@ describe('SubscriptionUpdater', function () {
DeletedSubscription: this.DeletedSubscription,
},
'../Analytics/AnalyticsManager': this.AnalyticsManager,
'../../infrastructure/Features': this.Features,
},
})
})
@ -267,6 +272,22 @@ describe('SubscriptionUpdater', function () {
this.subscription,
{}
)
this.SubscriptionModel.deleteOne.should.have.been.calledWith({
_id: this.subscription._id,
})
})
it('should not remove the subscription when expired if it has "managedUsers" feature', async function () {
this.Features.hasFeature.withArgs('saas').returns(true)
this.subscription.groupPolicy = { policy: true }
this.recurlySubscription.state = 'expired'
await this.SubscriptionUpdater.promises.updateSubscriptionFromRecurly(
this.recurlySubscription,
this.subscription,
{}
)
this.SubscriptionModel.deleteOne.should.not.have.been.called
})
it('should update all the users features', async function () {