mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-23 01:23:59 +00:00
Remove a user from being a collaborator when their account is deleted
This commit is contained in:
parent
a0fcc7e3ed
commit
b76cc7e314
4 changed files with 41 additions and 7 deletions
|
@ -87,6 +87,17 @@ module.exports = CollaboratorsHandler =
|
|||
logger.error err: err, "problem removing user from project collaberators"
|
||||
callback(err)
|
||||
|
||||
removeUserFromAllProjets: (user_id, callback = (error) ->) ->
|
||||
CollaboratorsHandler.getProjectsUserIsCollaboratorOf user_id, { _id: 1 }, (error, readAndWriteProjects = [], readOnlyProjects = []) ->
|
||||
return callback(error) if error?
|
||||
allProjects = readAndWriteProjects.concat(readOnlyProjects)
|
||||
jobs = []
|
||||
for project in allProjects
|
||||
do (project) ->
|
||||
jobs.push (cb) ->
|
||||
CollaboratorsHandler.removeUserFromProject project._id, user_id, cb
|
||||
async.series jobs, callback
|
||||
|
||||
addEmailToProject: (project_id, adding_user_id, unparsed_email, privilegeLevel, callback = (error, user) ->) ->
|
||||
emails = mimelib.parseAddresses(unparsed_email)
|
||||
email = emails[0]?.address?.toLowerCase()
|
||||
|
|
|
@ -24,9 +24,11 @@ module.exports = ProjectDeleter =
|
|||
update = {deletedByExternalDataSource: false}
|
||||
Project.update conditions, update, {}, callback
|
||||
|
||||
deleteUsersProjects: (owner_id, callback)->
|
||||
logger.log owner_id:owner_id, "deleting users projects"
|
||||
Project.remove owner_ref:owner_id, callback
|
||||
deleteUsersProjects: (user_id, callback)->
|
||||
logger.log {user_id}, "deleting users projects"
|
||||
Project.remove owner_ref:user_id, (error) ->
|
||||
return callback(error) if error?
|
||||
CollaboratorsHandler.removeUserFromAllProjets user_id, callback
|
||||
|
||||
deleteProject: (project_id, callback = (error) ->) ->
|
||||
# archiveProject takes care of the clean-up
|
||||
|
|
|
@ -276,6 +276,19 @@ describe "CollaboratorsHandler", ->
|
|||
it "should not add any users to the proejct", ->
|
||||
@CollaboratorHandler.addUserIdToProject.called.should.equal false
|
||||
|
||||
|
||||
|
||||
|
||||
describe "removeUserFromAllProjets", ->
|
||||
beforeEach (done) ->
|
||||
@CollaboratorHandler.getProjectsUserIsCollaboratorOf = sinon.stub()
|
||||
@CollaboratorHandler.getProjectsUserIsCollaboratorOf.withArgs(@user_id, { _id: 1 }).yields(
|
||||
null,
|
||||
[ { _id: "read-and-write-0" }, { _id: "read-and-write-1" } ],
|
||||
[ { _id: "read-only-0" }, { _id: "read-only-1" } ]
|
||||
)
|
||||
@CollaboratorHandler.removeUserFromProject = sinon.stub().yields()
|
||||
@CollaboratorHandler.removeUserFromAllProjets @user_id, done
|
||||
|
||||
it "should remove the user from each project", ->
|
||||
for project_id in ["read-and-write-0", "read-and-write-1", "read-only-0", "read-only-1"]
|
||||
@CollaboratorHandler.removeUserFromProject
|
||||
.calledWith(project_id, @user_id)
|
||||
.should.equal true
|
|
@ -27,13 +27,15 @@ describe 'ProjectDeleter', ->
|
|||
removeProjectFromAllTags: sinon.stub().callsArgWith(2)
|
||||
@ProjectGetter =
|
||||
getProject:sinon.stub()
|
||||
@CollaboratorsHandler =
|
||||
removeUserFromAllProjets: sinon.stub().yields()
|
||||
@deleter = SandboxedModule.require modulePath, requires:
|
||||
"../Editor/EditorController": @editorController
|
||||
'../../models/Project':{Project:@Project}
|
||||
'../DocumentUpdater/DocumentUpdaterHandler': @documentUpdaterHandler
|
||||
"../Tags/TagsHandler":@TagsHandler
|
||||
"../FileStore/FileStoreHandler": @FileStoreHandler = {}
|
||||
"../Collaborators/CollaboratorsHandler": @CollaboratorsHandler = {}
|
||||
"../Collaborators/CollaboratorsHandler": @CollaboratorsHandler
|
||||
"./ProjectGetter": @ProjectGetter
|
||||
'logger-sharelatex':
|
||||
log:->
|
||||
|
@ -74,6 +76,12 @@ describe 'ProjectDeleter', ->
|
|||
@Project.remove.calledWith(owner_ref:user_id).should.equal true
|
||||
done()
|
||||
|
||||
it "should remove all the projects the user is a collaborator of", (done)->
|
||||
user_id = 1234
|
||||
@deleter.deleteUsersProjects user_id, =>
|
||||
@CollaboratorsHandler.removeUserFromAllProjets.calledWith(user_id).should.equal true
|
||||
done()
|
||||
|
||||
describe "deleteProject", ->
|
||||
beforeEach (done) ->
|
||||
@project_id = "mock-project-id-123"
|
||||
|
|
Loading…
Reference in a new issue