2019-11-18 09:03:20 -05:00
|
|
|
const mongoose = require('../infrastructure/Mongoose')
|
2019-05-29 05:21:06 -04:00
|
|
|
const _ = require('underscore')
|
2020-02-12 10:13:09 -05:00
|
|
|
const { FolderSchema } = require('./Folder')
|
2019-05-29 05:21:06 -04:00
|
|
|
const Errors = require('../Features/Errors/Errors')
|
|
|
|
|
2019-11-18 09:03:20 -05:00
|
|
|
const concreteObjectId = mongoose.Types.ObjectId
|
2019-05-29 05:21:06 -04:00
|
|
|
const { Schema } = mongoose
|
|
|
|
const { ObjectId } = Schema
|
|
|
|
|
|
|
|
const DeletedDocSchema = new Schema({
|
|
|
|
name: String,
|
2021-04-27 03:52:58 -04:00
|
|
|
deletedAt: { type: Date },
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
const DeletedFileSchema = new Schema({
|
|
|
|
name: String,
|
|
|
|
created: {
|
2021-04-27 03:52:58 -04:00
|
|
|
type: Date,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
linkedFileData: { type: Schema.Types.Mixed },
|
|
|
|
hash: {
|
2021-04-27 03:52:58 -04:00
|
|
|
type: String,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
2021-04-27 03:52:58 -04:00
|
|
|
deletedAt: { type: Date },
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-10-23 08:24:09 -04:00
|
|
|
const AuditLogEntrySchema = new Schema({
|
|
|
|
_id: false,
|
|
|
|
operation: { type: String },
|
|
|
|
initiatorId: { type: Schema.Types.ObjectId },
|
|
|
|
timestamp: { type: Date },
|
2021-04-27 03:52:58 -04:00
|
|
|
info: { type: Object },
|
2019-10-23 08:24:09 -04:00
|
|
|
})
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
const ProjectSchema = new Schema({
|
|
|
|
name: { type: String, default: 'new project' },
|
|
|
|
lastUpdated: {
|
|
|
|
type: Date,
|
|
|
|
default() {
|
|
|
|
return new Date()
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
lastUpdatedBy: { type: ObjectId, ref: 'User' },
|
|
|
|
lastOpened: { type: Date },
|
|
|
|
active: { type: Boolean, default: true },
|
|
|
|
owner_ref: { type: ObjectId, ref: 'User' },
|
|
|
|
collaberator_refs: [{ type: ObjectId, ref: 'User' }],
|
|
|
|
readOnly_refs: [{ type: ObjectId, ref: 'User' }],
|
|
|
|
rootDoc_id: { type: ObjectId },
|
|
|
|
rootFolder: [FolderSchema],
|
|
|
|
version: { type: Number }, // incremented for every change in the project structure (folders and filenames)
|
|
|
|
publicAccesLevel: { type: String, default: 'private' },
|
|
|
|
compiler: { type: String, default: 'pdflatex' },
|
|
|
|
spellCheckLanguage: { type: String, default: 'en' },
|
|
|
|
deletedByExternalDataSource: { type: Boolean, default: false },
|
|
|
|
description: { type: String, default: '' },
|
2019-10-02 10:06:57 -04:00
|
|
|
archived: { type: Schema.Types.Mixed },
|
2019-08-27 06:38:17 -04:00
|
|
|
trashed: [{ type: ObjectId, ref: 'User' }],
|
2019-05-29 05:21:06 -04:00
|
|
|
deletedDocs: [DeletedDocSchema],
|
|
|
|
deletedFiles: [DeletedFileSchema],
|
|
|
|
imageName: { type: String },
|
|
|
|
brandVariationId: { type: String },
|
|
|
|
track_changes: { type: Object },
|
|
|
|
tokens: {
|
|
|
|
readOnly: {
|
|
|
|
type: String,
|
|
|
|
index: {
|
|
|
|
unique: true,
|
2021-04-27 03:52:58 -04:00
|
|
|
partialFilterExpression: { 'tokens.readOnly': { $exists: true } },
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
readAndWrite: {
|
|
|
|
type: String,
|
|
|
|
index: {
|
|
|
|
unique: true,
|
2021-04-27 03:52:58 -04:00
|
|
|
partialFilterExpression: { 'tokens.readAndWrite': { $exists: true } },
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
readAndWritePrefix: {
|
|
|
|
type: String,
|
|
|
|
index: {
|
|
|
|
unique: true,
|
|
|
|
partialFilterExpression: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'tokens.readAndWritePrefix': { $exists: true },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
tokenAccessReadOnly_refs: [{ type: ObjectId, ref: 'User' }],
|
|
|
|
tokenAccessReadAndWrite_refs: [{ type: ObjectId, ref: 'User' }],
|
|
|
|
fromV1TemplateId: { type: Number },
|
|
|
|
fromV1TemplateVersionId: { type: Number },
|
|
|
|
overleaf: {
|
|
|
|
id: { type: Number },
|
|
|
|
imported_at_ver_id: { type: Number },
|
|
|
|
token: { type: String },
|
|
|
|
read_token: { type: String },
|
|
|
|
history: {
|
|
|
|
id: { type: Number },
|
|
|
|
display: { type: Boolean },
|
2021-04-27 03:52:58 -04:00
|
|
|
upgradedAt: { type: Date },
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
collabratecUsers: [
|
|
|
|
{
|
|
|
|
user_id: { type: ObjectId, ref: 'User' },
|
|
|
|
collabratec_document_id: { type: String },
|
|
|
|
collabratec_privategroup_id: { type: String },
|
|
|
|
added_at: {
|
|
|
|
type: Date,
|
|
|
|
default() {
|
|
|
|
return new Date()
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-10-23 08:24:09 -04:00
|
|
|
],
|
2019-11-26 08:11:19 -05:00
|
|
|
auditLog: [AuditLogEntrySchema],
|
2021-04-27 03:52:58 -04:00
|
|
|
deferredTpdsFlushCounter: { type: Number },
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
ProjectSchema.statics.getProject = function (projectOrId, fields, callback) {
|
2019-11-05 09:09:14 -05:00
|
|
|
if (projectOrId._id != null) {
|
2019-11-18 09:03:20 -05:00
|
|
|
callback(null, projectOrId)
|
2019-05-29 05:21:06 -04:00
|
|
|
} else {
|
|
|
|
try {
|
2019-11-05 09:09:14 -05:00
|
|
|
concreteObjectId(projectOrId.toString())
|
2019-05-29 05:21:06 -04:00
|
|
|
} catch (e) {
|
|
|
|
return callback(new Errors.NotFoundError(e.message))
|
|
|
|
}
|
2019-11-18 09:03:20 -05:00
|
|
|
this.findById(projectOrId, fields, callback)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-18 09:03:20 -05:00
|
|
|
function applyToAllFilesRecursivly(folder, fun) {
|
2019-05-29 05:21:06 -04:00
|
|
|
_.each(folder.fileRefs, file => fun(file))
|
2019-11-18 09:03:20 -05:00
|
|
|
_.each(folder.folders, folder => applyToAllFilesRecursivly(folder, fun))
|
|
|
|
}
|
|
|
|
ProjectSchema.statics.applyToAllFilesRecursivly = applyToAllFilesRecursivly
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-11-18 09:03:20 -05:00
|
|
|
exports.Project = mongoose.model('Project', ProjectSchema)
|
2019-05-29 05:21:06 -04:00
|
|
|
exports.ProjectSchema = ProjectSchema
|