mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
moved deleteProject to the project deleter
This commit is contained in:
parent
5378890e57
commit
9134fa7b4c
5 changed files with 87 additions and 25 deletions
|
@ -5,6 +5,7 @@ ProjectEditorHandler = require('../Project/ProjectEditorHandler')
|
|||
ProjectEntityHandler = require('../Project/ProjectEntityHandler')
|
||||
ProjectOptionsHandler = require('../Project/ProjectOptionsHandler')
|
||||
ProjectDetailsHandler = require('../Project/ProjectDetailsHandler')
|
||||
ProjectDeleter = require("../Project/ProjectDeleter")
|
||||
ProjectGetter = require('../Project/ProjectGetter')
|
||||
ProjectHandler = new (require('../../handlers/ProjectHandler'))()
|
||||
DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler')
|
||||
|
@ -240,7 +241,8 @@ module.exports = EditorController =
|
|||
deleteProject: (project_id, callback)->
|
||||
Metrics.inc "editor.delete-project"
|
||||
logger.log project_id:project_id, "recived message to delete project"
|
||||
ProjectHandler.deleteProject project_id, callback
|
||||
console.log ProjectDeleter
|
||||
ProjectDeleter.deleteProject project_id, callback
|
||||
|
||||
renameEntity: (project_id, entity_id, entityType, newName, callback)->
|
||||
newName = sanitize.escape(newName)
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
Project = require('../../models/Project').Project
|
||||
logger = require('logger-sharelatex')
|
||||
editorController = require('../Editor/EditorController')
|
||||
|
||||
documentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler')
|
||||
tagsHandler = require("../Tags/TagsHandler")
|
||||
async = require("async")
|
||||
AutomaticSnapshotManager = require('../Versioning/AutomaticSnapshotManager')
|
||||
FileStoreHandler = require("../FileStore/FileStoreHandler")
|
||||
|
||||
module.exports =
|
||||
|
||||
|
@ -11,9 +14,40 @@ module.exports =
|
|||
update = {deletedByExternalDataSource:true}
|
||||
|
||||
Project.update conditions, update, {}, (err)->
|
||||
editorController.notifyUsersProjectHasBeenDeletedOrRenamed project_id, ->
|
||||
require('../Editor/EditorController').notifyUsersProjectHasBeenDeletedOrRenamed project_id, ->
|
||||
callback()
|
||||
|
||||
deleteUsersProjects: (owner_id, callback)->
|
||||
logger.log owner_id:owner_id, "deleting users projects"
|
||||
Project.remove owner_ref:owner_id, callback
|
||||
|
||||
|
||||
deleteProject: (project_id, callback = (error) ->)->
|
||||
logger.log project_id:project_id, "deleting project"
|
||||
Project.findById project_id, (err, project)=>
|
||||
if err? or !project?
|
||||
logger.err err:err, project_id:project_id, "error getting project to delete it"
|
||||
callback(err)
|
||||
else
|
||||
async.series [
|
||||
(cb)->
|
||||
documentUpdaterHandler.flushProjectToMongoAndDelete project_id, cb
|
||||
(cb)->
|
||||
Project.applyToAllFilesRecursivly project.rootFolder[0], (file)=>
|
||||
FileStoreHandler.deleteFile project_id, file._id, ->
|
||||
cb()
|
||||
(cb)->
|
||||
AutomaticSnapshotManager.unmarkProjectAsUpdated project_id, cb
|
||||
(cb)->
|
||||
tagsHandler.removeProjectFromAllTags project.owner_ref, project_id, cb
|
||||
(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.remove {_id:project_id}, cb
|
||||
], callback
|
||||
|
|
|
@ -10,6 +10,7 @@ SecurityManager = require '../managers/SecurityManager'
|
|||
Settings = require('settings-sharelatex')
|
||||
projectCreationHandler = require '../Features/Project/ProjectCreationHandler'
|
||||
projectDuplicator = require('../Features/Project/ProjectDuplicator')
|
||||
projectDeleter = require("../Features/Project/ProjectDeleter")
|
||||
ProjectZipStreamManager = require '../Features/Downloads/ProjectZipStreamManager'
|
||||
metrics = require('../infrastructure/Metrics')
|
||||
TagsHandler = require('../Features/Tags/TagsHandler')
|
||||
|
@ -198,7 +199,7 @@ module.exports = class ProjectController
|
|||
deleteProject: (req, res)->
|
||||
project_id = req.params.Project_id
|
||||
logger.log project_id:project_id, "deleting project"
|
||||
ProjectHandler.deleteProject project_id, (err)->
|
||||
projectDeleter.deleteProject project_id, (err)->
|
||||
if err?
|
||||
res.send 500
|
||||
else
|
||||
|
|
|
@ -31,26 +31,7 @@ module.exports = class ProjectHandler
|
|||
if callback?
|
||||
callback err
|
||||
|
||||
deleteProject: (project_id, callback = (error) ->)->
|
||||
logger.log project_id:project_id, "deleting project"
|
||||
Project.findById project_id, (err, project)=>
|
||||
if project?
|
||||
require('../Features/DocumentUpdater/DocumentUpdaterHandler').flushProjectToMongoAndDelete project_id, (error) ->
|
||||
return callback(error) if error?
|
||||
Project.applyToAllFilesRecursivly project.rootFolder[0], (file)=>
|
||||
FileStoreHandler.deleteFile project_id, file._id, ->
|
||||
Project.remove {_id:project_id}, (err)->
|
||||
if callback?
|
||||
callback(err)
|
||||
require('../Features/Versioning/AutomaticSnapshotManager').unmarkProjectAsUpdated project_id, ->
|
||||
tagsHandler.removeProjectFromAllTags project.owner_ref, project_id,->
|
||||
project.collaberator_refs.forEach (collaberator_ref)->
|
||||
tagsHandler.removeProjectFromAllTags collaberator_ref, project_id, ->
|
||||
project.readOnly_refs.forEach (readOnly_ref)->
|
||||
tagsHandler.removeProjectFromAllTags readOnly_ref, project_id,->
|
||||
else
|
||||
if callback?
|
||||
callback(err)
|
||||
|
||||
|
||||
setPublicAccessLevel : (project_id, newAccessLevel, callback)->
|
||||
logger.log project_id: project_id, level: newAccessLevel, "set public access level"
|
||||
|
|
|
@ -7,14 +7,32 @@ sinon = require('sinon')
|
|||
describe 'Project deleter', ->
|
||||
|
||||
beforeEach ->
|
||||
@project_id = "12312"
|
||||
@project =
|
||||
_id: @project_id
|
||||
rootFolder:[]
|
||||
collaberator_refs:["collab1", "collab2"]
|
||||
readOnly_refs:["readOnly1", "readOnly2"]
|
||||
owner_ref:"owner ref here"
|
||||
|
||||
@Project =
|
||||
update: sinon.stub().callsArgWith(3)
|
||||
remove: sinon.stub().callsArgWith(1)
|
||||
findById: sinon.stub().callsArgWith(1, null, @project)
|
||||
applyToAllFilesRecursivly: sinon.stub()
|
||||
@documentUpdaterHandler =
|
||||
flushProjectToMongoAndDelete:sinon.stub().callsArgWith(1)
|
||||
@AutomaticSnapshotManager =
|
||||
unmarkProjectAsUpdated:sinon.stub().callsArgWith(1)
|
||||
@editorController = notifyUsersProjectHasBeenDeletedOrRenamed : sinon.stub().callsArgWith(1)
|
||||
@TagsHandler =
|
||||
removeProjectFromAllTags: sinon.stub().callsArgWith(2)
|
||||
@deleter = SandboxedModule.require modulePath, requires:
|
||||
"../Editor/EditorController": @editorController
|
||||
'../../models/Project':{Project:@Project}
|
||||
'../DocumentUpdater/DocumentUpdaterHandler': @documentUpdaterHandler
|
||||
'../Versioning/AutomaticSnapshotManager':@AutomaticSnapshotManager
|
||||
"../Tags/TagsHandler":@TagsHandler
|
||||
'logger-sharelatex':
|
||||
log:->
|
||||
|
||||
|
@ -39,3 +57,29 @@ describe 'Project deleter', ->
|
|||
@deleter.deleteUsersProjects user_id, =>
|
||||
@Project.remove.calledWith(owner_ref:user_id).should.equal true
|
||||
done()
|
||||
|
||||
|
||||
describe "deleteProject", ->
|
||||
beforeEach ->
|
||||
@Project.remove.callsArgWith(1)
|
||||
|
||||
it "should flushProjectToMongoAndDelete in doc updater", (done)->
|
||||
@deleter.deleteProject @project_id, =>
|
||||
@documentUpdaterHandler.flushProjectToMongoAndDelete.calledWith(@project_id).should.equal true
|
||||
done()
|
||||
|
||||
it "should remove the project", (done)->
|
||||
@deleter.deleteProject @project_id, =>
|
||||
@Project.remove.calledWith(_id:@project_id).should.equal true
|
||||
done()
|
||||
|
||||
it "should removeProjectFromAllTags", (done)->
|
||||
@deleter.deleteProject @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
|
||||
|
||||
done()
|
||||
|
||||
|
|
Loading…
Reference in a new issue