diff --git a/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee b/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee index d1c355b79a..ef2f96ea3d 100644 --- a/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee +++ b/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee @@ -21,6 +21,11 @@ module.exports = CollaboratorsHandler = members.push { id: member_id, privilegeLevel: "readAndWrite" } return callback null, members + getMemberIds: (project_id, callback = (error, member_ids) ->) -> + CollaboratorsHandler.getMemberIdsWithPrivilegeLevels project_id, (error, members) -> + return callback(error) if error? + return callback null, members.map (m) -> m.id + getMembersWithPrivilegeLevels: (project_id, callback = (error, members) ->) -> CollaboratorsHandler.getMemberIdsWithPrivilegeLevels project_id, (error, members) -> return callback(error) if error? diff --git a/services/web/app/coffee/Features/Project/ProjectDeleter.coffee b/services/web/app/coffee/Features/Project/ProjectDeleter.coffee index 6fdba733e7..3c11a777d6 100644 --- a/services/web/app/coffee/Features/Project/ProjectDeleter.coffee +++ b/services/web/app/coffee/Features/Project/ProjectDeleter.coffee @@ -4,6 +4,7 @@ documentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler') tagsHandler = require("../Tags/TagsHandler") async = require("async") FileStoreHandler = require("../FileStore/FileStoreHandler") +CollaboratorsHandler = require("../Collaborators/CollaboratorsHandler") module.exports = ProjectDeleter = @@ -43,16 +44,10 @@ module.exports = ProjectDeleter = (cb)-> documentUpdaterHandler.flushProjectToMongoAndDelete project_id, cb (cb)-> - tagsHandler.removeProjectFromAllTags project.owner_ref, project_id, (err)-> + CollaboratorsHandler.getMemberIds project_id, (error, member_ids = []) -> + for member_id in member_ids + tagsHandler.removeProjectFromAllTags member_id, project_id, (err)-> cb() #doesn't matter if this fails or the order it happens in - (cb)-> - project.collaberator_refs.forEach (collaberator_ref)-> - tagsHandler.removeProjectFromAllTags collaberator_ref, project_id, -> - cb() - (cb)-> - project.readOnly_refs.forEach (readOnly_ref)-> - tagsHandler.removeProjectFromAllTags readOnly_ref, project_id, -> - cb() (cb)-> Project.update {_id:project_id}, { $set: { archived: true }}, cb ], (err)-> diff --git a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee index f97364b756..f0fd8db4a9 100644 --- a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee @@ -44,6 +44,19 @@ describe "CollaboratorsHandler", -> ]) .should.equal true + describe "getMemberIds", -> + beforeEach -> + @CollaboratorHandler.getMemberIdsWithPrivilegeLevels = sinon.stub() + @CollaboratorHandler.getMemberIdsWithPrivilegeLevels + .withArgs(@project_id) + .yields(null, [{id: "member-id-1"}, {id: "member-id-2"}]) + @CollaboratorHandler.getMemberIds @project_id, @callback + + it "should return the ids", -> + @callback + .calledWith(null, ["member-id-1", "member-id-2"]) + .should.equal true + describe "getMembersWithPrivilegeLevels", -> beforeEach -> @CollaboratorHandler.getMemberIdsWithPrivilegeLevels = sinon.stub() diff --git a/services/web/test/UnitTests/coffee/Project/ProjectDeleterTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectDeleterTests.coffee index 13f5d2a694..7ed1dac666 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectDeleterTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectDeleterTests.coffee @@ -31,6 +31,7 @@ describe 'ProjectDeleter', -> '../DocumentUpdater/DocumentUpdaterHandler': @documentUpdaterHandler "../Tags/TagsHandler":@TagsHandler "../FileStore/FileStoreHandler": @FileStoreHandler = {} + "../Collaborators/CollaboratorsHandler": @CollaboratorsHandler = {} 'logger-sharelatex': log:-> @@ -89,6 +90,8 @@ describe 'ProjectDeleter', -> describe "archiveProject", -> beforeEach -> + @CollaboratorsHandler.getMemberIds = sinon.stub() + @CollaboratorsHandler.getMemberIds.withArgs(@project_id).yields(null, ["member-id-1", "member-id-2"]) @Project.update.callsArgWith(2) it "should flushProjectToMongoAndDelete in doc updater", (done)-> @@ -107,12 +110,8 @@ describe 'ProjectDeleter', -> it "should removeProjectFromAllTags", (done)-> @deleter.archiveProject @project_id, => - @TagsHandler.removeProjectFromAllTags.calledWith(@project.owner_ref, @project_id).should.equal true - @TagsHandler.removeProjectFromAllTags.calledWith(@project.collaberator_refs[0], @project_id).should.equal true - @TagsHandler.removeProjectFromAllTags.calledWith(@project.collaberator_refs[1], @project_id).should.equal true - @TagsHandler.removeProjectFromAllTags.calledWith(@project.readOnly_refs[0], @project_id).should.equal true - @TagsHandler.removeProjectFromAllTags.calledWith(@project.readOnly_refs[1], @project_id).should.equal true - + @TagsHandler.removeProjectFromAllTags.calledWith("member-id-1", @project_id).should.equal true + @TagsHandler.removeProjectFromAllTags.calledWith("member-id-2", @project_id).should.equal true done() describe "restoreProject", ->