config.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import { PresetThemes } from '@growi/preset-themes';
  2. import { Types, Schema } from 'mongoose';
  3. import uniqueValidator from 'mongoose-unique-validator';
  4. import { RehypeSanitizeOption } from '../../interfaces/rehype';
  5. import { getOrCreateModel } from '../util/mongoose-utils';
  6. export interface Config {
  7. _id: Types.ObjectId;
  8. ns: string;
  9. key: string;
  10. value: string;
  11. }
  12. /*
  13. * define methods type
  14. */
  15. interface ModelMethods { any }
  16. const schema = new Schema<Config>({
  17. ns: { type: String, required: true },
  18. key: { type: String, required: true },
  19. value: { type: String, required: true },
  20. });
  21. // define unique compound index
  22. schema.index({ ns: 1, key: 1 }, { unique: true });
  23. schema.plugin(uniqueValidator);
  24. /**
  25. * default values when GROWI is cleanly installed
  26. */
  27. export const generateConfigsForInstalling = (): { [key: string]: any } => {
  28. // eslint-disable-next-line no-use-before-define
  29. const config = defaultCrowiConfigs;
  30. // overwrite
  31. config['app:installed'] = true;
  32. config['app:fileUpload'] = true;
  33. config['app:isV5Compatible'] = true;
  34. return config;
  35. };
  36. /**
  37. * default values when migrated from Official Crowi
  38. */
  39. export const defaultCrowiConfigs: { [key: string]: any } = {
  40. /* eslint-disable key-spacing */
  41. 'app:installed' : false,
  42. 'app:confidential' : undefined,
  43. 'app:fileUpload' : false,
  44. 'app:globalLang' : 'en_US',
  45. 'security:restrictGuestMode' : 'Deny',
  46. 'security:registrationMode' : 'Open',
  47. 'security:registrationWhiteList' : [],
  48. 'security:list-policy:hideRestrictedByOwner' : false,
  49. 'security:list-policy:hideRestrictedByGroup' : false,
  50. // DEPRECATED: 'security:pageCompleteDeletionAuthority' : undefined,
  51. 'security:pageDeletionAuthority' : undefined,
  52. 'security:pageCompleteDeletionAuthority' : undefined,
  53. 'security:pageRecursiveDeletionAuthority' : undefined,
  54. 'security:pageRecursiveCompleteDeletionAuthority' : undefined,
  55. 'security:disableLinkSharing' : false,
  56. 'security:passport-local:isEnabled' : true,
  57. 'security:passport-ldap:isEnabled' : false,
  58. 'security:passport-ldap:serverUrl' : undefined,
  59. 'security:passport-ldap:isUserBind' : undefined,
  60. 'security:passport-ldap:bindDN' : undefined,
  61. 'security:passport-ldap:bindDNPassword' : undefined,
  62. 'security:passport-ldap:searchFilter' : undefined,
  63. 'security:passport-ldap:attrMapUsername' : undefined,
  64. 'security:passport-ldap:attrMapName' : undefined,
  65. 'security:passport-ldap:attrMapMail' : undefined,
  66. 'security:passport-ldap:groupSearchBase' : undefined,
  67. 'security:passport-ldap:groupSearchFilter' : undefined,
  68. 'security:passport-ldap:groupDnProperty' : undefined,
  69. 'security:passport-ldap:isSameUsernameTreatedAsIdenticalUser': false,
  70. 'security:passport-saml:isEnabled' : false,
  71. 'security:passport-saml:isSameEmailTreatedAsIdenticalUser': false,
  72. 'security:passport-google:isEnabled' : false,
  73. 'security:passport-google:clientId': undefined,
  74. 'security:passport-google:clientSecret': undefined,
  75. 'security:passport-google:isSameUsernameTreatedAsIdenticalUser': false,
  76. 'security:passport-github:isEnabled' : false,
  77. 'security:passport-github:clientId': undefined,
  78. 'security:passport-github:clientSecret': undefined,
  79. 'security:passport-github:isSameUsernameTreatedAsIdenticalUser': false,
  80. 'security:passport-oidc:isEnabled' : false,
  81. 'aws:s3Bucket' : 'growi',
  82. 'aws:s3Region' : 'ap-northeast-1',
  83. 'aws:s3AccessKeyId' : undefined,
  84. 'aws:s3SecretAccessKey' : undefined,
  85. 'aws:s3CustomEndpoint' : undefined,
  86. 'mail:from' : undefined,
  87. 'mail:smtpHost' : undefined,
  88. 'mail:smtpPort' : undefined,
  89. 'mail:smtpUser' : undefined,
  90. 'mail:smtpPassword' : undefined,
  91. 'customize:css' : undefined,
  92. 'customize:script' : undefined,
  93. 'customize:noscript' : undefined,
  94. 'customize:title' : undefined,
  95. 'customize:highlightJsStyle' : 'github',
  96. 'customize:highlightJsStyleBorder' : false,
  97. 'customize:theme' : PresetThemes.DEFAULT,
  98. 'customize:theme:forcedColorScheme' : null,
  99. 'customize:isContainerFluid' : false,
  100. 'customize:isEnabledTimeline' : true,
  101. 'customize:isEnabledAttachTitleHeader' : false,
  102. 'customize:showPageLimitationS' : 20,
  103. 'customize:showPageLimitationM' : 10,
  104. 'customize:showPageLimitationL' : 50,
  105. 'customize:showPageLimitationXL' : 20,
  106. 'customize:isEnabledStaleNotification': false,
  107. 'customize:isAllReplyShown': false,
  108. 'customize:isSearchScopeChildrenAsDefault': false,
  109. 'customize:isSidebarDrawerMode': false,
  110. 'customize:isSidebarClosedAtDockMode': false,
  111. 'notification:owner-page:isEnabled': false,
  112. 'notification:group-page:isEnabled': false,
  113. 'importer:esa:team_name': undefined,
  114. 'importer:esa:access_token': undefined,
  115. 'importer:qiita:team_name': undefined,
  116. 'importer:qiita:access_token': undefined,
  117. /* eslint-enable key-spacing */
  118. };
  119. export const defaultMarkdownConfigs: { [key: string]: any } = {
  120. // don't use it, but won't turn it off
  121. 'markdown:xss:tagWhiteList': [],
  122. 'markdown:xss:attrWhiteList': [],
  123. 'markdown:rehypeSanitize:isEnabledPrevention': true,
  124. 'markdown:rehypeSanitize:option': RehypeSanitizeOption.RECOMMENDED,
  125. 'markdown:rehypeSanitize:tagNames': [],
  126. 'markdown:rehypeSanitize:attributes': '{}',
  127. 'markdown:isEnabledLinebreaks': false,
  128. 'markdown:isEnabledLinebreaksInComments': true,
  129. 'markdown:adminPreferredIndentSize': 4,
  130. 'markdown:isIndentSizeForced': false,
  131. };
  132. export const defaultNotificationConfigs: { [key: string]: any } = {
  133. 'slack:isIncomingWebhookPrioritized': false,
  134. 'slack:incomingWebhookUrl': undefined,
  135. 'slack:token': undefined,
  136. };
  137. export default getOrCreateModel<Config, ModelMethods>('Config', schema);