config.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. // disable no-return-await for model functions
  2. /* eslint-disable no-return-await */
  3. /* eslint-disable no-use-before-define */
  4. module.exports = function(crowi) {
  5. const mongoose = require('mongoose');
  6. const configSchema = new mongoose.Schema({
  7. ns: { type: String, required: true, index: true },
  8. key: { type: String, required: true, index: true },
  9. value: { type: String, required: true },
  10. });
  11. /**
  12. * default values when GROWI is cleanly installed
  13. */
  14. function getConfigsForInstalling() {
  15. const config = getDefaultCrowiConfigs();
  16. // overwrite
  17. config['app:installed'] = true;
  18. config['app:fileUpload'] = true;
  19. config['customize:behavior'] = 'growi';
  20. config['customize:layout'] = 'growi';
  21. config['customize:isSavedStatesOfTabChanges'] = false;
  22. return config;
  23. }
  24. /**
  25. * default values when migrated from Official Crowi
  26. */
  27. function getDefaultCrowiConfigs() {
  28. /* eslint-disable key-spacing */
  29. return {
  30. 'app:installed' : false,
  31. 'app:confidential' : undefined,
  32. 'app:fileUpload' : false,
  33. 'app:globalLang' : 'en-US',
  34. 'security:restrictGuestMode' : 'Deny',
  35. 'security:registrationMode' : 'Open',
  36. 'security:registrationWhiteList' : [],
  37. 'security:list-policy:hideRestrictedByOwner' : false,
  38. 'security:list-policy:hideRestrictedByGroup' : false,
  39. 'security:pageCompleteDeletionAuthority' : undefined,
  40. 'security:passport-local:isEnabled' : true,
  41. 'security:passport-ldap:isEnabled' : false,
  42. 'security:passport-ldap:serverUrl' : undefined,
  43. 'security:passport-ldap:isUserBind' : undefined,
  44. 'security:passport-ldap:bindDN' : undefined,
  45. 'security:passport-ldap:bindDNPassword' : undefined,
  46. 'security:passport-ldap:searchFilter' : undefined,
  47. 'security:passport-ldap:attrMapUsername' : undefined,
  48. 'security:passport-ldap:attrMapName' : undefined,
  49. 'security:passport-ldap:attrMapMail' : undefined,
  50. 'security:passport-ldap:groupSearchBase' : undefined,
  51. 'security:passport-ldap:groupSearchFilter' : undefined,
  52. 'security:passport-ldap:groupDnProperty' : undefined,
  53. 'security:passport-ldap:isSameUsernameTreatedAsIdenticalUser': false,
  54. 'security:passport-saml:isEnabled' : false,
  55. 'security:passport-saml:isSameEmailTreatedAsIdenticalUser': false,
  56. 'security:passport-google:isEnabled' : false,
  57. 'security:passport-github:isEnabled' : false,
  58. 'security:passport-twitter:isEnabled' : false,
  59. 'security:passport-oidc:isEnabled' : false,
  60. 'security:passport-basic:isEnabled' : false,
  61. 'aws:bucket' : 'growi',
  62. 'aws:region' : 'ap-northeast-1',
  63. 'aws:accessKeyId' : undefined,
  64. 'aws:secretAccessKey' : undefined,
  65. 'aws:customEndpoint' : undefined,
  66. 'mail:from' : undefined,
  67. 'mail:smtpHost' : undefined,
  68. 'mail:smtpPort' : undefined,
  69. 'mail:smtpUser' : undefined,
  70. 'mail:smtpPassword' : undefined,
  71. 'google:clientId' : undefined,
  72. 'google:clientSecret' : undefined,
  73. 'plugin:isEnabledPlugins' : true,
  74. 'customize:css' : undefined,
  75. 'customize:script' : undefined,
  76. 'customize:header' : undefined,
  77. 'customize:title' : undefined,
  78. 'customize:highlightJsStyle' : 'github',
  79. 'customize:highlightJsStyleBorder' : false,
  80. 'customize:theme' : 'default',
  81. 'customize:behavior' : 'crowi',
  82. 'customize:layout' : 'crowi',
  83. 'customize:isEnabledTimeline' : true,
  84. 'customize:isSavedStatesOfTabChanges' : true,
  85. 'customize:isEnabledAttachTitleHeader' : false,
  86. 'customize:showRecentCreatedNumber' : 10,
  87. 'importer:esa:team_name': undefined,
  88. 'importer:esa:access_token': undefined,
  89. 'importer:qiita:team_name': undefined,
  90. 'importer:qiita:access_token': undefined,
  91. };
  92. /* eslint-enable key-spacing */
  93. }
  94. function getDefaultMarkdownConfigs() {
  95. return {
  96. 'markdown:xss:isEnabledPrevention': true,
  97. 'markdown:xss:option': 2,
  98. 'markdown:xss:tagWhiteList': [],
  99. 'markdown:xss:attrWhiteList': [],
  100. 'markdown:isEnabledLinebreaks': false,
  101. 'markdown:isEnabledLinebreaksInComments': true,
  102. 'markdown:presentation:pageBreakSeparator': 1,
  103. 'markdown:presentation:pageBreakCustomSeparator': undefined,
  104. };
  105. }
  106. function getDefaultNotificationConfigs() {
  107. return {
  108. 'slack:isIncomingWebhookPrioritized': false,
  109. 'slack:incomingWebhookUrl': undefined,
  110. 'slack:token': undefined,
  111. };
  112. }
  113. /**
  114. * It is deprecated to use this for anything other than AppService#isDBInitialized.
  115. */
  116. configSchema.statics.getConfigsObjectForInstalling = function() {
  117. return getConfigsForInstalling();
  118. };
  119. /**
  120. * It is deprecated to use this for anything other than ConfigLoader#load.
  121. */
  122. configSchema.statics.getDefaultCrowiConfigsObject = function() {
  123. return getDefaultCrowiConfigs();
  124. };
  125. /**
  126. * It is deprecated to use this for anything other than ConfigLoader#load.
  127. */
  128. configSchema.statics.getDefaultMarkdownConfigsObject = function() {
  129. return getDefaultMarkdownConfigs();
  130. };
  131. /**
  132. * It is deprecated to use this for anything other than ConfigLoader#load.
  133. */
  134. configSchema.statics.getDefaultNotificationConfigsObject = function() {
  135. return getDefaultNotificationConfigs();
  136. };
  137. configSchema.statics.getLocalconfig = function() {
  138. const env = process.env;
  139. const localConfig = {
  140. crowi: {
  141. title: crowi.appService.getAppTitle(),
  142. url: crowi.appService.getSiteUrl(),
  143. },
  144. upload: {
  145. image: crowi.fileUploadService.getIsUploadable(),
  146. file: crowi.fileUploadService.getFileUploadEnabled(),
  147. },
  148. behaviorType: crowi.configManager.getConfig('crowi', 'customize:behavior'),
  149. layoutType: crowi.configManager.getConfig('crowi', 'customize:layout'),
  150. isEnabledLinebreaks: crowi.configManager.getConfig('markdown', 'markdown:isEnabledLinebreaks'),
  151. isEnabledLinebreaksInComments: crowi.configManager.getConfig('markdown', 'markdown:isEnabledLinebreaksInComments'),
  152. isEnabledXssPrevention: crowi.configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention'),
  153. isEnabledTimeline: crowi.configManager.getConfig('crowi', 'customize:isEnabledTimeline'),
  154. xssOption: crowi.configManager.getConfig('markdown', 'markdown:xss:option'),
  155. tagWhiteList: crowi.xssService.getTagWhiteList(),
  156. attrWhiteList: crowi.xssService.getAttrWhiteList(),
  157. highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
  158. isSavedStatesOfTabChanges: crowi.configManager.getConfig('crowi', 'customize:isSavedStatesOfTabChanges'),
  159. hasSlackConfig: crowi.slackNotificationService.hasSlackConfig(),
  160. env: {
  161. PLANTUML_URI: env.PLANTUML_URI || null,
  162. BLOCKDIAG_URI: env.BLOCKDIAG_URI || null,
  163. HACKMD_URI: env.HACKMD_URI || null,
  164. MATHJAX: env.MATHJAX || null,
  165. NO_CDN: env.NO_CDN || null,
  166. },
  167. recentCreatedLimit: crowi.configManager.getConfig('crowi', 'customize:showRecentCreatedNumber'),
  168. isAclEnabled: crowi.aclService.isAclEnabled(),
  169. globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
  170. };
  171. return localConfig;
  172. };
  173. const Config = mongoose.model('Config', configSchema);
  174. return Config;
  175. };