You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.7 KiB

  1. const graphHelper = require('../../helpers/graph')
  2. const _ = require('lodash')
  3. /* global WIKI */
  4. module.exports = {
  5. Query: {
  6. async site() { return {} }
  7. },
  8. Mutation: {
  9. async site() { return {} }
  10. },
  11. SiteQuery: {
  12. async config(obj, args, context, info) {
  13. return {
  14. host: WIKI.config.host,
  15. title: WIKI.config.title,
  16. company: WIKI.config.company,
  17. contentLicense: WIKI.config.contentLicense,
  18. logoUrl: WIKI.config.logoUrl,
  19. ...WIKI.config.seo,
  20. ...WIKI.config.features,
  21. ...WIKI.config.security,
  22. authAutoLogin: WIKI.config.auth.autoLogin,
  23. authEnforce2FA: WIKI.config.auth.enforce2FA,
  24. authHideLocal: WIKI.config.auth.hideLocal,
  25. authLoginBgUrl: WIKI.config.auth.loginBgUrl,
  26. authJwtAudience: WIKI.config.auth.audience,
  27. authJwtExpiration: WIKI.config.auth.tokenExpiration,
  28. authJwtRenewablePeriod: WIKI.config.auth.tokenRenewal,
  29. uploadMaxFileSize: WIKI.config.uploads.maxFileSize,
  30. uploadMaxFiles: WIKI.config.uploads.maxFiles
  31. }
  32. }
  33. },
  34. SiteMutation: {
  35. async updateConfig(obj, args, context) {
  36. try {
  37. if (args.host) {
  38. let siteHost = _.trim(args.host)
  39. if (siteHost.endsWith('/')) {
  40. siteHost = siteHost.slice(0, -1)
  41. }
  42. WIKI.config.host = siteHost
  43. }
  44. if (args.title) {
  45. WIKI.config.title = _.trim(args.title)
  46. }
  47. if (args.company) {
  48. WIKI.config.company = _.trim(args.company)
  49. }
  50. if (args.contentLicense) {
  51. WIKI.config.contentLicense = args.contentLicense
  52. }
  53. if (args.logoUrl) {
  54. WIKI.config.logoUrl = _.trim(args.logoUrl)
  55. }
  56. WIKI.config.seo = {
  57. description: _.get(args, 'description', WIKI.config.seo.description),
  58. robots: _.get(args, 'robots', WIKI.config.seo.robots),
  59. analyticsService: _.get(args, 'analyticsService', WIKI.config.seo.analyticsService),
  60. analyticsId: _.get(args, 'analyticsId', WIKI.config.seo.analyticsId)
  61. }
  62. WIKI.config.auth = {
  63. autoLogin: _.get(args, 'authAutoLogin', WIKI.config.auth.autoLogin),
  64. enforce2FA: _.get(args, 'authEnforce2FA', WIKI.config.auth.enforce2FA),
  65. hideLocal: _.get(args, 'authHideLocal', WIKI.config.auth.hideLocal),
  66. loginBgUrl: _.get(args, 'authLoginBgUrl', WIKI.config.auth.loginBgUrl),
  67. audience: _.get(args, 'authJwtAudience', WIKI.config.auth.audience),
  68. tokenExpiration: _.get(args, 'authJwtExpiration', WIKI.config.auth.tokenExpiration),
  69. tokenRenewal: _.get(args, 'authJwtRenewablePeriod', WIKI.config.auth.tokenRenewal)
  70. }
  71. WIKI.config.features = {
  72. featurePageRatings: _.get(args, 'featurePageRatings', WIKI.config.features.featurePageRatings),
  73. featurePageComments: _.get(args, 'featurePageComments', WIKI.config.features.featurePageComments),
  74. featurePersonalWikis: _.get(args, 'featurePersonalWikis', WIKI.config.features.featurePersonalWikis)
  75. }
  76. WIKI.config.security = {
  77. securityOpenRedirect: _.get(args, 'securityOpenRedirect', WIKI.config.security.securityOpenRedirect),
  78. securityIframe: _.get(args, 'securityIframe', WIKI.config.security.securityIframe),
  79. securityReferrerPolicy: _.get(args, 'securityReferrerPolicy', WIKI.config.security.securityReferrerPolicy),
  80. securityTrustProxy: _.get(args, 'securityTrustProxy', WIKI.config.security.securityTrustProxy),
  81. securitySRI: _.get(args, 'securitySRI', WIKI.config.security.securitySRI),
  82. securityHSTS: _.get(args, 'securityHSTS', WIKI.config.security.securityHSTS),
  83. securityHSTSDuration: _.get(args, 'securityHSTSDuration', WIKI.config.security.securityHSTSDuration),
  84. securityCSP: _.get(args, 'securityCSP', WIKI.config.security.securityCSP),
  85. securityCSPDirectives: _.get(args, 'securityCSPDirectives', WIKI.config.security.securityCSPDirectives)
  86. }
  87. WIKI.config.uploads = {
  88. maxFileSize: _.get(args, 'uploadMaxFileSize', WIKI.config.uploads.maxFileSize),
  89. maxFiles: _.get(args, 'uploadMaxFiles', WIKI.config.uploads.maxFiles)
  90. }
  91. await WIKI.configSvc.saveToDb(['host', 'title', 'company', 'contentLicense', 'seo', 'logoUrl', 'auth', 'features', 'security', 'uploads'])
  92. if (WIKI.config.security.securityTrustProxy) {
  93. WIKI.app.enable('trust proxy')
  94. } else {
  95. WIKI.app.disable('trust proxy')
  96. }
  97. return {
  98. responseResult: graphHelper.generateSuccess('Site configuration updated successfully')
  99. }
  100. } catch (err) {
  101. return graphHelper.generateError(err)
  102. }
  103. }
  104. }
  105. }