diff --git a/services/web/app/coffee/Features/User/UserDeleter.coffee b/services/web/app/coffee/Features/User/UserDeleter.coffee index 57126af4a5..56ff06df4c 100644 --- a/services/web/app/coffee/Features/User/UserDeleter.coffee +++ b/services/web/app/coffee/Features/User/UserDeleter.coffee @@ -2,6 +2,8 @@ User = require("../../models/User").User NewsletterManager = require "../../managers/NewsletterManager" ProjectDeleter = require("../Project/ProjectDeleter") logger = require("logger-sharelatex") +SubscriptionHandler = require("../Subscription/SubscriptionHandler") +async = require("async") module.exports = @@ -10,13 +12,19 @@ module.exports = logger.err "user_id is null when trying to delete user" return callback("no user_id") User.findById user_id, (err, user)-> - logger.log user:user, "deleting user" if err? return callback(err) - NewsletterManager.unsubscribe user, (err)-> + logger.log user:user, "deleting user" + async.series [ + (cb)-> + NewsletterManager.unsubscribe user, cb + (cb)-> + ProjectDeleter.deleteUsersProjects user._id, cb + (cb)-> + SubscriptionHandler.cancelSubscription user._id, cb + (cb)-> + user.remove cb + ], (err)-> if err? - return callback(err) - ProjectDeleter.deleteUsersProjects user._id, (err)-> - if err? - return callback(err) - user.remove callback + logger.err err:err, user_id:user_id, "something went wrong deleteing the user" + callback err diff --git a/services/web/test/UnitTests/coffee/User/UserDeleterTests.coffee b/services/web/test/UnitTests/coffee/User/UserDeleterTests.coffee index 2b84589f50..79a7b965c4 100644 --- a/services/web/test/UnitTests/coffee/User/UserDeleterTests.coffee +++ b/services/web/test/UnitTests/coffee/User/UserDeleterTests.coffee @@ -21,9 +21,12 @@ describe "UserDeleter", -> @ProjectDeleter = deleteUsersProjects: sinon.stub().callsArgWith(1) + @SubscriptionHandler = + cancelSubscription: sinon.stub().callsArgWith(1) @UserDeleter = SandboxedModule.require modulePath, requires: "../../models/User": User: @User "../../managers/NewsletterManager": @NewsletterManager + "../Subscription/SubscriptionHandler": @SubscriptionHandler "../Project/ProjectDeleter": @ProjectDeleter describe "deleteUser", -> @@ -44,4 +47,7 @@ describe "UserDeleter", -> @ProjectDeleter.deleteUsersProjects.calledWith(@user._id).should.equal true done() - + it "should unsubscribe the user", (done)-> + @UserDeleter.deleteUser @user._id, (err)=> + @SubscriptionHandler.cancelSubscription.calledWith(@user._id).should.equal true + done()