config.js 9.2 KB

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