2017-05-10 14:31:17 +00:00
|
|
|
mongoose = require('mongoose')
|
2014-02-12 10:23:40 +00:00
|
|
|
Settings = require 'settings-sharelatex'
|
|
|
|
_ = require('underscore')
|
|
|
|
FolderSchema = require('./Folder.js').FolderSchema
|
|
|
|
logger = require('logger-sharelatex')
|
|
|
|
concreteObjectId = require('mongoose').Types.ObjectId
|
2016-03-23 15:14:49 +00:00
|
|
|
Errors = require "../Features/Errors/Errors"
|
2014-02-12 10:23:40 +00:00
|
|
|
|
|
|
|
Schema = mongoose.Schema
|
|
|
|
ObjectId = Schema.ObjectId
|
|
|
|
|
2014-04-30 10:15:29 +00:00
|
|
|
DeletedDocSchema = new Schema
|
|
|
|
name: String
|
|
|
|
|
2018-03-27 11:08:30 +00:00
|
|
|
DeletedFileSchema = new Schema
|
|
|
|
name: String
|
|
|
|
deletedAt: {type: Date}
|
|
|
|
|
2014-02-12 10:23:40 +00:00
|
|
|
ProjectSchema = new Schema
|
|
|
|
name : {type:String, default:'new project'}
|
|
|
|
lastUpdated : {type:Date, default: () -> new Date()}
|
2017-08-21 15:49:08 +00:00
|
|
|
lastOpened : {type:Date}
|
|
|
|
active : { type: Boolean, default: true }
|
2014-02-12 10:23:40 +00:00
|
|
|
owner_ref : {type:ObjectId, ref:'User'}
|
|
|
|
collaberator_refs : [ type:ObjectId, ref:'User' ]
|
|
|
|
readOnly_refs : [ type:ObjectId, ref:'User' ]
|
|
|
|
rootDoc_id : {type: ObjectId}
|
|
|
|
rootFolder : [FolderSchema]
|
2018-03-01 15:15:09 +00:00
|
|
|
version : {type: Number} # incremented for every change in the project structure (folders and filenames)
|
2014-02-12 10:23:40 +00:00
|
|
|
publicAccesLevel : {type: String, default: 'private'}
|
2017-08-21 15:49:08 +00:00
|
|
|
compiler : {type:String, default:'pdflatex'}
|
2014-02-12 10:23:40 +00:00
|
|
|
spellCheckLanguage : {type:String, default:'en'}
|
|
|
|
deletedByExternalDataSource : {type: Boolean, default: false}
|
|
|
|
description : {type:String, default:''}
|
2014-04-28 11:53:43 +00:00
|
|
|
archived : { type: Boolean }
|
2014-04-30 10:15:29 +00:00
|
|
|
deletedDocs : [DeletedDocSchema]
|
2018-03-27 11:08:30 +00:00
|
|
|
deletedFiles : [DeletedFileSchema]
|
2016-01-14 16:35:42 +00:00
|
|
|
imageName : { type: String }
|
2017-06-21 12:40:28 +00:00
|
|
|
track_changes : { type: Object }
|
2017-09-18 09:27:28 +00:00
|
|
|
tokens :
|
2017-11-21 10:33:02 +00:00
|
|
|
readOnly : {
|
|
|
|
type: String,
|
|
|
|
index: {
|
|
|
|
unique: true,
|
|
|
|
partialFilterExpression: {'tokens.readOnly': {$exists: true}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
readAndWrite : {
|
|
|
|
type: String,
|
|
|
|
index: {
|
|
|
|
unique: true,
|
|
|
|
partialFilterExpression: {'tokens.readAndWrite': {$exists: true}}
|
|
|
|
}
|
|
|
|
}
|
2017-09-19 08:27:22 +00:00
|
|
|
tokenAccessReadOnly_refs : [ type:ObjectId, ref:'User' ]
|
|
|
|
tokenAccessReadAndWrite_refs : [ type:ObjectId, ref:'User' ]
|
2018-02-20 14:19:54 +00:00
|
|
|
fromV1TemplateId: { type: Number }
|
|
|
|
fromV1TemplateVersionId: { type: Number }
|
2017-08-21 15:49:08 +00:00
|
|
|
overleaf :
|
|
|
|
id : { type: Number }
|
2017-08-29 13:21:05 +00:00
|
|
|
imported_at_ver_id : { type: Number }
|
2017-09-05 08:50:39 +00:00
|
|
|
token : { type: String }
|
|
|
|
read_token : { type: String }
|
2017-10-27 14:24:18 +00:00
|
|
|
history :
|
|
|
|
id : { type: Number }
|
2017-12-18 16:39:27 +00:00
|
|
|
display : { type: Boolean }
|
2014-02-12 10:23:40 +00:00
|
|
|
|
|
|
|
ProjectSchema.statics.getProject = (project_or_id, fields, callback)->
|
|
|
|
if project_or_id._id?
|
|
|
|
callback null, project_or_id
|
|
|
|
else
|
|
|
|
try
|
|
|
|
concreteObjectId(project_or_id.toString())
|
|
|
|
catch e
|
|
|
|
return callback(new Errors.NotFoundError(e.message))
|
|
|
|
this.findById project_or_id, fields, callback
|
|
|
|
|
|
|
|
applyToAllFilesRecursivly = ProjectSchema.statics.applyToAllFilesRecursivly = (folder, fun)->
|
|
|
|
_.each folder.fileRefs, (file)->
|
|
|
|
fun(file)
|
|
|
|
_.each folder.folders, (folder)->
|
|
|
|
applyToAllFilesRecursivly(folder, fun)
|
|
|
|
|
2017-11-22 13:37:57 +00:00
|
|
|
conn = mongoose.createConnection(Settings.mongo.url, {
|
|
|
|
server: {poolSize: Settings.mongo.poolSize || 10},
|
|
|
|
config: {autoIndex: false}
|
|
|
|
})
|
2014-02-12 10:23:40 +00:00
|
|
|
|
|
|
|
Project = conn.model('Project', ProjectSchema)
|
|
|
|
|
|
|
|
mongoose.model 'Project', ProjectSchema
|
|
|
|
exports.Project = Project
|
|
|
|
exports.ProjectSchema = ProjectSchema
|