renamed SubscriptionDomainAllocator -> SubscriptionDomainHandler

This commit is contained in:
Henry Oswald 2015-05-27 20:57:54 +01:00
parent 4773d6d22f
commit 22b94e9246
8 changed files with 38 additions and 38 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")
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"

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -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)->

View file

@ -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()

View file

@ -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, {}

View file

@ -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 = {}