2014-02-12 10:23:40 +00:00
|
|
|
mongoose = require('mongoose')
|
|
|
|
Settings = require 'settings-sharelatex'
|
|
|
|
_ = require('underscore')
|
|
|
|
FolderSchema = require('./Folder.js').FolderSchema
|
|
|
|
logger = require('logger-sharelatex')
|
2014-03-31 15:46:28 +00:00
|
|
|
sanitize = require('sanitizer')
|
2014-02-12 10:23:40 +00:00
|
|
|
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
|
|
|
|
|
2014-02-12 10:23:40 +00:00
|
|
|
ProjectSchema = new Schema
|
|
|
|
name : {type:String, default:'new project'}
|
|
|
|
lastUpdated : {type:Date, default: () -> new Date()}
|
2015-08-13 21:40:28 +00:00
|
|
|
lastOpened : {type:Date}
|
2015-08-19 10:54:30 +00:00
|
|
|
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]
|
|
|
|
publicAccesLevel : {type: String, default: 'private'}
|
|
|
|
compiler : {type:String, default:'pdflatex'}
|
|
|
|
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]
|
2016-01-14 16:35:42 +00:00
|
|
|
imageName : { type: String }
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
ProjectSchema.methods.getSafeProjectName = ->
|
|
|
|
safeProjectName = this.name.replace(new RegExp("\\W", "g"), '_')
|
2014-03-31 15:46:28 +00:00
|
|
|
return sanitize.escape(safeProjectName)
|
2014-02-12 10:23:40 +00:00
|
|
|
|
|
|
|
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: Settings.mongo.poolSize || 10)
|
|
|
|
|
|
|
|
Project = conn.model('Project', ProjectSchema)
|
|
|
|
|
|
|
|
mongoose.model 'Project', ProjectSchema
|
|
|
|
exports.Project = Project
|
|
|
|
exports.ProjectSchema = ProjectSchema
|