config.js 9.4 KB

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