From 22b94e924687e4ead0096638094cb6b2b767e3ca Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 27 May 2015 20:57:54 +0100 Subject: [PATCH] renamed SubscriptionDomainAllocator -> SubscriptionDomainHandler --- .../SubscriptionController.coffee | 4 ++-- ...offee => SubscriptionDomainHandler.coffee} | 10 ++++----- .../SubscriptionGroupController.coffee | 12 +++++----- .../Features/User/UserController.coffee | 2 +- .../SubscriptionControllerTests.coffee | 6 ++--- ... => SubscriptionDomainHandlerTests.coffee} | 22 +++++++++---------- .../SubscriptionGroupControllerTests.coffee | 16 +++++++------- .../coffee/User/UserControllerTests.coffee | 4 ++-- 8 files changed, 38 insertions(+), 38 deletions(-) rename services/web/app/coffee/Features/Subscription/{SubscriptionDomainAllocator.coffee => SubscriptionDomainHandler.coffee} (79%) rename services/web/test/UnitTests/coffee/Subscription/{SubscriptionDomainAllocatorTests.coffee => SubscriptionDomainHandlerTests.coffee} (66%) diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee index 7971110eb7..ea03458093 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") +SubscriptionDomainHandler = require("./SubscriptionDomainHandler") module.exports = SubscriptionController = @@ -84,7 +84,7 @@ module.exports = SubscriptionController = SecurityManager.getCurrentUser req, (error, user) => return next(error) if error? LimitationsManager.userHasSubscriptionOrIsGroupMember user, (err, hasSubOrIsGroupMember, subscription)-> - groupLicenceInviteUrl = SubscriptionDomainAllocator.getDomainLicencePage(user) + groupLicenceInviteUrl = SubscriptionDomainHandler.getDomainLicencePage(user) if subscription?.customAccount logger.log user: user, "redirecting to plans" res.redirect "/user/subscription/custom_account" diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionDomainAllocator.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionDomainHandler.coffee similarity index 79% rename from services/web/app/coffee/Features/Subscription/SubscriptionDomainAllocator.coffee rename to services/web/app/coffee/Features/Subscription/SubscriptionDomainHandler.coffee index 90401b0de5..b57c3492f6 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionDomainAllocator.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionDomainHandler.coffee @@ -4,18 +4,18 @@ settings = require("settings-sharelatex") SubscriptionGroupHandler = require("./SubscriptionGroupHandler") _s = require("underscore.string") -module.exports = SubscriptionDomainAllocator = +module.exports = SubscriptionDomainHandler = getLicenceUserCanJoin: (user, callback)-> - licence = SubscriptionDomainAllocator._findDomainLicence(user.email) + licence = SubscriptionDomainHandler._findDomainLicence(user.email) if licence? callback null, licence else callback() attemptToJoinGroup: (user, callback)-> - licence = SubscriptionDomainAllocator._findDomainLicence(user.email) + licence = SubscriptionDomainHandler._findDomainLicence(user.email) if licence? and user.emailVerified SubscriptionGroupHandler.addUserToGroup licence.adminUser_id, user.email, callback else @@ -26,7 +26,7 @@ module.exports = SubscriptionDomainAllocator = getDomainLicencePage: (user)-> - licence = SubscriptionDomainAllocator._findDomainLicence(user.email) + licence = SubscriptionDomainHandler._findDomainLicence(user.email) if licence?.verifyEmail return "/user/subscription/#{licence.subscription_id}/group/invited" else @@ -34,7 +34,7 @@ module.exports = SubscriptionDomainAllocator = autoAllocate: (user, callback = ->)-> - licence = SubscriptionDomainAllocator._findDomainLicence(user.email) + licence = SubscriptionDomainHandler._findDomainLicence(user.email) # if licence? SubscriptionGroupHandler.addUserToGroup licence.adminUser_id, user.email, callback diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee index e60e4e4600..31d8077788 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee @@ -5,7 +5,7 @@ SubscriptionLocator = require("./SubscriptionLocator") ErrorsController = require("../Errors/ErrorController") settings = require("settings-sharelatex") -SubscriptionDomainAllocator = require("./SubscriptionDomainAllocator") +SubscriptionDomainHandler = require("./SubscriptionDomainHandler") _ = require("underscore") module.exports = @@ -42,7 +42,7 @@ module.exports = renderGroupInvitePage: (req, res)-> subscription_id = req.params.subscription_id user_id = req.session.user._id - licence = SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId(subscription_id) + licence = SubscriptionDomainHandler.findDomainLicenceBySubscriptionId(subscription_id) if !licence? return ErrorsController.notFound(req, res) SubscriptionGroupHandler.isUserPartOfGroup user_id, licence.subscription_id, (err, partOfGroup)-> @@ -57,7 +57,7 @@ module.exports = beginJoinGroup: (req, res)-> subscription_id = req.params.subscription_id user_id = req.session.user._id - licence = SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId(subscription_id) + licence = SubscriptionDomainHandler.findDomainLicenceBySubscriptionId(subscription_id) if !licence? return ErrorsController.notFound(req, res) SubscriptionGroupHandler.sendVerificationEmail subscription_id, licence.name, req.session.user.email, (err)-> @@ -68,7 +68,7 @@ module.exports = completeJoin: (req, res)-> subscription_id = req.params.subscription_id - if !SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId(subscription_id)? + if !SubscriptionDomainHandler.findDomainLicenceBySubscriptionId(subscription_id)? return ErrorsController.notFound(req, res) SubscriptionGroupHandler.processGroupVerification req.session.user.email, subscription_id, req.query.token, (err)-> if err? @@ -78,8 +78,8 @@ module.exports = renderSuccessfulJoinPage: (req, res)-> subscription_id = req.params.subscription_id - licence = SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId(subscription_id) - if !SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId(subscription_id)? + licence = SubscriptionDomainHandler.findDomainLicenceBySubscriptionId(subscription_id) + if !SubscriptionDomainHandler.findDomainLicenceBySubscriptionId(subscription_id)? return ErrorsController.notFound(req, res) res.render "subscriptions/group/successful_join", title: "Sucessfully joined group" diff --git a/services/web/app/coffee/Features/User/UserController.coffee b/services/web/app/coffee/Features/User/UserController.coffee index 1efe77e44c..a374939545 100644 --- a/services/web/app/coffee/Features/User/UserController.coffee +++ b/services/web/app/coffee/Features/User/UserController.coffee @@ -8,7 +8,7 @@ metrics = require("../../infrastructure/Metrics") Url = require("url") AuthenticationManager = require("../Authentication/AuthenticationManager") UserUpdater = require("./UserUpdater") -SubscriptionDomainAllocator = require("../Subscription/SubscriptionDomainAllocator") +SubscriptionDomainHandler = require("../Subscription/SubscriptionDomainHandler") EmailHandler = require("../Email/EmailHandler") OneTimeTokenHandler = require "../Security/OneTimeTokenHandler" settings = require "settings-sharelatex" diff --git a/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee b/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee index 18488c0fe7..56e31c5f26 100644 --- a/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee @@ -58,7 +58,7 @@ describe "SubscriptionController sanboxed", -> gaExperiments:{} @GeoIpLookup = getCurrencyCode:sinon.stub() - @SubscriptionDomainAllocator = + @SubscriptionDomainHandler = getDomainLicencePage:sinon.stub() @SubscriptionController = SandboxedModule.require modulePath, requires: '../../managers/SecurityManager': @SecurityManager @@ -70,7 +70,7 @@ describe "SubscriptionController sanboxed", -> './RecurlyWrapper': @RecurlyWrapper "logger-sharelatex": log:-> "settings-sharelatex": @settings - "./SubscriptionDomainAllocator":@SubscriptionDomainAllocator + "./SubscriptionDomainHandler":@SubscriptionDomainHandler @res = new MockResponse() @@ -211,7 +211,7 @@ describe "SubscriptionController sanboxed", -> describe "with a potential domain licence", -> beforeEach () -> @groupUrl = "/go/over-here" - @SubscriptionDomainAllocator.getDomainLicencePage.returns(@groupUrl) + @SubscriptionDomainHandler.getDomainLicencePage.returns(@groupUrl) describe "without an existing subscription", -> beforeEach (done)-> diff --git a/services/web/test/UnitTests/coffee/Subscription/SubscriptionDomainAllocatorTests.coffee b/services/web/test/UnitTests/coffee/Subscription/SubscriptionDomainHandlerTests.coffee similarity index 66% rename from services/web/test/UnitTests/coffee/Subscription/SubscriptionDomainAllocatorTests.coffee rename to services/web/test/UnitTests/coffee/Subscription/SubscriptionDomainHandlerTests.coffee index 7c48b889fb..21a44da1ca 100644 --- a/services/web/test/UnitTests/coffee/Subscription/SubscriptionDomainAllocatorTests.coffee +++ b/services/web/test/UnitTests/coffee/Subscription/SubscriptionDomainHandlerTests.coffee @@ -3,10 +3,10 @@ SandboxedModule = require('sandboxed-module') assert = require('assert') path = require('path') sinon = require('sinon') -modulePath = path.join __dirname, "../../../../app/js/Features/Subscription/SubscriptionDomainAllocator" +modulePath = path.join __dirname, "../../../../app/js/Features/Subscription/SubscriptionDomainHandler" expect = require("chai").expect -describe "SubscriptionDomainAllocator", -> +describe "SubscriptionDomainHandler", -> beforeEach -> @@ -18,7 +18,7 @@ describe "SubscriptionDomainAllocator", -> ] @SubscriptionGroupHandler = addUserToGroup: sinon.stub().callsArg(2) - @SubscriptionDomainAllocator = SandboxedModule.require modulePath, requires: + @SubscriptionDomainHandler = SandboxedModule.require modulePath, requires: "settings-sharelatex":@settings "logger-sharelatex": log:-> "./SubscriptionGroupHandler": @SubscriptionGroupHandler @@ -28,33 +28,33 @@ describe "SubscriptionDomainAllocator", -> describe "_findDomainLicence", -> it "should find the domain", (done)-> - licence = @SubscriptionDomainAllocator._findDomainLicence "bob@uni.edu" + licence = @SubscriptionDomainHandler._findDomainLicence "bob@uni.edu" licence.adminUser_id.should.equal @adminUser_id done() it "should find one of the other emails in the domain list", (done)-> - licence = @SubscriptionDomainAllocator._findDomainLicence "sally@student.uni.edu" + licence = @SubscriptionDomainHandler._findDomainLicence "sally@student.uni.edu" licence.adminUser_id.should.equal @adminUser_id done() it "should return undefined if no licence matches", (done)-> - licence = @SubscriptionDomainAllocator._findDomainLicence "bob@other.edu" + licence = @SubscriptionDomainHandler._findDomainLicence "bob@other.edu" expect(licence).to.not.exist done(licence) describe "autoAllocate", -> beforeEach -> @email = "bob@somewhere.com" - @SubscriptionDomainAllocator._findDomainLicence = sinon.stub() + @SubscriptionDomainHandler._findDomainLicence = sinon.stub() it "should call the SubscriptionGroupHandler if there is licence", (done)-> - @SubscriptionDomainAllocator._findDomainLicence.returns(@settings.domainLicences[1]) - @SubscriptionDomainAllocator.autoAllocate {email:@email}, (err)=> + @SubscriptionDomainHandler._findDomainLicence.returns(@settings.domainLicences[1]) + @SubscriptionDomainHandler.autoAllocate {email:@email}, (err)=> @SubscriptionGroupHandler.addUserToGroup.calledWith(@adminUser_id, @email).should.equal true done() it "should not call the SubscriptionGroupHandler if there is no licence", (done)-> - @SubscriptionDomainAllocator._findDomainLicence.returns() - @SubscriptionDomainAllocator.autoAllocate {email:@email}, (err)=> + @SubscriptionDomainHandler._findDomainLicence.returns() + @SubscriptionDomainHandler.autoAllocate {email:@email}, (err)=> @SubscriptionGroupHandler.addUserToGroup.called.should.equal false done() \ No newline at end of file diff --git a/services/web/test/UnitTests/coffee/Subscription/SubscriptionGroupControllerTests.coffee b/services/web/test/UnitTests/coffee/Subscription/SubscriptionGroupControllerTests.coffee index 828657a1e1..8dd5d93e8c 100644 --- a/services/web/test/UnitTests/coffee/Subscription/SubscriptionGroupControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Subscription/SubscriptionGroupControllerTests.coffee @@ -19,7 +19,7 @@ describe "Subscription Group Controller", -> @SubscriptionLocator = getUsersSubscription: sinon.stub().callsArgWith(1, null, @subscription) - @SubscriptionDomainAllocator = + @SubscriptionDomainHandler = findDomainLicenceBySubscriptionId:sinon.stub() @OneTimeTokenHandler = @@ -33,7 +33,7 @@ describe "Subscription Group Controller", -> "./SubscriptionGroupHandler":@GroupHandler "logger-sharelatex": log:-> "./SubscriptionLocator": @SubscriptionLocator - "./SubscriptionDomainAllocator":@SubscriptionDomainAllocator + "./SubscriptionDomainHandler":@SubscriptionDomainHandler "../Errors/ErrorController":@ErrorsController @adminUserId = "123jlkj" @@ -90,7 +90,7 @@ describe "Subscription Group Controller", -> describe "renderGroupInvitePage", -> describe "with a valid licence", -> beforeEach -> - @SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId.returns({subscription_id:@subscription_id, adminUser_id:@adminUserId}) + @SubscriptionDomainHandler.findDomainLicenceBySubscriptionId.returns({subscription_id:@subscription_id, adminUser_id:@adminUserId}) it "should render subscriptions/group/invite if not part of group", (done)-> @GroupHandler.isUserPartOfGroup.callsArgWith(2, null, false) @@ -110,7 +110,7 @@ describe "Subscription Group Controller", -> describe "without a valid licence", -> beforeEach -> - @SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId.returns(undefined) + @SubscriptionDomainHandler.findDomainLicenceBySubscriptionId.returns(undefined) it "should send a 500", (done)-> @Controller.renderGroupInvitePage @req, {} @@ -123,7 +123,7 @@ describe "Subscription Group Controller", -> describe "with a valid licence", -> beforeEach -> @licenceName = "get amazing licence" - @SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId.returns({name:@licenceName}) + @SubscriptionDomainHandler.findDomainLicenceBySubscriptionId.returns({name:@licenceName}) @GroupHandler.sendVerificationEmail.callsArgWith(3) it "should ask the SubscriptionGroupHandler to send the verification email", (done)-> @@ -136,7 +136,7 @@ describe "Subscription Group Controller", -> describe "without a valid licence", -> beforeEach -> - @SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId.returns(undefined) + @SubscriptionDomainHandler.findDomainLicenceBySubscriptionId.returns(undefined) it "should send a 500", (done)-> @Controller.beginJoinGroup @req, {} @@ -148,7 +148,7 @@ describe "Subscription Group Controller", -> describe "with a valid licence", -> beforeEach -> @GroupHandler.processGroupVerification.callsArgWith(3) - @SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId.returns({name:@licenceName}) + @SubscriptionDomainHandler.findDomainLicenceBySubscriptionId.returns({name:@licenceName}) it "should redirect to the success page upon processGroupVerification", (done)-> @req.query.token = @token @@ -161,7 +161,7 @@ describe "Subscription Group Controller", -> describe "without a valid licence", -> beforeEach -> - @SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId.returns(undefined) + @SubscriptionDomainHandler.findDomainLicenceBySubscriptionId.returns(undefined) it "should send a 500", (done)-> @Controller.completeJoin @req, {} diff --git a/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee b/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee index cb94bc8618..3bc8a3ca46 100644 --- a/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee @@ -36,7 +36,7 @@ describe "UserController", -> setUserPassword: sinon.stub() @ReferalAllocator = allocate:sinon.stub() - @SubscriptionDomainAllocator = + @SubscriptionDomainHandler = autoAllocate:sinon.stub() @UserUpdater = changeEmailAddress:sinon.stub() @@ -56,7 +56,7 @@ describe "UserController", -> "../Authentication/AuthenticationController": @AuthenticationController "../Authentication/AuthenticationManager": @AuthenticationManager "../Referal/ReferalAllocator":@ReferalAllocator - "../Subscription/SubscriptionDomainAllocator":@SubscriptionDomainAllocator + "../Subscription/SubscriptionDomainHandler":@SubscriptionDomainHandler "../Email/EmailHandler": @EmailHandler "../Security/OneTimeTokenHandler": @OneTimeTokenHandler "crypto": @crypto = {}