mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
pull logic checking if user is already part of a group out of controller into handler
This commit is contained in:
parent
72e528e9d1
commit
f27c072ae1
4 changed files with 41 additions and 9 deletions
|
@ -41,11 +41,12 @@ module.exports =
|
||||||
|
|
||||||
renderGroupInvitePage: (req, res)->
|
renderGroupInvitePage: (req, res)->
|
||||||
subscription_id = req.params.subscription_id
|
subscription_id = req.params.subscription_id
|
||||||
|
user_id = req.session.user._id
|
||||||
licence = SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId(subscription_id)
|
licence = SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId(subscription_id)
|
||||||
SubscriptionGroupHandler.getPopulatedListOfMembers licence.adminUser_id, (err, users)->
|
SubscriptionGroupHandler.isUserPartOfGroup user_id, licence.subscription_id, (err, partOfGroup)->
|
||||||
userInSubscription = _.find users, (user)-> user._id == req.session.user._id
|
if partOfGroup
|
||||||
if userInSubscription?
|
|
||||||
return res.redirect("/user/subscription/custom_account")
|
return res.redirect("/user/subscription/custom_account")
|
||||||
|
else
|
||||||
res.render "subscriptions/group/invite",
|
res.render "subscriptions/group/invite",
|
||||||
title: "Group Invitation"
|
title: "Group Invitation"
|
||||||
subscription_id:subscription_id
|
subscription_id:subscription_id
|
||||||
|
|
|
@ -5,7 +5,7 @@ SubscriptionUpdater = require("./SubscriptionUpdater")
|
||||||
SubscriptionLocator = require("./SubscriptionLocator")
|
SubscriptionLocator = require("./SubscriptionLocator")
|
||||||
UserLocator = require("../User/UserLocator")
|
UserLocator = require("../User/UserLocator")
|
||||||
LimitationsManager = require("./LimitationsManager")
|
LimitationsManager = require("./LimitationsManager")
|
||||||
|
logger = require("logger-sharelatex")
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
|
|
||||||
|
@ -37,6 +37,15 @@ module.exports =
|
||||||
async.series jobs, (err)->
|
async.series jobs, (err)->
|
||||||
callback(err, users)
|
callback(err, users)
|
||||||
|
|
||||||
|
isUserPartOfGroup: (user_id, subscription_id, callback=(err, partOfGroup)->)->
|
||||||
|
SubscriptionLocator.getSubscriptionByMemberIdAndId user_id, subscription_id, (err, subscription)->
|
||||||
|
if subscription?
|
||||||
|
partOfGroup = true
|
||||||
|
else
|
||||||
|
partOfGroup = false
|
||||||
|
logger.log user_id:user_id, subscription_id:subscription_id, partOfGroup:partOfGroup, "checking if user is part of a group"
|
||||||
|
callback(err, partOfGroup)
|
||||||
|
|
||||||
|
|
||||||
buildUserViewModel = (user)->
|
buildUserViewModel = (user)->
|
||||||
u =
|
u =
|
||||||
|
|
|
@ -18,3 +18,6 @@ module.exports =
|
||||||
|
|
||||||
getSubscription: (subscription_id, callback)->
|
getSubscription: (subscription_id, callback)->
|
||||||
Subscription.findOne _id:subscription_id, callback
|
Subscription.findOne _id:subscription_id, callback
|
||||||
|
|
||||||
|
getSubscriptionByMemberIdAndId: (user_id, subscription_id, callback)->
|
||||||
|
Subscription.findOne member_ids: user_id, _id:subscription_id, callback
|
||||||
|
|
|
@ -10,10 +10,12 @@ describe "Subscription Group Handler", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@adminUser_id = "12321"
|
@adminUser_id = "12321"
|
||||||
@newEmail = "bob@smith.com"
|
@newEmail = "bob@smith.com"
|
||||||
@user = {_id:"3121321", email:@newEmail}
|
@user_id = "3121321"
|
||||||
|
@user = {_id:@user_id, email:@newEmail}
|
||||||
|
|
||||||
@SubscriptionLocator =
|
@SubscriptionLocator =
|
||||||
getUsersSubscription: sinon.stub()
|
getUsersSubscription: sinon.stub()
|
||||||
|
getSubscriptionByMemberIdAndId: sinon.stub()
|
||||||
|
|
||||||
@UserCreator =
|
@UserCreator =
|
||||||
getUserOrCreateHoldingAccount: sinon.stub().callsArgWith(1, null, @user)
|
getUserOrCreateHoldingAccount: sinon.stub().callsArgWith(1, null, @user)
|
||||||
|
@ -100,3 +102,20 @@ describe "Subscription Group Handler", ->
|
||||||
assert.deepEqual users[2], {_id:@subscription.member_ids[2]}
|
assert.deepEqual users[2], {_id:@subscription.member_ids[2]}
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe "isUserPartOfGroup", ->
|
||||||
|
beforeEach ->
|
||||||
|
@subscription_id = "123ed13123"
|
||||||
|
|
||||||
|
it "should return true when user is part of subscription", (done)->
|
||||||
|
@SubscriptionLocator.getSubscriptionByMemberIdAndId.callsArgWith(2, null, {_id:@subscription_id})
|
||||||
|
@Handler.isUserPartOfGroup @user_id, @subscription_id, (err, partOfGroup)->
|
||||||
|
partOfGroup.should.equal true
|
||||||
|
done()
|
||||||
|
|
||||||
|
it "should return false when no subscription is found", (done)->
|
||||||
|
@SubscriptionLocator.getSubscriptionByMemberIdAndId.callsArgWith(2, null)
|
||||||
|
@Handler.isUserPartOfGroup @user_id, @subscription_id, (err, partOfGroup)->
|
||||||
|
partOfGroup.should.equal false
|
||||||
|
done()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue