From 79fa49a43d1b79bf8793d1c13bea1f57f044de4f Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 27 May 2015 15:07:46 +0100 Subject: [PATCH] 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 --- .../SubscriptionController.coffee | 8 +++-- .../SubscriptionControllerTests.coffee | 33 ++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee index adaf8e6e65..7971110eb7 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee @@ -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" diff --git a/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee b/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee index 624f55ef0d..71fd9f51a5 100644 --- a/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee @@ -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