diff --git a/public/openapi/read.yaml b/public/openapi/read.yaml index 1e1b721d6f..7c4e1f9e97 100644 --- a/public/openapi/read.yaml +++ b/public/openapi/read.yaml @@ -168,6 +168,8 @@ paths: $ref: 'read/admin/upload/file.yaml' /api/admin/uploadDefaultAvatar: $ref: 'read/admin/uploadDefaultAvatar.yaml' + /api/admin/config: + $ref: 'read/admin/config.yaml' /api/config: $ref: 'read/config.yaml' /api/users: diff --git a/public/openapi/read/admin/config.yaml b/public/openapi/read/admin/config.yaml new file mode 100644 index 0000000000..61e035d2fe --- /dev/null +++ b/public/openapi/read/admin/config.yaml @@ -0,0 +1,290 @@ +get: + tags: + - admin + summary: Get forum settings and admin only settings + description: This route retrieves forum settings and user-specific settings for client-side and admin-side options on the forum. + responses: + "200": + description: "" + content: + application/json: + schema: + type: object + properties: + relative_path: + type: string + upload_url: + type: string + assetBaseUrl: + type: string + asset_base_url: + type: string + siteTitle: + type: string + browserTitle: + type: string + titleLayout: + type: string + showSiteTitle: + type: boolean + maintenanceMode: + type: boolean + postQueue: + type: number + minimumTitleLength: + type: number + maximumTitleLength: + type: number + minimumPostLength: + type: number + maximumPostLength: + type: number + minimumTagsPerTopic: + type: number + maximumTagsPerTopic: + type: number + minimumTagLength: + type: number + undoTimeout: + type: number + maximumTagLength: + type: number + useOutgoingLinksPage: + type: boolean + allowGuestHandles: + type: boolean + allowTopicsThumbnail: + type: boolean + usePagination: + type: boolean + disableChat: + type: boolean + disableChatMessageEditing: + type: boolean + maximumChatMessageLength: + type: number + socketioTransports: + type: array + items: + type: string + socketioOrigins: + type: string + websocketAddress: + type: string + maxReconnectionAttempts: + type: number + reconnectionDelay: + type: number + topicsPerPage: + type: number + postsPerPage: + type: number + maximumFileSize: + type: number + theme:id: + type: string + theme:src: + type: string + defaultLang: + type: string + userLang: + type: string + loggedIn: + type: boolean + uid: + type: number + description: A user identifier + cache-buster: + type: string + topicPostSort: + type: string + categoryTopicSort: + type: string + csrf_token: + type: string + searchEnabled: + type: boolean + searchDefaultInQuick: + type: string + disableCustomUserSkins: + type: boolean + bootswatchSkin: + type: string + defaultBootswatchSkin: + type: string + composer:showHelpTab: + type: boolean + enablePostHistory: + type: boolean + timeagoCutoff: + type: number + timeagoCodes: + type: array + items: + type: string + cookies: + type: object + properties: + enabled: + type: boolean + message: + type: string + dismiss: + type: string + link: + type: string + link_url: + type: string + thumbs: + type: object + properties: + size: + type: number + acpLang: + type: string + openOutgoingLinksInNewTab: + type: boolean + topicSearchEnabled: + type: boolean + hideSubCategories: + type: boolean + hideCategoryLastPost: + type: boolean + enableQuickReply: + type: boolean + iconBackgrounds: + type: array + items: + type: string + description: A valid CSS colour code + example: '#fff' + emailPrompt: + type: number + useragent: + type: object + properties: + isYaBrowser: + type: boolean + isAuthoritative: + type: boolean + isMobile: + type: boolean + isMobileNative: + type: boolean + isTablet: + type: boolean + isiPad: + type: boolean + isiPod: + type: boolean + isiPhone: + type: boolean + isiPhoneNative: + type: boolean + isAndroid: + type: boolean + isAndroidNative: + type: boolean + isBlackberry: + type: boolean + isOpera: + type: boolean + isIE: + type: boolean + isEdge: + type: boolean + isIECompatibilityMode: + type: boolean + isSafari: + type: boolean + isFirefox: + type: boolean + isWebkit: + type: boolean + isChrome: + type: boolean + isKonqueror: + type: boolean + isOmniWeb: + type: boolean + isSeaMonkey: + type: boolean + isFlock: + type: boolean + isAmaya: + type: boolean + isPhantomJS: + type: boolean + isEpiphany: + type: boolean + isDesktop: + type: boolean + isWindows: + type: boolean + isLinux: + type: boolean + isLinux64: + type: boolean + isMac: + type: boolean + isChromeOS: + type: boolean + isBada: + type: boolean + isSamsung: + type: boolean + isRaspberry: + type: boolean + isBot: + type: boolean + isCurl: + type: boolean + isAndroidTablet: + type: boolean + isWinJs: + type: boolean + isKindleFire: + type: boolean + isSilk: + type: boolean + isCaptive: + type: boolean + isSmartTV: + type: boolean + isUC: + type: boolean + isFacebook: + type: boolean + isAlamoFire: + type: boolean + isElectron: + type: boolean + silkAccelerated: + type: boolean + browser: + type: string + version: + type: string + os: + type: string + platform: + type: string + geoIp: + type: object + source: + type: string + isWechat: + type: boolean + composer-default: + type: object + fontawesome: + type: object + properties: + pro: + type: boolean + styles: + type: array + items: + type: string + version: + type: string diff --git a/public/openapi/read/config.yaml b/public/openapi/read/config.yaml index 69520e29a3..ceb99c0d58 100644 --- a/public/openapi/read/config.yaml +++ b/public/openapi/read/config.yaml @@ -94,9 +94,6 @@ get: uid: type: number description: A user identifier - isACP: - type: boolean - description: true if admin page is being loaded, false otherwise cache-buster: type: string topicPostSort: diff --git a/src/controllers/admin.js b/src/controllers/admin.js index c56c8f2ed8..b167f606e6 100644 --- a/src/controllers/admin.js +++ b/src/controllers/admin.js @@ -1,7 +1,9 @@ 'use strict'; const privileges = require('../privileges'); +const plugins = require('../plugins'); const helpers = require('./helpers'); +const apiController = require('./api'); const adminController = { dashboard: require('./admin/dashboard'), @@ -55,4 +57,15 @@ adminController.routeIndex = async (req, res) => { return helpers.notAllowed(req, res); }; +adminController.loadConfig = async function (req) { + const config = await apiController.loadConfig(req); + await plugins.hooks.fire('filter:config.get.admin', config); + return config; +}; + +adminController.getConfig = async (req, res) => { + const config = await adminController.loadConfig(req); + res.json(config); +}; + module.exports = adminController; diff --git a/src/controllers/api.js b/src/controllers/api.js index 7c575b6070..22574a9ce6 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -67,7 +67,6 @@ apiController.loadConfig = async function (req) { userLang: req.query.lang ? validator.escape(String(req.query.lang)) : (meta.config.defaultLang || 'en-GB'), loggedIn: !!req.user, uid: req.uid, - isACP: !!(req.res && req.res.locals && req.res.locals.renderAdminHeader), 'cache-buster': meta.config['cache-buster'] || '', topicPostSort: meta.config.topicPostSort || 'oldest_to_newest', categoryTopicSort: meta.config.categoryTopicSort || 'recently_replied', diff --git a/src/middleware/admin.js b/src/middleware/admin.js index b514fb5cca..bf89079103 100644 --- a/src/middleware/admin.js +++ b/src/middleware/admin.js @@ -10,7 +10,7 @@ const privileges = require('../privileges'); const helpers = require('./helpers'); const controllers = { - api: require('../controllers/api'), + admin: require('../controllers/admin'), helpers: require('../controllers/helpers'), }; @@ -22,7 +22,7 @@ middleware.buildHeader = helpers.try(async (req, res, next) => { await require('./index').applyCSRFasync(req, res); } - res.locals.config = await controllers.api.loadConfig(req); + res.locals.config = await controllers.admin.loadConfig(req); next(); }); diff --git a/src/promisify.js b/src/promisify.js index da6aad1fd2..47b2f3a9f4 100644 --- a/src/promisify.js +++ b/src/promisify.js @@ -37,7 +37,7 @@ module.exports = function (theModule, ignoreKeys) { } function wrapCallback(origFn, callbackFn) { - return async function wrapperCallback(...args) { + return function wrapperCallback(...args) { if (args.length && typeof args[args.length - 1] === 'function') { const cb = args.pop(); args.push((err, res) => (res !== undefined ? cb(err, res) : cb(err))); diff --git a/src/routes/admin.js b/src/routes/admin.js index 01e228dabe..6e6721c13e 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -61,6 +61,7 @@ module.exports = function (app, name, middleware, controllers) { function apiRoutes(router, name, middleware, controllers) { + router.get(`/api/${name}/config`, middleware.ensureLoggedIn, helpers.tryRoute(controllers.admin.getConfig)); router.get(`/api/${name}/users/csv`, middleware.ensureLoggedIn, helpers.tryRoute(controllers.admin.users.getCSV)); router.get(`/api/${name}/groups/:groupname/csv`, middleware.ensureLoggedIn, helpers.tryRoute(controllers.admin.groups.getCSV)); router.get(`/api/${name}/analytics`, middleware.ensureLoggedIn, helpers.tryRoute(controllers.admin.dashboard.getAnalytics));