config.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. 'customize:isAllReplyShown': false,
  95. 'importer:esa:team_name': undefined,
  96. 'importer:esa:access_token': undefined,
  97. 'importer:qiita:team_name': undefined,
  98. 'importer:qiita:access_token': undefined,
  99. };
  100. /* eslint-enable key-spacing */
  101. }
  102. function getDefaultMarkdownConfigs() {
  103. return {
  104. 'markdown:xss:isEnabledPrevention': true,
  105. 'markdown:xss:option': 2,
  106. 'markdown:xss:tagWhiteList': [],
  107. 'markdown:xss:attrWhiteList': [],
  108. 'markdown:isEnabledLinebreaks': false,
  109. 'markdown:isEnabledLinebreaksInComments': true,
  110. 'markdown:presentation:pageBreakSeparator': 1,
  111. 'markdown:presentation:pageBreakCustomSeparator': undefined,
  112. };
  113. }
  114. function getDefaultNotificationConfigs() {
  115. return {
  116. 'slack:isIncomingWebhookPrioritized': false,
  117. 'slack:incomingWebhookUrl': undefined,
  118. 'slack:token': undefined,
  119. };
  120. }
  121. /**
  122. * It is deprecated to use this for anything other than AppService#isDBInitialized.
  123. */
  124. configSchema.statics.getConfigsObjectForInstalling = function() {
  125. return getConfigsForInstalling();
  126. };
  127. /**
  128. * It is deprecated to use this for anything other than ConfigLoader#load.
  129. */
  130. configSchema.statics.getDefaultCrowiConfigsObject = function() {
  131. return getDefaultCrowiConfigs();
  132. };
  133. /**
  134. * It is deprecated to use this for anything other than ConfigLoader#load.
  135. */
  136. configSchema.statics.getDefaultMarkdownConfigsObject = function() {
  137. return getDefaultMarkdownConfigs();
  138. };
  139. /**
  140. * It is deprecated to use this for anything other than ConfigLoader#load.
  141. */
  142. configSchema.statics.getDefaultNotificationConfigsObject = function() {
  143. return getDefaultNotificationConfigs();
  144. };
  145. configSchema.statics.getLocalconfig = function() {
  146. const env = process.env;
  147. const localConfig = {
  148. crowi: {
  149. title: crowi.appService.getAppTitle(),
  150. url: crowi.appService.getSiteUrl(),
  151. },
  152. upload: {
  153. image: crowi.fileUploadService.getIsUploadable(),
  154. file: crowi.fileUploadService.getFileUploadEnabled(),
  155. },
  156. behaviorType: crowi.configManager.getConfig('crowi', 'customize:behavior'),
  157. layoutType: crowi.configManager.getConfig('crowi', 'customize:layout'),
  158. themeType: crowi.configManager.getConfig('crowi', 'customize:theme'),
  159. isEnabledLinebreaks: crowi.configManager.getConfig('markdown', 'markdown:isEnabledLinebreaks'),
  160. isEnabledLinebreaksInComments: crowi.configManager.getConfig('markdown', 'markdown:isEnabledLinebreaksInComments'),
  161. pageBreakSeparator: crowi.configManager.getConfig('markdown', 'markdown:presentation:pageBreakSeparator'),
  162. pageBreakCustomSeparator: crowi.configManager.getConfig('markdown', 'markdown:presentation:pageBreakCustomSeparator'),
  163. isEnabledXssPrevention: crowi.configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention'),
  164. isEnabledTimeline: crowi.configManager.getConfig('crowi', 'customize:isEnabledTimeline'),
  165. isAllReplyShown: crowi.configManager.getConfig('crowi', 'customize:isAllReplyShown'),
  166. xssOption: crowi.configManager.getConfig('markdown', 'markdown:xss:option'),
  167. tagWhiteList: crowi.xssService.getTagWhiteList(),
  168. attrWhiteList: crowi.xssService.getAttrWhiteList(),
  169. highlightJsStyle: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyle'),
  170. highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
  171. customizeTitle: crowi.configManager.getConfig('crowi', 'customize:title'),
  172. customizeHeader: crowi.configManager.getConfig('crowi', 'customize:header'),
  173. customizeCss: crowi.configManager.getConfig('crowi', 'customize:css'),
  174. isSavedStatesOfTabChanges: crowi.configManager.getConfig('crowi', 'customize:isSavedStatesOfTabChanges'),
  175. isEnabledAttachTitleHeader: crowi.configManager.getConfig('crowi', 'customize:isEnabledAttachTitleHeader'),
  176. customizeScript: crowi.configManager.getConfig('crowi', 'customize:script'),
  177. hasSlackConfig: crowi.slackNotificationService.hasSlackConfig(),
  178. env: {
  179. PLANTUML_URI: env.PLANTUML_URI || null,
  180. BLOCKDIAG_URI: env.BLOCKDIAG_URI || null,
  181. HACKMD_URI: env.HACKMD_URI || null,
  182. MATHJAX: env.MATHJAX || null,
  183. NO_CDN: env.NO_CDN || null,
  184. },
  185. recentCreatedLimit: crowi.configManager.getConfig('crowi', 'customize:showRecentCreatedNumber'),
  186. isEnabledStaleNotification: crowi.configManager.getConfig('crowi', 'customize:isEnabledStaleNotification'),
  187. isAclEnabled: crowi.aclService.isAclEnabled(),
  188. isSearchServiceReachable: crowi.searchService.isReachable,
  189. globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
  190. };
  191. return localConfig;
  192. };
  193. const Config = mongoose.model('Config', configSchema);
  194. return Config;
  195. };