mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -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"
|
NewsletterManager = require "../../managers/NewsletterManager"
|
||||||
ProjectDeleter = require("../Project/ProjectDeleter")
|
ProjectDeleter = require("../Project/ProjectDeleter")
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
|
SubscriptionHandler = require("../Subscription/SubscriptionHandler")
|
||||||
|
async = require("async")
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
|
|
||||||
|
@ -10,13 +12,19 @@ module.exports =
|
||||||
logger.err "user_id is null when trying to delete user"
|
logger.err "user_id is null when trying to delete user"
|
||||||
return callback("no user_id")
|
return callback("no user_id")
|
||||||
User.findById user_id, (err, user)->
|
User.findById user_id, (err, user)->
|
||||||
logger.log user:user, "deleting user"
|
|
||||||
if err?
|
if err?
|
||||||
return callback(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?
|
if err?
|
||||||
return callback(err)
|
logger.err err:err, user_id:user_id, "something went wrong deleteing the user"
|
||||||
ProjectDeleter.deleteUsersProjects user._id, (err)->
|
callback err
|
||||||
if err?
|
|
||||||
return callback(err)
|
|
||||||
user.remove callback
|
|
||||||
|
|
|
@ -21,9 +21,12 @@ describe "UserDeleter", ->
|
||||||
@ProjectDeleter =
|
@ProjectDeleter =
|
||||||
deleteUsersProjects: sinon.stub().callsArgWith(1)
|
deleteUsersProjects: sinon.stub().callsArgWith(1)
|
||||||
|
|
||||||
|
@SubscriptionHandler =
|
||||||
|
cancelSubscription: sinon.stub().callsArgWith(1)
|
||||||
@UserDeleter = SandboxedModule.require modulePath, requires:
|
@UserDeleter = SandboxedModule.require modulePath, requires:
|
||||||
"../../models/User": User: @User
|
"../../models/User": User: @User
|
||||||
"../../managers/NewsletterManager": @NewsletterManager
|
"../../managers/NewsletterManager": @NewsletterManager
|
||||||
|
"../Subscription/SubscriptionHandler": @SubscriptionHandler
|
||||||
"../Project/ProjectDeleter": @ProjectDeleter
|
"../Project/ProjectDeleter": @ProjectDeleter
|
||||||
|
|
||||||
describe "deleteUser", ->
|
describe "deleteUser", ->
|
||||||
|
@ -44,4 +47,7 @@ describe "UserDeleter", ->
|
||||||
@ProjectDeleter.deleteUsersProjects.calledWith(@user._id).should.equal true
|
@ProjectDeleter.deleteUsersProjects.calledWith(@user._id).should.equal true
|
||||||
done()
|
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