config.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // disable no-return-await for model functions
  2. /* eslint-disable no-return-await */
  3. /* eslint-disable no-use-before-define */
  4. module.exports = function(crowi) {
  5. const mongoose = require('mongoose');
  6. const configSchema = new mongoose.Schema({
  7. ns: { type: String, required: true, index: true },
  8. key: { type: String, required: true, index: true },
  9. value: { type: String, required: true },
  10. });
  11. /**
  12. * default values when GROWI is cleanly installed
  13. */
  14. function getConfigsForInstalling() {
  15. const config = getDefaultCrowiConfigs();
  16. // overwrite
  17. config['app:installed'] = true;
  18. config['app:fileUpload'] = true;
  19. config['customize:behavior'] = 'growi';
  20. config['customize:layout'] = 'growi';
  21. config['customize:isSavedStatesOfTabChanges'] = false;
  22. return config;
  23. }
  24. /**
  25. * default values when migrated from Official Crowi
  26. */
  27. function getDefaultCrowiConfigs() {
  28. /* eslint-disable key-spacing */
  29. return {
  30. 'app:installed' : false,
  31. 'app:confidential' : undefined,
  32. 'app:fileUpload' : false,
  33. 'app:globalLang' : 'en-US',
  34. 'security:restrictGuestMode' : 'Deny',
  35. 'security:registrationMode' : 'Open',
  36. 'security:registrationWhiteList' : [],
  37. 'security:list-policy:hideRestrictedByOwner' : false,
  38. 'security:list-policy:hideRestrictedByGroup' : false,
  39. 'security:pageCompleteDeletionAuthority' : undefined,
  40. 'security:passport-ldap:isEnabled' : false,
  41. 'security:passport-ldap:serverUrl' : undefined,
  42. 'security:passport-ldap:isUserBind' : undefined,
  43. 'security:passport-ldap:bindDN' : undefined,
  44. 'security:passport-ldap:bindDNPassword' : undefined,
  45. 'security:passport-ldap:searchFilter' : undefined,
  46. 'security:passport-ldap:attrMapUsername' : undefined,
  47. 'security:passport-ldap:attrMapName' : undefined,
  48. 'security:passport-ldap:attrMapMail' : undefined,
  49. 'security:passport-ldap:groupSearchBase' : undefined,
  50. 'security:passport-ldap:groupSearchFilter' : undefined,
  51. 'security:passport-ldap:groupDnProperty' : undefined,
  52. 'security:passport-ldap:isSameUsernameTreatedAsIdenticalUser': false,
  53. 'security:passport-saml:isEnabled' : false,
  54. 'security:passport-saml:isSameEmailTreatedAsIdenticalUser': false,
  55. 'security:passport-google:isEnabled' : false,
  56. 'security:passport-github:isEnabled' : false,
  57. 'security:passport-twitter:isEnabled' : false,
  58. 'security:passport-oidc:isEnabled' : false,
  59. 'security:passport-basic:isEnabled' : false,
  60. 'aws:bucket' : 'growi',
  61. 'aws:region' : 'ap-northeast-1',
  62. 'aws:accessKeyId' : undefined,
  63. 'aws:secretAccessKey' : undefined,
  64. 'mail:from' : undefined,
  65. 'mail:smtpHost' : undefined,
  66. 'mail:smtpPort' : undefined,
  67. 'mail:smtpUser' : undefined,
  68. 'mail:smtpPassword' : undefined,
  69. 'google:clientId' : undefined,
  70. 'google:clientSecret' : undefined,
  71. 'plugin:isEnabledPlugins' : true,
  72. 'customize:css' : undefined,
  73. 'customize:script' : undefined,
  74. 'customize:header' : undefined,
  75. 'customize:title' : undefined,
  76. 'customize:highlightJsStyle' : 'github',
  77. 'customize:highlightJsStyleBorder' : false,
  78. 'customize:theme' : 'default',
  79. 'customize:behavior' : 'crowi',
  80. 'customize:layout' : 'crowi',
  81. 'customize:isEnabledTimeline' : true,
  82. 'customize:isSavedStatesOfTabChanges' : true,
  83. 'customize:isEnabledAttachTitleHeader' : false,
  84. 'customize:showRecentCreatedNumber' : 10,
  85. 'importer:esa:team_name': undefined,
  86. 'importer:esa:access_token': undefined,
  87. 'importer:qiita:team_name': undefined,
  88. 'importer:qiita:access_token': undefined,
  89. };
  90. /* eslint-enable key-spacing */
  91. }
  92. function getDefaultMarkdownConfigs() {
  93. return {
  94. 'markdown:xss:isEnabledPrevention': true,
  95. 'markdown:xss:option': 2,
  96. 'markdown:xss:tagWhiteList': [],
  97. 'markdown:xss:attrWhiteList': [],
  98. 'markdown:isEnabledLinebreaks': false,
  99. 'markdown:isEnabledLinebreaksInComments': true,
  100. 'markdown:presentation:pageBreakSeparator': 1,
  101. 'markdown:presentation:pageBreakCustomSeparator': undefined,
  102. };
  103. }
  104. function getDefaultNotificationConfigs() {
  105. return {
  106. 'slack:isIncomingWebhookPrioritized': false,
  107. 'slack:incomingWebhookUrl': undefined,
  108. 'slack:token': undefined,
  109. };
  110. }
  111. /**
  112. * It is deprecated to use this for anything other than AppService#isDBInitialized.
  113. */
  114. configSchema.statics.getConfigsObjectForInstalling = function() {
  115. return getConfigsForInstalling();
  116. };
  117. /**
  118. * It is deprecated to use this for anything other than ConfigLoader#load.
  119. */
  120. configSchema.statics.getDefaultCrowiConfigsObject = function() {
  121. return getDefaultCrowiConfigs();
  122. };
  123. /**
  124. * It is deprecated to use this for anything other than ConfigLoader#load.
  125. */
  126. configSchema.statics.getDefaultMarkdownConfigsObject = function() {
  127. return getDefaultMarkdownConfigs();
  128. };
  129. /**
  130. * It is deprecated to use this for anything other than ConfigLoader#load.
  131. */
  132. configSchema.statics.getDefaultNotificationConfigsObject = function() {
  133. return getDefaultNotificationConfigs();
  134. };
  135. configSchema.statics.getLocalconfig = function() {
  136. const env = process.env;
  137. const localConfig = {
  138. crowi: {
  139. title: crowi.appService.getAppTitle(),
  140. url: crowi.appService.getSiteUrl(),
  141. },
  142. upload: {
  143. image: crowi.fileUploadService.getIsUploadable(),
  144. file: crowi.fileUploadService.getFileUploadEnabled(),
  145. },
  146. behaviorType: crowi.configManager.getConfig('crowi', 'customize:behavior'),
  147. layoutType: crowi.configManager.getConfig('crowi', 'customize:layout'),
  148. isEnabledLinebreaks: crowi.configManager.getConfig('markdown', 'markdown:isEnabledLinebreaks'),
  149. isEnabledLinebreaksInComments: crowi.configManager.getConfig('markdown', 'markdown:isEnabledLinebreaksInComments'),
  150. isEnabledXssPrevention: crowi.configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention'),
  151. xssOption: crowi.configManager.getConfig('markdown', 'markdown:xss:option'),
  152. tagWhiteList: crowi.xssService.getTagWhiteList(),
  153. attrWhiteList: crowi.xssService.getAttrWhiteList(),
  154. highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
  155. isSavedStatesOfTabChanges: crowi.configManager.getConfig('crowi', 'customize:isSavedStatesOfTabChanges'),
  156. hasSlackConfig: crowi.slackNotificationService.hasSlackConfig(),
  157. env: {
  158. PLANTUML_URI: env.PLANTUML_URI || null,
  159. BLOCKDIAG_URI: env.BLOCKDIAG_URI || null,
  160. HACKMD_URI: env.HACKMD_URI || null,
  161. MATHJAX: env.MATHJAX || null,
  162. NO_CDN: env.NO_CDN || null,
  163. },
  164. recentCreatedLimit: crowi.configManager.getConfig('crowi', 'customize:showRecentCreatedNumber'),
  165. isAclEnabled: !crowi.aclService.getIsPublicWikiOnly(),
  166. globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
  167. };
  168. return localConfig;
  169. };
  170. const Config = mongoose.model('Config', configSchema);
  171. return Config;
  172. };