mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
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:
commit
5bdaf8fb5a
3 changed files with 13 additions and 15 deletions
|
@ -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) =>
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)->
|
||||||
|
|
Loading…
Reference in a new issue