2018-12-24 06:03:10 +00:00
|
|
|
const graphHelper = require('../../helpers/graph')
|
2020-04-24 04:17:10 +00:00
|
|
|
const _ = require('lodash')
|
2018-12-24 06:03:10 +00:00
|
|
|
|
|
|
|
/* global WIKI */
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
Query: {
|
|
|
|
async site() { return {} }
|
|
|
|
},
|
|
|
|
Mutation: {
|
|
|
|
async site() { return {} }
|
|
|
|
},
|
|
|
|
SiteQuery: {
|
|
|
|
async config(obj, args, context, info) {
|
|
|
|
return {
|
|
|
|
host: WIKI.config.host,
|
|
|
|
title: WIKI.config.title,
|
|
|
|
company: WIKI.config.company,
|
2020-02-23 20:20:55 +00:00
|
|
|
contentLicense: WIKI.config.contentLicense,
|
2019-12-19 04:45:19 +00:00
|
|
|
logoUrl: WIKI.config.logoUrl,
|
2022-06-25 02:20:36 +00:00
|
|
|
pageExtensions: WIKI.config.pageExtensions.join(', '),
|
2018-12-24 06:03:10 +00:00
|
|
|
...WIKI.config.seo,
|
2019-08-25 02:19:35 +00:00
|
|
|
...WIKI.config.features,
|
2020-05-10 19:55:28 +00:00
|
|
|
...WIKI.config.security,
|
2020-07-03 23:36:33 +00:00
|
|
|
authAutoLogin: WIKI.config.auth.autoLogin,
|
2020-07-06 03:55:11 +00:00
|
|
|
authEnforce2FA: WIKI.config.auth.enforce2FA,
|
2020-07-05 05:36:02 +00:00
|
|
|
authHideLocal: WIKI.config.auth.hideLocal,
|
2020-07-03 23:36:33 +00:00
|
|
|
authLoginBgUrl: WIKI.config.auth.loginBgUrl,
|
|
|
|
authJwtAudience: WIKI.config.auth.audience,
|
|
|
|
authJwtExpiration: WIKI.config.auth.tokenExpiration,
|
|
|
|
authJwtRenewablePeriod: WIKI.config.auth.tokenRenewal,
|
2020-05-10 19:55:28 +00:00
|
|
|
uploadMaxFileSize: WIKI.config.uploads.maxFileSize,
|
2021-12-18 02:41:23 +00:00
|
|
|
uploadMaxFiles: WIKI.config.uploads.maxFiles,
|
2021-12-25 01:18:12 +00:00
|
|
|
uploadScanSVG: WIKI.config.uploads.scanSVG,
|
|
|
|
uploadForceDownload: WIKI.config.uploads.forceDownload
|
2018-12-24 06:03:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
SiteMutation: {
|
|
|
|
async updateConfig(obj, args, context) {
|
|
|
|
try {
|
2022-04-09 06:42:16 +00:00
|
|
|
if (args.hasOwnProperty('host')) {
|
2020-05-10 19:55:28 +00:00
|
|
|
let siteHost = _.trim(args.host)
|
|
|
|
if (siteHost.endsWith('/')) {
|
2020-06-04 04:32:58 +00:00
|
|
|
siteHost = siteHost.slice(0, -1)
|
2020-05-10 19:55:28 +00:00
|
|
|
}
|
|
|
|
WIKI.config.host = siteHost
|
|
|
|
}
|
|
|
|
|
2022-04-09 06:42:16 +00:00
|
|
|
if (args.hasOwnProperty('title')) {
|
2020-05-10 19:55:28 +00:00
|
|
|
WIKI.config.title = _.trim(args.title)
|
|
|
|
}
|
|
|
|
|
2022-04-09 06:42:16 +00:00
|
|
|
if (args.hasOwnProperty('company')) {
|
2020-05-10 19:55:28 +00:00
|
|
|
WIKI.config.company = _.trim(args.company)
|
|
|
|
}
|
|
|
|
|
2022-04-09 06:42:16 +00:00
|
|
|
if (args.hasOwnProperty('contentLicense')) {
|
2020-05-10 19:55:28 +00:00
|
|
|
WIKI.config.contentLicense = args.contentLicense
|
|
|
|
}
|
|
|
|
|
2022-04-09 06:42:16 +00:00
|
|
|
if (args.hasOwnProperty('logoUrl')) {
|
2020-05-10 19:55:28 +00:00
|
|
|
WIKI.config.logoUrl = _.trim(args.logoUrl)
|
|
|
|
}
|
|
|
|
|
2022-06-25 02:20:36 +00:00
|
|
|
if (args.hasOwnProperty('pageExtensions')) {
|
|
|
|
WIKI.config.pageExtensions = _.trim(args.pageExtensions).split(',').map(p => p.trim().toLowerCase()).filter(p => p !== '')
|
|
|
|
}
|
|
|
|
|
2018-12-24 06:03:10 +00:00
|
|
|
WIKI.config.seo = {
|
2020-05-10 19:55:28 +00:00
|
|
|
description: _.get(args, 'description', WIKI.config.seo.description),
|
|
|
|
robots: _.get(args, 'robots', WIKI.config.seo.robots),
|
|
|
|
analyticsService: _.get(args, 'analyticsService', WIKI.config.seo.analyticsService),
|
|
|
|
analyticsId: _.get(args, 'analyticsId', WIKI.config.seo.analyticsId)
|
2018-12-24 06:03:10 +00:00
|
|
|
}
|
2020-05-10 19:55:28 +00:00
|
|
|
|
2020-07-03 23:36:33 +00:00
|
|
|
WIKI.config.auth = {
|
|
|
|
autoLogin: _.get(args, 'authAutoLogin', WIKI.config.auth.autoLogin),
|
2020-07-06 03:55:11 +00:00
|
|
|
enforce2FA: _.get(args, 'authEnforce2FA', WIKI.config.auth.enforce2FA),
|
2020-07-05 05:36:02 +00:00
|
|
|
hideLocal: _.get(args, 'authHideLocal', WIKI.config.auth.hideLocal),
|
2020-07-03 23:36:33 +00:00
|
|
|
loginBgUrl: _.get(args, 'authLoginBgUrl', WIKI.config.auth.loginBgUrl),
|
|
|
|
audience: _.get(args, 'authJwtAudience', WIKI.config.auth.audience),
|
|
|
|
tokenExpiration: _.get(args, 'authJwtExpiration', WIKI.config.auth.tokenExpiration),
|
|
|
|
tokenRenewal: _.get(args, 'authJwtRenewablePeriod', WIKI.config.auth.tokenRenewal)
|
|
|
|
}
|
|
|
|
|
2018-12-24 06:03:10 +00:00
|
|
|
WIKI.config.features = {
|
2020-05-10 19:55:28 +00:00
|
|
|
featurePageRatings: _.get(args, 'featurePageRatings', WIKI.config.features.featurePageRatings),
|
|
|
|
featurePageComments: _.get(args, 'featurePageComments', WIKI.config.features.featurePageComments),
|
|
|
|
featurePersonalWikis: _.get(args, 'featurePersonalWikis', WIKI.config.features.featurePersonalWikis)
|
2018-12-24 06:03:10 +00:00
|
|
|
}
|
2020-05-10 19:55:28 +00:00
|
|
|
|
2019-08-25 02:19:35 +00:00
|
|
|
WIKI.config.security = {
|
2020-05-29 22:24:20 +00:00
|
|
|
securityOpenRedirect: _.get(args, 'securityOpenRedirect', WIKI.config.security.securityOpenRedirect),
|
2020-05-10 19:55:28 +00:00
|
|
|
securityIframe: _.get(args, 'securityIframe', WIKI.config.security.securityIframe),
|
|
|
|
securityReferrerPolicy: _.get(args, 'securityReferrerPolicy', WIKI.config.security.securityReferrerPolicy),
|
|
|
|
securityTrustProxy: _.get(args, 'securityTrustProxy', WIKI.config.security.securityTrustProxy),
|
|
|
|
securitySRI: _.get(args, 'securitySRI', WIKI.config.security.securitySRI),
|
|
|
|
securityHSTS: _.get(args, 'securityHSTS', WIKI.config.security.securityHSTS),
|
|
|
|
securityHSTSDuration: _.get(args, 'securityHSTSDuration', WIKI.config.security.securityHSTSDuration),
|
|
|
|
securityCSP: _.get(args, 'securityCSP', WIKI.config.security.securityCSP),
|
|
|
|
securityCSPDirectives: _.get(args, 'securityCSPDirectives', WIKI.config.security.securityCSPDirectives)
|
|
|
|
}
|
|
|
|
|
|
|
|
WIKI.config.uploads = {
|
|
|
|
maxFileSize: _.get(args, 'uploadMaxFileSize', WIKI.config.uploads.maxFileSize),
|
2021-12-18 02:41:23 +00:00
|
|
|
maxFiles: _.get(args, 'uploadMaxFiles', WIKI.config.uploads.maxFiles),
|
2021-12-25 01:18:12 +00:00
|
|
|
scanSVG: _.get(args, 'uploadScanSVG', WIKI.config.uploads.scanSVG),
|
|
|
|
forceDownload: _.get(args, 'uploadForceDownload', WIKI.config.uploads.forceDownload)
|
2019-08-25 02:19:35 +00:00
|
|
|
}
|
2020-05-10 19:55:28 +00:00
|
|
|
|
2022-06-25 02:20:36 +00:00
|
|
|
await WIKI.configSvc.saveToDb(['host', 'title', 'company', 'contentLicense', 'seo', 'logoUrl', 'pageExtensions', 'auth', 'features', 'security', 'uploads'])
|
2018-12-24 06:03:10 +00:00
|
|
|
|
2019-10-05 20:58:34 +00:00
|
|
|
if (WIKI.config.security.securityTrustProxy) {
|
|
|
|
WIKI.app.enable('trust proxy')
|
|
|
|
} else {
|
|
|
|
WIKI.app.disable('trust proxy')
|
|
|
|
}
|
|
|
|
|
2018-12-24 06:03:10 +00:00
|
|
|
return {
|
|
|
|
responseResult: graphHelper.generateSuccess('Site configuration updated successfully')
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
return graphHelper.generateError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|