2019-09-30 10:46:15 -04:00
|
|
|
const Path = require('path')
|
|
|
|
const fs = require('fs')
|
|
|
|
const crypto = require('crypto')
|
2019-05-29 05:21:06 -04:00
|
|
|
const async = require('async')
|
|
|
|
const logger = require('logger-sharelatex')
|
2020-05-26 06:32:05 -04:00
|
|
|
const { ObjectId } = require('../../infrastructure/mongojs')
|
2019-09-30 10:46:15 -04:00
|
|
|
const ProjectDeleter = require('./ProjectDeleter')
|
|
|
|
const ProjectDuplicator = require('./ProjectDuplicator')
|
|
|
|
const ProjectCreationHandler = require('./ProjectCreationHandler')
|
|
|
|
const EditorController = require('../Editor/EditorController')
|
2019-08-09 05:40:11 -04:00
|
|
|
const ProjectHelper = require('./ProjectHelper')
|
2019-05-29 05:21:06 -04:00
|
|
|
const metrics = require('metrics-sharelatex')
|
|
|
|
const { User } = require('../../models/User')
|
|
|
|
const TagsHandler = require('../Tags/TagsHandler')
|
|
|
|
const SubscriptionLocator = require('../Subscription/SubscriptionLocator')
|
|
|
|
const NotificationsHandler = require('../Notifications/NotificationsHandler')
|
|
|
|
const LimitationsManager = require('../Subscription/LimitationsManager')
|
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
|
const AuthorizationManager = require('../Authorization/AuthorizationManager')
|
|
|
|
const InactiveProjectManager = require('../InactiveData/InactiveProjectManager')
|
|
|
|
const ProjectUpdateHandler = require('./ProjectUpdateHandler')
|
|
|
|
const ProjectGetter = require('./ProjectGetter')
|
|
|
|
const PrivilegeLevels = require('../Authorization/PrivilegeLevels')
|
|
|
|
const AuthenticationController = require('../Authentication/AuthenticationController')
|
|
|
|
const PackageVersions = require('../../infrastructure/PackageVersions')
|
|
|
|
const Sources = require('../Authorization/Sources')
|
|
|
|
const TokenAccessHandler = require('../TokenAccess/TokenAccessHandler')
|
2019-10-07 04:30:51 -04:00
|
|
|
const CollaboratorsGetter = require('../Collaborators/CollaboratorsGetter')
|
2019-05-29 05:21:06 -04:00
|
|
|
const ProjectEntityHandler = require('./ProjectEntityHandler')
|
2019-11-26 08:11:19 -05:00
|
|
|
const TpdsProjectFlusher = require('../ThirdPartyDataStore/TpdsProjectFlusher')
|
2019-05-29 05:21:06 -04:00
|
|
|
const UserGetter = require('../User/UserGetter')
|
|
|
|
const NotificationsBuilder = require('../Notifications/NotificationsBuilder')
|
|
|
|
const { V1ConnectionError } = require('../Errors/Errors')
|
|
|
|
const Features = require('../../infrastructure/Features')
|
|
|
|
const BrandVariationsHandler = require('../BrandVariations/BrandVariationsHandler')
|
|
|
|
const { getUserAffiliations } = require('../Institutions/InstitutionsAPI')
|
2019-12-10 03:10:05 -05:00
|
|
|
const UserController = require('../User/UserController')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2020-01-02 14:22:06 -05:00
|
|
|
const _ssoAvailable = (affiliation, session, linkedInstitutionIds) => {
|
|
|
|
if (!affiliation.institution) return false
|
|
|
|
|
2020-04-22 10:12:40 -04:00
|
|
|
// institution.confirmed is for the domain being confirmed, not the email
|
|
|
|
// Do not show SSO UI for unconfirmed domains
|
|
|
|
if (!affiliation.institution.confirmed) return false
|
|
|
|
|
2020-01-02 14:22:06 -05:00
|
|
|
// Could have multiple emails at the same institution, and if any are
|
|
|
|
// linked to the institution then do not show notification for others
|
|
|
|
if (
|
|
|
|
linkedInstitutionIds.indexOf(affiliation.institution.id.toString()) === -1
|
|
|
|
) {
|
|
|
|
if (affiliation.institution.ssoEnabled) return true
|
|
|
|
if (affiliation.institution.ssoBeta && session.samlBeta) return true
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-09-30 10:46:15 -04:00
|
|
|
const ProjectController = {
|
2019-05-29 05:21:06 -04:00
|
|
|
_isInPercentageRollout(rolloutName, objectId, percentage) {
|
|
|
|
if (Settings.bypassPercentageRollouts === true) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
const data = `${rolloutName}:${objectId.toString()}`
|
|
|
|
const md5hash = crypto
|
|
|
|
.createHash('md5')
|
|
|
|
.update(data)
|
|
|
|
.digest('hex')
|
|
|
|
const counter = parseInt(md5hash.slice(26, 32), 16)
|
|
|
|
return counter % 100 < percentage
|
|
|
|
},
|
|
|
|
|
|
|
|
updateProjectSettings(req, res, next) {
|
2019-09-30 10:46:15 -04:00
|
|
|
const projectId = req.params.Project_id
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
|
|
const jobs = []
|
|
|
|
|
|
|
|
if (req.body.compiler != null) {
|
|
|
|
jobs.push(callback =>
|
2019-09-30 10:46:15 -04:00
|
|
|
EditorController.setCompiler(projectId, req.body.compiler, callback)
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.body.imageName != null) {
|
|
|
|
jobs.push(callback =>
|
2019-09-30 10:46:15 -04:00
|
|
|
EditorController.setImageName(projectId, req.body.imageName, callback)
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.body.name != null) {
|
|
|
|
jobs.push(callback =>
|
2019-09-30 10:46:15 -04:00
|
|
|
EditorController.renameProject(projectId, req.body.name, callback)
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.body.spellCheckLanguage != null) {
|
|
|
|
jobs.push(callback =>
|
2019-09-30 10:46:15 -04:00
|
|
|
EditorController.setSpellCheckLanguage(
|
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
req.body.spellCheckLanguage,
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.body.rootDocId != null) {
|
|
|
|
jobs.push(callback =>
|
2019-09-30 10:46:15 -04:00
|
|
|
EditorController.setRootDoc(projectId, req.body.rootDocId, callback)
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-09-30 10:46:15 -04:00
|
|
|
async.series(jobs, error => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (error != null) {
|
|
|
|
return next(error)
|
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
res.sendStatus(204)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
updateProjectAdminSettings(req, res, next) {
|
2019-09-30 10:46:15 -04:00
|
|
|
const projectId = req.params.Project_id
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
|
|
const jobs = []
|
|
|
|
if (req.body.publicAccessLevel != null) {
|
|
|
|
jobs.push(callback =>
|
2019-09-30 10:46:15 -04:00
|
|
|
EditorController.setPublicAccessLevel(
|
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
req.body.publicAccessLevel,
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-09-30 10:46:15 -04:00
|
|
|
async.series(jobs, error => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (error != null) {
|
|
|
|
return next(error)
|
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
res.sendStatus(204)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteProject(req, res) {
|
2019-09-30 10:46:15 -04:00
|
|
|
const projectId = req.params.Project_id
|
2019-05-29 05:21:06 -04:00
|
|
|
const user = AuthenticationController.getSessionUser(req)
|
2019-09-30 10:46:15 -04:00
|
|
|
const cb = err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
2019-09-30 10:46:15 -04:00
|
|
|
res.sendStatus(500)
|
2019-05-29 05:21:06 -04:00
|
|
|
} else {
|
2019-09-30 10:46:15 -04:00
|
|
|
res.sendStatus(200)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
}
|
2020-02-12 06:30:41 -05:00
|
|
|
ProjectDeleter.deleteProject(
|
|
|
|
projectId,
|
|
|
|
{ deleterUser: user, ipAddress: req.ip },
|
|
|
|
cb
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
|
2019-10-02 10:06:57 -04:00
|
|
|
archiveProject(req, res, next) {
|
|
|
|
const projectId = req.params.Project_id
|
2019-11-25 10:41:12 -05:00
|
|
|
const userId = AuthenticationController.getLoggedInUserId(req)
|
2019-10-02 10:06:57 -04:00
|
|
|
|
2019-11-25 10:41:12 -05:00
|
|
|
ProjectDeleter.archiveProject(projectId, userId, function(err) {
|
2019-10-02 10:06:57 -04:00
|
|
|
if (err != null) {
|
|
|
|
return next(err)
|
|
|
|
} else {
|
|
|
|
return res.sendStatus(200)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
unarchiveProject(req, res, next) {
|
|
|
|
const projectId = req.params.Project_id
|
2019-11-25 10:41:12 -05:00
|
|
|
const userId = AuthenticationController.getLoggedInUserId(req)
|
2019-10-02 10:06:57 -04:00
|
|
|
|
2019-11-25 10:41:12 -05:00
|
|
|
ProjectDeleter.unarchiveProject(projectId, userId, function(err) {
|
|
|
|
if (err != null) {
|
|
|
|
return next(err)
|
|
|
|
} else {
|
|
|
|
return res.sendStatus(200)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
trashProject(req, res, next) {
|
|
|
|
const projectId = req.params.project_id
|
|
|
|
const userId = AuthenticationController.getLoggedInUserId(req)
|
|
|
|
|
|
|
|
ProjectDeleter.trashProject(projectId, userId, function(err) {
|
|
|
|
if (err != null) {
|
|
|
|
return next(err)
|
|
|
|
} else {
|
|
|
|
return res.sendStatus(200)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
untrashProject(req, res, next) {
|
|
|
|
const projectId = req.params.project_id
|
|
|
|
const userId = AuthenticationController.getLoggedInUserId(req)
|
2019-10-02 10:06:57 -04:00
|
|
|
|
2019-11-25 10:41:12 -05:00
|
|
|
ProjectDeleter.untrashProject(projectId, userId, function(err) {
|
2019-10-02 10:06:57 -04:00
|
|
|
if (err != null) {
|
|
|
|
return next(err)
|
|
|
|
} else {
|
|
|
|
return res.sendStatus(200)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2019-07-18 10:18:56 -04:00
|
|
|
expireDeletedProjectsAfterDuration(req, res) {
|
2019-09-30 10:46:15 -04:00
|
|
|
ProjectDeleter.expireDeletedProjectsAfterDuration(err => {
|
2019-07-18 10:18:56 -04:00
|
|
|
if (err != null) {
|
2019-09-30 10:46:15 -04:00
|
|
|
res.sendStatus(500)
|
2019-07-18 10:18:56 -04:00
|
|
|
} else {
|
2019-09-30 10:46:15 -04:00
|
|
|
res.sendStatus(200)
|
2019-07-18 10:18:56 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
expireDeletedProject(req, res, next) {
|
|
|
|
const { projectId } = req.params
|
2019-09-30 10:46:15 -04:00
|
|
|
ProjectDeleter.expireDeletedProject(projectId, err => {
|
2019-07-18 10:18:56 -04:00
|
|
|
if (err != null) {
|
2019-09-30 10:46:15 -04:00
|
|
|
next(err)
|
2019-07-18 10:18:56 -04:00
|
|
|
} else {
|
2019-09-30 10:46:15 -04:00
|
|
|
res.sendStatus(200)
|
2019-07-18 10:18:56 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
restoreProject(req, res) {
|
2019-09-30 10:46:15 -04:00
|
|
|
const projectId = req.params.Project_id
|
|
|
|
ProjectDeleter.restoreProject(projectId, err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
2019-09-30 10:46:15 -04:00
|
|
|
res.sendStatus(500)
|
2019-05-29 05:21:06 -04:00
|
|
|
} else {
|
2019-09-30 10:46:15 -04:00
|
|
|
res.sendStatus(200)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
cloneProject(req, res, next) {
|
|
|
|
res.setTimeout(5 * 60 * 1000) // allow extra time for the copy to complete
|
|
|
|
metrics.inc('cloned-project')
|
2019-09-30 10:46:15 -04:00
|
|
|
const projectId = req.params.Project_id
|
2019-05-29 05:21:06 -04:00
|
|
|
const { projectName } = req.body
|
2019-09-30 10:46:15 -04:00
|
|
|
logger.log({ projectId, projectName }, 'cloning project')
|
2019-05-29 05:21:06 -04:00
|
|
|
if (!AuthenticationController.isUserLoggedIn(req)) {
|
|
|
|
return res.send({ redir: '/register' })
|
|
|
|
}
|
|
|
|
const currentUser = AuthenticationController.getSessionUser(req)
|
2020-06-30 08:04:59 -04:00
|
|
|
const { first_name: firstName, last_name: lastName, email } = currentUser
|
2019-09-30 10:46:15 -04:00
|
|
|
ProjectDuplicator.duplicate(
|
2019-05-29 05:21:06 -04:00
|
|
|
currentUser,
|
2019-09-30 10:46:15 -04:00
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
projectName,
|
2019-09-30 10:46:15 -04:00
|
|
|
(err, project) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
2019-07-01 09:48:09 -04:00
|
|
|
logger.warn(
|
2019-09-30 10:46:15 -04:00
|
|
|
{ err, projectId, userId: currentUser._id },
|
2019-05-29 05:21:06 -04:00
|
|
|
'error cloning project'
|
|
|
|
)
|
|
|
|
return next(err)
|
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
res.send({
|
2019-05-29 05:21:06 -04:00
|
|
|
name: project.name,
|
|
|
|
project_id: project._id,
|
2020-05-12 10:46:29 -04:00
|
|
|
owner_ref: project.owner_ref,
|
2020-06-30 08:04:59 -04:00
|
|
|
owner: {
|
|
|
|
first_name: firstName,
|
|
|
|
last_name: lastName,
|
|
|
|
email,
|
|
|
|
_id: currentUser._id
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
newProject(req, res, next) {
|
2020-07-01 05:08:53 -04:00
|
|
|
const currentUser = AuthenticationController.getSessionUser(req)
|
|
|
|
const {
|
|
|
|
first_name: firstName,
|
|
|
|
last_name: lastName,
|
|
|
|
email,
|
|
|
|
_id: userId
|
|
|
|
} = currentUser
|
2019-05-29 05:21:06 -04:00
|
|
|
const projectName =
|
|
|
|
req.body.projectName != null ? req.body.projectName.trim() : undefined
|
|
|
|
const { template } = req.body
|
2019-11-19 09:19:08 -05:00
|
|
|
|
2019-09-30 10:46:15 -04:00
|
|
|
async.waterfall(
|
2019-05-29 05:21:06 -04:00
|
|
|
[
|
2019-09-30 10:46:15 -04:00
|
|
|
cb => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (template === 'example') {
|
2019-09-30 10:46:15 -04:00
|
|
|
ProjectCreationHandler.createExampleProject(userId, projectName, cb)
|
2019-05-29 05:21:06 -04:00
|
|
|
} else {
|
2019-09-30 10:46:15 -04:00
|
|
|
ProjectCreationHandler.createBasicProject(userId, projectName, cb)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2019-09-30 10:46:15 -04:00
|
|
|
(err, project) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
return next(err)
|
|
|
|
}
|
2020-07-01 05:08:53 -04:00
|
|
|
res.send({
|
|
|
|
project_id: project._id,
|
|
|
|
owner_ref: project.owner_ref,
|
|
|
|
owner: {
|
|
|
|
first_name: firstName,
|
|
|
|
last_name: lastName,
|
|
|
|
email,
|
|
|
|
_id: userId
|
|
|
|
}
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
renameProject(req, res, next) {
|
2019-09-30 10:46:15 -04:00
|
|
|
const projectId = req.params.Project_id
|
2019-05-29 05:21:06 -04:00
|
|
|
const newName = req.body.newProjectName
|
2019-09-30 10:46:15 -04:00
|
|
|
EditorController.renameProject(projectId, newName, err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
return next(err)
|
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
res.sendStatus(200)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
userProjectsJson(req, res, next) {
|
2019-09-30 10:46:15 -04:00
|
|
|
const userId = AuthenticationController.getLoggedInUserId(req)
|
|
|
|
ProjectGetter.findAllUsersProjects(
|
|
|
|
userId,
|
2019-08-27 06:38:17 -04:00
|
|
|
'name lastUpdated publicAccesLevel archived trashed owner_ref tokens',
|
2019-09-30 10:46:15 -04:00
|
|
|
(err, projects) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
return next(err)
|
|
|
|
}
|
2019-12-02 12:09:31 -05:00
|
|
|
|
|
|
|
// _buildProjectList already converts archived/trashed to booleans so isArchivedOrTrashed should not be used here
|
2019-09-30 10:46:15 -04:00
|
|
|
projects = ProjectController._buildProjectList(projects, userId)
|
2019-12-02 12:09:31 -05:00
|
|
|
.filter(p => !(p.archived || p.trashed))
|
2019-05-29 05:21:06 -04:00
|
|
|
.map(p => ({ _id: p.id, name: p.name, accessLevel: p.accessLevel }))
|
|
|
|
|
2019-09-30 10:46:15 -04:00
|
|
|
res.json({ projects })
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
projectEntitiesJson(req, res, next) {
|
2019-09-30 10:46:15 -04:00
|
|
|
const projectId = req.params.Project_id
|
|
|
|
ProjectGetter.getProject(projectId, (err, project) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
return next(err)
|
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
ProjectEntityHandler.getAllEntitiesFromProject(
|
|
|
|
project,
|
|
|
|
(err, docs, files) => {
|
|
|
|
if (err != null) {
|
|
|
|
return next(err)
|
|
|
|
}
|
|
|
|
const entities = docs
|
|
|
|
.concat(files)
|
2020-07-07 08:55:57 -04:00
|
|
|
// Sort by path ascending
|
|
|
|
.sort((a, b) => (a.path > b.path ? 1 : a.path < b.path ? -1 : 0))
|
2019-09-30 10:46:15 -04:00
|
|
|
.map(e => ({
|
|
|
|
path: e.path,
|
|
|
|
type: e.doc != null ? 'doc' : 'file'
|
|
|
|
}))
|
|
|
|
res.json({ project_id: projectId, entities })
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
projectListPage(req, res, next) {
|
|
|
|
const timer = new metrics.Timer('project-list')
|
2019-09-30 10:46:15 -04:00
|
|
|
const userId = AuthenticationController.getLoggedInUserId(req)
|
2019-05-29 05:21:06 -04:00
|
|
|
const currentUser = AuthenticationController.getSessionUser(req)
|
2019-10-30 11:42:37 -04:00
|
|
|
let noV1Connection = false
|
2020-03-11 09:21:54 -04:00
|
|
|
let institutionLinkingError
|
2019-09-30 10:46:15 -04:00
|
|
|
async.parallel(
|
2019-05-29 05:21:06 -04:00
|
|
|
{
|
|
|
|
tags(cb) {
|
2019-09-30 10:46:15 -04:00
|
|
|
TagsHandler.getAllTags(userId, cb)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
notifications(cb) {
|
2019-09-30 10:46:15 -04:00
|
|
|
NotificationsHandler.getUserNotifications(userId, cb)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
projects(cb) {
|
2019-09-30 10:46:15 -04:00
|
|
|
ProjectGetter.findAllUsersProjects(
|
|
|
|
userId,
|
2019-11-25 10:41:12 -05:00
|
|
|
'name lastUpdated lastUpdatedBy publicAccesLevel archived trashed owner_ref tokens',
|
2019-05-29 05:21:06 -04:00
|
|
|
cb
|
|
|
|
)
|
|
|
|
},
|
|
|
|
hasSubscription(cb) {
|
2019-09-30 10:46:15 -04:00
|
|
|
LimitationsManager.hasPaidSubscription(
|
|
|
|
currentUser,
|
|
|
|
(error, hasPaidSubscription) => {
|
|
|
|
if (error != null && error instanceof V1ConnectionError) {
|
2019-10-30 11:42:37 -04:00
|
|
|
noV1Connection = true
|
2019-09-30 10:46:15 -04:00
|
|
|
return cb(null, true)
|
|
|
|
}
|
|
|
|
cb(error, hasPaidSubscription)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
user(cb) {
|
2019-09-30 10:46:15 -04:00
|
|
|
User.findById(
|
|
|
|
userId,
|
2019-10-21 12:02:01 -04:00
|
|
|
'emails featureSwitches overleaf awareOfV2 features lastLoginIp',
|
2019-05-29 05:21:06 -04:00
|
|
|
cb
|
|
|
|
)
|
|
|
|
},
|
|
|
|
userAffiliations(cb) {
|
2019-08-12 07:27:55 -04:00
|
|
|
if (!Features.hasFeature('affiliations')) {
|
2020-05-11 08:08:34 -04:00
|
|
|
return cb(null, [])
|
2019-08-12 07:27:55 -04:00
|
|
|
}
|
2019-10-30 11:42:37 -04:00
|
|
|
getUserAffiliations(userId, (error, affiliations) => {
|
|
|
|
if (error && error instanceof V1ConnectionError) {
|
|
|
|
noV1Connection = true
|
|
|
|
return cb(null, [])
|
|
|
|
}
|
|
|
|
cb(error, affiliations)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
},
|
2019-09-30 10:46:15 -04:00
|
|
|
(err, results) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
2019-07-01 09:48:09 -04:00
|
|
|
logger.warn({ err }, 'error getting data for project list page')
|
2019-05-29 05:21:06 -04:00
|
|
|
return next(err)
|
|
|
|
}
|
2019-10-21 12:02:01 -04:00
|
|
|
const { notifications, user, userAffiliations } = results
|
2019-12-10 03:10:05 -05:00
|
|
|
// Handle case of deleted user
|
|
|
|
if (user == null) {
|
|
|
|
UserController.logout(req, res, next)
|
|
|
|
return
|
|
|
|
}
|
2020-05-19 15:05:36 -04:00
|
|
|
const tags = results.tags
|
2019-10-29 11:41:13 -04:00
|
|
|
const notificationsInstitution = []
|
2019-09-30 10:46:15 -04:00
|
|
|
for (const notification of notifications) {
|
|
|
|
notification.html = req.i18n.translate(
|
|
|
|
notification.templateKey,
|
|
|
|
notification.messageOpts
|
|
|
|
)
|
|
|
|
}
|
2019-10-21 12:02:01 -04:00
|
|
|
|
|
|
|
// Institution SSO Notifications
|
2020-01-02 14:22:06 -05:00
|
|
|
if (Features.hasFeature('saml')) {
|
2019-10-21 12:02:01 -04:00
|
|
|
const samlSession = req.session.saml
|
|
|
|
// Notification: SSO Available
|
|
|
|
const linkedInstitutionIds = []
|
|
|
|
user.emails.forEach(email => {
|
|
|
|
if (email.samlProviderId) {
|
|
|
|
linkedInstitutionIds.push(email.samlProviderId)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (Array.isArray(userAffiliations)) {
|
|
|
|
userAffiliations.forEach(affiliation => {
|
|
|
|
if (
|
2020-01-02 14:22:06 -05:00
|
|
|
_ssoAvailable(affiliation, req.session, linkedInstitutionIds)
|
2019-10-21 12:02:01 -04:00
|
|
|
) {
|
2019-10-29 11:41:13 -04:00
|
|
|
notificationsInstitution.push({
|
2019-10-21 12:02:01 -04:00
|
|
|
email: affiliation.email,
|
|
|
|
institutionId: affiliation.institution.id,
|
|
|
|
institutionName: affiliation.institution.name,
|
|
|
|
templateKey: 'notification_institution_sso_available'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if (samlSession) {
|
|
|
|
// Notification: After SSO Linked
|
|
|
|
if (samlSession.linked) {
|
2019-10-29 11:41:13 -04:00
|
|
|
notificationsInstitution.push({
|
2019-10-21 12:02:01 -04:00
|
|
|
email: samlSession.institutionEmail,
|
|
|
|
institutionName: samlSession.linked.universityName,
|
|
|
|
templateKey: 'notification_institution_sso_linked'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notification: After SSO Linked or Logging in
|
|
|
|
// The requested email does not match primary email returned from
|
|
|
|
// the institution
|
2019-11-13 09:22:54 -05:00
|
|
|
if (
|
|
|
|
samlSession.requestedEmail &&
|
|
|
|
samlSession.emailNonCanonical &&
|
|
|
|
!samlSession.linkedToAnother
|
|
|
|
) {
|
2019-10-29 11:41:13 -04:00
|
|
|
notificationsInstitution.push({
|
2019-10-21 12:02:01 -04:00
|
|
|
institutionEmail: samlSession.emailNonCanonical,
|
|
|
|
requestedEmail: samlSession.requestedEmail,
|
|
|
|
templateKey: 'notification_institution_sso_non_canonical'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notification: Tried to register, but account already existed
|
2019-11-06 08:41:08 -05:00
|
|
|
// registerIntercept is set before the institution callback.
|
|
|
|
// institutionEmail is set after institution callback.
|
|
|
|
// Check for both in case SSO flow was abandoned
|
2019-11-12 08:59:04 -05:00
|
|
|
if (
|
|
|
|
samlSession.registerIntercept &&
|
|
|
|
samlSession.institutionEmail &&
|
|
|
|
!samlSession.linkedToAnother
|
|
|
|
) {
|
2019-10-29 11:41:13 -04:00
|
|
|
notificationsInstitution.push({
|
2019-10-21 12:02:01 -04:00
|
|
|
email: samlSession.institutionEmail,
|
|
|
|
templateKey: 'notification_institution_sso_already_registered'
|
|
|
|
})
|
|
|
|
}
|
2019-11-12 08:59:04 -05:00
|
|
|
|
|
|
|
// Notification: Already linked to another account
|
|
|
|
if (samlSession.linkedToAnother) {
|
|
|
|
notificationsInstitution.push({
|
|
|
|
templateKey: 'notification_institution_sso_linked_by_another'
|
|
|
|
})
|
|
|
|
}
|
2020-03-11 09:21:54 -04:00
|
|
|
|
|
|
|
// Notification: When there is a session error
|
|
|
|
if (samlSession.error) {
|
|
|
|
institutionLinkingError = samlSession.error
|
|
|
|
notificationsInstitution.push({
|
|
|
|
message: samlSession.error.message,
|
|
|
|
templateKey: 'notification_institution_sso_error',
|
|
|
|
tryAgain: samlSession.error.tryAgain
|
|
|
|
})
|
|
|
|
}
|
2019-10-21 12:02:01 -04:00
|
|
|
}
|
|
|
|
delete req.session.saml
|
|
|
|
}
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
const portalTemplates = ProjectController._buildPortalTemplatesList(
|
2019-10-21 12:02:01 -04:00
|
|
|
userAffiliations
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
const projects = ProjectController._buildProjectList(
|
|
|
|
results.projects,
|
2020-05-19 15:05:36 -04:00
|
|
|
userId
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
2020-05-19 15:05:36 -04:00
|
|
|
const warnings = ProjectController._buildWarningsList(noV1Connection)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
|
|
// in v2 add notifications for matching university IPs
|
2019-09-30 10:46:15 -04:00
|
|
|
if (Settings.overleaf != null && req.ip !== user.lastLoginIp) {
|
|
|
|
NotificationsBuilder.ipMatcherAffiliation(user._id).create(req.ip)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
|
2019-09-30 10:46:15 -04:00
|
|
|
ProjectController._injectProjectUsers(projects, (error, projects) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (error != null) {
|
|
|
|
return next(error)
|
|
|
|
}
|
|
|
|
const viewModel = {
|
|
|
|
title: 'your_projects',
|
|
|
|
priority_title: true,
|
|
|
|
projects,
|
|
|
|
tags,
|
|
|
|
notifications: notifications || [],
|
2019-10-29 11:41:13 -04:00
|
|
|
notificationsInstitution,
|
2019-05-29 05:21:06 -04:00
|
|
|
portalTemplates,
|
|
|
|
user,
|
|
|
|
userAffiliations,
|
|
|
|
hasSubscription: results.hasSubscription,
|
2020-03-11 09:21:54 -04:00
|
|
|
institutionLinkingError,
|
2019-05-29 05:21:06 -04:00
|
|
|
warnings,
|
|
|
|
zipFileSizeLimit: Settings.maxUploadSize
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
2019-07-15 09:09:04 -04:00
|
|
|
Settings.algolia &&
|
|
|
|
Settings.algolia.app_id &&
|
|
|
|
Settings.algolia.read_only_api_key
|
2019-05-29 05:21:06 -04:00
|
|
|
) {
|
|
|
|
viewModel.showUserDetailsArea = true
|
|
|
|
viewModel.algolia_api_key = Settings.algolia.read_only_api_key
|
|
|
|
viewModel.algolia_app_id = Settings.algolia.app_id
|
|
|
|
} else {
|
|
|
|
viewModel.showUserDetailsArea = false
|
|
|
|
}
|
|
|
|
|
|
|
|
const paidUser =
|
|
|
|
(user.features != null ? user.features.github : undefined) &&
|
|
|
|
(user.features != null ? user.features.dropbox : undefined) // use a heuristic for paid account
|
|
|
|
const freeUserProportion = 0.1
|
|
|
|
const sampleFreeUser =
|
|
|
|
parseInt(user._id.toString().slice(-2), 16) <
|
|
|
|
freeUserProportion * 255
|
|
|
|
const showFrontWidget = paidUser || sampleFreeUser
|
2019-11-19 09:19:08 -05:00
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
if (showFrontWidget) {
|
|
|
|
viewModel.frontChatWidgetRoomId =
|
|
|
|
Settings.overleaf != null
|
|
|
|
? Settings.overleaf.front_chat_widget_room_id
|
|
|
|
: undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
res.render('project/list', viewModel)
|
2019-09-30 10:46:15 -04:00
|
|
|
timer.done()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
loadEditor(req, res, next) {
|
|
|
|
const timer = new metrics.Timer('load-editor')
|
|
|
|
if (!Settings.editorIsOpen) {
|
|
|
|
return res.render('general/closed', { title: 'updating_site' })
|
|
|
|
}
|
|
|
|
|
2020-06-30 08:04:59 -04:00
|
|
|
let anonymous, userId, sessionUser
|
2019-05-29 05:21:06 -04:00
|
|
|
if (AuthenticationController.isUserLoggedIn(req)) {
|
2020-06-30 08:04:59 -04:00
|
|
|
sessionUser = AuthenticationController.getSessionUser(req)
|
2019-09-30 10:46:15 -04:00
|
|
|
userId = AuthenticationController.getLoggedInUserId(req)
|
2019-05-29 05:21:06 -04:00
|
|
|
anonymous = false
|
|
|
|
} else {
|
2020-06-30 08:04:59 -04:00
|
|
|
sessionUser = null
|
2019-05-29 05:21:06 -04:00
|
|
|
anonymous = true
|
2019-09-30 10:46:15 -04:00
|
|
|
userId = null
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
|
2019-09-30 10:46:15 -04:00
|
|
|
const projectId = req.params.Project_id
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-09-30 10:46:15 -04:00
|
|
|
async.auto(
|
2019-05-29 05:21:06 -04:00
|
|
|
{
|
|
|
|
project(cb) {
|
2019-09-30 10:46:15 -04:00
|
|
|
ProjectGetter.getProject(
|
|
|
|
projectId,
|
2019-05-29 05:21:06 -04:00
|
|
|
{
|
|
|
|
name: 1,
|
|
|
|
lastUpdated: 1,
|
|
|
|
track_changes: 1,
|
|
|
|
owner_ref: 1,
|
|
|
|
brandVariationId: 1,
|
|
|
|
overleaf: 1,
|
|
|
|
tokens: 1
|
|
|
|
},
|
2019-09-30 10:46:15 -04:00
|
|
|
(err, project) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
return cb(err)
|
|
|
|
}
|
2020-05-20 09:03:02 -04:00
|
|
|
cb(null, project)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
user(cb) {
|
2019-09-30 10:46:15 -04:00
|
|
|
if (userId == null) {
|
|
|
|
cb(null, defaultSettingsForAnonymousUser(userId))
|
2019-05-29 05:21:06 -04:00
|
|
|
} else {
|
2020-07-16 02:48:02 -04:00
|
|
|
User.findById(
|
|
|
|
userId,
|
|
|
|
'email first_name last_name referal_id signUpDate featureSwitches features refProviders alphaProgram betaProgram isAdmin ace',
|
|
|
|
(err, user) => {
|
|
|
|
// Handle case of deleted user
|
|
|
|
if (user == null) {
|
|
|
|
UserController.logout(req, res, next)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.log({ projectId, userId }, 'got user')
|
|
|
|
cb(err, user)
|
2019-12-10 03:10:05 -05:00
|
|
|
}
|
2020-07-16 02:48:02 -04:00
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
subscription(cb) {
|
2019-09-30 10:46:15 -04:00
|
|
|
if (userId == null) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return cb()
|
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
SubscriptionLocator.getUsersSubscription(userId, cb)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
activate(cb) {
|
2019-09-30 10:46:15 -04:00
|
|
|
InactiveProjectManager.reactivateProjectIfRequired(projectId, cb)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
markAsOpened(cb) {
|
|
|
|
// don't need to wait for this to complete
|
2019-09-30 10:46:15 -04:00
|
|
|
ProjectUpdateHandler.markAsOpened(projectId, () => {})
|
|
|
|
cb()
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
isTokenMember(cb) {
|
2019-09-30 10:46:15 -04:00
|
|
|
if (userId == null) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return cb()
|
|
|
|
}
|
2019-10-07 04:30:51 -04:00
|
|
|
CollaboratorsGetter.userIsTokenMember(userId, projectId, cb)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
brandVariation: [
|
|
|
|
'project',
|
2019-09-30 10:46:15 -04:00
|
|
|
(cb, results) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (
|
|
|
|
(results.project != null
|
|
|
|
? results.project.brandVariationId
|
|
|
|
: undefined) == null
|
|
|
|
) {
|
|
|
|
return cb()
|
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
BrandVariationsHandler.getBrandVariationById(
|
2019-05-29 05:21:06 -04:00
|
|
|
results.project.brandVariationId,
|
|
|
|
(error, brandVariationDetails) => cb(error, brandVariationDetails)
|
|
|
|
)
|
|
|
|
}
|
2019-11-26 08:11:19 -05:00
|
|
|
],
|
|
|
|
flushToTpds: cb => {
|
|
|
|
TpdsProjectFlusher.flushProjectToTpdsIfNeeded(projectId, cb)
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
2019-09-30 10:46:15 -04:00
|
|
|
(err, results) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
2019-07-01 09:48:09 -04:00
|
|
|
logger.warn({ err }, 'error getting details for project page')
|
2019-05-29 05:21:06 -04:00
|
|
|
return next(err)
|
|
|
|
}
|
|
|
|
const { project } = results
|
|
|
|
const { user } = results
|
|
|
|
const { subscription } = results
|
|
|
|
const { brandVariation } = results
|
|
|
|
|
2020-02-25 04:39:53 -05:00
|
|
|
const anonRequestToken = TokenAccessHandler.getRequestToken(
|
|
|
|
req,
|
|
|
|
projectId
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
const { isTokenMember } = results
|
2020-06-30 08:04:59 -04:00
|
|
|
const allowedImageNames = ProjectHelper.getAllowedImagesForUser(
|
|
|
|
sessionUser
|
|
|
|
)
|
2019-09-30 10:46:15 -04:00
|
|
|
AuthorizationManager.getPrivilegeLevelForProject(
|
|
|
|
userId,
|
|
|
|
projectId,
|
2020-02-25 04:39:53 -05:00
|
|
|
anonRequestToken,
|
2019-09-30 10:46:15 -04:00
|
|
|
(error, privilegeLevel) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
let allowedFreeTrial
|
|
|
|
if (error != null) {
|
|
|
|
return next(error)
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
privilegeLevel == null ||
|
|
|
|
privilegeLevel === PrivilegeLevels.NONE
|
|
|
|
) {
|
|
|
|
return res.sendStatus(401)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
subscription != null &&
|
|
|
|
subscription.freeTrial != null &&
|
|
|
|
subscription.freeTrial.expiresAt != null
|
|
|
|
) {
|
|
|
|
allowedFreeTrial = !!subscription.freeTrial.allowed || true
|
|
|
|
}
|
|
|
|
|
2020-04-02 06:01:41 -04:00
|
|
|
let wsUrl = Settings.wsUrl
|
|
|
|
let metricName = 'load-editor-ws'
|
|
|
|
if (user.betaProgram && Settings.wsUrlBeta !== undefined) {
|
|
|
|
wsUrl = Settings.wsUrlBeta
|
|
|
|
metricName += '-beta'
|
2020-05-26 06:32:05 -04:00
|
|
|
} else if (
|
|
|
|
Settings.wsUrlV2 &&
|
|
|
|
Settings.wsUrlV2Percentage > 0 &&
|
|
|
|
(ObjectId(projectId).getTimestamp() / 1000) %
|
|
|
|
100 <
|
|
|
|
Settings.wsUrlV2Percentage
|
|
|
|
) {
|
|
|
|
wsUrl = Settings.wsUrlV2
|
|
|
|
metricName += '-v2'
|
2020-04-02 06:01:41 -04:00
|
|
|
}
|
|
|
|
if (req.query && req.query.ws === 'fallback') {
|
|
|
|
// `?ws=fallback` will connect to the bare origin, and ignore
|
|
|
|
// the custom wsUrl. Hence it must load the client side
|
|
|
|
// javascript from there too.
|
|
|
|
// Not resetting it here would possibly load a socket.io v2
|
|
|
|
// client and connect to a v0 endpoint.
|
|
|
|
wsUrl = undefined
|
|
|
|
metricName += '-fallback'
|
|
|
|
}
|
|
|
|
metrics.inc(metricName)
|
|
|
|
|
2020-07-09 09:48:28 -04:00
|
|
|
const enableOptimize =
|
|
|
|
!!Settings.experimentId && !user.features.zotero
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
res.render('project/editor', {
|
|
|
|
title: project.name,
|
|
|
|
priority_title: true,
|
|
|
|
bodyClasses: ['editor'],
|
|
|
|
project_id: project._id,
|
|
|
|
user: {
|
2019-09-30 10:46:15 -04:00
|
|
|
id: userId,
|
2019-05-29 05:21:06 -04:00
|
|
|
email: user.email,
|
|
|
|
first_name: user.first_name,
|
|
|
|
last_name: user.last_name,
|
|
|
|
referal_id: user.referal_id,
|
|
|
|
signUpDate: user.signUpDate,
|
|
|
|
subscription: {
|
|
|
|
freeTrial: { allowed: allowedFreeTrial }
|
|
|
|
},
|
|
|
|
featureSwitches: user.featureSwitches,
|
|
|
|
features: user.features,
|
|
|
|
refProviders: user.refProviders,
|
2020-06-29 09:05:08 -04:00
|
|
|
alphaProgram: user.alphaProgram,
|
2019-05-29 05:21:06 -04:00
|
|
|
betaProgram: user.betaProgram,
|
|
|
|
isAdmin: user.isAdmin
|
|
|
|
},
|
|
|
|
userSettings: {
|
|
|
|
mode: user.ace.mode,
|
|
|
|
editorTheme: user.ace.theme,
|
|
|
|
fontSize: user.ace.fontSize,
|
|
|
|
autoComplete: user.ace.autoComplete,
|
|
|
|
autoPairDelimiters: user.ace.autoPairDelimiters,
|
|
|
|
pdfViewer: user.ace.pdfViewer,
|
|
|
|
syntaxValidation: user.ace.syntaxValidation,
|
2020-03-24 09:05:55 -04:00
|
|
|
fontFamily: user.ace.fontFamily || 'lucida',
|
|
|
|
lineHeight: user.ace.lineHeight || 'normal',
|
2019-05-29 05:21:06 -04:00
|
|
|
overallTheme: user.ace.overallTheme
|
|
|
|
},
|
|
|
|
trackChangesState: project.track_changes,
|
|
|
|
privilegeLevel,
|
|
|
|
chatUrl: Settings.apis.chat.url,
|
|
|
|
anonymous,
|
2020-02-25 04:39:53 -05:00
|
|
|
anonymousAccessToken: anonymous ? anonRequestToken : null,
|
2019-05-29 05:21:06 -04:00
|
|
|
isTokenMember,
|
2019-10-18 05:32:19 -04:00
|
|
|
isRestrictedTokenMember: AuthorizationManager.isRestrictedUser(
|
|
|
|
userId,
|
|
|
|
privilegeLevel,
|
|
|
|
isTokenMember
|
|
|
|
),
|
2019-05-29 05:21:06 -04:00
|
|
|
languages: Settings.languages,
|
|
|
|
editorThemes: THEME_LIST,
|
|
|
|
maxDocLength: Settings.max_doc_length,
|
2019-09-30 10:46:15 -04:00
|
|
|
useV2History:
|
|
|
|
project.overleaf &&
|
|
|
|
project.overleaf.history &&
|
|
|
|
Boolean(project.overleaf.history.display),
|
2019-05-29 05:21:06 -04:00
|
|
|
brandVariation,
|
2020-06-30 08:04:59 -04:00
|
|
|
allowedImageNames,
|
2019-12-02 02:58:15 -05:00
|
|
|
gitBridgePublicBaseUrl: Settings.gitBridgePublicBaseUrl,
|
2020-04-02 06:01:41 -04:00
|
|
|
wsUrl,
|
2020-07-09 09:48:28 -04:00
|
|
|
showSupport: Features.hasFeature('support'),
|
2020-07-16 11:41:58 -04:00
|
|
|
gaOptimize: enableOptimize,
|
|
|
|
customOptimizeEvent: true
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2019-09-30 10:46:15 -04:00
|
|
|
timer.done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
2020-05-19 15:05:36 -04:00
|
|
|
_buildProjectList(allProjects, userId) {
|
2019-05-29 05:21:06 -04:00
|
|
|
let project
|
|
|
|
const {
|
|
|
|
owned,
|
|
|
|
readAndWrite,
|
|
|
|
readOnly,
|
|
|
|
tokenReadAndWrite,
|
|
|
|
tokenReadOnly
|
|
|
|
} = allProjects
|
|
|
|
const projects = []
|
2019-09-30 10:46:15 -04:00
|
|
|
for (project of owned) {
|
2019-05-29 05:21:06 -04:00
|
|
|
projects.push(
|
|
|
|
ProjectController._buildProjectViewModel(
|
|
|
|
project,
|
|
|
|
'owner',
|
2019-08-09 05:40:11 -04:00
|
|
|
Sources.OWNER,
|
|
|
|
userId
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
// Invite-access
|
2019-09-30 10:46:15 -04:00
|
|
|
for (project of readAndWrite) {
|
2019-05-29 05:21:06 -04:00
|
|
|
projects.push(
|
|
|
|
ProjectController._buildProjectViewModel(
|
|
|
|
project,
|
|
|
|
'readWrite',
|
2019-08-09 05:40:11 -04:00
|
|
|
Sources.INVITE,
|
|
|
|
userId
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
for (project of readOnly) {
|
2019-05-29 05:21:06 -04:00
|
|
|
projects.push(
|
|
|
|
ProjectController._buildProjectViewModel(
|
|
|
|
project,
|
|
|
|
'readOnly',
|
2019-08-09 05:40:11 -04:00
|
|
|
Sources.INVITE,
|
|
|
|
userId
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
// Token-access
|
|
|
|
// Only add these projects if they're not already present, this gives us cascading access
|
|
|
|
// from 'owner' => 'token-read-only'
|
2019-09-30 10:46:15 -04:00
|
|
|
for (project of tokenReadAndWrite) {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (
|
|
|
|
projects.filter(p => p.id.toString() === project._id.toString())
|
|
|
|
.length === 0
|
|
|
|
) {
|
|
|
|
projects.push(
|
|
|
|
ProjectController._buildProjectViewModel(
|
|
|
|
project,
|
|
|
|
'readAndWrite',
|
2019-08-09 05:40:11 -04:00
|
|
|
Sources.TOKEN,
|
|
|
|
userId
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
for (project of tokenReadOnly) {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (
|
|
|
|
projects.filter(p => p.id.toString() === project._id.toString())
|
|
|
|
.length === 0
|
|
|
|
) {
|
|
|
|
projects.push(
|
|
|
|
ProjectController._buildProjectViewModel(
|
|
|
|
project,
|
|
|
|
'readOnly',
|
2019-08-09 05:40:11 -04:00
|
|
|
Sources.TOKEN,
|
|
|
|
userId
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return projects
|
|
|
|
},
|
|
|
|
|
2019-08-09 05:40:11 -04:00
|
|
|
_buildProjectViewModel(project, accessLevel, source, userId) {
|
2019-11-25 10:41:12 -05:00
|
|
|
const archived = ProjectHelper.isArchived(project, userId)
|
|
|
|
// If a project is simultaneously trashed and archived, we will consider it archived but not trashed.
|
|
|
|
const trashed = ProjectHelper.isTrashed(project, userId) && !archived
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
TokenAccessHandler.protectTokens(project, accessLevel)
|
|
|
|
const model = {
|
|
|
|
id: project._id,
|
|
|
|
name: project.name,
|
|
|
|
lastUpdated: project.lastUpdated,
|
|
|
|
lastUpdatedBy: project.lastUpdatedBy,
|
|
|
|
publicAccessLevel: project.publicAccesLevel,
|
|
|
|
accessLevel,
|
|
|
|
source,
|
2019-11-25 10:41:12 -05:00
|
|
|
archived,
|
|
|
|
trashed,
|
2019-05-29 05:21:06 -04:00
|
|
|
owner_ref: project.owner_ref,
|
|
|
|
isV1Project: false
|
|
|
|
}
|
2019-09-18 06:01:13 -04:00
|
|
|
if (accessLevel === PrivilegeLevels.READ_ONLY && source === Sources.TOKEN) {
|
|
|
|
model.owner_ref = null
|
|
|
|
model.lastUpdatedBy = null
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
return model
|
|
|
|
},
|
|
|
|
|
|
|
|
_injectProjectUsers(projects, callback) {
|
|
|
|
const users = {}
|
2019-09-30 10:46:15 -04:00
|
|
|
for (const project of projects) {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (project.owner_ref != null) {
|
|
|
|
users[project.owner_ref.toString()] = true
|
|
|
|
}
|
|
|
|
if (project.lastUpdatedBy != null) {
|
|
|
|
users[project.lastUpdatedBy.toString()] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-30 10:46:15 -04:00
|
|
|
const userIds = Object.keys(users)
|
|
|
|
async.eachSeries(
|
|
|
|
userIds,
|
|
|
|
(userId, cb) => {
|
2019-10-01 07:27:15 -04:00
|
|
|
UserGetter.getUser(
|
2019-09-30 10:46:15 -04:00
|
|
|
userId,
|
|
|
|
{ first_name: 1, last_name: 1, email: 1 },
|
|
|
|
(error, user) => {
|
|
|
|
if (error != null) {
|
|
|
|
return cb(error)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
users[userId] = user
|
|
|
|
cb()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
if (error != null) {
|
|
|
|
return callback(error)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
for (const project of projects) {
|
|
|
|
if (project.owner_ref != null) {
|
|
|
|
project.owner = users[project.owner_ref.toString()]
|
|
|
|
}
|
|
|
|
if (project.lastUpdatedBy != null) {
|
|
|
|
project.lastUpdatedBy =
|
|
|
|
users[project.lastUpdatedBy.toString()] || null
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
callback(null, projects)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
|
2020-05-19 15:05:36 -04:00
|
|
|
_buildWarningsList(noConnection) {
|
|
|
|
return noConnection
|
|
|
|
? [
|
|
|
|
'Error accessing Overleaf V1. Some of your projects or features may be missing.'
|
|
|
|
]
|
|
|
|
: []
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_buildPortalTemplatesList(affiliations) {
|
|
|
|
if (affiliations == null) {
|
|
|
|
affiliations = []
|
|
|
|
}
|
|
|
|
const portalTemplates = []
|
2019-09-30 10:46:15 -04:00
|
|
|
for (let aff of affiliations) {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (
|
|
|
|
aff.portal &&
|
|
|
|
aff.portal.slug &&
|
|
|
|
aff.portal.templates_count &&
|
|
|
|
aff.portal.templates_count > 0
|
|
|
|
) {
|
|
|
|
const portalPath = aff.institution.isUniversity ? '/edu/' : '/org/'
|
|
|
|
portalTemplates.push({
|
|
|
|
name: aff.institution.name,
|
|
|
|
url: Settings.siteUrl + portalPath + aff.portal.slug
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return portalTemplates
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-30 10:46:15 -04:00
|
|
|
var defaultSettingsForAnonymousUser = userId => ({
|
|
|
|
id: userId,
|
2019-05-29 05:21:06 -04:00
|
|
|
ace: {
|
|
|
|
mode: 'none',
|
|
|
|
theme: 'textmate',
|
|
|
|
fontSize: '12',
|
|
|
|
autoComplete: true,
|
|
|
|
spellCheckLanguage: '',
|
|
|
|
pdfViewer: '',
|
|
|
|
syntaxValidation: true
|
|
|
|
},
|
|
|
|
subscription: {
|
|
|
|
freeTrial: {
|
|
|
|
allowed: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
featureSwitches: {
|
|
|
|
github: false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
var THEME_LIST = []
|
2019-09-30 10:46:15 -04:00
|
|
|
function generateThemeList() {
|
2019-05-29 05:21:06 -04:00
|
|
|
const files = fs.readdirSync(
|
2019-10-30 07:19:44 -04:00
|
|
|
Path.join(
|
|
|
|
__dirname,
|
2019-11-05 09:00:13 -05:00
|
|
|
'/../../../../frontend/js/vendor/',
|
2019-10-30 07:19:44 -04:00
|
|
|
PackageVersions.lib('ace')
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
2019-09-30 10:46:15 -04:00
|
|
|
const result = []
|
|
|
|
for (let file of files) {
|
|
|
|
if (file.slice(-2) === 'js' && /^theme-/.test(file)) {
|
|
|
|
const cleanName = file.slice(0, -3).slice(6)
|
|
|
|
result.push(THEME_LIST.push(cleanName))
|
|
|
|
} else {
|
|
|
|
result.push(undefined)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-30 10:46:15 -04:00
|
|
|
generateThemeList()
|
|
|
|
|
|
|
|
module.exports = ProjectController
|