2014-02-12 05:23:40 -05:00
|
|
|
Project = require('../../models/Project').Project
|
|
|
|
logger = require('logger-sharelatex')
|
2014-04-07 08:47:10 -04:00
|
|
|
documentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler')
|
|
|
|
tagsHandler = require("../Tags/TagsHandler")
|
|
|
|
async = require("async")
|
|
|
|
AutomaticSnapshotManager = require('../Versioning/AutomaticSnapshotManager')
|
|
|
|
FileStoreHandler = require("../FileStore/FileStoreHandler")
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
markAsDeletedByExternalSource : (project_id, callback)->
|
|
|
|
logger.log project_id:project_id, "marking project as deleted by external data source"
|
|
|
|
conditions = {_id:project_id}
|
|
|
|
update = {deletedByExternalDataSource:true}
|
|
|
|
|
|
|
|
Project.update conditions, update, {}, (err)->
|
2014-04-07 08:47:10 -04:00
|
|
|
require('../Editor/EditorController').notifyUsersProjectHasBeenDeletedOrRenamed project_id, ->
|
2014-02-12 05:23:40 -05:00
|
|
|
callback()
|
|
|
|
|
|
|
|
deleteUsersProjects: (owner_id, callback)->
|
|
|
|
logger.log owner_id:owner_id, "deleting users projects"
|
|
|
|
Project.remove owner_ref:owner_id, callback
|
2014-04-07 08:47:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
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)->
|
2014-04-16 12:44:57 -04:00
|
|
|
tagsHandler.removeProjectFromAllTags project.owner_ref, project_id, (err)->
|
|
|
|
cb() #doesn't matter if this fails or the order it happens in
|
2014-04-07 08:47:10 -04:00
|
|
|
(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)->
|
2014-04-28 07:53:43 -04:00
|
|
|
Project.update {_id:project_id}, { $set: { archived: true }}, cb
|
2014-04-16 12:44:57 -04:00
|
|
|
], (err)->
|
|
|
|
if err?
|
|
|
|
logger.err err:err, "problem deleting project"
|
|
|
|
callback(err)
|