2014-04-08 10:28:18 -04:00
|
|
|
async = require("async")
|
2014-04-08 09:34:03 -04:00
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
projectDeleter = require("./ProjectDeleter")
|
2014-04-08 09:53:33 -04:00
|
|
|
projectDuplicator = require("./ProjectDuplicator")
|
2014-04-08 10:25:22 -04:00
|
|
|
projectCreationHandler = require("./ProjectCreationHandler")
|
2014-04-28 12:47:47 -04:00
|
|
|
editorController = require("../Editor/EditorController")
|
2017-04-03 11:18:30 -04:00
|
|
|
metrics = require('metrics-sharelatex')
|
2014-04-08 12:44:31 -04:00
|
|
|
User = require('../../models/User').User
|
2014-04-08 11:40:12 -04:00
|
|
|
TagsHandler = require("../Tags/TagsHandler")
|
|
|
|
SubscriptionLocator = require("../Subscription/SubscriptionLocator")
|
2016-01-22 00:41:22 -05:00
|
|
|
NotificationsHandler = require("../Notifications/NotificationsHandler")
|
2014-08-07 10:29:06 -04:00
|
|
|
LimitationsManager = require("../Subscription/LimitationsManager")
|
2017-02-14 09:26:36 -05:00
|
|
|
underscore = require("underscore")
|
2014-04-08 12:44:31 -04:00
|
|
|
Settings = require("settings-sharelatex")
|
2016-03-10 12:17:26 -05:00
|
|
|
AuthorizationManager = require("../Authorization/AuthorizationManager")
|
2014-06-24 15:28:53 -04:00
|
|
|
fs = require "fs"
|
2015-08-13 17:40:28 -04:00
|
|
|
InactiveProjectManager = require("../InactiveData/InactiveProjectManager")
|
|
|
|
ProjectUpdateHandler = require("./ProjectUpdateHandler")
|
2016-03-03 12:19:03 -05:00
|
|
|
ProjectGetter = require("./ProjectGetter")
|
2016-03-15 10:35:01 -04:00
|
|
|
PrivilegeLevels = require("../Authorization/PrivilegeLevels")
|
2016-09-05 10:58:31 -04:00
|
|
|
AuthenticationController = require("../Authentication/AuthenticationController")
|
2016-09-22 06:02:20 -04:00
|
|
|
PackageVersions = require("../../infrastructure/PackageVersions")
|
2017-02-14 03:34:30 -05:00
|
|
|
AnalyticsManager = require "../Analytics/AnalyticsManager"
|
2017-10-12 05:57:11 -04:00
|
|
|
Sources = require "../Authorization/Sources"
|
2017-10-13 06:20:57 -04:00
|
|
|
TokenAccessHandler = require '../TokenAccess/TokenAccessHandler'
|
2017-10-25 05:34:18 -04:00
|
|
|
CollaboratorsHandler = require '../Collaborators/CollaboratorsHandler'
|
2017-11-15 10:54:47 -05:00
|
|
|
Modules = require '../../infrastructure/Modules'
|
2018-05-04 05:45:13 -04:00
|
|
|
ProjectEntityHandler = require './ProjectEntityHandler'
|
2018-09-05 10:28:26 -04:00
|
|
|
UserGetter = require("../User/UserGetter")
|
|
|
|
NotificationsBuilder = require("../Notifications/NotificationsBuilder")
|
2017-11-10 10:50:17 -05:00
|
|
|
crypto = require 'crypto'
|
2018-06-19 11:25:31 -04:00
|
|
|
{ V1ConnectionError } = require '../Errors/Errors'
|
2018-07-16 10:53:28 -04:00
|
|
|
Features = require('../../infrastructure/Features')
|
2018-10-17 09:14:17 -04:00
|
|
|
BrandVariationsHandler = require("../BrandVariations/BrandVariationsHandler")
|
2018-12-03 13:58:26 -05:00
|
|
|
{ getUserAffiliations } = require("../Institutions/InstitutionsAPI")
|
2019-01-07 06:15:38 -05:00
|
|
|
V1Handler = require "../V1/V1Handler"
|
2014-04-08 09:34:03 -04:00
|
|
|
|
2014-06-16 08:34:38 -04:00
|
|
|
module.exports = ProjectController =
|
2014-04-08 09:34:03 -04:00
|
|
|
|
2017-11-10 10:50:17 -05:00
|
|
|
_isInPercentageRollout: (rolloutName, objectId, percentage) ->
|
2017-11-10 10:59:11 -05:00
|
|
|
if Settings.bypassPercentageRollouts == true
|
2017-11-10 09:15:43 -05:00
|
|
|
return true
|
2017-11-10 10:50:17 -05:00
|
|
|
data = "#{rolloutName}:#{objectId.toString()}"
|
|
|
|
md5hash = crypto.createHash('md5').update(data).digest('hex')
|
|
|
|
counter = parseInt(md5hash.slice(26, 32), 16)
|
2017-11-02 07:17:08 -04:00
|
|
|
return (counter % 100) < percentage
|
|
|
|
|
2014-06-25 08:51:02 -04:00
|
|
|
updateProjectSettings: (req, res, next) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
|
|
|
|
jobs = []
|
|
|
|
|
|
|
|
if req.body.compiler?
|
|
|
|
jobs.push (callback) ->
|
|
|
|
editorController.setCompiler project_id, req.body.compiler, callback
|
|
|
|
|
2018-08-13 05:22:23 -04:00
|
|
|
if req.body.imageName?
|
|
|
|
jobs.push (callback) ->
|
|
|
|
editorController.setImageName project_id, req.body.imageName, callback
|
|
|
|
|
2014-06-25 08:51:02 -04:00
|
|
|
if req.body.name?
|
|
|
|
jobs.push (callback) ->
|
|
|
|
editorController.renameProject project_id, req.body.name, callback
|
|
|
|
|
|
|
|
if req.body.spellCheckLanguage?
|
|
|
|
jobs.push (callback) ->
|
|
|
|
editorController.setSpellCheckLanguage project_id, req.body.spellCheckLanguage, callback
|
|
|
|
|
|
|
|
if req.body.rootDocId?
|
|
|
|
jobs.push (callback) ->
|
|
|
|
editorController.setRootDoc project_id, req.body.rootDocId, callback
|
|
|
|
|
2016-03-10 06:13:57 -05:00
|
|
|
async.series jobs, (error) ->
|
|
|
|
return next(error) if error?
|
|
|
|
res.sendStatus(204)
|
2016-09-02 11:17:37 -04:00
|
|
|
|
2016-03-10 06:13:57 -05:00
|
|
|
updateProjectAdminSettings: (req, res, next) ->
|
|
|
|
project_id = req.params.Project_id
|
2016-09-02 11:17:37 -04:00
|
|
|
|
2016-03-10 06:13:57 -05:00
|
|
|
jobs = []
|
2014-06-25 08:51:02 -04:00
|
|
|
if req.body.publicAccessLevel?
|
|
|
|
jobs.push (callback) ->
|
|
|
|
editorController.setPublicAccessLevel project_id, req.body.publicAccessLevel, callback
|
|
|
|
|
|
|
|
async.series jobs, (error) ->
|
|
|
|
return next(error) if error?
|
2015-07-08 11:56:38 -04:00
|
|
|
res.sendStatus(204)
|
2014-06-25 08:51:02 -04:00
|
|
|
|
2014-06-03 12:35:44 -04:00
|
|
|
deleteProject: (req, res) ->
|
2014-04-08 09:34:03 -04:00
|
|
|
project_id = req.params.Project_id
|
2014-06-04 07:45:04 -04:00
|
|
|
forever = req.query?.forever?
|
2016-03-08 09:38:23 -05:00
|
|
|
logger.log project_id: project_id, forever: forever, "received request to archive project"
|
2014-06-04 07:45:04 -04:00
|
|
|
|
|
|
|
if forever
|
|
|
|
doDelete = projectDeleter.deleteProject
|
|
|
|
else
|
|
|
|
doDelete = projectDeleter.archiveProject
|
|
|
|
|
|
|
|
doDelete project_id, (err)->
|
2014-06-03 12:35:44 -04:00
|
|
|
if err?
|
2015-07-08 11:56:38 -04:00
|
|
|
res.sendStatus 500
|
2014-06-03 12:35:44 -04:00
|
|
|
else
|
2015-07-08 11:56:38 -04:00
|
|
|
res.sendStatus 200
|
2014-06-03 12:35:44 -04:00
|
|
|
|
|
|
|
restoreProject: (req, res) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
logger.log project_id:project_id, "received request to restore project"
|
|
|
|
projectDeleter.restoreProject project_id, (err)->
|
2014-04-08 09:34:03 -04:00
|
|
|
if err?
|
2015-07-08 11:56:38 -04:00
|
|
|
res.sendStatus 500
|
2014-04-08 09:34:03 -04:00
|
|
|
else
|
2015-07-08 11:56:38 -04:00
|
|
|
res.sendStatus 200
|
2014-04-08 09:53:33 -04:00
|
|
|
|
2014-11-10 06:23:07 -05:00
|
|
|
cloneProject: (req, res, next)->
|
2014-04-08 09:53:33 -04:00
|
|
|
metrics.inc "cloned-project"
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
projectName = req.body.projectName
|
|
|
|
logger.log project_id:project_id, projectName:projectName, "cloning project"
|
2016-09-23 11:21:07 -04:00
|
|
|
if !AuthenticationController.isUserLoggedIn(req)
|
2014-04-08 09:53:33 -04:00
|
|
|
return res.send redir:"/register"
|
2016-09-07 05:30:58 -04:00
|
|
|
currentUser = AuthenticationController.getSessionUser(req)
|
|
|
|
projectDuplicator.duplicate currentUser, project_id, projectName, (err, project)->
|
|
|
|
if err?
|
|
|
|
logger.error err:err, project_id: project_id, user_id: currentUser._id, "error cloning project"
|
|
|
|
return next(err)
|
|
|
|
res.send(project_id:project._id)
|
2014-04-08 10:25:22 -04:00
|
|
|
|
|
|
|
|
2017-05-19 11:21:02 -04:00
|
|
|
newProject: (req, res, next)->
|
2016-09-05 10:58:31 -04:00
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
2014-07-09 06:05:00 -04:00
|
|
|
projectName = req.body.projectName?.trim()
|
|
|
|
template = req.body.template
|
2016-09-05 10:58:31 -04:00
|
|
|
logger.log user: user_id, projectType: template, name: projectName, "creating project"
|
2014-04-08 10:28:18 -04:00
|
|
|
async.waterfall [
|
|
|
|
(cb)->
|
|
|
|
if template == 'example'
|
2016-09-05 10:58:31 -04:00
|
|
|
projectCreationHandler.createExampleProject user_id, projectName, cb
|
2014-04-08 10:25:22 -04:00
|
|
|
else
|
2016-09-05 10:58:31 -04:00
|
|
|
projectCreationHandler.createBasicProject user_id, projectName, cb
|
2014-04-08 10:28:18 -04:00
|
|
|
], (err, project)->
|
2017-05-19 11:21:02 -04:00
|
|
|
return next(err) if err?
|
|
|
|
logger.log project: project, user: user_id, name: projectName, templateType: template, "created project"
|
|
|
|
res.send {project_id:project._id}
|
2014-04-08 11:40:12 -04:00
|
|
|
|
|
|
|
|
2017-05-19 11:21:02 -04:00
|
|
|
renameProject: (req, res, next)->
|
2014-04-28 12:47:47 -04:00
|
|
|
project_id = req.params.Project_id
|
|
|
|
newName = req.body.newProjectName
|
|
|
|
editorController.renameProject project_id, newName, (err)->
|
2017-05-19 11:21:02 -04:00
|
|
|
return next(err) if err?
|
|
|
|
res.sendStatus 200
|
2014-04-28 12:47:47 -04:00
|
|
|
|
2018-05-04 05:45:13 -04:00
|
|
|
userProjectsJson: (req, res, next) ->
|
2018-05-04 04:44:13 -04:00
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
|
|
|
ProjectGetter.findAllUsersProjects user_id,
|
|
|
|
'name lastUpdated publicAccesLevel archived owner_ref tokens', (err, projects) ->
|
|
|
|
return next(err) if err?
|
|
|
|
projects = ProjectController._buildProjectList(projects)
|
|
|
|
.filter((p) -> !p.archived)
|
|
|
|
.filter((p) -> !p.isV1Project)
|
|
|
|
.map((p) -> {_id: p.id, name: p.name, accessLevel: p.accessLevel})
|
|
|
|
|
|
|
|
res.json({projects: projects})
|
|
|
|
|
2018-05-04 05:45:13 -04:00
|
|
|
projectEntitiesJson: (req, res, next) ->
|
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
|
|
|
project_id = req.params.Project_id
|
2018-05-24 05:22:17 -04:00
|
|
|
ProjectGetter.getProject project_id, (err, project) ->
|
2018-05-22 11:40:39 -04:00
|
|
|
return next(err) if err?
|
2018-05-24 05:22:17 -04:00
|
|
|
ProjectEntityHandler.getAllEntitiesFromProject project, (err, docs, files) ->
|
2018-05-04 05:45:13 -04:00
|
|
|
return next(err) if err?
|
2018-05-24 05:22:17 -04:00
|
|
|
entities = docs.concat(files)
|
|
|
|
.sort (a, b) -> a.path > b.path # Sort by path ascending
|
|
|
|
.map (e) -> {
|
|
|
|
path: e.path,
|
|
|
|
type: if e.doc? then 'doc' else 'file'
|
|
|
|
}
|
|
|
|
res.json({project_id: project_id, entities: entities})
|
2018-05-04 05:45:13 -04:00
|
|
|
|
2014-04-08 11:40:12 -04:00
|
|
|
projectListPage: (req, res, next)->
|
|
|
|
timer = new metrics.Timer("project-list")
|
2016-09-05 10:58:31 -04:00
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
2016-09-07 05:30:58 -04:00
|
|
|
currentUser = AuthenticationController.getSessionUser(req)
|
|
|
|
async.parallel {
|
|
|
|
tags: (cb)->
|
|
|
|
TagsHandler.getAllTags user_id, cb
|
|
|
|
notifications: (cb)->
|
|
|
|
NotificationsHandler.getUserNotifications user_id, cb
|
|
|
|
projects: (cb)->
|
2018-09-13 09:00:30 -04:00
|
|
|
ProjectGetter.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel archived owner_ref tokens', cb
|
2017-10-31 05:38:55 -04:00
|
|
|
v1Projects: (cb) ->
|
2017-11-15 11:28:41 -05:00
|
|
|
Modules.hooks.fire "findAllV1Projects", user_id, (error, projects = []) ->
|
2018-06-19 11:25:56 -04:00
|
|
|
if error? and error instanceof V1ConnectionError
|
2017-11-15 12:19:37 -05:00
|
|
|
return cb(null, projects: [], tags: [], noConnection: true)
|
|
|
|
return cb(error, projects[0]) # hooks.fire returns an array of results, only need first
|
2016-09-07 05:30:58 -04:00
|
|
|
hasSubscription: (cb)->
|
2018-09-03 10:09:57 -04:00
|
|
|
LimitationsManager.hasPaidSubscription currentUser, (error, hasPaidSubscription) ->
|
2018-06-19 11:25:31 -04:00
|
|
|
if error? and error instanceof V1ConnectionError
|
|
|
|
return cb(null, true)
|
2018-09-03 10:09:57 -04:00
|
|
|
return cb(error, hasPaidSubscription)
|
2016-09-07 05:30:58 -04:00
|
|
|
user: (cb) ->
|
2018-04-30 12:13:57 -04:00
|
|
|
User.findById user_id, "featureSwitches overleaf awareOfV2 features", cb
|
2018-12-03 13:58:26 -05:00
|
|
|
userAffiliations: (cb) ->
|
|
|
|
getUserAffiliations user_id, cb
|
2016-09-07 05:30:58 -04:00
|
|
|
}, (err, results)->
|
|
|
|
if err?
|
|
|
|
logger.err err:err, "error getting data for project list page"
|
|
|
|
return next(err)
|
|
|
|
logger.log results:results, user_id:user_id, "rendering project list"
|
2017-10-31 08:37:18 -04:00
|
|
|
v1Tags = results.v1Projects?.tags or []
|
|
|
|
tags = results.tags[0].concat(v1Tags)
|
2016-09-07 05:30:58 -04:00
|
|
|
notifications = require("underscore").map results.notifications, (notification)->
|
|
|
|
notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts)
|
|
|
|
return notification
|
2018-12-03 13:58:26 -05:00
|
|
|
portalTemplates = ProjectController._buildPortalTemplatesList results.userAffiliations
|
2017-10-31 05:38:55 -04:00
|
|
|
projects = ProjectController._buildProjectList results.projects, results.v1Projects?.projects
|
2016-09-07 05:30:58 -04:00
|
|
|
user = results.user
|
2018-12-03 13:58:26 -05:00
|
|
|
userAffiliations = results.userAffiliations
|
2017-11-30 11:59:13 -05:00
|
|
|
warnings = ProjectController._buildWarningsList results.v1Projects
|
|
|
|
|
2018-09-05 10:28:26 -04:00
|
|
|
# in v2 add notifications for matching university IPs
|
|
|
|
if Settings.overleaf?
|
|
|
|
UserGetter.getUser user_id, { 'lastLoginIp': 1 }, (error, user) ->
|
2018-09-07 13:15:32 -04:00
|
|
|
if req.ip != user.lastLoginIp
|
|
|
|
NotificationsBuilder.ipMatcherAffiliation(user._id, req.ip).create()
|
2018-04-30 12:13:57 -04:00
|
|
|
|
2016-09-07 05:30:58 -04:00
|
|
|
ProjectController._injectProjectOwners projects, (error, projects) ->
|
|
|
|
return next(error) if error?
|
|
|
|
viewModel = {
|
|
|
|
title:'your_projects'
|
|
|
|
priority_title: true
|
|
|
|
projects: projects
|
|
|
|
tags: tags
|
|
|
|
notifications: notifications or []
|
2018-12-03 13:58:26 -05:00
|
|
|
portalTemplates: portalTemplates
|
2016-09-07 05:30:58 -04:00
|
|
|
user: user
|
2018-12-03 13:58:26 -05:00
|
|
|
userAffiliations: userAffiliations
|
2018-06-22 09:05:48 -04:00
|
|
|
hasSubscription: results.hasSubscription
|
2017-11-01 10:13:50 -04:00
|
|
|
isShowingV1Projects: results.v1Projects?
|
2017-11-30 11:59:13 -05:00
|
|
|
warnings: warnings
|
2016-09-07 05:30:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if Settings?.algolia?.app_id? and Settings?.algolia?.read_only_api_key?
|
|
|
|
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
|
|
|
|
|
2018-05-24 04:51:29 -04:00
|
|
|
paidUser = user.features?.github and user.features?.dropbox # use a heuristic for paid account
|
2018-04-30 12:19:21 -04:00
|
|
|
freeUserProportion = 0.10
|
2018-04-30 12:13:57 -04:00
|
|
|
sampleFreeUser = parseInt(user._id.toString().slice(-2), 16) < freeUserProportion * 255
|
|
|
|
showFrontWidget = paidUser or sampleFreeUser
|
|
|
|
logger.log {paidUser, sampleFreeUser, showFrontWidget}, 'deciding whether to show front widget'
|
|
|
|
if showFrontWidget
|
|
|
|
viewModel.frontChatWidgetRoomId = Settings.overleaf?.front_chat_widget_room_id
|
|
|
|
|
2016-09-07 05:30:58 -04:00
|
|
|
res.render 'project/list', viewModel
|
|
|
|
timer.done()
|
2014-04-08 11:56:34 -04:00
|
|
|
|
|
|
|
|
2014-04-10 12:49:39 -04:00
|
|
|
loadEditor: (req, res, next)->
|
2014-04-08 12:44:31 -04:00
|
|
|
timer = new metrics.Timer("load-editor")
|
|
|
|
if !Settings.editorIsOpen
|
2014-08-01 08:47:14 -04:00
|
|
|
return res.render("general/closed", {title:"updating_site"})
|
2014-04-08 12:44:31 -04:00
|
|
|
|
2016-09-07 11:40:49 -04:00
|
|
|
if AuthenticationController.isUserLoggedIn(req)
|
2016-09-05 10:58:31 -04:00
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
2014-04-10 12:49:39 -04:00
|
|
|
anonymous = false
|
|
|
|
else
|
|
|
|
anonymous = true
|
2016-03-22 05:39:25 -04:00
|
|
|
user_id = null
|
2016-01-14 09:53:08 -05:00
|
|
|
|
2014-04-10 12:49:39 -04:00
|
|
|
project_id = req.params.Project_id
|
2017-01-05 10:02:10 -05:00
|
|
|
logger.log project_id:project_id, anonymous:anonymous, user_id:user_id, "loading editor"
|
2016-01-14 09:53:08 -05:00
|
|
|
|
2018-10-17 09:14:17 -04:00
|
|
|
async.auto {
|
2014-04-08 12:59:29 -04:00
|
|
|
project: (cb)->
|
2017-11-02 07:17:08 -04:00
|
|
|
ProjectGetter.getProject(
|
|
|
|
project_id,
|
2019-01-03 12:56:24 -05:00
|
|
|
{ name: 1, lastUpdated: 1, track_changes: 1, owner_ref: 1, brandVariationId: 1, overleaf: 1, tokens: 1 },
|
|
|
|
(err, project) ->
|
|
|
|
return cb(err) if err?
|
|
|
|
return cb(null, project) unless project.overleaf?.id? and project.tokens?.readAndWrite? and Settings.projectImportingCheckMaxCreateDelta?
|
|
|
|
createDelta = (new Date().getTime() - new Date(project._id.getTimestamp()).getTime()) / 1000
|
|
|
|
return cb(null, project) unless createDelta < Settings.projectImportingCheckMaxCreateDelta
|
2019-01-07 06:15:38 -05:00
|
|
|
V1Handler.getDocExported project.tokens.readAndWrite, (err, doc_exported) ->
|
2019-01-03 12:56:24 -05:00
|
|
|
return next err if err?
|
2019-01-07 06:15:38 -05:00
|
|
|
project.exporting = doc_exported.exporting
|
2019-01-03 12:56:24 -05:00
|
|
|
cb(null, project)
|
2017-11-02 07:17:08 -04:00
|
|
|
)
|
2014-04-08 12:59:29 -04:00
|
|
|
user: (cb)->
|
2016-03-22 05:39:25 -04:00
|
|
|
if !user_id?
|
2014-04-10 12:49:39 -04:00
|
|
|
cb null, defaultSettingsForAnonymousUser(user_id)
|
|
|
|
else
|
2015-07-22 05:38:28 -04:00
|
|
|
User.findById user_id, (err, user)->
|
|
|
|
logger.log project_id:project_id, user_id:user_id, "got user"
|
|
|
|
cb err, user
|
2014-04-08 12:59:29 -04:00
|
|
|
subscription: (cb)->
|
2016-03-22 05:39:25 -04:00
|
|
|
if !user_id?
|
2014-04-10 12:49:39 -04:00
|
|
|
return cb()
|
2014-04-08 12:59:29 -04:00
|
|
|
SubscriptionLocator.getUsersSubscription user_id, cb
|
2015-08-13 17:40:28 -04:00
|
|
|
activate: (cb)->
|
|
|
|
InactiveProjectManager.reactivateProjectIfRequired project_id, cb
|
2016-01-14 09:53:08 -05:00
|
|
|
markAsOpened: (cb)->
|
2015-08-14 06:27:11 -04:00
|
|
|
#don't need to wait for this to complete
|
|
|
|
ProjectUpdateHandler.markAsOpened project_id, ->
|
|
|
|
cb()
|
2017-10-25 05:34:18 -04:00
|
|
|
isTokenMember: (cb) ->
|
|
|
|
cb = underscore.once(cb)
|
|
|
|
if !user_id?
|
|
|
|
return cb()
|
|
|
|
CollaboratorsHandler.userIsTokenMember user_id, project_id, cb
|
2018-10-17 09:14:17 -04:00
|
|
|
brandVariation: [ "project", (cb, results) ->
|
|
|
|
if !results.project?.brandVariationId?
|
|
|
|
return cb()
|
|
|
|
BrandVariationsHandler.getBrandVariationById results.project.brandVariationId, (error, brandVariationDetails) ->
|
|
|
|
cb(error, brandVariationDetails)
|
|
|
|
]
|
2014-04-08 12:59:29 -04:00
|
|
|
}, (err, results)->
|
|
|
|
if err?
|
2014-04-10 12:49:39 -04:00
|
|
|
logger.err err:err, "error getting details for project page"
|
|
|
|
return next err
|
2014-04-08 12:59:29 -04:00
|
|
|
project = results.project
|
|
|
|
user = results.user
|
|
|
|
subscription = results.subscription
|
2018-10-17 09:14:17 -04:00
|
|
|
brandVariation = results.brandVariation
|
2018-12-03 13:58:26 -05:00
|
|
|
|
2017-09-26 09:50:45 -04:00
|
|
|
daysSinceLastUpdated = (new Date() - project.lastUpdated) / 86400000
|
2015-07-22 05:38:48 -04:00
|
|
|
logger.log project_id:project_id, daysSinceLastUpdated:daysSinceLastUpdated, "got db results for loading editor"
|
|
|
|
|
2017-10-13 06:20:57 -04:00
|
|
|
token = TokenAccessHandler.getRequestToken(req, project_id)
|
2017-10-25 05:34:18 -04:00
|
|
|
isTokenMember = results.isTokenMember
|
2017-10-13 06:20:57 -04:00
|
|
|
AuthorizationManager.getPrivilegeLevelForProject user_id, project_id, token, (error, privilegeLevel)->
|
2016-03-10 12:17:26 -05:00
|
|
|
return next(error) if error?
|
2016-03-15 10:35:01 -04:00
|
|
|
if !privilegeLevel? or privilegeLevel == PrivilegeLevels.NONE
|
2015-07-08 11:56:38 -04:00
|
|
|
return res.sendStatus 401
|
2014-04-08 12:59:29 -04:00
|
|
|
|
2019-01-03 12:56:24 -05:00
|
|
|
if project.exporting
|
|
|
|
res.render 'project/importing',
|
|
|
|
bodyClasses: ["editor"]
|
|
|
|
return
|
|
|
|
|
2014-04-08 12:59:29 -04:00
|
|
|
if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt?
|
|
|
|
allowedFreeTrial = !!subscription.freeTrial.allowed || true
|
2016-01-14 09:53:08 -05:00
|
|
|
|
2015-07-21 20:06:23 -04:00
|
|
|
logger.log project_id:project_id, "rendering editor page"
|
2014-04-08 12:59:29 -04:00
|
|
|
res.render 'project/editor',
|
|
|
|
title: project.name
|
|
|
|
priority_title: true
|
|
|
|
bodyClasses: ["editor"]
|
2014-06-21 17:20:37 -04:00
|
|
|
project_id : project._id
|
2014-07-09 06:05:00 -04:00
|
|
|
user : {
|
2016-03-31 06:53:59 -04:00
|
|
|
id : user_id
|
2014-04-08 12:59:29 -04:00
|
|
|
email : user.email
|
|
|
|
first_name : user.first_name
|
|
|
|
last_name : user.last_name
|
|
|
|
referal_id : user.referal_id
|
2016-07-21 11:42:22 -04:00
|
|
|
signUpDate : user.signUpDate
|
2014-04-08 12:59:29 -04:00
|
|
|
subscription :
|
|
|
|
freeTrial: {allowed: allowedFreeTrial}
|
2014-10-07 08:31:13 -04:00
|
|
|
featureSwitches: user.featureSwitches
|
2016-03-31 12:10:49 -04:00
|
|
|
features: user.features
|
2016-04-01 06:36:19 -04:00
|
|
|
refProviders: user.refProviders
|
2016-06-06 08:12:24 -04:00
|
|
|
betaProgram: user.betaProgram
|
2014-07-09 06:05:00 -04:00
|
|
|
}
|
|
|
|
userSettings: {
|
2014-04-08 12:59:29 -04:00
|
|
|
mode : user.ace.mode
|
2018-08-27 10:25:00 -04:00
|
|
|
editorTheme : user.ace.theme
|
2014-04-08 12:59:29 -04:00
|
|
|
fontSize : user.ace.fontSize
|
|
|
|
autoComplete: user.ace.autoComplete
|
2017-07-06 06:06:51 -04:00
|
|
|
autoPairDelimiters: user.ace.autoPairDelimiters
|
2014-04-08 12:59:29 -04:00
|
|
|
pdfViewer : user.ace.pdfViewer
|
2016-10-06 06:51:24 -04:00
|
|
|
syntaxValidation: user.ace.syntaxValidation
|
2018-05-10 13:03:54 -04:00
|
|
|
fontFamily: user.ace.fontFamily
|
|
|
|
lineHeight: user.ace.lineHeight
|
2018-08-28 05:10:16 -04:00
|
|
|
overallTheme: user.ace.overallTheme
|
2014-07-09 06:05:00 -04:00
|
|
|
}
|
2017-06-21 08:40:28 -04:00
|
|
|
trackChangesState: project.track_changes
|
2014-04-08 12:59:29 -04:00
|
|
|
privilegeLevel: privilegeLevel
|
|
|
|
chatUrl: Settings.apis.chat.url
|
|
|
|
anonymous: anonymous
|
2017-10-20 05:10:21 -04:00
|
|
|
anonymousAccessToken: req._anonymousAccessToken
|
2017-10-25 05:34:18 -04:00
|
|
|
isTokenMember: isTokenMember
|
2014-04-08 12:59:29 -04:00
|
|
|
languages: Settings.languages
|
2018-08-27 10:25:00 -04:00
|
|
|
editorThemes: THEME_LIST
|
2015-11-06 07:51:43 -05:00
|
|
|
maxDocLength: Settings.max_doc_length
|
2017-12-13 11:11:12 -05:00
|
|
|
useV2History: !!project.overleaf?.history?.display
|
2018-07-16 09:20:53 -04:00
|
|
|
richTextEnabled: Features.hasFeature('rich-text')
|
2018-05-23 07:55:49 -04:00
|
|
|
showTestControls: req.query?.tc == 'true' || user.isAdmin
|
2018-10-17 09:14:17 -04:00
|
|
|
brandVariation: brandVariation
|
2018-08-13 05:22:23 -04:00
|
|
|
allowedImageNames: Settings.allowedImageNames || []
|
2018-11-14 06:08:15 -05:00
|
|
|
gitBridgePublicBaseUrl: Settings.gitBridgePublicBaseUrl
|
2015-11-06 07:51:43 -05:00
|
|
|
timer.done()
|
2014-04-08 12:59:29 -04:00
|
|
|
|
2017-11-01 10:10:12 -04:00
|
|
|
_buildProjectList: (allProjects, v1Projects = [])->
|
2017-10-20 06:49:20 -04:00
|
|
|
{owned, readAndWrite, readOnly, tokenReadAndWrite, tokenReadOnly} = allProjects
|
2014-06-16 08:34:38 -04:00
|
|
|
projects = []
|
2017-10-20 06:49:20 -04:00
|
|
|
for project in owned
|
2017-10-12 05:57:11 -04:00
|
|
|
projects.push ProjectController._buildProjectViewModel(project, "owner", Sources.OWNER)
|
2017-10-05 08:20:06 -04:00
|
|
|
# Invite-access
|
2017-10-20 06:49:20 -04:00
|
|
|
for project in readAndWrite
|
2017-10-12 05:57:11 -04:00
|
|
|
projects.push ProjectController._buildProjectViewModel(project, "readWrite", Sources.INVITE)
|
2017-10-20 06:49:20 -04:00
|
|
|
for project in readOnly
|
2017-10-12 05:57:11 -04:00
|
|
|
projects.push ProjectController._buildProjectViewModel(project, "readOnly", Sources.INVITE)
|
2017-11-01 10:10:12 -04:00
|
|
|
for project in v1Projects
|
|
|
|
projects.push ProjectController._buildV1ProjectViewModel(project)
|
2017-10-05 08:20:06 -04:00
|
|
|
# Token-access
|
2017-10-17 06:10:31 -04:00
|
|
|
# Only add these projects if they're not already present, this gives us cascading access
|
|
|
|
# from 'owner' => 'token-read-only'
|
2017-10-20 06:49:20 -04:00
|
|
|
for project in tokenReadAndWrite
|
2017-10-17 06:10:31 -04:00
|
|
|
if projects.filter((p) -> p.id.toString() == project._id.toString()).length == 0
|
|
|
|
projects.push ProjectController._buildProjectViewModel(project, "readAndWrite", Sources.TOKEN)
|
2017-10-20 06:49:20 -04:00
|
|
|
for project in tokenReadOnly
|
2017-10-17 06:10:31 -04:00
|
|
|
if projects.filter((p) -> p.id.toString() == project._id.toString()).length == 0
|
|
|
|
projects.push ProjectController._buildProjectViewModel(project, "readOnly", Sources.TOKEN)
|
2014-06-16 08:34:38 -04:00
|
|
|
|
|
|
|
return projects
|
|
|
|
|
2017-10-12 05:57:11 -04:00
|
|
|
_buildProjectViewModel: (project, accessLevel, source) ->
|
2017-10-19 11:26:01 -04:00
|
|
|
TokenAccessHandler.protectTokens(project, accessLevel)
|
2017-10-05 08:20:06 -04:00
|
|
|
model = {
|
2014-06-16 08:34:38 -04:00
|
|
|
id: project._id
|
|
|
|
name: project.name
|
|
|
|
lastUpdated: project.lastUpdated
|
|
|
|
publicAccessLevel: project.publicAccesLevel
|
|
|
|
accessLevel: accessLevel
|
2017-10-12 05:57:11 -04:00
|
|
|
source: source
|
2014-06-16 08:34:38 -04:00
|
|
|
archived: !!project.archived
|
|
|
|
owner_ref: project.owner_ref
|
2017-10-19 11:26:01 -04:00
|
|
|
tokens: project.tokens
|
2017-10-30 11:32:54 -04:00
|
|
|
isV1Project: false
|
2014-06-16 08:34:38 -04:00
|
|
|
}
|
2017-10-05 08:20:06 -04:00
|
|
|
return model
|
2014-06-16 08:34:38 -04:00
|
|
|
|
2017-11-01 10:10:12 -04:00
|
|
|
_buildV1ProjectViewModel: (project) ->
|
2018-01-23 08:47:48 -05:00
|
|
|
projectViewModel = {
|
2017-10-30 05:42:44 -04:00
|
|
|
id: project.id
|
|
|
|
name: project.title
|
2017-11-03 05:30:58 -04:00
|
|
|
lastUpdated: new Date(project.updated_at * 1000) # Convert from epoch
|
2017-10-30 10:29:20 -04:00
|
|
|
archived: project.removed || project.archived
|
2017-10-30 11:32:54 -04:00
|
|
|
isV1Project: true
|
2017-10-30 05:42:44 -04:00
|
|
|
}
|
2018-01-23 08:47:48 -05:00
|
|
|
if (project.owner? and project.owner.user_is_owner) or (project.creator? and project.creator.user_is_creator)
|
|
|
|
projectViewModel.accessLevel = "owner"
|
|
|
|
else
|
|
|
|
projectViewModel.accessLevel = "readOnly"
|
|
|
|
if project.owner?
|
|
|
|
projectViewModel.owner = {
|
|
|
|
first_name: project.owner.name
|
|
|
|
}
|
|
|
|
else if project.creator?
|
|
|
|
projectViewModel.owner = {
|
|
|
|
first_name: project.creator.name
|
|
|
|
}
|
|
|
|
return projectViewModel
|
|
|
|
|
2017-10-30 05:42:44 -04:00
|
|
|
|
2014-06-16 08:34:38 -04:00
|
|
|
_injectProjectOwners: (projects, callback = (error, projects) ->) ->
|
|
|
|
users = {}
|
|
|
|
for project in projects
|
|
|
|
if project.owner_ref?
|
|
|
|
users[project.owner_ref.toString()] = true
|
|
|
|
|
|
|
|
jobs = []
|
|
|
|
for user_id, _ of users
|
|
|
|
do (user_id) ->
|
|
|
|
jobs.push (callback) ->
|
|
|
|
User.findById user_id, "first_name last_name", (error, user) ->
|
|
|
|
return callback(error) if error?
|
|
|
|
users[user_id] = user
|
|
|
|
callback()
|
|
|
|
|
|
|
|
async.series jobs, (error) ->
|
|
|
|
for project in projects
|
|
|
|
if project.owner_ref?
|
|
|
|
project.owner = users[project.owner_ref.toString()]
|
|
|
|
callback null, projects
|
|
|
|
|
2017-11-30 11:59:13 -05:00
|
|
|
_buildWarningsList: (v1ProjectData = {}) ->
|
|
|
|
warnings = []
|
|
|
|
if v1ProjectData.noConnection
|
|
|
|
warnings.push 'No V1 Connection'
|
|
|
|
if v1ProjectData.hasHiddenV1Projects
|
|
|
|
warnings.push "Looks like you've got a lot of V1 projects! Some of them may be hidden on V2. To view them all, use the V1 dashboard."
|
|
|
|
return warnings
|
|
|
|
|
2018-12-03 13:58:26 -05:00
|
|
|
_buildPortalTemplatesList: (affiliations = []) ->
|
|
|
|
portalTemplates = []
|
|
|
|
for aff in affiliations
|
|
|
|
if aff.portal && aff.portal.slug && aff.portal.templates_count && aff.portal.templates_count > 0
|
|
|
|
portalPath = if aff.institution.isUniversity then '/edu/' else '/org/'
|
|
|
|
portalTemplates.push({
|
|
|
|
name: aff.institution.name
|
|
|
|
url: Settings.siteUrl + portalPath + aff.portal.slug
|
|
|
|
})
|
|
|
|
return portalTemplates
|
|
|
|
|
2014-04-10 12:49:39 -04:00
|
|
|
defaultSettingsForAnonymousUser = (user_id)->
|
2014-04-08 12:59:29 -04:00
|
|
|
id : user_id
|
|
|
|
ace:
|
|
|
|
mode:'none'
|
|
|
|
theme:'textmate'
|
|
|
|
fontSize: '12'
|
|
|
|
autoComplete: true
|
|
|
|
spellCheckLanguage: ""
|
|
|
|
pdfViewer: ""
|
2016-10-06 06:51:24 -04:00
|
|
|
syntaxValidation: true
|
2014-04-08 12:59:29 -04:00
|
|
|
subscription:
|
|
|
|
freeTrial:
|
|
|
|
allowed: true
|
|
|
|
featureSwitches:
|
2014-10-07 08:31:13 -04:00
|
|
|
github: false
|
2014-04-08 12:44:31 -04:00
|
|
|
|
2014-06-24 15:28:53 -04:00
|
|
|
THEME_LIST = []
|
|
|
|
do generateThemeList = () ->
|
2016-09-22 06:02:20 -04:00
|
|
|
files = fs.readdirSync __dirname + '/../../../../public/js/' + PackageVersions.lib('ace')
|
2014-06-24 15:28:53 -04:00
|
|
|
for file in files
|
2018-08-27 14:25:01 -04:00
|
|
|
if file.slice(-2) == "js" and /^theme-/.test(file)
|
2014-07-09 12:59:04 -04:00
|
|
|
cleanName = file.slice(0,-3).slice(6)
|
2016-09-02 11:17:37 -04:00
|
|
|
THEME_LIST.push cleanName
|