Merge pull request #1063 from sharelatex/ta-remove-add-user-to-group

Remove addUserToGroup Action

GitOrigin-RevId: 4f0cbf3dce47ee317b14784402128960a2caffa1
This commit is contained in:
Timothée Alby 2018-10-25 17:08:52 +02:00 committed by sharelatex
parent aff47a4b11
commit aa549dd0d4
5 changed files with 0 additions and 99 deletions

View file

@ -9,25 +9,6 @@ async = require("async")
module.exports = module.exports =
addUserToGroup: (req, res, next)->
adminUserId = AuthenticationController.getLoggedInUserId(req)
newEmail = req.body?.email?.toLowerCase()?.trim()
getManagedSubscription adminUserId, (error, subscription) ->
return next(error) if error?
logger.log adminUserId:adminUserId, newEmail:newEmail, "adding user to group subscription"
SubscriptionGroupHandler.addUserToGroup subscription._id, newEmail, (err, user)->
if err?
logger.err err:err, newEmail:newEmail, adminUserId:adminUserId, "error adding user from group"
return res.sendStatus 500
result =
user:user
if err and err.limitReached
result.limitReached = true
res.json(result)
removeUserFromGroup: (req, res, next)-> removeUserFromGroup: (req, res, next)->
adminUserId = AuthenticationController.getLoggedInUserId(req) adminUserId = AuthenticationController.getLoggedInUserId(req)
userToRemove_id = req.params.user_id userToRemove_id = req.params.user_id

View file

@ -15,31 +15,6 @@ UserMembershipViewModel = require("../UserMembership/UserMembershipViewModel")
module.exports = SubscriptionGroupHandler = module.exports = SubscriptionGroupHandler =
addUserToGroup: (subscriptionId, newEmail, callback)->
logger.log subscriptionId:subscriptionId, newEmail:newEmail, "adding user to group"
LimitationsManager.hasGroupMembersLimitReached subscriptionId, (err, limitReached, subscription)->
if err?
logger.err err:err, subscriptionId:subscriptionId, newEmail:newEmail, "error checking if limit reached for group plan"
return callback(err)
if limitReached
logger.err subscriptionId:subscriptionId, newEmail:newEmail, "group subscription limit reached not adding user to group"
return callback(limitReached:limitReached)
UserGetter.getUserByAnyEmail newEmail, (err, user)->
return callback(err) if err?
if user?
SubscriptionUpdater.addUserToGroup subscriptionId, user._id, (err)->
if err?
logger.err err:err, "error adding user to group"
return callback(err)
NotificationsBuilder.groupPlan(user, {subscription_id:subscription._id}).read()
userViewModel = UserMembershipViewModel.build(user)
callback(err, userViewModel)
else
TeamInvitesHandler.createInvite subscriptionId, newEmail, (err) ->
return callback(err) if err?
userViewModel = UserMembershipViewModel.build(newEmail)
callback(err, userViewModel)
removeUserFromGroup: (subscriptionId, userToRemove_id, callback)-> removeUserFromGroup: (subscriptionId, userToRemove_id, callback)->
SubscriptionUpdater.removeUserFromGroup subscriptionId, userToRemove_id, callback SubscriptionUpdater.removeUserFromGroup subscriptionId, userToRemove_id, callback

View file

@ -21,7 +21,6 @@ module.exports =
webRouter.get '/subscription/group', AuthenticationController.requireLogin(), SubscriptionGroupController.redirectToSubscriptionGroupAdminPage webRouter.get '/subscription/group', AuthenticationController.requireLogin(), SubscriptionGroupController.redirectToSubscriptionGroupAdminPage
webRouter.post '/subscription/group/user', AuthenticationController.requireLogin(), SubscriptionGroupController.addUserToGroup
webRouter.get '/subscription/group/export', AuthenticationController.requireLogin(), SubscriptionGroupController.exportGroupCsv webRouter.get '/subscription/group/export', AuthenticationController.requireLogin(), SubscriptionGroupController.exportGroupCsv
webRouter.delete '/subscription/group/user/:user_id', AuthenticationController.requireLogin(), SubscriptionGroupController.removeUserFromGroup webRouter.delete '/subscription/group/user/:user_id', AuthenticationController.requireLogin(), SubscriptionGroupController.removeUserFromGroup
webRouter.delete '/subscription/group/user', AuthenticationController.requireLogin(), SubscriptionGroupController.removeSelfFromGroup webRouter.delete '/subscription/group/user', AuthenticationController.requireLogin(), SubscriptionGroupController.removeSelfFromGroup

View file

@ -24,7 +24,6 @@ describe "SubscriptionGroupController", ->
_id: @subscriptionId _id: @subscriptionId
} }
@GroupHandler = @GroupHandler =
addUserToGroup: sinon.stub().callsArgWith(2, null, @user)
removeUserFromGroup: sinon.stub().callsArgWith(2) removeUserFromGroup: sinon.stub().callsArgWith(2)
isUserPartOfGroup: sinon.stub() isUserPartOfGroup: sinon.stub()
getPopulatedListOfMembers: sinon.stub().callsArgWith(1, null, [@user]) getPopulatedListOfMembers: sinon.stub().callsArgWith(1, null, [@user])
@ -57,19 +56,6 @@ describe "SubscriptionGroupController", ->
@token = "super-secret-token" @token = "super-secret-token"
describe "addUserToGroup", ->
it "should use the subscription id for the logged in user and take the email address from the body", (done)->
newEmail = " boB@gmaiL.com "
@req.body = email: newEmail
res =
json : (data)=>
@GroupHandler.addUserToGroup.calledWith(@subscriptionId, "bob@gmail.com").should.equal true
data.user.should.deep.equal @user
done()
@Controller.addUserToGroup @req, res
describe "removeUserFromGroup", -> describe "removeUserFromGroup", ->
it "should use the subscription id for the logged in user and take the user id from the params", (done)-> it "should use the subscription id for the logged in user and take the user id from the params", (done)->
userIdToRemove = "31231" userIdToRemove = "31231"

View file

@ -29,7 +29,6 @@ describe "SubscriptionGroupHandler", ->
getUserOrCreateHoldingAccount: sinon.stub().callsArgWith(1, null, @user) getUserOrCreateHoldingAccount: sinon.stub().callsArgWith(1, null, @user)
@SubscriptionUpdater = @SubscriptionUpdater =
addUserToGroup: sinon.stub().callsArgWith(2)
removeUserFromGroup: sinon.stub().callsArgWith(2) removeUserFromGroup: sinon.stub().callsArgWith(2)
@TeamInvitesHandler = @TeamInvitesHandler =
@ -82,45 +81,6 @@ describe "SubscriptionGroupHandler", ->
warn:-> warn:->
describe "addUserToGroup", ->
beforeEach ->
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, false, @subscription)
@UserGetter.getUserByAnyEmail.callsArgWith(1, null, @user)
it "should find the user", (done)->
@Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
@UserGetter.getUserByAnyEmail.calledWith(@newEmail).should.equal true
done()
it "should add the user to the group", (done)->
@Handler.addUserToGroup @subscription_id, @newEmail, (err)=>
@SubscriptionUpdater.addUserToGroup.calledWith(@subscription_id, @user._id).should.equal true
done()
it "should not add the user to the group if the limit has been reached", (done)->
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, true, @subscription)
@Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
@SubscriptionUpdater.addUserToGroup.called.should.equal false
done()
it "should return error that limit has been reached", (done)->
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, true, @subscription)
@Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
err.limitReached.should.equal true
done()
it "should mark any notification as read if it is part of a licence", (done)->
@Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
@NotificationsBuilder.groupPlan.calledWith(@user, {subscription_id:@subscription._id}).should.equal true
@readStub.called.should.equal true
done()
it "should add an email invite if no user is found", (done) ->
@UserGetter.getUserByAnyEmail.callsArgWith(1, null, null)
@Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
@TeamInvitesHandler.createInvite.calledWith(@adminUser_id, @newEmail).should.equal true
done()
describe "removeUserFromGroup", -> describe "removeUserFromGroup", ->
it "should call the subscription updater to remove the user", (done)-> it "should call the subscription updater to remove the user", (done)->