Remove a user from being a collaborator when their account is deleted

This commit is contained in:
James Allen 2016-06-30 14:21:44 +01:00
parent a0fcc7e3ed
commit b76cc7e314
4 changed files with 41 additions and 7 deletions

View file

@ -87,6 +87,17 @@ module.exports = CollaboratorsHandler =
logger.error err: err, "problem removing user from project collaberators" logger.error err: err, "problem removing user from project collaberators"
callback(err) 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) ->) -> addEmailToProject: (project_id, adding_user_id, unparsed_email, privilegeLevel, callback = (error, user) ->) ->
emails = mimelib.parseAddresses(unparsed_email) emails = mimelib.parseAddresses(unparsed_email)
email = emails[0]?.address?.toLowerCase() email = emails[0]?.address?.toLowerCase()

View file

@ -24,9 +24,11 @@ module.exports = ProjectDeleter =
update = {deletedByExternalDataSource: false} update = {deletedByExternalDataSource: false}
Project.update conditions, update, {}, callback Project.update conditions, update, {}, callback
deleteUsersProjects: (owner_id, callback)-> deleteUsersProjects: (user_id, callback)->
logger.log owner_id:owner_id, "deleting users projects" logger.log {user_id}, "deleting users projects"
Project.remove owner_ref:owner_id, callback Project.remove owner_ref:user_id, (error) ->
return callback(error) if error?
CollaboratorsHandler.removeUserFromAllProjets user_id, callback
deleteProject: (project_id, callback = (error) ->) -> deleteProject: (project_id, callback = (error) ->) ->
# archiveProject takes care of the clean-up # archiveProject takes care of the clean-up

View file

@ -276,6 +276,19 @@ describe "CollaboratorsHandler", ->
it "should not add any users to the proejct", -> it "should not add any users to the proejct", ->
@CollaboratorHandler.addUserIdToProject.called.should.equal false @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

View file

@ -27,13 +27,15 @@ describe 'ProjectDeleter', ->
removeProjectFromAllTags: sinon.stub().callsArgWith(2) removeProjectFromAllTags: sinon.stub().callsArgWith(2)
@ProjectGetter = @ProjectGetter =
getProject:sinon.stub() getProject:sinon.stub()
@CollaboratorsHandler =
removeUserFromAllProjets: sinon.stub().yields()
@deleter = SandboxedModule.require modulePath, requires: @deleter = SandboxedModule.require modulePath, requires:
"../Editor/EditorController": @editorController "../Editor/EditorController": @editorController
'../../models/Project':{Project:@Project} '../../models/Project':{Project:@Project}
'../DocumentUpdater/DocumentUpdaterHandler': @documentUpdaterHandler '../DocumentUpdater/DocumentUpdaterHandler': @documentUpdaterHandler
"../Tags/TagsHandler":@TagsHandler "../Tags/TagsHandler":@TagsHandler
"../FileStore/FileStoreHandler": @FileStoreHandler = {} "../FileStore/FileStoreHandler": @FileStoreHandler = {}
"../Collaborators/CollaboratorsHandler": @CollaboratorsHandler = {} "../Collaborators/CollaboratorsHandler": @CollaboratorsHandler
"./ProjectGetter": @ProjectGetter "./ProjectGetter": @ProjectGetter
'logger-sharelatex': 'logger-sharelatex':
log:-> log:->
@ -74,6 +76,12 @@ describe 'ProjectDeleter', ->
@Project.remove.calledWith(owner_ref:user_id).should.equal true @Project.remove.calledWith(owner_ref:user_id).should.equal true
done() 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", -> describe "deleteProject", ->
beforeEach (done) -> beforeEach (done) ->
@project_id = "mock-project-id-123" @project_id = "mock-project-id-123"