Features.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. const _ = require('lodash')
  2. const Settings = require('@overleaf/settings')
  3. const publicRegistrationModuleAvailable =
  4. Settings.moduleImportSequence.includes('public-registration')
  5. const supportModuleAvailable = Settings.moduleImportSequence.includes('support')
  6. const symbolPaletteModuleAvailable =
  7. Settings.moduleImportSequence.includes('symbol-palette')
  8. const trackChangesModuleAvailable =
  9. Settings.moduleImportSequence.includes('track-changes')
  10. /**
  11. * @typedef {Object} Settings
  12. * @property {Object | undefined} apis
  13. * @property {Object | undefined} apis.linkedUrlProxy
  14. * @property {string | undefined} apis.linkedUrlProxy.url
  15. * @property {Object | undefined} apis.references
  16. * @property {string | undefined} apis.references.url
  17. * @property {boolean | undefined} enableGithubSync
  18. * @property {boolean | undefined} enableGitBridge
  19. * @property {boolean | undefined} enableHomepage
  20. * @property {boolean | undefined} enableSaml
  21. * @property {boolean | undefined} ldap
  22. * @property {boolean | undefined} oauth
  23. * @property {Object | undefined} overleaf
  24. * @property {Object | undefined} overleaf.oauth
  25. * @property {boolean | undefined} saml
  26. */
  27. const Features = {
  28. /**
  29. * @returns {boolean}
  30. */
  31. externalAuthenticationSystemUsed() {
  32. return (
  33. (Boolean(Settings.ldap) && Boolean(Settings.ldap.enable)) ||
  34. (Boolean(Settings.saml) && Boolean(Settings.saml.enable)) ||
  35. Boolean(_.get(Settings, ['overleaf', 'oauth']))
  36. )
  37. },
  38. /**
  39. * Whether a feature is enabled in the appliation's configuration
  40. *
  41. * @param {string} feature
  42. * @returns {boolean}
  43. */
  44. hasFeature(feature) {
  45. switch (feature) {
  46. case 'saas':
  47. return Boolean(Settings.overleaf)
  48. case 'homepage':
  49. return Boolean(Settings.enableHomepage)
  50. case 'registration-page':
  51. return (
  52. !Features.externalAuthenticationSystemUsed() ||
  53. Boolean(Settings.overleaf)
  54. )
  55. case 'registration':
  56. return publicRegistrationModuleAvailable || Boolean(Settings.overleaf)
  57. case 'github-sync':
  58. return Boolean(Settings.enableGithubSync)
  59. case 'git-bridge':
  60. return Boolean(Settings.enableGitBridge)
  61. case 'oauth':
  62. return Boolean(Settings.oauth)
  63. case 'templates-server-pro':
  64. return Boolean(Settings.templates)
  65. case 'affiliations':
  66. case 'analytics':
  67. return Boolean(_.get(Settings, ['apis', 'v1', 'url']))
  68. case 'overleaf-integration':
  69. return Boolean(Settings.overleaf)
  70. case 'references':
  71. return Boolean(_.get(Settings, ['apis', 'references', 'url']))
  72. case 'saml':
  73. return Boolean(Settings.enableSaml)
  74. case 'linked-project-file':
  75. return Boolean(Settings.enabledLinkedFileTypes.includes('project_file'))
  76. case 'linked-project-output-file':
  77. return Boolean(
  78. Settings.enabledLinkedFileTypes.includes('project_output_file')
  79. )
  80. case 'link-url':
  81. return Boolean(
  82. _.get(Settings, ['apis', 'linkedUrlProxy', 'url']) &&
  83. Settings.enabledLinkedFileTypes.includes('url')
  84. )
  85. case 'public-registration':
  86. return publicRegistrationModuleAvailable
  87. case 'support':
  88. return supportModuleAvailable
  89. case 'symbol-palette':
  90. return symbolPaletteModuleAvailable
  91. case 'track-changes':
  92. return trackChangesModuleAvailable
  93. default:
  94. throw new Error(`unknown feature: ${feature}`)
  95. }
  96. },
  97. }
  98. module.exports = Features