config.js 9.4 KB

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