ProjectController.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  1. const _ = require('lodash')
  2. const OError = require('@overleaf/o-error')
  3. const crypto = require('crypto')
  4. const async = require('async')
  5. const logger = require('@overleaf/logger')
  6. const { ObjectId } = require('mongodb')
  7. const ProjectDeleter = require('./ProjectDeleter')
  8. const ProjectDuplicator = require('./ProjectDuplicator')
  9. const ProjectCreationHandler = require('./ProjectCreationHandler')
  10. const EditorController = require('../Editor/EditorController')
  11. const ProjectHelper = require('./ProjectHelper')
  12. const metrics = require('@overleaf/metrics')
  13. const { User } = require('../../models/User')
  14. const TagsHandler = require('../Tags/TagsHandler')
  15. const SubscriptionLocator = require('../Subscription/SubscriptionLocator')
  16. const NotificationsHandler = require('../Notifications/NotificationsHandler')
  17. const LimitationsManager = require('../Subscription/LimitationsManager')
  18. const Settings = require('@overleaf/settings')
  19. const AuthorizationManager = require('../Authorization/AuthorizationManager')
  20. const InactiveProjectManager = require('../InactiveData/InactiveProjectManager')
  21. const ProjectUpdateHandler = require('./ProjectUpdateHandler')
  22. const ProjectGetter = require('./ProjectGetter')
  23. const PrivilegeLevels = require('../Authorization/PrivilegeLevels')
  24. const SessionManager = require('../Authentication/SessionManager')
  25. const Sources = require('../Authorization/Sources')
  26. const TokenAccessHandler = require('../TokenAccess/TokenAccessHandler')
  27. const CollaboratorsGetter = require('../Collaborators/CollaboratorsGetter')
  28. const ProjectEntityHandler = require('./ProjectEntityHandler')
  29. const TpdsProjectFlusher = require('../ThirdPartyDataStore/TpdsProjectFlusher')
  30. const UserGetter = require('../User/UserGetter')
  31. const NotificationsBuilder = require('../Notifications/NotificationsBuilder')
  32. const { V1ConnectionError } = require('../Errors/Errors')
  33. const Features = require('../../infrastructure/Features')
  34. const BrandVariationsHandler = require('../BrandVariations/BrandVariationsHandler')
  35. const UserController = require('../User/UserController')
  36. const AnalyticsManager = require('../Analytics/AnalyticsManager')
  37. const Modules = require('../../infrastructure/Modules')
  38. const SplitTestHandler = require('../SplitTests/SplitTestHandler')
  39. const FeaturesUpdater = require('../Subscription/FeaturesUpdater')
  40. const SpellingHandler = require('../Spelling/SpellingHandler')
  41. const UserPrimaryEmailCheckHandler = require('../User/UserPrimaryEmailCheckHandler')
  42. const { hasAdminAccess } = require('../Helpers/AdminAuthorizationHelper')
  43. const InstitutionsFeatures = require('../Institutions/InstitutionsFeatures')
  44. const SubscriptionViewModelBuilder = require('../Subscription/SubscriptionViewModelBuilder')
  45. const SurveyHandler = require('../Survey/SurveyHandler')
  46. const _ssoAvailable = (affiliation, session, linkedInstitutionIds) => {
  47. if (!affiliation.institution) return false
  48. // institution.confirmed is for the domain being confirmed, not the email
  49. // Do not show SSO UI for unconfirmed domains
  50. if (!affiliation.institution.confirmed) return false
  51. // Could have multiple emails at the same institution, and if any are
  52. // linked to the institution then do not show notification for others
  53. if (
  54. linkedInstitutionIds.indexOf(affiliation.institution.id.toString()) === -1
  55. ) {
  56. if (affiliation.institution.ssoEnabled) return true
  57. if (affiliation.institution.ssoBeta && session.samlBeta) return true
  58. return false
  59. }
  60. return false
  61. }
  62. const ProjectController = {
  63. _isInPercentageRollout(rolloutName, objectId, percentage) {
  64. if (Settings.bypassPercentageRollouts === true) {
  65. return true
  66. }
  67. const data = `${rolloutName}:${objectId.toString()}`
  68. const md5hash = crypto.createHash('md5').update(data).digest('hex')
  69. const counter = parseInt(md5hash.slice(26, 32), 16)
  70. return counter % 100 < percentage
  71. },
  72. updateProjectSettings(req, res, next) {
  73. const projectId = req.params.Project_id
  74. const jobs = []
  75. if (req.body.compiler != null) {
  76. jobs.push(callback =>
  77. EditorController.setCompiler(projectId, req.body.compiler, callback)
  78. )
  79. }
  80. if (req.body.imageName != null) {
  81. jobs.push(callback =>
  82. EditorController.setImageName(projectId, req.body.imageName, callback)
  83. )
  84. }
  85. if (req.body.name != null) {
  86. jobs.push(callback =>
  87. EditorController.renameProject(projectId, req.body.name, callback)
  88. )
  89. }
  90. if (req.body.spellCheckLanguage != null) {
  91. jobs.push(callback =>
  92. EditorController.setSpellCheckLanguage(
  93. projectId,
  94. req.body.spellCheckLanguage,
  95. callback
  96. )
  97. )
  98. }
  99. if (req.body.rootDocId != null) {
  100. jobs.push(callback =>
  101. EditorController.setRootDoc(projectId, req.body.rootDocId, callback)
  102. )
  103. }
  104. async.series(jobs, error => {
  105. if (error != null) {
  106. return next(error)
  107. }
  108. res.sendStatus(204)
  109. })
  110. },
  111. updateProjectAdminSettings(req, res, next) {
  112. const projectId = req.params.Project_id
  113. const jobs = []
  114. if (req.body.publicAccessLevel != null) {
  115. jobs.push(callback =>
  116. EditorController.setPublicAccessLevel(
  117. projectId,
  118. req.body.publicAccessLevel,
  119. callback
  120. )
  121. )
  122. }
  123. async.series(jobs, error => {
  124. if (error != null) {
  125. return next(error)
  126. }
  127. res.sendStatus(204)
  128. })
  129. },
  130. deleteProject(req, res) {
  131. const projectId = req.params.Project_id
  132. const user = SessionManager.getSessionUser(req.session)
  133. const cb = err => {
  134. if (err != null) {
  135. res.sendStatus(500)
  136. } else {
  137. res.sendStatus(200)
  138. }
  139. }
  140. ProjectDeleter.deleteProject(
  141. projectId,
  142. { deleterUser: user, ipAddress: req.ip },
  143. cb
  144. )
  145. },
  146. archiveProject(req, res, next) {
  147. const projectId = req.params.Project_id
  148. const userId = SessionManager.getLoggedInUserId(req.session)
  149. ProjectDeleter.archiveProject(projectId, userId, function (err) {
  150. if (err != null) {
  151. return next(err)
  152. } else {
  153. return res.sendStatus(200)
  154. }
  155. })
  156. },
  157. unarchiveProject(req, res, next) {
  158. const projectId = req.params.Project_id
  159. const userId = SessionManager.getLoggedInUserId(req.session)
  160. ProjectDeleter.unarchiveProject(projectId, userId, function (err) {
  161. if (err != null) {
  162. return next(err)
  163. } else {
  164. return res.sendStatus(200)
  165. }
  166. })
  167. },
  168. trashProject(req, res, next) {
  169. const projectId = req.params.project_id
  170. const userId = SessionManager.getLoggedInUserId(req.session)
  171. ProjectDeleter.trashProject(projectId, userId, function (err) {
  172. if (err != null) {
  173. return next(err)
  174. } else {
  175. return res.sendStatus(200)
  176. }
  177. })
  178. },
  179. untrashProject(req, res, next) {
  180. const projectId = req.params.project_id
  181. const userId = SessionManager.getLoggedInUserId(req.session)
  182. ProjectDeleter.untrashProject(projectId, userId, function (err) {
  183. if (err != null) {
  184. return next(err)
  185. } else {
  186. return res.sendStatus(200)
  187. }
  188. })
  189. },
  190. expireDeletedProjectsAfterDuration(req, res) {
  191. ProjectDeleter.expireDeletedProjectsAfterDuration(err => {
  192. if (err != null) {
  193. res.sendStatus(500)
  194. } else {
  195. res.sendStatus(200)
  196. }
  197. })
  198. },
  199. expireDeletedProject(req, res, next) {
  200. const { projectId } = req.params
  201. ProjectDeleter.expireDeletedProject(projectId, err => {
  202. if (err != null) {
  203. next(err)
  204. } else {
  205. res.sendStatus(200)
  206. }
  207. })
  208. },
  209. restoreProject(req, res) {
  210. const projectId = req.params.Project_id
  211. ProjectDeleter.restoreProject(projectId, err => {
  212. if (err != null) {
  213. res.sendStatus(500)
  214. } else {
  215. res.sendStatus(200)
  216. }
  217. })
  218. },
  219. cloneProject(req, res, next) {
  220. res.setTimeout(5 * 60 * 1000) // allow extra time for the copy to complete
  221. metrics.inc('cloned-project')
  222. const projectId = req.params.Project_id
  223. const { projectName } = req.body
  224. logger.debug({ projectId, projectName }, 'cloning project')
  225. if (!SessionManager.isUserLoggedIn(req.session)) {
  226. return res.json({ redir: '/register' })
  227. }
  228. const currentUser = SessionManager.getSessionUser(req.session)
  229. const { first_name: firstName, last_name: lastName, email } = currentUser
  230. ProjectDuplicator.duplicate(
  231. currentUser,
  232. projectId,
  233. projectName,
  234. (err, project) => {
  235. if (err != null) {
  236. OError.tag(err, 'error cloning project', {
  237. projectId,
  238. userId: currentUser._id,
  239. })
  240. return next(err)
  241. }
  242. res.json({
  243. name: project.name,
  244. project_id: project._id,
  245. owner_ref: project.owner_ref,
  246. owner: {
  247. first_name: firstName,
  248. last_name: lastName,
  249. email,
  250. _id: currentUser._id,
  251. },
  252. })
  253. }
  254. )
  255. },
  256. newProject(req, res, next) {
  257. const currentUser = SessionManager.getSessionUser(req.session)
  258. const {
  259. first_name: firstName,
  260. last_name: lastName,
  261. email,
  262. _id: userId,
  263. } = currentUser
  264. const projectName =
  265. req.body.projectName != null ? req.body.projectName.trim() : undefined
  266. const { template } = req.body
  267. async.waterfall(
  268. [
  269. cb => {
  270. if (template === 'example') {
  271. ProjectCreationHandler.createExampleProject(userId, projectName, cb)
  272. } else {
  273. ProjectCreationHandler.createBasicProject(userId, projectName, cb)
  274. }
  275. },
  276. ],
  277. (err, project) => {
  278. if (err != null) {
  279. return next(err)
  280. }
  281. res.json({
  282. project_id: project._id,
  283. owner_ref: project.owner_ref,
  284. owner: {
  285. first_name: firstName,
  286. last_name: lastName,
  287. email,
  288. _id: userId,
  289. },
  290. })
  291. }
  292. )
  293. },
  294. renameProject(req, res, next) {
  295. const projectId = req.params.Project_id
  296. const newName = req.body.newProjectName
  297. EditorController.renameProject(projectId, newName, err => {
  298. if (err != null) {
  299. return next(err)
  300. }
  301. res.sendStatus(200)
  302. })
  303. },
  304. userProjectsJson(req, res, next) {
  305. const userId = SessionManager.getLoggedInUserId(req.session)
  306. ProjectGetter.findAllUsersProjects(
  307. userId,
  308. 'name lastUpdated publicAccesLevel archived trashed owner_ref tokens',
  309. (err, projects) => {
  310. if (err != null) {
  311. return next(err)
  312. }
  313. // _buildProjectList already converts archived/trashed to booleans so isArchivedOrTrashed should not be used here
  314. projects = ProjectController._buildProjectList(projects, userId)
  315. .filter(p => !(p.archived || p.trashed))
  316. .map(p => ({ _id: p.id, name: p.name, accessLevel: p.accessLevel }))
  317. res.json({ projects })
  318. }
  319. )
  320. },
  321. projectEntitiesJson(req, res, next) {
  322. const projectId = req.params.Project_id
  323. ProjectGetter.getProject(projectId, (err, project) => {
  324. if (err != null) {
  325. return next(err)
  326. }
  327. const { docs, files } =
  328. ProjectEntityHandler.getAllEntitiesFromProject(project)
  329. const entities = docs
  330. .concat(files)
  331. // Sort by path ascending
  332. .sort((a, b) => (a.path > b.path ? 1 : a.path < b.path ? -1 : 0))
  333. .map(e => ({
  334. path: e.path,
  335. type: e.doc != null ? 'doc' : 'file',
  336. }))
  337. res.json({ project_id: projectId, entities })
  338. })
  339. },
  340. projectListPage(req, res, next) {
  341. const timer = new metrics.Timer('project-list')
  342. const userId = SessionManager.getLoggedInUserId(req.session)
  343. const currentUser = SessionManager.getSessionUser(req.session)
  344. async.parallel(
  345. {
  346. tags(cb) {
  347. TagsHandler.getAllTags(userId, cb)
  348. },
  349. notifications(cb) {
  350. NotificationsHandler.getUserNotifications(userId, cb)
  351. },
  352. projects(cb) {
  353. ProjectGetter.findAllUsersProjects(
  354. userId,
  355. 'name lastUpdated lastUpdatedBy publicAccesLevel archived trashed owner_ref tokens',
  356. cb
  357. )
  358. },
  359. hasSubscription(cb) {
  360. LimitationsManager.hasPaidSubscription(
  361. currentUser,
  362. (error, hasPaidSubscription) => {
  363. if (error != null && error instanceof V1ConnectionError) {
  364. return cb(null, true)
  365. }
  366. cb(error, hasPaidSubscription)
  367. }
  368. )
  369. },
  370. user(cb) {
  371. User.findById(
  372. userId,
  373. 'email emails featureSwitches overleaf awareOfV2 features lastLoginIp lastPrimaryEmailCheck signUpDate',
  374. cb
  375. )
  376. },
  377. userEmailsData(cb) {
  378. const result = { list: [], allInReconfirmNotificationPeriods: [] }
  379. UserGetter.getUserFullEmails(userId, (error, fullEmails) => {
  380. if (error && error instanceof V1ConnectionError) {
  381. return cb(null, result)
  382. }
  383. if (!Features.hasFeature('affiliations')) {
  384. result.list = fullEmails
  385. return cb(null, result)
  386. }
  387. Modules.hooks.fire(
  388. 'allInReconfirmNotificationPeriodsForUser',
  389. fullEmails,
  390. (error, results) => {
  391. if (error != null) {
  392. return cb(error)
  393. }
  394. // Module.hooks.fire accepts multiple methods
  395. // and does async.series
  396. const allInReconfirmNotificationPeriods =
  397. (results && results[0]) || []
  398. return cb(null, {
  399. list: fullEmails,
  400. allInReconfirmNotificationPeriods,
  401. })
  402. }
  403. )
  404. })
  405. },
  406. usersBestSubscription(cb) {
  407. if (!Features.hasFeature('saas')) {
  408. return cb()
  409. }
  410. SubscriptionViewModelBuilder.getBestSubscription(
  411. { _id: userId },
  412. (err, subscription) => {
  413. if (err) {
  414. // do not fail loading the project list when fetching the best subscription fails
  415. return cb(null, { type: 'error' })
  416. }
  417. cb(null, subscription)
  418. }
  419. )
  420. },
  421. primaryEmailCheckActive(cb) {
  422. SplitTestHandler.getAssignment(
  423. req,
  424. res,
  425. 'primary-email-check',
  426. (err, assignment) => {
  427. if (err) {
  428. logger.warn(
  429. { err },
  430. 'failed to get "primary-email-check" split test assignment'
  431. )
  432. cb(null, false)
  433. } else {
  434. cb(null, assignment.variant === 'active')
  435. }
  436. }
  437. )
  438. },
  439. survey(cb) {
  440. SurveyHandler.getSurvey(userId, (err, survey) => {
  441. if (err) {
  442. logger.warn({ err }, 'failed to get survey')
  443. // do not fail loading the project list if we fail to load the survey
  444. cb(null, null)
  445. } else {
  446. cb(null, survey)
  447. }
  448. })
  449. },
  450. },
  451. (err, results) => {
  452. if (err != null) {
  453. OError.tag(err, 'error getting data for project list page')
  454. return next(err)
  455. }
  456. const { notifications, user, userEmailsData, primaryEmailCheckActive } =
  457. results
  458. if (
  459. user &&
  460. primaryEmailCheckActive &&
  461. UserPrimaryEmailCheckHandler.requiresPrimaryEmailCheck(user)
  462. ) {
  463. return res.redirect('/user/emails/primary-email-check')
  464. }
  465. const userEmails = userEmailsData.list || []
  466. const userAffiliations = userEmails
  467. .filter(emailData => !!emailData.affiliation)
  468. .map(emailData => {
  469. const result = emailData.affiliation
  470. result.email = emailData.email
  471. return result
  472. })
  473. const { allInReconfirmNotificationPeriods } = userEmailsData
  474. // Handle case of deleted user
  475. if (user == null) {
  476. UserController.logout(req, res, next)
  477. return
  478. }
  479. const tags = results.tags
  480. const notificationsInstitution = []
  481. for (const notification of notifications) {
  482. notification.html = req.i18n.translate(
  483. notification.templateKey,
  484. notification.messageOpts
  485. )
  486. }
  487. // Institution SSO Notifications
  488. let reconfirmedViaSAML
  489. if (Features.hasFeature('saml')) {
  490. reconfirmedViaSAML = _.get(req.session, ['saml', 'reconfirmed'])
  491. const samlSession = req.session.saml
  492. // Notification: SSO Available
  493. const linkedInstitutionIds = []
  494. user.emails.forEach(email => {
  495. if (email.samlProviderId) {
  496. linkedInstitutionIds.push(email.samlProviderId)
  497. }
  498. })
  499. if (Array.isArray(userAffiliations)) {
  500. userAffiliations.forEach(affiliation => {
  501. if (
  502. _ssoAvailable(affiliation, req.session, linkedInstitutionIds)
  503. ) {
  504. notificationsInstitution.push({
  505. email: affiliation.email,
  506. institutionId: affiliation.institution.id,
  507. institutionName: affiliation.institution.name,
  508. templateKey: 'notification_institution_sso_available',
  509. })
  510. }
  511. })
  512. }
  513. if (samlSession) {
  514. // Notification: After SSO Linked
  515. if (samlSession.linked) {
  516. notificationsInstitution.push({
  517. email: samlSession.institutionEmail,
  518. institutionName: samlSession.linked.universityName,
  519. templateKey: 'notification_institution_sso_linked',
  520. })
  521. }
  522. // Notification: After SSO Linked or Logging in
  523. // The requested email does not match primary email returned from
  524. // the institution
  525. if (
  526. samlSession.requestedEmail &&
  527. samlSession.emailNonCanonical &&
  528. !samlSession.error
  529. ) {
  530. notificationsInstitution.push({
  531. institutionEmail: samlSession.emailNonCanonical,
  532. requestedEmail: samlSession.requestedEmail,
  533. templateKey: 'notification_institution_sso_non_canonical',
  534. })
  535. }
  536. // Notification: Tried to register, but account already existed
  537. // registerIntercept is set before the institution callback.
  538. // institutionEmail is set after institution callback.
  539. // Check for both in case SSO flow was abandoned
  540. if (
  541. samlSession.registerIntercept &&
  542. samlSession.institutionEmail &&
  543. !samlSession.error
  544. ) {
  545. notificationsInstitution.push({
  546. email: samlSession.institutionEmail,
  547. templateKey: 'notification_institution_sso_already_registered',
  548. })
  549. }
  550. // Notification: When there is a session error
  551. if (samlSession.error) {
  552. notificationsInstitution.push({
  553. templateKey: 'notification_institution_sso_error',
  554. error: samlSession.error,
  555. })
  556. }
  557. }
  558. delete req.session.saml
  559. }
  560. const portalTemplates =
  561. ProjectController._buildPortalTemplatesList(userAffiliations)
  562. const projects = ProjectController._buildProjectList(
  563. results.projects,
  564. userId
  565. )
  566. // in v2 add notifications for matching university IPs
  567. if (Settings.overleaf != null && req.ip !== user.lastLoginIp) {
  568. NotificationsBuilder.ipMatcherAffiliation(user._id).create(
  569. req.ip,
  570. () => {}
  571. )
  572. }
  573. ProjectController._injectProjectUsers(projects, (error, projects) => {
  574. if (error != null) {
  575. return next(error)
  576. }
  577. const viewModel = {
  578. title: 'your_projects',
  579. priority_title: true,
  580. projects,
  581. tags,
  582. notifications: notifications || [],
  583. notificationsInstitution,
  584. allInReconfirmNotificationPeriods,
  585. portalTemplates,
  586. user,
  587. userAffiliations,
  588. userEmails,
  589. hasSubscription: results.hasSubscription,
  590. reconfirmedViaSAML,
  591. zipFileSizeLimit: Settings.maxUploadSize,
  592. isOverleaf: !!Settings.overleaf,
  593. metadata: { viewport: false },
  594. showThinFooter: true, // don't show the fat footer on the projects dashboard, as there's a fixed space available
  595. usersBestSubscription: results.usersBestSubscription,
  596. survey: results.survey,
  597. }
  598. const paidUser =
  599. (user.features != null ? user.features.github : undefined) &&
  600. (user.features != null ? user.features.dropbox : undefined) // use a heuristic for paid account
  601. const freeUserProportion = 0.1
  602. const sampleFreeUser =
  603. parseInt(user._id.toString().slice(-2), 16) <
  604. freeUserProportion * 255
  605. const showFrontWidget = paidUser || sampleFreeUser
  606. if (showFrontWidget) {
  607. viewModel.frontChatWidgetRoomId =
  608. Settings.overleaf != null
  609. ? Settings.overleaf.front_chat_widget_room_id
  610. : undefined
  611. }
  612. // null test targeting logged in users
  613. SplitTestHandler.promises.getAssignment(
  614. req,
  615. res,
  616. 'null-test-dashboard'
  617. )
  618. res.render('project/list', viewModel)
  619. timer.done()
  620. })
  621. }
  622. )
  623. },
  624. loadEditor(req, res, next) {
  625. const timer = new metrics.Timer('load-editor')
  626. if (!Settings.editorIsOpen) {
  627. return res.render('general/closed', { title: 'updating_site' })
  628. }
  629. let anonymous, userId, sessionUser
  630. if (SessionManager.isUserLoggedIn(req.session)) {
  631. sessionUser = SessionManager.getSessionUser(req.session)
  632. userId = SessionManager.getLoggedInUserId(req.session)
  633. anonymous = false
  634. } else {
  635. sessionUser = null
  636. anonymous = true
  637. userId = null
  638. }
  639. const projectId = req.params.Project_id
  640. async.auto(
  641. {
  642. project(cb) {
  643. ProjectGetter.getProject(
  644. projectId,
  645. {
  646. name: 1,
  647. lastUpdated: 1,
  648. track_changes: 1,
  649. owner_ref: 1,
  650. brandVariationId: 1,
  651. overleaf: 1,
  652. tokens: 1,
  653. },
  654. (err, project) => {
  655. if (err != null) {
  656. return cb(err)
  657. }
  658. cb(null, project)
  659. }
  660. )
  661. },
  662. user(cb) {
  663. if (userId == null) {
  664. cb(null, defaultSettingsForAnonymousUser(userId))
  665. } else {
  666. User.updateOne(
  667. { _id: ObjectId(userId) },
  668. { $set: { lastActive: new Date() } },
  669. {},
  670. () => {}
  671. )
  672. User.findById(
  673. userId,
  674. 'email first_name last_name referal_id signUpDate featureSwitches features featuresEpoch refProviders alphaProgram betaProgram isAdmin ace',
  675. (err, user) => {
  676. // Handle case of deleted user
  677. if (user == null) {
  678. UserController.logout(req, res, next)
  679. return
  680. }
  681. if (err) {
  682. return cb(err)
  683. }
  684. logger.debug({ projectId, userId }, 'got user')
  685. if (FeaturesUpdater.featuresEpochIsCurrent(user)) {
  686. return cb(null, user)
  687. }
  688. ProjectController._refreshFeatures(req, user, cb)
  689. }
  690. )
  691. }
  692. },
  693. userHasInstitutionLicence(cb) {
  694. if (!userId) {
  695. return cb(null, false)
  696. }
  697. InstitutionsFeatures.hasLicence(userId, (error, hasLicence) => {
  698. if (error) {
  699. // Don't fail if we can't get affiliation licences
  700. return cb(null, false)
  701. }
  702. cb(null, hasLicence)
  703. })
  704. },
  705. learnedWords(cb) {
  706. if (!userId) {
  707. return cb(null, [])
  708. }
  709. SpellingHandler.getUserDictionary(userId, cb)
  710. },
  711. subscription(cb) {
  712. if (userId == null) {
  713. return cb()
  714. }
  715. SubscriptionLocator.getUsersSubscription(userId, cb)
  716. },
  717. userIsMemberOfGroupSubscription(cb) {
  718. if (sessionUser == null) {
  719. return cb(null, false)
  720. }
  721. LimitationsManager.userIsMemberOfGroupSubscription(
  722. sessionUser,
  723. (error, isMember) => {
  724. cb(error, isMember)
  725. }
  726. )
  727. },
  728. activate(cb) {
  729. InactiveProjectManager.reactivateProjectIfRequired(projectId, cb)
  730. },
  731. markAsOpened(cb) {
  732. // don't need to wait for this to complete
  733. ProjectUpdateHandler.markAsOpened(projectId, () => {})
  734. cb()
  735. },
  736. isTokenMember(cb) {
  737. if (userId == null) {
  738. return cb()
  739. }
  740. CollaboratorsGetter.userIsTokenMember(userId, projectId, cb)
  741. },
  742. brandVariation: [
  743. 'project',
  744. (results, cb) => {
  745. if (
  746. (results.project != null
  747. ? results.project.brandVariationId
  748. : undefined) == null
  749. ) {
  750. return cb()
  751. }
  752. BrandVariationsHandler.getBrandVariationById(
  753. results.project.brandVariationId,
  754. (error, brandVariationDetails) => cb(error, brandVariationDetails)
  755. )
  756. },
  757. ],
  758. flushToTpds: cb => {
  759. TpdsProjectFlusher.flushProjectToTpdsIfNeeded(projectId, cb)
  760. },
  761. sharingModalSplitTest(cb) {
  762. SplitTestHandler.getAssignment(
  763. req,
  764. res,
  765. 'project-share-modal-paywall',
  766. {},
  767. () => {
  768. // do not fail editor load if assignment fails
  769. cb()
  770. }
  771. )
  772. },
  773. sharingModalNullTest(cb) {
  774. // null test targeting logged in users, for front-end side
  775. SplitTestHandler.getAssignment(
  776. req,
  777. res,
  778. 'null-test-share-modal',
  779. {},
  780. () => {
  781. // do not fail editor load if assignment fails
  782. cb()
  783. }
  784. )
  785. },
  786. newSourceEditorAssignment(cb) {
  787. SplitTestHandler.getAssignment(
  788. req,
  789. res,
  790. 'source-editor',
  791. {},
  792. (error, assignment) => {
  793. // do not fail editor load if assignment fails
  794. if (error) {
  795. cb(null)
  796. } else {
  797. cb(null, assignment)
  798. }
  799. }
  800. )
  801. },
  802. pdfDetachAssignment(cb) {
  803. SplitTestHandler.getAssignment(
  804. req,
  805. res,
  806. 'pdf-detach',
  807. {},
  808. (error, assignment) => {
  809. // do not fail editor load if assignment fails
  810. if (error) {
  811. cb(null)
  812. } else {
  813. cb(null, assignment)
  814. }
  815. }
  816. )
  817. },
  818. pdfjsAssignment(cb) {
  819. SplitTestHandler.getAssignment(
  820. req,
  821. res,
  822. 'pdfjs',
  823. {},
  824. (error, assignment) => {
  825. // do not fail editor load if assignment fails
  826. if (error) {
  827. cb(null, { variant: 'default' })
  828. } else {
  829. cb(null, assignment)
  830. }
  831. }
  832. )
  833. },
  834. dictionaryEditorAssignment(cb) {
  835. SplitTestHandler.getAssignment(
  836. req,
  837. res,
  838. 'dictionary-editor',
  839. {},
  840. (error, assignment) => {
  841. // do not fail editor load if assignment fails
  842. if (error) {
  843. cb(null, { variant: 'default' })
  844. } else {
  845. cb(null, assignment)
  846. }
  847. }
  848. )
  849. },
  850. stopOnFirstErrorAssignment(cb) {
  851. SplitTestHandler.getAssignment(
  852. req,
  853. res,
  854. 'stop-on-first-error',
  855. (error, assignment) => {
  856. // do not fail editor load if assignment fails
  857. if (error) {
  858. cb(null, { variant: 'default' })
  859. } else {
  860. cb(null, assignment)
  861. }
  862. }
  863. )
  864. },
  865. interstitialPaymentFromPaywallAssignment(cb) {
  866. SplitTestHandler.getAssignment(
  867. req,
  868. res,
  869. 'interstitial-payment-from-paywall',
  870. (error, assignment) => {
  871. // do not fail editor load if assignment fails
  872. if (error) {
  873. cb(null, { variant: 'default' })
  874. } else {
  875. cb(null, assignment)
  876. }
  877. }
  878. )
  879. },
  880. latexLogParserAssignment(cb) {
  881. SplitTestHandler.getAssignment(
  882. req,
  883. res,
  884. 'latex-log-parser',
  885. (error, assignment) => {
  886. // do not fail editor load if assignment fails
  887. if (error) {
  888. cb(null, { variant: 'default' })
  889. } else {
  890. cb(null, assignment)
  891. }
  892. }
  893. )
  894. },
  895. compileTimeWarningAssignment: [
  896. 'user',
  897. (results, cb) => {
  898. if (results.user?.features?.compileTimeout <= 60) {
  899. SplitTestHandler.getAssignment(
  900. req,
  901. res,
  902. 'compile-time-warning',
  903. {},
  904. () => {
  905. // do not fail editor load if assignment fails
  906. cb()
  907. }
  908. )
  909. } else {
  910. cb()
  911. }
  912. },
  913. ],
  914. linkSharingUpgradePromptAssignment(cb) {
  915. SplitTestHandler.getAssignment(
  916. req,
  917. res,
  918. 'link-sharing-upgrade-prompt',
  919. (error, assignment) => {
  920. // do not fail editor load if assignment fails
  921. if (error) {
  922. cb(null, { variant: 'default' })
  923. } else {
  924. cb(null, assignment)
  925. }
  926. }
  927. )
  928. },
  929. trackPdfDownloadAssignment(cb) {
  930. SplitTestHandler.getAssignment(req, res, 'track-pdf-download', () => {
  931. // We'll pick up the assignment from the res.locals assignment.
  932. cb()
  933. })
  934. },
  935. pdfCachingModeAssignment(cb) {
  936. SplitTestHandler.getAssignment(req, res, 'pdf-caching-mode', () => {
  937. // We'll pick up the assignment from the res.locals assignment.
  938. cb()
  939. })
  940. },
  941. },
  942. (
  943. err,
  944. {
  945. project,
  946. user,
  947. userHasInstitutionLicence,
  948. learnedWords,
  949. subscription,
  950. userIsMemberOfGroupSubscription,
  951. isTokenMember,
  952. brandVariation,
  953. newSourceEditorAssignment,
  954. pdfDetachAssignment,
  955. pdfjsAssignment,
  956. dictionaryEditorAssignment,
  957. stopOnFirstErrorAssignment,
  958. }
  959. ) => {
  960. if (err != null) {
  961. OError.tag(err, 'error getting details for project page')
  962. return next(err)
  963. }
  964. const anonRequestToken = TokenAccessHandler.getRequestToken(
  965. req,
  966. projectId
  967. )
  968. const allowedImageNames = ProjectHelper.getAllowedImagesForUser(user)
  969. AuthorizationManager.getPrivilegeLevelForProject(
  970. userId,
  971. projectId,
  972. anonRequestToken,
  973. (error, privilegeLevel) => {
  974. let allowedFreeTrial = true
  975. if (error != null) {
  976. return next(error)
  977. }
  978. if (
  979. privilegeLevel == null ||
  980. privilegeLevel === PrivilegeLevels.NONE
  981. ) {
  982. return res.sendStatus(401)
  983. }
  984. if (subscription != null) {
  985. allowedFreeTrial = false
  986. }
  987. let wsUrl = Settings.wsUrl
  988. let metricName = 'load-editor-ws'
  989. if (user.betaProgram && Settings.wsUrlBeta !== undefined) {
  990. wsUrl = Settings.wsUrlBeta
  991. metricName += '-beta'
  992. } else if (
  993. Settings.wsUrlV2 &&
  994. Settings.wsUrlV2Percentage > 0 &&
  995. (ObjectId(projectId).getTimestamp() / 1000) % 100 <
  996. Settings.wsUrlV2Percentage
  997. ) {
  998. wsUrl = Settings.wsUrlV2
  999. metricName += '-v2'
  1000. }
  1001. if (req.query && req.query.ws === 'fallback') {
  1002. // `?ws=fallback` will connect to the bare origin, and ignore
  1003. // the custom wsUrl. Hence it must load the client side
  1004. // javascript from there too.
  1005. // Not resetting it here would possibly load a socket.io v2
  1006. // client and connect to a v0 endpoint.
  1007. wsUrl = undefined
  1008. metricName += '-fallback'
  1009. }
  1010. metrics.inc(metricName)
  1011. if (userId) {
  1012. AnalyticsManager.recordEventForUser(userId, 'project-opened', {
  1013. projectId: project._id,
  1014. })
  1015. }
  1016. function shouldDisplayFeature(name, variantFlag) {
  1017. if (req.query && req.query[name]) {
  1018. return req.query[name] === 'true'
  1019. } else {
  1020. return variantFlag === true
  1021. }
  1022. }
  1023. const showPdfDetach = shouldDisplayFeature(
  1024. 'pdf_detach',
  1025. pdfDetachAssignment.variant === 'enabled'
  1026. )
  1027. const debugPdfDetach = shouldDisplayFeature('debug_pdf_detach')
  1028. let detachRole = null
  1029. if (showPdfDetach) {
  1030. detachRole = req.params.detachRole
  1031. }
  1032. const showNewSourceEditorOption =
  1033. (newSourceEditorAssignment &&
  1034. newSourceEditorAssignment.variant === 'codemirror') ||
  1035. user.betaProgram ||
  1036. shouldDisplayFeature('new_source_editor', false) // also allow override via ?new_source_editor=true
  1037. const showSymbolPalette =
  1038. !Features.hasFeature('saas') ||
  1039. (user.features && user.features.symbolPalette)
  1040. const dictionaryEditorEnabled = shouldDisplayFeature(
  1041. 'dictionary-editor',
  1042. dictionaryEditorAssignment.variant === 'enabled'
  1043. )
  1044. // Persistent upgrade prompts
  1045. const showHeaderUpgradePrompt =
  1046. Features.hasFeature('saas') &&
  1047. userId &&
  1048. !subscription &&
  1049. !userIsMemberOfGroupSubscription &&
  1050. !userHasInstitutionLicence
  1051. const showStopOnFirstError =
  1052. stopOnFirstErrorAssignment.variant === 'enabled'
  1053. const template =
  1054. detachRole === 'detached'
  1055. ? 'project/editor_detached'
  1056. : 'project/editor'
  1057. res.render(template, {
  1058. title: project.name,
  1059. priority_title: true,
  1060. bodyClasses: ['editor'],
  1061. project_id: project._id,
  1062. projectName: project.name,
  1063. user: {
  1064. id: userId,
  1065. email: user.email,
  1066. first_name: user.first_name,
  1067. last_name: user.last_name,
  1068. referal_id: user.referal_id,
  1069. signUpDate: user.signUpDate,
  1070. allowedFreeTrial,
  1071. featureSwitches: user.featureSwitches,
  1072. features: user.features,
  1073. refProviders: _.mapValues(user.refProviders, Boolean),
  1074. alphaProgram: user.alphaProgram,
  1075. betaProgram: user.betaProgram,
  1076. isAdmin: hasAdminAccess(user),
  1077. },
  1078. userSettings: {
  1079. mode: user.ace.mode,
  1080. editorTheme: user.ace.theme,
  1081. fontSize: user.ace.fontSize,
  1082. autoComplete: user.ace.autoComplete,
  1083. autoPairDelimiters: user.ace.autoPairDelimiters,
  1084. pdfViewer: user.ace.pdfViewer,
  1085. syntaxValidation: user.ace.syntaxValidation,
  1086. fontFamily: user.ace.fontFamily || 'lucida',
  1087. lineHeight: user.ace.lineHeight || 'normal',
  1088. overallTheme: user.ace.overallTheme,
  1089. },
  1090. privilegeLevel,
  1091. anonymous,
  1092. anonymousAccessToken: anonymous ? anonRequestToken : null,
  1093. isTokenMember,
  1094. isRestrictedTokenMember: AuthorizationManager.isRestrictedUser(
  1095. userId,
  1096. privilegeLevel,
  1097. isTokenMember
  1098. ),
  1099. languages: Settings.languages,
  1100. learnedWords,
  1101. editorThemes: THEME_LIST,
  1102. legacyEditorThemes: LEGACY_THEME_LIST,
  1103. maxDocLength: Settings.max_doc_length,
  1104. useV2History:
  1105. project.overleaf &&
  1106. project.overleaf.history &&
  1107. Boolean(project.overleaf.history.display),
  1108. brandVariation,
  1109. allowedImageNames,
  1110. gitBridgePublicBaseUrl: Settings.gitBridgePublicBaseUrl,
  1111. wsUrl,
  1112. showSupport: Features.hasFeature('support'),
  1113. pdfjsVariant: pdfjsAssignment.variant,
  1114. dictionaryEditorEnabled,
  1115. showPdfDetach,
  1116. debugPdfDetach,
  1117. showNewSourceEditorOption,
  1118. showSymbolPalette,
  1119. showStopOnFirstError,
  1120. detachRole,
  1121. metadata: { viewport: false },
  1122. showHeaderUpgradePrompt,
  1123. })
  1124. timer.done()
  1125. }
  1126. )
  1127. }
  1128. )
  1129. },
  1130. _refreshFeatures(req, user, callback) {
  1131. // If the feature refresh has failed in this session, don't retry
  1132. // it - require the user to log in again.
  1133. if (req.session.feature_refresh_failed) {
  1134. metrics.inc('features-refresh', 1, {
  1135. path: 'load-editor',
  1136. status: 'skipped',
  1137. })
  1138. return callback(null, user)
  1139. }
  1140. // If the refresh takes too long then return the current
  1141. // features. Note that the user.features property may still be
  1142. // updated in the background after the callback is called.
  1143. callback = _.once(callback)
  1144. const refreshTimeoutHandler = setTimeout(() => {
  1145. req.session.feature_refresh_failed = { reason: 'timeout', at: new Date() }
  1146. metrics.inc('features-refresh', 1, {
  1147. path: 'load-editor',
  1148. status: 'timeout',
  1149. })
  1150. callback(null, user)
  1151. }, 5000)
  1152. // try to refresh user features now
  1153. const timer = new metrics.Timer('features-refresh-on-load-editor')
  1154. FeaturesUpdater.refreshFeatures(
  1155. user._id,
  1156. 'load-editor',
  1157. (err, features) => {
  1158. clearTimeout(refreshTimeoutHandler)
  1159. timer.done()
  1160. if (err) {
  1161. // keep a record to prevent unneceary retries and leave
  1162. // the original features unmodified if the refresh failed
  1163. req.session.feature_refresh_failed = {
  1164. reason: 'error',
  1165. at: new Date(),
  1166. }
  1167. metrics.inc('features-refresh', 1, {
  1168. path: 'load-editor',
  1169. status: 'error',
  1170. })
  1171. } else {
  1172. user.features = features
  1173. metrics.inc('features-refresh', 1, {
  1174. path: 'load-editor',
  1175. status: 'success',
  1176. })
  1177. }
  1178. return callback(null, user)
  1179. }
  1180. )
  1181. },
  1182. _buildProjectList(allProjects, userId) {
  1183. let project
  1184. const { owned, readAndWrite, readOnly, tokenReadAndWrite, tokenReadOnly } =
  1185. allProjects
  1186. const projects = []
  1187. for (project of owned) {
  1188. projects.push(
  1189. ProjectController._buildProjectViewModel(
  1190. project,
  1191. 'owner',
  1192. Sources.OWNER,
  1193. userId
  1194. )
  1195. )
  1196. }
  1197. // Invite-access
  1198. for (project of readAndWrite) {
  1199. projects.push(
  1200. ProjectController._buildProjectViewModel(
  1201. project,
  1202. 'readWrite',
  1203. Sources.INVITE,
  1204. userId
  1205. )
  1206. )
  1207. }
  1208. for (project of readOnly) {
  1209. projects.push(
  1210. ProjectController._buildProjectViewModel(
  1211. project,
  1212. 'readOnly',
  1213. Sources.INVITE,
  1214. userId
  1215. )
  1216. )
  1217. }
  1218. // Token-access
  1219. // Only add these projects if they're not already present, this gives us cascading access
  1220. // from 'owner' => 'token-read-only'
  1221. for (project of tokenReadAndWrite) {
  1222. if (
  1223. projects.filter(p => p.id.toString() === project._id.toString())
  1224. .length === 0
  1225. ) {
  1226. projects.push(
  1227. ProjectController._buildProjectViewModel(
  1228. project,
  1229. 'readAndWrite',
  1230. Sources.TOKEN,
  1231. userId
  1232. )
  1233. )
  1234. }
  1235. }
  1236. for (project of tokenReadOnly) {
  1237. if (
  1238. projects.filter(p => p.id.toString() === project._id.toString())
  1239. .length === 0
  1240. ) {
  1241. projects.push(
  1242. ProjectController._buildProjectViewModel(
  1243. project,
  1244. 'readOnly',
  1245. Sources.TOKEN,
  1246. userId
  1247. )
  1248. )
  1249. }
  1250. }
  1251. return projects
  1252. },
  1253. _buildProjectViewModel(project, accessLevel, source, userId) {
  1254. const archived = ProjectHelper.isArchived(project, userId)
  1255. // If a project is simultaneously trashed and archived, we will consider it archived but not trashed.
  1256. const trashed = ProjectHelper.isTrashed(project, userId) && !archived
  1257. TokenAccessHandler.protectTokens(project, accessLevel)
  1258. const model = {
  1259. id: project._id,
  1260. name: project.name,
  1261. lastUpdated: project.lastUpdated,
  1262. lastUpdatedBy: project.lastUpdatedBy,
  1263. publicAccessLevel: project.publicAccesLevel,
  1264. accessLevel,
  1265. source,
  1266. archived,
  1267. trashed,
  1268. owner_ref: project.owner_ref,
  1269. isV1Project: false,
  1270. }
  1271. if (accessLevel === PrivilegeLevels.READ_ONLY && source === Sources.TOKEN) {
  1272. model.owner_ref = null
  1273. model.lastUpdatedBy = null
  1274. }
  1275. return model
  1276. },
  1277. _injectProjectUsers(projects, callback) {
  1278. const users = {}
  1279. for (const project of projects) {
  1280. if (project.owner_ref != null) {
  1281. users[project.owner_ref.toString()] = true
  1282. }
  1283. if (project.lastUpdatedBy != null) {
  1284. users[project.lastUpdatedBy.toString()] = true
  1285. }
  1286. }
  1287. const userIds = Object.keys(users)
  1288. async.eachSeries(
  1289. userIds,
  1290. (userId, cb) => {
  1291. UserGetter.getUser(
  1292. userId,
  1293. { first_name: 1, last_name: 1, email: 1 },
  1294. (error, user) => {
  1295. if (error != null) {
  1296. return cb(error)
  1297. }
  1298. users[userId] = user
  1299. cb()
  1300. }
  1301. )
  1302. },
  1303. error => {
  1304. if (error != null) {
  1305. return callback(error)
  1306. }
  1307. for (const project of projects) {
  1308. if (project.owner_ref != null) {
  1309. project.owner = users[project.owner_ref.toString()]
  1310. }
  1311. if (project.lastUpdatedBy != null) {
  1312. project.lastUpdatedBy =
  1313. users[project.lastUpdatedBy.toString()] || null
  1314. }
  1315. }
  1316. callback(null, projects)
  1317. }
  1318. )
  1319. },
  1320. _buildPortalTemplatesList(affiliations) {
  1321. if (affiliations == null) {
  1322. affiliations = []
  1323. }
  1324. const portalTemplates = []
  1325. for (const aff of affiliations) {
  1326. if (
  1327. aff.portal &&
  1328. aff.portal.slug &&
  1329. aff.portal.templates_count &&
  1330. aff.portal.templates_count > 0
  1331. ) {
  1332. const portalPath = aff.institution.isUniversity ? '/edu/' : '/org/'
  1333. portalTemplates.push({
  1334. name: aff.institution.name,
  1335. url: Settings.siteUrl + portalPath + aff.portal.slug,
  1336. })
  1337. }
  1338. }
  1339. return portalTemplates
  1340. },
  1341. }
  1342. const defaultSettingsForAnonymousUser = userId => ({
  1343. id: userId,
  1344. ace: {
  1345. mode: 'none',
  1346. theme: 'textmate',
  1347. fontSize: '12',
  1348. autoComplete: true,
  1349. spellCheckLanguage: '',
  1350. pdfViewer: '',
  1351. syntaxValidation: true,
  1352. },
  1353. subscription: {
  1354. freeTrial: {
  1355. allowed: true,
  1356. },
  1357. },
  1358. featureSwitches: {
  1359. github: false,
  1360. },
  1361. alphaProgram: false,
  1362. betaProgram: false,
  1363. })
  1364. const THEME_LIST = [
  1365. 'cobalt',
  1366. 'dracula',
  1367. 'eclipse',
  1368. 'monokai',
  1369. 'overleaf',
  1370. 'textmate',
  1371. ]
  1372. const LEGACY_THEME_LIST = [
  1373. 'ambiance',
  1374. 'chaos',
  1375. 'chrome',
  1376. 'clouds',
  1377. 'clouds_midnight',
  1378. 'crimson_editor',
  1379. 'dawn',
  1380. 'dreamweaver',
  1381. 'github',
  1382. 'gob',
  1383. 'gruvbox',
  1384. 'idle_fingers',
  1385. 'iplastic',
  1386. 'katzenmilch',
  1387. 'kr_theme',
  1388. 'kuroir',
  1389. 'merbivore',
  1390. 'merbivore_soft',
  1391. 'mono_industrial',
  1392. 'nord_dark',
  1393. 'pastel_on_dark',
  1394. 'solarized_dark',
  1395. 'solarized_light',
  1396. 'sqlserver',
  1397. 'terminal',
  1398. 'tomorrow',
  1399. 'tomorrow_night',
  1400. 'tomorrow_night_blue',
  1401. 'tomorrow_night_bright',
  1402. 'tomorrow_night_eighties',
  1403. 'twilight',
  1404. 'vibrant_ink',
  1405. 'xcode',
  1406. ]
  1407. module.exports = ProjectController