mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #1063 from sharelatex/ta-remove-add-user-to-group
Remove addUserToGroup Action GitOrigin-RevId: 4f0cbf3dce47ee317b14784402128960a2caffa1
This commit is contained in:
parent
aff47a4b11
commit
aa549dd0d4
5 changed files with 0 additions and 99 deletions
|
@ -9,25 +9,6 @@ async = require("async")
|
|||
|
||||
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)->
|
||||
adminUserId = AuthenticationController.getLoggedInUserId(req)
|
||||
userToRemove_id = req.params.user_id
|
||||
|
|
|
@ -15,31 +15,6 @@ UserMembershipViewModel = require("../UserMembership/UserMembershipViewModel")
|
|||
|
||||
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)->
|
||||
SubscriptionUpdater.removeUserFromGroup subscriptionId, userToRemove_id, callback
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ module.exports =
|
|||
|
||||
|
||||
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.delete '/subscription/group/user/:user_id', AuthenticationController.requireLogin(), SubscriptionGroupController.removeUserFromGroup
|
||||
webRouter.delete '/subscription/group/user', AuthenticationController.requireLogin(), SubscriptionGroupController.removeSelfFromGroup
|
||||
|
|
|
@ -24,7 +24,6 @@ describe "SubscriptionGroupController", ->
|
|||
_id: @subscriptionId
|
||||
}
|
||||
@GroupHandler =
|
||||
addUserToGroup: sinon.stub().callsArgWith(2, null, @user)
|
||||
removeUserFromGroup: sinon.stub().callsArgWith(2)
|
||||
isUserPartOfGroup: sinon.stub()
|
||||
getPopulatedListOfMembers: sinon.stub().callsArgWith(1, null, [@user])
|
||||
|
@ -57,19 +56,6 @@ describe "SubscriptionGroupController", ->
|
|||
@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", ->
|
||||
it "should use the subscription id for the logged in user and take the user id from the params", (done)->
|
||||
userIdToRemove = "31231"
|
||||
|
|
|
@ -29,7 +29,6 @@ describe "SubscriptionGroupHandler", ->
|
|||
getUserOrCreateHoldingAccount: sinon.stub().callsArgWith(1, null, @user)
|
||||
|
||||
@SubscriptionUpdater =
|
||||
addUserToGroup: sinon.stub().callsArgWith(2)
|
||||
removeUserFromGroup: sinon.stub().callsArgWith(2)
|
||||
|
||||
@TeamInvitesHandler =
|
||||
|
@ -82,45 +81,6 @@ describe "SubscriptionGroupHandler", ->
|
|||
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", ->
|
||||
|
||||
it "should call the subscription updater to remove the user", (done)->
|
||||
|
|
Loading…
Reference in a new issue