Merge pull request #736 from sharelatex/ja-delete-sub-on-expiry

Delete a subscription on expiry, rather than set personal plan code
This commit is contained in:
James Allen 2018-07-10 11:27:51 +01:00 committed by GitHub
commit 5bdaf8fb5a
3 changed files with 13 additions and 15 deletions

View file

@ -19,7 +19,7 @@ module.exports = LimitationsManager =
if user.features? and user.features.collaborators? if user.features? and user.features.collaborators?
callback null, user.features.collaborators callback null, user.features.collaborators
else else
callback null, Settings.defaultPlanCode.collaborators callback null, Settings.defaultFeatures.collaborators
canAddXCollaborators: (project_id, x_collaborators, callback = (error, allowed)->) -> canAddXCollaborators: (project_id, x_collaborators, callback = (error, allowed)->) ->
@allowedNumberOfCollaboratorsInProject project_id, (error, allowed_number) => @allowedNumberOfCollaboratorsInProject project_id, (error, allowed_number) =>

View file

@ -78,16 +78,16 @@ module.exports = SubscriptionUpdater =
_updateSubscriptionFromRecurly: (recurlySubscription, subscription, callback)-> _updateSubscriptionFromRecurly: (recurlySubscription, subscription, callback)->
logger.log recurlySubscription:recurlySubscription, subscription:subscription, "updaing subscription" logger.log recurlySubscription:recurlySubscription, subscription:subscription, "updaing subscription"
plan = PlansLocator.findLocalPlanInSettings(recurlySubscription.plan.plan_code)
if recurlySubscription.state == "expired" if recurlySubscription.state == "expired"
subscription.recurlySubscription_id = undefined return SubscriptionUpdater.deleteSubscription subscription._id, callback
subscription.planCode = Settings.defaultPlanCode subscription.recurlySubscription_id = recurlySubscription.uuid
else subscription.freeTrial.expiresAt = undefined
subscription.recurlySubscription_id = recurlySubscription.uuid subscription.freeTrial.planCode = undefined
subscription.freeTrial.expiresAt = undefined subscription.freeTrial.allowed = true
subscription.freeTrial.planCode = undefined subscription.planCode = recurlySubscription.plan.plan_code
subscription.freeTrial.allowed = true plan = PlansLocator.findLocalPlanInSettings(subscription.planCode)
subscription.planCode = recurlySubscription.plan.plan_code if !plan?
return callback(new Error("plan code not found: #{subscription.planCode}"))
if plan.groupPlan if plan.groupPlan
subscription.groupPlan = true subscription.groupPlan = true
subscription.membersLimit = plan.membersLimit subscription.membersLimit = plan.membersLimit

View file

@ -103,6 +103,7 @@ describe "SubscriptionUpdater", ->
describe "_updateSubscriptionFromRecurly", -> describe "_updateSubscriptionFromRecurly", ->
beforeEach -> beforeEach ->
@FeaturesUpdater.refreshFeatures = sinon.stub().callsArgWith(1) @FeaturesUpdater.refreshFeatures = sinon.stub().callsArgWith(1)
@SubscriptionUpdater.deleteSubscription = sinon.stub().yields()
it "should update the subscription with token etc when not expired", (done)-> it "should update the subscription with token etc when not expired", (done)->
@SubscriptionUpdater._updateSubscriptionFromRecurly @recurlySubscription, @subscription, (err)=> @SubscriptionUpdater._updateSubscriptionFromRecurly @recurlySubscription, @subscription, (err)=>
@ -116,13 +117,10 @@ describe "SubscriptionUpdater", ->
@FeaturesUpdater.refreshFeatures.calledWith(@adminUser._id).should.equal true @FeaturesUpdater.refreshFeatures.calledWith(@adminUser._id).should.equal true
done() done()
it "should remove the recurlySubscription_id when expired", (done)-> it "should remove the subscription when expired", (done)->
@recurlySubscription.state = "expired" @recurlySubscription.state = "expired"
@SubscriptionUpdater._updateSubscriptionFromRecurly @recurlySubscription, @subscription, (err)=> @SubscriptionUpdater._updateSubscriptionFromRecurly @recurlySubscription, @subscription, (err)=>
assert.equal(@subscription.recurlySubscription_id, undefined) @SubscriptionUpdater.deleteSubscription.calledWith(@subscription._id).should.equal true
@subscription.save.called.should.equal true
@FeaturesUpdater.refreshFeatures.calledWith(@adminUser._id).should.equal true
done() done()
it "should update all the users features", (done)-> it "should update all the users features", (done)->