| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- const loggerFactory = require('@alias/logger');
- const logger = loggerFactory('growi:routes:apiv3:app-settings');
- const express = require('express');
- const router = express.Router();
- const { body } = require('express-validator/check');
- const ErrorV3 = require('../../models/vo/error-apiv3');
- const validator = {
- appSetting: [
- body('title').trim(),
- body('confidential'),
- body('globalLang').isIn(['en-US', 'ja']),
- body('fileUpload').isBoolean(),
- ],
- siteUrlSetting: [
- body('siteUrl').trim(),
- ],
- };
- /**
- * @swagger
- * tags:
- * name: AppSettings
- */
- /**
- * @swagger
- *
- * components:
- * schemas:
- * AppSettingParams:
- * type: object
- * properties:
- * title:
- * type: String
- * description: site name show on page header and tilte of HTML
- * confidential:
- * type: String
- * description: confidential show on page header
- * globalLang:
- * type: String
- * description: language set when create user
- * fileUpload:
- * type: boolean
- * description: enable upload file except image file
- * siteUrl:
- * type: String
- * description: Site URL. e.g. https://example.com, https://example.com:8080
- * envSiteUrl:
- * type: String
- * description: environment variable 'APP_SITE_URL'
- */
- module.exports = (crowi) => {
- const accessTokenParser = require('../../middleware/access-token-parser')(crowi);
- const loginRequired = require('../../middleware/login-required')(crowi);
- const loginRequiredStrictly = require('../../middleware/login-required')(crowi);
- const adminRequired = require('../../middleware/admin-required')(crowi);
- const csrf = require('../../middleware/csrf')(crowi);
- const { ApiV3FormValidator } = crowi.middlewares;
- /**
- * @swagger
- *
- * /app-settings/:
- * get:
- * tags: [AppSettings]
- * description: get app setting params
- * responses:
- * 200:
- * description: Resources are available
- * content:
- * application/json:
- * schema:
- * properties:
- * title:
- * type: String
- * description: site name show on page header and tilte of HTML
- * confidential:
- * type: String
- * description: confidential show on page header
- * globalLang:
- * type: String
- * description: language set when create user
- * fileUpload:
- * type: boolean
- * description: enable upload file except image file
- * siteUrl:
- * type: String
- * description: Site URL. e.g. https://example.com, https://example.com:8080
- * envSiteUrl:
- * type: String
- * description: environment variable 'APP_SITE_URL'
- */
- router.get('/', accessTokenParser, loginRequired, adminRequired, async(req, res) => {
- const appSettingParams = {
- title: crowi.configManager.getConfig('crowi', 'app:title'),
- confidential: crowi.configManager.getConfig('crowi', 'app:confidential'),
- globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
- fileUpload: crowi.configManager.getConfig('crowi', 'app:fileUpload'),
- siteUrl: crowi.configManager.getConfig('crowi', 'app:siteUrl'),
- envSiteUrl: crowi.configManager.getConfigFromEnvVars('crowi', 'app:siteUrl'),
- };
- return res.apiv3({ appSettingParams });
- });
- /**
- * @swagger
- *
- * /app-settings/app-setting:
- * put:
- * tags: [AppSettings]
- * description: Update app setting
- * requestBody:
- * required: true
- * content:
- * application/json:
- * schema:
- * type: object
- * properties:
- * title:
- * type: String
- * description: site name show on page header and tilte of HTML
- * confidential:
- * type: String
- * description: confidential show on page header
- * globalLang:
- * type: String
- * description: language set when create user
- * fileUpload:
- * type: boolean
- * description: enable upload file except image file
- * responses:
- * 200:
- * description: Succeeded to update app setting
- * content:
- * application/json:
- * schema:
- * properties:
- * status:
- * $ref: '#/components/schemas/appSettingParams'
- */
- router.put('/app-setting', loginRequiredStrictly, adminRequired, csrf, validator.appSetting, ApiV3FormValidator, async(req, res) => {
- const requestAppSettingParams = {
- 'app:title': req.body.title,
- 'app:confidential': req.body.confidential,
- 'app:globalLang': req.body.globalLang,
- 'app:fileUpload': req.body.fileUpload,
- };
- try {
- await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestAppSettingParams);
- const appSettingParams = {
- title: crowi.configManager.getConfig('crowi', 'app:title'),
- confidential: crowi.configManager.getConfig('crowi', 'app:confidential'),
- globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
- fileUpload: crowi.configManager.getConfig('crowi', 'app:fileUpload'),
- };
- return res.apiv3({ appSettingParams });
- }
- catch (err) {
- const msg = 'Error occurred in updating app setting';
- logger.error('Error', err);
- return res.apiv3Err(new ErrorV3(msg, 'update-appSetting-failed'));
- }
- });
- /**
- * @swagger
- *
- * /app-settings/site-url-setting:
- * put:
- * tags: [AppSettings]
- * description: Update site url setting
- * requestBody:
- * required: true
- * content:
- * application/json:
- * schema:
- * type: object
- * properties:
- * siteUrl:
- * type: String
- * description: Site URL. e.g. https://example.com, https://example.com:8080
- * responses:
- * 200:
- * description: Succeeded to update site url setting
- * content:
- * application/json:
- * schema:
- * properties:
- * status:
- * $ref: '#/components/schemas/appSettingParams'
- */
- router.put('/site-url-setting', loginRequiredStrictly, adminRequired, csrf, validator.siteUrlSetting, ApiV3FormValidator, async(req, res) => {
- const requestSiteUrlSettingParams = {
- 'app:siteUrl': req.body.siteUrl,
- };
- try {
- await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestSiteUrlSettingParams);
- const appSettingParams = {
- siteUrl: crowi.configManager.getConfig('crowi', 'app:siteUrl'),
- };
- return res.apiv3({ appSettingParams });
- }
- catch (err) {
- const msg = 'Error occurred in updating site url setting';
- logger.error('Error', err);
- return res.apiv3Err(new ErrorV3(msg, 'update-siteUrlSetting-failed'));
- }
- });
- return router;
- };
|