config.js 8.7 KB

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