config.ts 5.7 KB

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