config.js 8.4 KB

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