Features.js 3.1 KB

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