mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-03 04:43:20 +00:00
Merge branch 'sk-account-sync'
This commit is contained in:
commit
18ae27fd66
2 changed files with 46 additions and 6 deletions
|
@ -62,6 +62,9 @@ module.exports = SubscriptionUpdater =
|
|||
invited_emails: email
|
||||
}, callback
|
||||
|
||||
refreshSubscription: (user_id, callback=(err)->) ->
|
||||
SubscriptionUpdater._setUsersMinimumFeatures user_id, callback
|
||||
|
||||
deleteSubscription: (subscription_id, callback = (error) ->) ->
|
||||
SubscriptionLocator.getSubscription subscription_id, (err, subscription) ->
|
||||
return callback(err) if err?
|
||||
|
@ -106,17 +109,29 @@ module.exports = SubscriptionUpdater =
|
|||
SubscriptionLocator.getUsersSubscription user_id, cb
|
||||
groupSubscription: (cb)->
|
||||
SubscriptionLocator.getGroupSubscriptionMemberOf user_id, cb
|
||||
v1PlanCode: (cb) ->
|
||||
Modules = require '../../infrastructure/Modules'
|
||||
Modules.hooks.fire 'getV1PlanCode', user_id, (err, results) ->
|
||||
cb(err, results?[0] || null)
|
||||
async.series jobs, (err, results)->
|
||||
if err?
|
||||
logger.err err:err, user_id:user, "error getting subscription or group for _setUsersMinimumFeatures"
|
||||
logger.err err:err, user_id:user_id,
|
||||
"error getting subscription or group for _setUsersMinimumFeatures"
|
||||
return callback(err)
|
||||
{subscription, groupSubscription} = results
|
||||
if subscription? and subscription.planCode? and subscription.planCode != Settings.defaultPlanCode
|
||||
logger.log user_id:user_id, "using users subscription plan code for features"
|
||||
UserFeaturesUpdater.updateFeatures user_id, subscription.planCode, callback
|
||||
else if groupSubscription? and groupSubscription.planCode?
|
||||
{subscription, groupSubscription, v1PlanCode} = results
|
||||
# Group Subscription
|
||||
if groupSubscription? and groupSubscription.planCode?
|
||||
logger.log user_id:user_id, "using group which user is memor of for features"
|
||||
UserFeaturesUpdater.updateFeatures user_id, groupSubscription.planCode, callback
|
||||
# Personal Subscription
|
||||
else if subscription? and subscription.planCode? and subscription.planCode != Settings.defaultPlanCode
|
||||
logger.log user_id:user_id, "using users subscription plan code for features"
|
||||
UserFeaturesUpdater.updateFeatures user_id, subscription.planCode, callback
|
||||
# V1 Subscription
|
||||
else if v1PlanCode?
|
||||
logger.log user_id: user_id, "using the V1 plan for features"
|
||||
UserFeaturesUpdater.updateFeatures user_id, v1PlanCode, callback
|
||||
# Default
|
||||
else
|
||||
logger.log user_id:user_id, "using default features for user with no subscription or group"
|
||||
UserFeaturesUpdater.updateFeatures user_id, Settings.defaultPlanCode, (err)->
|
||||
|
|
|
@ -57,6 +57,7 @@ describe "SubscriptionUpdater", ->
|
|||
|
||||
@ReferalAllocator = assignBonus:sinon.stub().callsArgWith(1)
|
||||
@ReferalAllocator.cock = true
|
||||
@Modules = {hooks: {fire: sinon.stub().callsArgWith(2, null, null)}}
|
||||
@SubscriptionUpdater = SandboxedModule.require modulePath, requires:
|
||||
'../../models/Subscription': Subscription:@SubscriptionModel
|
||||
'./UserFeaturesUpdater': @UserFeaturesUpdater
|
||||
|
@ -65,6 +66,7 @@ describe "SubscriptionUpdater", ->
|
|||
"logger-sharelatex": log:->
|
||||
'settings-sharelatex': @Settings
|
||||
"../Referal/ReferalAllocator" : @ReferalAllocator
|
||||
'../../infrastructure/Modules': @Modules
|
||||
|
||||
|
||||
describe "syncSubscription", ->
|
||||
|
@ -204,10 +206,22 @@ describe "SubscriptionUpdater", ->
|
|||
assert.equal args[1], @groupSubscription.planCode
|
||||
done()
|
||||
|
||||
it "should call updateFeatures with the overleaf subscription if set", (done)->
|
||||
@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null)
|
||||
@SubscriptionLocator.getGroupSubscriptionMemberOf.callsArgWith(1, null, null)
|
||||
@Modules.hooks.fire = sinon.stub().callsArgWith(2, null, ['ol_pro'])
|
||||
|
||||
@SubscriptionUpdater._setUsersMinimumFeatures @adminUser._id, (err)=>
|
||||
args = @UserFeaturesUpdater.updateFeatures.args[0]
|
||||
assert.equal args[0], @adminUser._id
|
||||
assert.equal args[1], 'ol_pro'
|
||||
done()
|
||||
|
||||
it "should call not call updateFeatures with users subscription if the subscription plan code is the default one (downgraded)", (done)->
|
||||
@subscription.planCode = @Settings.defaultPlanCode
|
||||
@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, @subscription)
|
||||
@SubscriptionLocator.getGroupSubscriptionMemberOf.callsArgWith(1, null, @groupSubscription)
|
||||
@Modules.hooks.fire = sinon.stub().callsArgWith(2, null, null)
|
||||
@SubscriptionUpdater._setUsersMinimumFeatures @adminuser_id, (err)=>
|
||||
args = @UserFeaturesUpdater.updateFeatures.args[0]
|
||||
assert.equal args[0], @adminUser._id
|
||||
|
@ -218,6 +232,7 @@ describe "SubscriptionUpdater", ->
|
|||
it "should call updateFeatures with default if there are no subscriptions for user", (done)->
|
||||
@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null)
|
||||
@SubscriptionLocator.getGroupSubscriptionMemberOf.callsArgWith(1, null)
|
||||
@Modules.hooks.fire = sinon.stub().callsArgWith(2, null, null)
|
||||
@SubscriptionUpdater._setUsersMinimumFeatures @adminuser_id, (err)=>
|
||||
args = @UserFeaturesUpdater.updateFeatures.args[0]
|
||||
assert.equal args[0], @adminUser._id
|
||||
|
@ -263,3 +278,13 @@ describe "SubscriptionUpdater", ->
|
|||
@SubscriptionUpdater._setUsersMinimumFeatures
|
||||
.calledWith(user_id)
|
||||
.should.equal true
|
||||
|
||||
describe 'refreshSubscription', ->
|
||||
beforeEach ->
|
||||
@SubscriptionUpdater._setUsersMinimumFeatures = sinon.stub()
|
||||
.callsArgWith(1, null)
|
||||
|
||||
it 'should call to _setUsersMinimumFeatures', ->
|
||||
@SubscriptionUpdater.refreshSubscription(@adminUser._id, ()->)
|
||||
@SubscriptionUpdater._setUsersMinimumFeatures.callCount.should.equal 1
|
||||
@SubscriptionUpdater._setUsersMinimumFeatures.calledWith(@adminUser._id).should.equal true
|
||||
|
|
Loading…
Reference in a new issue