if a user is elelable to be part of a group subscription and they go to

/user/subscription it should redirect them to the group subscription invite
This commit is contained in:
Henry Oswald 2015-05-27 15:07:46 +01:00
parent 1d21bddcf5
commit 79fa49a43d
2 changed files with 38 additions and 3 deletions

View file

@ -8,7 +8,7 @@ RecurlyWrapper = require './RecurlyWrapper'
Settings = require 'settings-sharelatex'
logger = require('logger-sharelatex')
GeoIpLookup = require("../../infrastructure/GeoIpLookup")
SubscriptionDomainAllocator = require("./SubscriptionDomainAllocator")
module.exports = SubscriptionController =
@ -84,9 +84,13 @@ module.exports = SubscriptionController =
SecurityManager.getCurrentUser req, (error, user) =>
return next(error) if error?
LimitationsManager.userHasSubscriptionOrIsGroupMember user, (err, hasSubOrIsGroupMember, subscription)->
groupLicenceInviteUrl = SubscriptionDomainAllocator.getDomainLicencePage(user)
if subscription?.customAccount
logger.log user: user, "redirecting to plans"
res.redirect "/user/subscription/custom_account"
res.redirect "/user/subscription/custom_account"
else if groupLicenceInviteUrl? and !hasSubOrIsGroupMember
logger.log user:user, "redirecting to group subscription invite page"
res.redirect groupLicenceInviteUrl
else if !hasSubOrIsGroupMember
logger.log user: user, "redirecting to plans"
res.redirect "/user/subscription/plans"

View file

@ -58,7 +58,8 @@ describe "SubscriptionController sanboxed", ->
gaExperiments:{}
@GeoIpLookup =
getCurrencyCode:sinon.stub()
@SubscriptionDomainAllocator =
getDomainLicencePage:sinon.stub()
@SubscriptionController = SandboxedModule.require modulePath, requires:
'../../managers/SecurityManager': @SecurityManager
'./SubscriptionHandler': @SubscriptionHandler
@ -69,6 +70,7 @@ describe "SubscriptionController sanboxed", ->
'./RecurlyWrapper': @RecurlyWrapper
"logger-sharelatex": log:->
"settings-sharelatex": @settings
"./SubscriptionDomainAllocator":@SubscriptionDomainAllocator
@res = new MockResponse()
@ -206,6 +208,35 @@ describe "SubscriptionController sanboxed", ->
@res.redirected.should.equal true
@res.redirectedTo.should.equal "/user/subscription/plans"
describe "with a potential domain licence", ->
beforeEach () ->
@groupUrl = "/go/over-here"
@SubscriptionDomainAllocator.getDomainLicencePage.returns(@groupUrl)
describe "without an existing subscription", ->
beforeEach (done)->
@res.callback = done
@LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, false)
@SubscriptionController.userSubscriptionPage @req, @res
it "should redirect to the group invite url", ->
@res.redirected.should.equal true
@res.redirectedTo.should.equal @groupUrl
describe "with an existing subscription", ->
beforeEach (done)->
@res.callback = done
@LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, true)
@SubscriptionController.userSubscriptionPage @req, @res
it "should render the dashboard", ->
@res.renderedTemplate.should.equal "subscriptions/dashboard"
describe "with a user with a paid subscription", ->
beforeEach (done) ->
@res.callback = done