TutorialController.mjs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import SessionManager from '../Authentication/SessionManager.mjs'
  2. import TutorialHandler from './TutorialHandler.mjs'
  3. import { expressify } from '@overleaf/promise-utils'
  4. const VALID_KEYS = [
  5. 'react-history-buttons-tutorial',
  6. 'writefull-integration',
  7. 'writefull-oauth-promotion',
  8. 'bib-file-tpr-prompt',
  9. 'ai-error-assistant-consent',
  10. 'workbench-consent',
  11. 'history-restore-promo',
  12. 'us-gov-banner',
  13. 'us-gov-banner-fedramp',
  14. 'editor-popup-ux-survey',
  15. 'wf-features-moved',
  16. 'review-mode',
  17. 'new-error-logs-promo',
  18. 'try-redesign-again-nudge-promo',
  19. 'write-and-cite-nudge-in-linked-file',
  20. 'ide-redesign-new-survey-promo',
  21. 'ide-redesign-beta-intro',
  22. 'ide-redesign-labs-user-beta-promo',
  23. 'rolling-compile-image-changed',
  24. 'groups-enterprise-banner',
  25. 'groups-enterprise-banner-repeat',
  26. 'new-editor-opt-in',
  27. 'new-editor-intro',
  28. 'new-editor-intro-2',
  29. 'old-editor-warning-tooltip',
  30. 'old-editor-warning-tooltip-2',
  31. 'workbench-rail-popover',
  32. ]
  33. async function completeTutorial(req, res, next) {
  34. const userId = SessionManager.getLoggedInUserId(req.session)
  35. const tutorialKey = req.params.tutorialKey
  36. if (!VALID_KEYS.includes(tutorialKey)) {
  37. return res.sendStatus(404)
  38. }
  39. await TutorialHandler.setTutorialState(userId, tutorialKey, 'completed')
  40. res.sendStatus(204)
  41. }
  42. async function postponeTutorial(req, res, next) {
  43. const userId = SessionManager.getLoggedInUserId(req.session)
  44. const tutorialKey = req.params.tutorialKey
  45. let postponedUntil
  46. if (req.body.postponedUntil) {
  47. postponedUntil = new Date(req.body.postponedUntil)
  48. }
  49. if (!VALID_KEYS.includes(tutorialKey)) {
  50. return res.sendStatus(404)
  51. }
  52. await TutorialHandler.setTutorialState(
  53. userId,
  54. tutorialKey,
  55. 'postponed',
  56. postponedUntil
  57. )
  58. res.sendStatus(204)
  59. }
  60. export default {
  61. completeTutorial: expressify(completeTutorial),
  62. postponeTutorial: expressify(postponeTutorial),
  63. }