mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
deleteing user account cancels any subscription
This commit is contained in:
parent
fe026b4b0b
commit
99dc141693
2 changed files with 22 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue