mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-10 22:50:46 +02:00
Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -17,14 +17,14 @@ const logger = require('logger-sharelatex')
|
||||
module.exports = {
|
||||
getProjectDetails(req, res, next) {
|
||||
const { project_id } = req.params
|
||||
return ProjectDetailsHandler.getDetails(project_id, function(
|
||||
err,
|
||||
projDetails
|
||||
) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
return ProjectDetailsHandler.getDetails(
|
||||
project_id,
|
||||
function (err, projDetails) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
return res.json(projDetails)
|
||||
}
|
||||
return res.json(projDetails)
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ module.exports = ProjectCollabratecDetailsHandler = {
|
||||
callback
|
||||
) {
|
||||
if (callback == null) {
|
||||
callback = function(err) {}
|
||||
callback = function (err) {}
|
||||
}
|
||||
return ProjectCollabratecDetailsHandler.setCollabratecUsers(
|
||||
project_id,
|
||||
@@ -36,7 +36,7 @@ module.exports = ProjectCollabratecDetailsHandler = {
|
||||
|
||||
isLinkedCollabratecUserProject(project_id, user_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(err, isLinked) {}
|
||||
callback = function (err, isLinked) {}
|
||||
}
|
||||
try {
|
||||
project_id = ObjectId(project_id)
|
||||
@@ -53,7 +53,7 @@ module.exports = ProjectCollabratecDetailsHandler = {
|
||||
}
|
||||
}
|
||||
}
|
||||
return Project.findOne(query, { _id: 1 }, function(err, project) {
|
||||
return Project.findOne(query, { _id: 1 }, function (err, project) {
|
||||
if (err != null) {
|
||||
callback(err)
|
||||
}
|
||||
@@ -68,7 +68,7 @@ module.exports = ProjectCollabratecDetailsHandler = {
|
||||
callback
|
||||
) {
|
||||
if (callback == null) {
|
||||
callback = function(err) {}
|
||||
callback = function (err) {}
|
||||
}
|
||||
try {
|
||||
project_id = ObjectId(project_id)
|
||||
@@ -102,7 +102,7 @@ module.exports = ProjectCollabratecDetailsHandler = {
|
||||
setCollabratecUsers(project_id, collabratec_users, callback) {
|
||||
let err
|
||||
if (callback == null) {
|
||||
callback = function(err) {}
|
||||
callback = function (err) {}
|
||||
}
|
||||
try {
|
||||
project_id = ObjectId(project_id)
|
||||
@@ -127,7 +127,7 @@ module.exports = ProjectCollabratecDetailsHandler = {
|
||||
|
||||
unlinkCollabratecUserProject(project_id, user_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(err) {}
|
||||
callback = function (err) {}
|
||||
}
|
||||
try {
|
||||
project_id = ObjectId(project_id)
|
||||
@@ -149,7 +149,7 @@ module.exports = ProjectCollabratecDetailsHandler = {
|
||||
|
||||
updateCollabratecUserIds(old_user_id, new_user_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(err) {}
|
||||
callback = function (err) {}
|
||||
}
|
||||
try {
|
||||
old_user_id = ObjectId(old_user_id)
|
||||
|
||||
@@ -64,10 +64,7 @@ const ProjectController = {
|
||||
return true
|
||||
}
|
||||
const data = `${rolloutName}:${objectId.toString()}`
|
||||
const md5hash = crypto
|
||||
.createHash('md5')
|
||||
.update(data)
|
||||
.digest('hex')
|
||||
const md5hash = crypto.createHash('md5').update(data).digest('hex')
|
||||
const counter = parseInt(md5hash.slice(26, 32), 16)
|
||||
return counter % 100 < percentage
|
||||
},
|
||||
@@ -162,7 +159,7 @@ const ProjectController = {
|
||||
const projectId = req.params.Project_id
|
||||
const userId = AuthenticationController.getLoggedInUserId(req)
|
||||
|
||||
ProjectDeleter.archiveProject(projectId, userId, function(err) {
|
||||
ProjectDeleter.archiveProject(projectId, userId, function (err) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
} else {
|
||||
@@ -175,7 +172,7 @@ const ProjectController = {
|
||||
const projectId = req.params.Project_id
|
||||
const userId = AuthenticationController.getLoggedInUserId(req)
|
||||
|
||||
ProjectDeleter.unarchiveProject(projectId, userId, function(err) {
|
||||
ProjectDeleter.unarchiveProject(projectId, userId, function (err) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
} else {
|
||||
@@ -188,7 +185,7 @@ const ProjectController = {
|
||||
const projectId = req.params.project_id
|
||||
const userId = AuthenticationController.getLoggedInUserId(req)
|
||||
|
||||
ProjectDeleter.trashProject(projectId, userId, function(err) {
|
||||
ProjectDeleter.trashProject(projectId, userId, function (err) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
} else {
|
||||
@@ -201,7 +198,7 @@ const ProjectController = {
|
||||
const projectId = req.params.project_id
|
||||
const userId = AuthenticationController.getLoggedInUserId(req)
|
||||
|
||||
ProjectDeleter.untrashProject(projectId, userId, function(err) {
|
||||
ProjectDeleter.untrashProject(projectId, userId, function (err) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
} else {
|
||||
|
||||
@@ -33,7 +33,7 @@ const AnalyticsManager = require('../Analytics/AnalyticsManager')
|
||||
const ProjectCreationHandler = {
|
||||
createBlankProject(owner_id, projectName, attributes, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, project) {}
|
||||
callback = function (error, project) {}
|
||||
}
|
||||
metrics.inc('project-creation')
|
||||
if (arguments.length === 3) {
|
||||
@@ -41,59 +41,60 @@ const ProjectCreationHandler = {
|
||||
attributes = {}
|
||||
}
|
||||
|
||||
return ProjectDetailsHandler.validateProjectName(projectName, function(
|
||||
error
|
||||
) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
if (attributes.overleaf !== undefined && attributes.overleaf != null) {
|
||||
return ProjectCreationHandler._createBlankProject(
|
||||
owner_id,
|
||||
projectName,
|
||||
attributes,
|
||||
function(error, project) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
AnalyticsManager.recordEvent(owner_id, 'project-imported', {
|
||||
projectId: project._id,
|
||||
attributes
|
||||
})
|
||||
return callback(error, project)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
return HistoryManager.initializeProject(function(error, history) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
attributes.overleaf = {
|
||||
history: { id: history != null ? history.overleaf_id : undefined }
|
||||
}
|
||||
return ProjectDetailsHandler.validateProjectName(
|
||||
projectName,
|
||||
function (error) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
if (attributes.overleaf !== undefined && attributes.overleaf != null) {
|
||||
return ProjectCreationHandler._createBlankProject(
|
||||
owner_id,
|
||||
projectName,
|
||||
attributes,
|
||||
function(error, project) {
|
||||
function (error, project) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
AnalyticsManager.recordEvent(owner_id, 'project-created', {
|
||||
AnalyticsManager.recordEvent(owner_id, 'project-imported', {
|
||||
projectId: project._id,
|
||||
attributes
|
||||
})
|
||||
return callback(error, project)
|
||||
}
|
||||
)
|
||||
})
|
||||
} else {
|
||||
return HistoryManager.initializeProject(function (error, history) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
attributes.overleaf = {
|
||||
history: { id: history != null ? history.overleaf_id : undefined }
|
||||
}
|
||||
return ProjectCreationHandler._createBlankProject(
|
||||
owner_id,
|
||||
projectName,
|
||||
attributes,
|
||||
function (error, project) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
AnalyticsManager.recordEvent(owner_id, 'project-created', {
|
||||
projectId: project._id,
|
||||
attributes
|
||||
})
|
||||
return callback(error, project)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
_createBlankProject(owner_id, projectName, attributes, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, project) {}
|
||||
callback = function (error, project) {}
|
||||
}
|
||||
const rootFolder = new Folder({ name: 'rootFolder' })
|
||||
|
||||
@@ -113,28 +114,29 @@ const ProjectCreationHandler = {
|
||||
}
|
||||
}
|
||||
project.rootFolder[0] = rootFolder
|
||||
return User.findById(owner_id, 'ace.spellCheckLanguage', function(
|
||||
err,
|
||||
user
|
||||
) {
|
||||
project.spellCheckLanguage = user.ace.spellCheckLanguage
|
||||
return project.save(function(err) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return callback(err, project)
|
||||
})
|
||||
})
|
||||
return User.findById(
|
||||
owner_id,
|
||||
'ace.spellCheckLanguage',
|
||||
function (err, user) {
|
||||
project.spellCheckLanguage = user.ace.spellCheckLanguage
|
||||
return project.save(function (err) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return callback(err, project)
|
||||
})
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
createProjectFromSnippet(owner_id, projectName, docLines, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, project) {}
|
||||
callback = function (error, project) {}
|
||||
}
|
||||
return ProjectCreationHandler.createBlankProject(
|
||||
owner_id,
|
||||
projectName,
|
||||
function(error, project) {
|
||||
function (error, project) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
@@ -150,12 +152,12 @@ const ProjectCreationHandler = {
|
||||
|
||||
createBasicProject(owner_id, projectName, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, project) {}
|
||||
callback = function (error, project) {}
|
||||
}
|
||||
return ProjectCreationHandler.createBlankProject(
|
||||
owner_id,
|
||||
projectName,
|
||||
function(error, project) {
|
||||
function (error, project) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
@@ -163,7 +165,7 @@ const ProjectCreationHandler = {
|
||||
'mainbasic.tex',
|
||||
owner_id,
|
||||
projectName,
|
||||
function(error, docLines) {
|
||||
function (error, docLines) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
@@ -181,12 +183,12 @@ const ProjectCreationHandler = {
|
||||
|
||||
createExampleProject(owner_id, projectName, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, project) {}
|
||||
callback = function (error, project) {}
|
||||
}
|
||||
return ProjectCreationHandler.createBlankProject(
|
||||
owner_id,
|
||||
projectName,
|
||||
function(error, project) {
|
||||
function (error, project) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
@@ -197,7 +199,7 @@ const ProjectCreationHandler = {
|
||||
'main.tex',
|
||||
owner_id,
|
||||
projectName,
|
||||
function(error, docLines) {
|
||||
function (error, docLines) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
@@ -214,7 +216,7 @@ const ProjectCreationHandler = {
|
||||
'references.bib',
|
||||
owner_id,
|
||||
projectName,
|
||||
function(error, docLines) {
|
||||
function (error, docLines) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
@@ -228,7 +230,7 @@ const ProjectCreationHandler = {
|
||||
)
|
||||
}
|
||||
),
|
||||
function(callback) {
|
||||
function (callback) {
|
||||
const universePath = Path.resolve(
|
||||
__dirname + '/../../../templates/project_files/universe.jpg'
|
||||
)
|
||||
@@ -251,7 +253,7 @@ const ProjectCreationHandler = {
|
||||
|
||||
_createRootDoc(project, owner_id, docLines, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, project) {}
|
||||
callback = function (error, project) {}
|
||||
}
|
||||
return ProjectEntityUpdateHandler.addDoc(
|
||||
project._id,
|
||||
@@ -259,7 +261,7 @@ const ProjectCreationHandler = {
|
||||
'main.tex',
|
||||
docLines,
|
||||
owner_id,
|
||||
function(error, doc) {
|
||||
function (error, doc) {
|
||||
if (error != null) {
|
||||
OError.tag(error, 'error adding root doc when creating project')
|
||||
return callback(error)
|
||||
@@ -275,47 +277,48 @@ const ProjectCreationHandler = {
|
||||
|
||||
_buildTemplate(template_name, user_id, project_name, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, output) {}
|
||||
callback = function (error, output) {}
|
||||
}
|
||||
return User.findById(user_id, 'first_name last_name', function(
|
||||
error,
|
||||
user
|
||||
) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
const monthNames = [
|
||||
'January',
|
||||
'February',
|
||||
'March',
|
||||
'April',
|
||||
'May',
|
||||
'June',
|
||||
'July',
|
||||
'August',
|
||||
'September',
|
||||
'October',
|
||||
'November',
|
||||
'December'
|
||||
]
|
||||
|
||||
const templatePath = Path.resolve(
|
||||
__dirname + `/../../../templates/project_files/${template_name}`
|
||||
)
|
||||
return fs.readFile(templatePath, function(error, template) {
|
||||
return User.findById(
|
||||
user_id,
|
||||
'first_name last_name',
|
||||
function (error, user) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
const data = {
|
||||
project_name,
|
||||
user,
|
||||
year: new Date().getUTCFullYear(),
|
||||
month: monthNames[new Date().getUTCMonth()]
|
||||
}
|
||||
const output = _.template(template.toString(), data)
|
||||
return callback(null, output.split('\n'))
|
||||
})
|
||||
})
|
||||
const monthNames = [
|
||||
'January',
|
||||
'February',
|
||||
'March',
|
||||
'April',
|
||||
'May',
|
||||
'June',
|
||||
'July',
|
||||
'August',
|
||||
'September',
|
||||
'October',
|
||||
'November',
|
||||
'December'
|
||||
]
|
||||
|
||||
const templatePath = Path.resolve(
|
||||
__dirname + `/../../../templates/project_files/${template_name}`
|
||||
)
|
||||
return fs.readFile(templatePath, function (error, template) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
const data = {
|
||||
project_name,
|
||||
user,
|
||||
year: new Date().getUTCFullYear(),
|
||||
month: monthNames[new Date().getUTCMonth()]
|
||||
}
|
||||
const output = _.template(template.toString(), data)
|
||||
return callback(null, output.split('\n'))
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -308,7 +308,7 @@ const ProjectEntityUpdateHandler = {
|
||||
|
||||
addDocWithRanges: wrapWithLock({
|
||||
beforeLock(next) {
|
||||
return function(
|
||||
return function (
|
||||
projectId,
|
||||
folderId,
|
||||
docName,
|
||||
@@ -457,7 +457,7 @@ const ProjectEntityUpdateHandler = {
|
||||
|
||||
addFile: wrapWithLock({
|
||||
beforeLock(next) {
|
||||
return function(
|
||||
return function (
|
||||
projectId,
|
||||
folderId,
|
||||
fileName,
|
||||
@@ -544,7 +544,7 @@ const ProjectEntityUpdateHandler = {
|
||||
|
||||
replaceFile: wrapWithLock({
|
||||
beforeLock(next) {
|
||||
return function(
|
||||
return function (
|
||||
projectId,
|
||||
fileId,
|
||||
fsPath,
|
||||
@@ -648,7 +648,7 @@ const ProjectEntityUpdateHandler = {
|
||||
}
|
||||
}),
|
||||
|
||||
upsertDoc: wrapWithLock(function(
|
||||
upsertDoc: wrapWithLock(function (
|
||||
projectId,
|
||||
folderId,
|
||||
docName,
|
||||
@@ -796,7 +796,7 @@ const ProjectEntityUpdateHandler = {
|
||||
|
||||
upsertFile: wrapWithLock({
|
||||
beforeLock(next) {
|
||||
return function(
|
||||
return function (
|
||||
projectId,
|
||||
folderId,
|
||||
fileName,
|
||||
@@ -974,7 +974,7 @@ const ProjectEntityUpdateHandler = {
|
||||
}
|
||||
}),
|
||||
|
||||
upsertDocWithPath: wrapWithLock(function(
|
||||
upsertDocWithPath: wrapWithLock(function (
|
||||
projectId,
|
||||
elementPath,
|
||||
docLines,
|
||||
@@ -1014,7 +1014,7 @@ const ProjectEntityUpdateHandler = {
|
||||
|
||||
upsertFileWithPath: wrapWithLock({
|
||||
beforeLock(next) {
|
||||
return function(
|
||||
return function (
|
||||
projectId,
|
||||
elementPath,
|
||||
fsPath,
|
||||
@@ -1102,7 +1102,7 @@ const ProjectEntityUpdateHandler = {
|
||||
}
|
||||
}),
|
||||
|
||||
deleteEntity: wrapWithLock(function(
|
||||
deleteEntity: wrapWithLock(function (
|
||||
projectId,
|
||||
entityId,
|
||||
entityType,
|
||||
@@ -1174,7 +1174,7 @@ const ProjectEntityUpdateHandler = {
|
||||
)
|
||||
),
|
||||
|
||||
mkdirp: wrapWithLock(function(projectId, path, callback) {
|
||||
mkdirp: wrapWithLock(function (projectId, path, callback) {
|
||||
for (let folder of path.split('/')) {
|
||||
if (folder.length > 0 && !SafePath.isCleanFilename(folder)) {
|
||||
return callback(new Errors.InvalidNameError('invalid element name'))
|
||||
@@ -1188,7 +1188,7 @@ const ProjectEntityUpdateHandler = {
|
||||
)
|
||||
}),
|
||||
|
||||
mkdirpWithExactCase: wrapWithLock(function(projectId, path, callback) {
|
||||
mkdirpWithExactCase: wrapWithLock(function (projectId, path, callback) {
|
||||
for (let folder of path.split('/')) {
|
||||
if (folder.length > 0 && !SafePath.isCleanFilename(folder)) {
|
||||
return callback(new Errors.InvalidNameError('invalid element name'))
|
||||
@@ -1202,7 +1202,7 @@ const ProjectEntityUpdateHandler = {
|
||||
)
|
||||
}),
|
||||
|
||||
addFolder: wrapWithLock(function(
|
||||
addFolder: wrapWithLock(function (
|
||||
projectId,
|
||||
parentFolderId,
|
||||
folderName,
|
||||
@@ -1219,7 +1219,7 @@ const ProjectEntityUpdateHandler = {
|
||||
)
|
||||
}),
|
||||
|
||||
moveEntity: wrapWithLock(function(
|
||||
moveEntity: wrapWithLock(function (
|
||||
projectId,
|
||||
entityId,
|
||||
destFolderId,
|
||||
@@ -1272,7 +1272,7 @@ const ProjectEntityUpdateHandler = {
|
||||
)
|
||||
}),
|
||||
|
||||
renameEntity: wrapWithLock(function(
|
||||
renameEntity: wrapWithLock(function (
|
||||
projectId,
|
||||
entityId,
|
||||
entityType,
|
||||
@@ -1572,7 +1572,7 @@ const ProjectEntityUpdateHandler = {
|
||||
|
||||
convertDocToFile: wrapWithLock({
|
||||
beforeLock(next) {
|
||||
return function(projectId, docId, userId, callback) {
|
||||
return function (projectId, docId, userId, callback) {
|
||||
DocumentUpdaterHandler.flushDocToMongo(projectId, docId, err => {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
|
||||
@@ -72,7 +72,7 @@ const ProjectGetter = {
|
||||
return callback(err)
|
||||
}
|
||||
|
||||
db.projects.findOne(query, { projection }, function(err, project) {
|
||||
db.projects.findOne(query, { projection }, function (err, project) {
|
||||
if (err) {
|
||||
OError.tag(err, 'error getting project', {
|
||||
query,
|
||||
@@ -85,43 +85,49 @@ const ProjectGetter = {
|
||||
},
|
||||
|
||||
getProjectIdByReadAndWriteToken(token, callback) {
|
||||
Project.findOne({ 'tokens.readAndWrite': token }, { _id: 1 }, function(
|
||||
err,
|
||||
project
|
||||
) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
Project.findOne(
|
||||
{ 'tokens.readAndWrite': token },
|
||||
{ _id: 1 },
|
||||
function (err, project) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
if (project == null) {
|
||||
return callback()
|
||||
}
|
||||
callback(null, project._id)
|
||||
}
|
||||
if (project == null) {
|
||||
return callback()
|
||||
}
|
||||
callback(null, project._id)
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
findAllUsersProjects(userId, fields, callback) {
|
||||
const CollaboratorsGetter = require('../Collaborators/CollaboratorsGetter')
|
||||
Project.find({ owner_ref: userId }, fields, function(error, ownedProjects) {
|
||||
if (error) {
|
||||
return callback(error)
|
||||
}
|
||||
CollaboratorsGetter.getProjectsUserIsMemberOf(userId, fields, function(
|
||||
error,
|
||||
projects
|
||||
) {
|
||||
Project.find(
|
||||
{ owner_ref: userId },
|
||||
fields,
|
||||
function (error, ownedProjects) {
|
||||
if (error) {
|
||||
return callback(error)
|
||||
}
|
||||
const result = {
|
||||
owned: ownedProjects || [],
|
||||
readAndWrite: projects.readAndWrite || [],
|
||||
readOnly: projects.readOnly || [],
|
||||
tokenReadAndWrite: projects.tokenReadAndWrite || [],
|
||||
tokenReadOnly: projects.tokenReadOnly || []
|
||||
}
|
||||
callback(null, result)
|
||||
})
|
||||
})
|
||||
CollaboratorsGetter.getProjectsUserIsMemberOf(
|
||||
userId,
|
||||
fields,
|
||||
function (error, projects) {
|
||||
if (error) {
|
||||
return callback(error)
|
||||
}
|
||||
const result = {
|
||||
owned: ownedProjects || [],
|
||||
readAndWrite: projects.readAndWrite || [],
|
||||
readOnly: projects.readOnly || [],
|
||||
tokenReadAndWrite: projects.tokenReadAndWrite || [],
|
||||
tokenReadOnly: projects.tokenReadOnly || []
|
||||
}
|
||||
callback(null, result)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -126,7 +126,7 @@ function _addSuffixToProjectName(name, suffix, maxLength) {
|
||||
|
||||
function _addNumericSuffixToProjectName(name, allProjectNames, maxLength) {
|
||||
const NUMERIC_SUFFIX_MATCH = / \((\d+)\)$/
|
||||
const suffixedName = function(basename, number) {
|
||||
const suffixedName = function (basename, number) {
|
||||
const suffix = ` (${number})`
|
||||
return basename.substr(0, maxLength - suffix.length) + suffix
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ const ProjectHistoryHandler = {
|
||||
setHistoryId(project_id, history_id, callback) {
|
||||
// reject invalid history ids
|
||||
if (callback == null) {
|
||||
callback = function(err) {}
|
||||
callback = function (err) {}
|
||||
}
|
||||
if (!history_id || typeof history_id !== 'number') {
|
||||
return callback(new Error('invalid history id'))
|
||||
@@ -34,7 +34,7 @@ const ProjectHistoryHandler = {
|
||||
return Project.updateOne(
|
||||
{ _id: project_id, 'overleaf.history.id': { $exists: false } },
|
||||
{ 'overleaf.history.id': history_id },
|
||||
function(err, result) {
|
||||
function (err, result) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
@@ -48,29 +48,32 @@ const ProjectHistoryHandler = {
|
||||
|
||||
getHistoryId(project_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(err, result) {}
|
||||
callback = function (err, result) {}
|
||||
}
|
||||
return ProjectDetailsHandler.getDetails(project_id, function(err, project) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
} // n.b. getDetails returns an error if the project doesn't exist
|
||||
return callback(
|
||||
null,
|
||||
__guard__(
|
||||
return ProjectDetailsHandler.getDetails(
|
||||
project_id,
|
||||
function (err, project) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
} // n.b. getDetails returns an error if the project doesn't exist
|
||||
return callback(
|
||||
null,
|
||||
__guard__(
|
||||
project != null ? project.overleaf : undefined,
|
||||
x1 => x1.history
|
||||
),
|
||||
x => x.id
|
||||
__guard__(
|
||||
project != null ? project.overleaf : undefined,
|
||||
x1 => x1.history
|
||||
),
|
||||
x => x.id
|
||||
)
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
upgradeHistory(project_id, callback) {
|
||||
// project must have an overleaf.history.id before allowing display of new history
|
||||
if (callback == null) {
|
||||
callback = function(err, result) {}
|
||||
callback = function (err, result) {}
|
||||
}
|
||||
return Project.updateOne(
|
||||
{ _id: project_id, 'overleaf.history.id': { $exists: true } },
|
||||
@@ -78,7 +81,7 @@ const ProjectHistoryHandler = {
|
||||
'overleaf.history.display': true,
|
||||
'overleaf.history.upgradedAt': new Date()
|
||||
},
|
||||
function(err, result) {
|
||||
function (err, result) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
@@ -93,7 +96,7 @@ const ProjectHistoryHandler = {
|
||||
|
||||
downgradeHistory(project_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(err, result) {}
|
||||
callback = function (err, result) {}
|
||||
}
|
||||
return Project.updateOne(
|
||||
{ _id: project_id, 'overleaf.history.upgradedAt': { $exists: true } },
|
||||
@@ -101,7 +104,7 @@ const ProjectHistoryHandler = {
|
||||
'overleaf.history.display': false,
|
||||
$unset: { 'overleaf.history.upgradedAt': 1 }
|
||||
},
|
||||
function(err, result) {
|
||||
function (err, result) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
@@ -120,45 +123,45 @@ const ProjectHistoryHandler = {
|
||||
// state. Setting a history id when one wasn't present before is ok,
|
||||
// because undefined history ids aren't cached.
|
||||
if (callback == null) {
|
||||
callback = function(err) {}
|
||||
callback = function (err) {}
|
||||
}
|
||||
return ProjectHistoryHandler.getHistoryId(project_id, function(
|
||||
err,
|
||||
history_id
|
||||
) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
if (history_id != null) {
|
||||
return callback()
|
||||
} // history already exists, success
|
||||
return HistoryManager.initializeProject(function(err, history) {
|
||||
return ProjectHistoryHandler.getHistoryId(
|
||||
project_id,
|
||||
function (err, history_id) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
if (!(history != null ? history.overleaf_id : undefined)) {
|
||||
return callback(new Error('failed to initialize history id'))
|
||||
}
|
||||
return ProjectHistoryHandler.setHistoryId(
|
||||
project_id,
|
||||
history.overleaf_id,
|
||||
function(err) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return ProjectEntityUpdateHandler.resyncProjectHistory(
|
||||
project_id,
|
||||
function(err) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return HistoryManager.flushProject(project_id, callback)
|
||||
}
|
||||
)
|
||||
if (history_id != null) {
|
||||
return callback()
|
||||
} // history already exists, success
|
||||
return HistoryManager.initializeProject(function (err, history) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
if (!(history != null ? history.overleaf_id : undefined)) {
|
||||
return callback(new Error('failed to initialize history id'))
|
||||
}
|
||||
return ProjectHistoryHandler.setHistoryId(
|
||||
project_id,
|
||||
history.overleaf_id,
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return ProjectEntityUpdateHandler.resyncProjectHistory(
|
||||
project_id,
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return HistoryManager.flushProject(project_id, callback)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,12 @@ function findElement(options, _callback) {
|
||||
const elementType = sanitizeTypeOfElement(type)
|
||||
|
||||
let count = 0
|
||||
const endOfBranch = function() {
|
||||
const endOfBranch = function () {
|
||||
if (--count === 0) {
|
||||
logger.warn(
|
||||
`element ${elementId} could not be found for project ${projectId ||
|
||||
project._id}`
|
||||
`element ${elementId} could not be found for project ${
|
||||
projectId || project._id
|
||||
}`
|
||||
)
|
||||
callback(new Errors.NotFoundError('entity not found'))
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ const _ = require('underscore')
|
||||
module.exports = ProjectRootDocManager = {
|
||||
setRootDocAutomatically(project_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
callback = function (error) {}
|
||||
}
|
||||
return ProjectEntityHandler.getAllDocs(project_id, function(error, docs) {
|
||||
return ProjectEntityHandler.getAllDocs(project_id, function (error, docs) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
@@ -38,23 +38,23 @@ module.exports = ProjectRootDocManager = {
|
||||
const jobs = _.map(
|
||||
docs,
|
||||
(doc, path) =>
|
||||
function(cb) {
|
||||
function (cb) {
|
||||
if (
|
||||
ProjectEntityUpdateHandler.isPathValidForRootDoc(path) &&
|
||||
DocumentHelper.contentHasDocumentclass(doc.lines)
|
||||
) {
|
||||
async.setImmediate(function() {
|
||||
async.setImmediate(function () {
|
||||
cb(doc._id)
|
||||
})
|
||||
} else {
|
||||
async.setImmediate(function() {
|
||||
async.setImmediate(function () {
|
||||
cb(null)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
return async.series(jobs, function(root_doc_id) {
|
||||
return async.series(jobs, function (root_doc_id) {
|
||||
if (root_doc_id != null) {
|
||||
return ProjectEntityUpdateHandler.setRootDoc(
|
||||
project_id,
|
||||
@@ -70,7 +70,7 @@ module.exports = ProjectRootDocManager = {
|
||||
|
||||
findRootDocFileFromDirectory(directoryPath, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, path, content) {}
|
||||
callback = function (error, path, content) {}
|
||||
}
|
||||
const filePathsPromise = globby(['**/*.{tex,Rtex}'], {
|
||||
cwd: directoryPath,
|
||||
@@ -88,7 +88,7 @@ module.exports = ProjectRootDocManager = {
|
||||
ProjectRootDocManager._sortFileList(
|
||||
unsortedFiles,
|
||||
directoryPath,
|
||||
function(err, files) {
|
||||
function (err, files) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
@@ -96,12 +96,12 @@ module.exports = ProjectRootDocManager = {
|
||||
|
||||
return async.until(
|
||||
() => doc != null || files.length === 0,
|
||||
function(cb) {
|
||||
function (cb) {
|
||||
const file = files.shift()
|
||||
return fs.readFile(
|
||||
Path.join(directoryPath, file),
|
||||
'utf8',
|
||||
function(error, content) {
|
||||
function (error, content) {
|
||||
if (error != null) {
|
||||
return cb(error)
|
||||
}
|
||||
@@ -131,11 +131,11 @@ module.exports = ProjectRootDocManager = {
|
||||
|
||||
setRootDocFromName(project_id, rootDocName, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
callback = function (error) {}
|
||||
}
|
||||
return ProjectEntityHandler.getAllDocPathsFromProjectById(
|
||||
project_id,
|
||||
function(error, docPaths) {
|
||||
function (error, docPaths) {
|
||||
let doc_id, path
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
@@ -180,89 +180,91 @@ module.exports = ProjectRootDocManager = {
|
||||
|
||||
ensureRootDocumentIsSet(project_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
callback = function (error) {}
|
||||
}
|
||||
return ProjectGetter.getProject(project_id, { rootDoc_id: 1 }, function(
|
||||
error,
|
||||
project
|
||||
) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
if (project == null) {
|
||||
return callback(new Error('project not found'))
|
||||
}
|
||||
return ProjectGetter.getProject(
|
||||
project_id,
|
||||
{ rootDoc_id: 1 },
|
||||
function (error, project) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
if (project == null) {
|
||||
return callback(new Error('project not found'))
|
||||
}
|
||||
|
||||
if (project.rootDoc_id != null) {
|
||||
return callback()
|
||||
} else {
|
||||
return ProjectRootDocManager.setRootDocAutomatically(
|
||||
project_id,
|
||||
callback
|
||||
)
|
||||
if (project.rootDoc_id != null) {
|
||||
return callback()
|
||||
} else {
|
||||
return ProjectRootDocManager.setRootDocAutomatically(
|
||||
project_id,
|
||||
callback
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
ensureRootDocumentIsValid(project_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
callback = function (error) {}
|
||||
}
|
||||
return ProjectGetter.getProject(project_id, { rootDoc_id: 1 }, function(
|
||||
error,
|
||||
project
|
||||
) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
if (project == null) {
|
||||
return callback(new Error('project not found'))
|
||||
}
|
||||
return ProjectGetter.getProject(
|
||||
project_id,
|
||||
{ rootDoc_id: 1 },
|
||||
function (error, project) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
if (project == null) {
|
||||
return callback(new Error('project not found'))
|
||||
}
|
||||
|
||||
if (project.rootDoc_id != null) {
|
||||
return ProjectEntityHandler.getAllDocPathsFromProjectById(
|
||||
project_id,
|
||||
function(error, docPaths) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
let rootDocValid = false
|
||||
for (let doc_id in docPaths) {
|
||||
const _path = docPaths[doc_id]
|
||||
if (doc_id === project.rootDoc_id) {
|
||||
rootDocValid = true
|
||||
if (project.rootDoc_id != null) {
|
||||
return ProjectEntityHandler.getAllDocPathsFromProjectById(
|
||||
project_id,
|
||||
function (error, docPaths) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
let rootDocValid = false
|
||||
for (let doc_id in docPaths) {
|
||||
const _path = docPaths[doc_id]
|
||||
if (doc_id === project.rootDoc_id) {
|
||||
rootDocValid = true
|
||||
}
|
||||
}
|
||||
if (rootDocValid) {
|
||||
return callback()
|
||||
} else {
|
||||
return ProjectEntityUpdateHandler.unsetRootDoc(project_id, () =>
|
||||
ProjectRootDocManager.setRootDocAutomatically(
|
||||
project_id,
|
||||
callback
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
if (rootDocValid) {
|
||||
return callback()
|
||||
} else {
|
||||
return ProjectEntityUpdateHandler.unsetRootDoc(project_id, () =>
|
||||
ProjectRootDocManager.setRootDocAutomatically(
|
||||
project_id,
|
||||
callback
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
return ProjectRootDocManager.setRootDocAutomatically(
|
||||
project_id,
|
||||
callback
|
||||
)
|
||||
)
|
||||
} else {
|
||||
return ProjectRootDocManager.setRootDocAutomatically(
|
||||
project_id,
|
||||
callback
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
_sortFileList(listToSort, rootDirectory, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, result) {}
|
||||
callback = function (error, result) {}
|
||||
}
|
||||
return async.mapLimit(
|
||||
listToSort,
|
||||
5,
|
||||
(filePath, cb) =>
|
||||
fs.stat(Path.join(rootDirectory, filePath), function(err, stat) {
|
||||
fs.stat(Path.join(rootDirectory, filePath), function (err, stat) {
|
||||
if (err != null) {
|
||||
return cb(err)
|
||||
}
|
||||
@@ -273,7 +275,7 @@ module.exports = ProjectRootDocManager = {
|
||||
name: Path.basename(filePath)
|
||||
})
|
||||
}),
|
||||
function(err, files) {
|
||||
function (err, files) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ const logger = require('logger-sharelatex')
|
||||
module.exports = {
|
||||
markAsUpdated(projectId, lastUpdatedAt, lastUpdatedBy, callback) {
|
||||
if (callback == null) {
|
||||
callback = function() {}
|
||||
callback = function () {}
|
||||
}
|
||||
if (lastUpdatedAt == null) {
|
||||
lastUpdatedAt = new Date()
|
||||
@@ -38,7 +38,7 @@ module.exports = {
|
||||
markAsOpened(project_id, callback) {
|
||||
const conditions = { _id: project_id }
|
||||
const update = { lastOpened: Date.now() }
|
||||
return Project.updateOne(conditions, update, {}, function(err) {
|
||||
return Project.updateOne(conditions, update, {}, function (err) {
|
||||
if (callback != null) {
|
||||
return callback()
|
||||
}
|
||||
@@ -48,7 +48,7 @@ module.exports = {
|
||||
markAsInactive(project_id, callback) {
|
||||
const conditions = { _id: project_id }
|
||||
const update = { active: false }
|
||||
return Project.updateOne(conditions, update, {}, function(err) {
|
||||
return Project.updateOne(conditions, update, {}, function (err) {
|
||||
if (callback != null) {
|
||||
return callback()
|
||||
}
|
||||
@@ -58,7 +58,7 @@ module.exports = {
|
||||
markAsActive(project_id, callback) {
|
||||
const conditions = { _id: project_id }
|
||||
const update = { active: true }
|
||||
return Project.updateOne(conditions, update, {}, function(err) {
|
||||
return Project.updateOne(conditions, update, {}, function (err) {
|
||||
if (callback != null) {
|
||||
return callback()
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
// frontend/js/ide/directives/SafePath.js
|
||||
// frontend/js/features/file-tree/util/safe-path.js
|
||||
|
||||
const load = function() {
|
||||
const load = function () {
|
||||
let SafePath
|
||||
const BADCHAR_RX = new RegExp(
|
||||
`\
|
||||
|
||||
Reference in New Issue
Block a user