From aa549dd0d4bd7e99aced59812f354d5ad513c80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Alby?= Date: Thu, 25 Oct 2018 17:08:52 +0200 Subject: [PATCH] Merge pull request #1063 from sharelatex/ta-remove-add-user-to-group Remove addUserToGroup Action GitOrigin-RevId: 4f0cbf3dce47ee317b14784402128960a2caffa1 --- .../SubscriptionGroupController.coffee | 19 --------- .../SubscriptionGroupHandler.coffee | 25 ------------ .../Subscription/SubscriptionRouter.coffee | 1 - .../SubscriptionGroupControllerTests.coffee | 14 ------- .../SubscriptionGroupHandlerTests.coffee | 40 ------------------- 5 files changed, 99 deletions(-) diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee index 803732e44c..cb87355359 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee @@ -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 diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionGroupHandler.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionGroupHandler.coffee index bb849fa7bd..53f4c05cf8 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionGroupHandler.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionGroupHandler.coffee @@ -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 diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionRouter.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionRouter.coffee index 042e26a8f0..b2f9bddfdd 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionRouter.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionRouter.coffee @@ -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 diff --git a/services/web/test/unit/coffee/Subscription/SubscriptionGroupControllerTests.coffee b/services/web/test/unit/coffee/Subscription/SubscriptionGroupControllerTests.coffee index 91706130f3..6c77cda1b8 100644 --- a/services/web/test/unit/coffee/Subscription/SubscriptionGroupControllerTests.coffee +++ b/services/web/test/unit/coffee/Subscription/SubscriptionGroupControllerTests.coffee @@ -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" diff --git a/services/web/test/unit/coffee/Subscription/SubscriptionGroupHandlerTests.coffee b/services/web/test/unit/coffee/Subscription/SubscriptionGroupHandlerTests.coffee index 2a92f564c8..f6b00e36d4 100644 --- a/services/web/test/unit/coffee/Subscription/SubscriptionGroupHandlerTests.coffee +++ b/services/web/test/unit/coffee/Subscription/SubscriptionGroupHandlerTests.coffee @@ -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)->