|
@@ -1,6 +1,4 @@
|
|
|
-import {
|
|
|
|
|
- ConfigSource, SCOPE,
|
|
|
|
|
-} from '@growi/core/dist/interfaces';
|
|
|
|
|
|
|
+import { ConfigSource, SCOPE } from '@growi/core/dist/interfaces';
|
|
|
import { ErrorV3 } from '@growi/core/dist/models';
|
|
import { ErrorV3 } from '@growi/core/dist/models';
|
|
|
import { body } from 'express-validator';
|
|
import { body } from 'express-validator';
|
|
|
|
|
|
|
@@ -15,7 +13,6 @@ import loggerFactory from '~/utils/logger';
|
|
|
import { generateAddActivityMiddleware } from '../../../middlewares/add-activity';
|
|
import { generateAddActivityMiddleware } from '../../../middlewares/add-activity';
|
|
|
import { apiV3FormValidator } from '../../../middlewares/apiv3-form-validator';
|
|
import { apiV3FormValidator } from '../../../middlewares/apiv3-form-validator';
|
|
|
|
|
|
|
|
-
|
|
|
|
|
const logger = loggerFactory('growi:routes:apiv3:app-settings');
|
|
const logger = loggerFactory('growi:routes:apiv3:app-settings');
|
|
|
|
|
|
|
|
const { pathUtils } = require('@growi/core/dist/utils');
|
|
const { pathUtils } = require('@growi/core/dist/utils');
|
|
@@ -23,7 +20,6 @@ const express = require('express');
|
|
|
|
|
|
|
|
const router = express.Router();
|
|
const router = express.Router();
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* @swagger
|
|
* @swagger
|
|
|
*
|
|
*
|
|
@@ -317,7 +313,9 @@ const router = express.Router();
|
|
|
*/
|
|
*/
|
|
|
/** @param {import('~/server/crowi').default} crowi Crowi instance */
|
|
/** @param {import('~/server/crowi').default} crowi Crowi instance */
|
|
|
module.exports = (crowi) => {
|
|
module.exports = (crowi) => {
|
|
|
- const loginRequiredStrictly = require('../../../middlewares/login-required')(crowi);
|
|
|
|
|
|
|
+ const loginRequiredStrictly = require('../../../middlewares/login-required')(
|
|
|
|
|
+ crowi,
|
|
|
|
|
+ );
|
|
|
const adminRequired = require('../../../middlewares/admin-required')(crowi);
|
|
const adminRequired = require('../../../middlewares/admin-required')(crowi);
|
|
|
const addActivity = generateAddActivityMiddleware();
|
|
const addActivity = generateAddActivityMiddleware();
|
|
|
|
|
|
|
@@ -333,29 +331,39 @@ module.exports = (crowi) => {
|
|
|
],
|
|
],
|
|
|
siteUrlSetting: [
|
|
siteUrlSetting: [
|
|
|
// https://regex101.com/r/5Xef8V/1
|
|
// https://regex101.com/r/5Xef8V/1
|
|
|
- body('siteUrl').trim().matches(/^(https?:\/\/)/).isURL({ require_tld: false }),
|
|
|
|
|
|
|
+ body('siteUrl')
|
|
|
|
|
+ .trim()
|
|
|
|
|
+ .matches(/^(https?:\/\/)/)
|
|
|
|
|
+ .isURL({ require_tld: false }),
|
|
|
],
|
|
],
|
|
|
mailSetting: [
|
|
mailSetting: [
|
|
|
- body('fromAddress').trim().if(value => value !== '').isEmail(),
|
|
|
|
|
|
|
+ body('fromAddress')
|
|
|
|
|
+ .trim()
|
|
|
|
|
+ .if((value) => value !== '')
|
|
|
|
|
+ .isEmail(),
|
|
|
body('transmissionMethod').isIn(['smtp', 'ses']),
|
|
body('transmissionMethod').isIn(['smtp', 'ses']),
|
|
|
],
|
|
],
|
|
|
smtpSetting: [
|
|
smtpSetting: [
|
|
|
body('smtpHost').trim(),
|
|
body('smtpHost').trim(),
|
|
|
- body('smtpPort').trim().if(value => value !== '').isPort(),
|
|
|
|
|
|
|
+ body('smtpPort')
|
|
|
|
|
+ .trim()
|
|
|
|
|
+ .if((value) => value !== '')
|
|
|
|
|
+ .isPort(),
|
|
|
body('smtpUser').trim(),
|
|
body('smtpUser').trim(),
|
|
|
body('smtpPassword').trim(),
|
|
body('smtpPassword').trim(),
|
|
|
],
|
|
],
|
|
|
sesSetting: [
|
|
sesSetting: [
|
|
|
- body('sesAccessKeyId').trim().if(value => value !== '').matches(/^[\da-zA-Z]+$/),
|
|
|
|
|
|
|
+ body('sesAccessKeyId')
|
|
|
|
|
+ .trim()
|
|
|
|
|
+ .if((value) => value !== '')
|
|
|
|
|
+ .matches(/^[\da-zA-Z]+$/),
|
|
|
body('sesSecretAccessKey').trim(),
|
|
body('sesSecretAccessKey').trim(),
|
|
|
],
|
|
],
|
|
|
pageBulkExportSettings: [
|
|
pageBulkExportSettings: [
|
|
|
body('isBulkExportPagesEnabled').isBoolean(),
|
|
body('isBulkExportPagesEnabled').isBoolean(),
|
|
|
body('bulkExportDownloadExpirationSeconds').isInt(),
|
|
body('bulkExportDownloadExpirationSeconds').isInt(),
|
|
|
],
|
|
],
|
|
|
- maintenanceMode: [
|
|
|
|
|
- body('flag').isBoolean(),
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ maintenanceMode: [body('flag').isBoolean()],
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -380,74 +388,138 @@ module.exports = (crowi) => {
|
|
|
* type: object
|
|
* type: object
|
|
|
* $ref: '#/components/schemas/AppSettingParams'
|
|
* $ref: '#/components/schemas/AppSettingParams'
|
|
|
*/
|
|
*/
|
|
|
- router.get('/', accessTokenParser([SCOPE.READ.ADMIN.APP], { acceptLegacy: true }), loginRequiredStrictly, adminRequired, async(req, res) => {
|
|
|
|
|
- const appSettingsParams = {
|
|
|
|
|
- title: configManager.getConfig('app:title'),
|
|
|
|
|
- confidential: configManager.getConfig('app:confidential'),
|
|
|
|
|
- globalLang: configManager.getConfig('app:globalLang'),
|
|
|
|
|
- isEmailPublishedForNewUser: configManager.getConfig('customize:isEmailPublishedForNewUser'),
|
|
|
|
|
- fileUpload: configManager.getConfig('app:fileUpload'),
|
|
|
|
|
- useOnlyEnvVarsForIsBulkExportPagesEnabled: configManager.getConfig('env:useOnlyEnvVars:app:isBulkExportPagesEnabled'),
|
|
|
|
|
- isV5Compatible: configManager.getConfig('app:isV5Compatible'),
|
|
|
|
|
- siteUrl: configManager.getConfig('app:siteUrl'),
|
|
|
|
|
- siteUrlUseOnlyEnvVars: configManager.getConfig('env:useOnlyEnvVars:app:siteUrl'),
|
|
|
|
|
- envSiteUrl: configManager.getConfig('app:siteUrl', ConfigSource.env),
|
|
|
|
|
- isMailerSetup: crowi.mailService.isMailerSetup,
|
|
|
|
|
- fromAddress: configManager.getConfig('mail:from'),
|
|
|
|
|
-
|
|
|
|
|
- transmissionMethod: configManager.getConfig('mail:transmissionMethod'),
|
|
|
|
|
- smtpHost: configManager.getConfig('mail:smtpHost'),
|
|
|
|
|
- smtpPort: configManager.getConfig('mail:smtpPort'),
|
|
|
|
|
- smtpUser: configManager.getConfig('mail:smtpUser'),
|
|
|
|
|
- smtpPassword: configManager.getConfig('mail:smtpPassword'),
|
|
|
|
|
- sesAccessKeyId: configManager.getConfig('mail:sesAccessKeyId'),
|
|
|
|
|
- sesSecretAccessKey: configManager.getConfig('mail:sesSecretAccessKey'),
|
|
|
|
|
-
|
|
|
|
|
- fileUploadType: configManager.getConfig('app:fileUploadType'),
|
|
|
|
|
- envFileUploadType: configManager.getConfig('app:fileUploadType', ConfigSource.env),
|
|
|
|
|
- useOnlyEnvVarForFileUploadType: configManager.getConfig('env:useOnlyEnvVars:app:fileUploadType'),
|
|
|
|
|
-
|
|
|
|
|
- s3Region: configManager.getConfig('aws:s3Region'),
|
|
|
|
|
- s3CustomEndpoint: configManager.getConfig('aws:s3CustomEndpoint'),
|
|
|
|
|
- s3Bucket: configManager.getConfig('aws:s3Bucket'),
|
|
|
|
|
- s3AccessKeyId: configManager.getConfig('aws:s3AccessKeyId'),
|
|
|
|
|
- s3ReferenceFileWithRelayMode: configManager.getConfig('aws:referenceFileWithRelayMode'),
|
|
|
|
|
-
|
|
|
|
|
- gcsUseOnlyEnvVars: configManager.getConfig('env:useOnlyEnvVars:gcs'),
|
|
|
|
|
- gcsApiKeyJsonPath: configManager.getConfig('gcs:apiKeyJsonPath'),
|
|
|
|
|
- gcsBucket: configManager.getConfig('gcs:bucket'),
|
|
|
|
|
- gcsUploadNamespace: configManager.getConfig('gcs:uploadNamespace'),
|
|
|
|
|
- gcsReferenceFileWithRelayMode: configManager.getConfig('gcs:referenceFileWithRelayMode'),
|
|
|
|
|
-
|
|
|
|
|
- envGcsApiKeyJsonPath: configManager.getConfig('gcs:apiKeyJsonPath', ConfigSource.env),
|
|
|
|
|
- envGcsBucket: configManager.getConfig('gcs:bucket', ConfigSource.env),
|
|
|
|
|
- envGcsUploadNamespace: configManager.getConfig('gcs:uploadNamespace', ConfigSource.env),
|
|
|
|
|
-
|
|
|
|
|
- azureUseOnlyEnvVars: configManager.getConfig('env:useOnlyEnvVars:azure'),
|
|
|
|
|
- azureTenantId: configManager.getConfig('azure:tenantId', ConfigSource.db),
|
|
|
|
|
- azureClientId: configManager.getConfig('azure:clientId', ConfigSource.db),
|
|
|
|
|
- azureClientSecret: configManager.getConfig('azure:clientSecret', ConfigSource.db),
|
|
|
|
|
- azureStorageAccountName: configManager.getConfig('azure:storageAccountName', ConfigSource.db),
|
|
|
|
|
- azureStorageContainerName: configManager.getConfig('azure:storageContainerName', ConfigSource.db),
|
|
|
|
|
- azureReferenceFileWithRelayMode: configManager.getConfig('azure:referenceFileWithRelayMode'),
|
|
|
|
|
-
|
|
|
|
|
- envAzureTenantId: configManager.getConfig('azure:tenantId', ConfigSource.env),
|
|
|
|
|
- envAzureClientId: configManager.getConfig('azure:clientId', ConfigSource.env),
|
|
|
|
|
- envAzureClientSecret: configManager.getConfig('azure:clientSecret', ConfigSource.env),
|
|
|
|
|
- envAzureStorageAccountName: configManager.getConfig('azure:storageAccountName', ConfigSource.env),
|
|
|
|
|
- envAzureStorageContainerName: configManager.getConfig('azure:storageContainerName', ConfigSource.env),
|
|
|
|
|
-
|
|
|
|
|
- isMaintenanceMode: configManager.getConfig('app:isMaintenanceMode'),
|
|
|
|
|
-
|
|
|
|
|
- isBulkExportPagesEnabled: configManager.getConfig('app:isBulkExportPagesEnabled'),
|
|
|
|
|
- envIsBulkExportPagesEnabled: configManager.getConfig('app:isBulkExportPagesEnabled'),
|
|
|
|
|
- bulkExportDownloadExpirationSeconds: configManager.getConfig('app:bulkExportDownloadExpirationSeconds'),
|
|
|
|
|
- // TODO: remove this property when bulk export can be relased for cloud (https://redmine.weseek.co.jp/issues/163220)
|
|
|
|
|
- isBulkExportDisabledForCloud: configManager.getConfig('app:growiCloudUri') != null,
|
|
|
|
|
- };
|
|
|
|
|
- return res.apiv3({ appSettingsParams });
|
|
|
|
|
-
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ router.get(
|
|
|
|
|
+ '/',
|
|
|
|
|
+ accessTokenParser([SCOPE.READ.ADMIN.APP], { acceptLegacy: true }),
|
|
|
|
|
+ loginRequiredStrictly,
|
|
|
|
|
+ adminRequired,
|
|
|
|
|
+ async (req, res) => {
|
|
|
|
|
+ const appSettingsParams = {
|
|
|
|
|
+ title: configManager.getConfig('app:title'),
|
|
|
|
|
+ confidential: configManager.getConfig('app:confidential'),
|
|
|
|
|
+ globalLang: configManager.getConfig('app:globalLang'),
|
|
|
|
|
+ isEmailPublishedForNewUser: configManager.getConfig(
|
|
|
|
|
+ 'customize:isEmailPublishedForNewUser',
|
|
|
|
|
+ ),
|
|
|
|
|
+ fileUpload: configManager.getConfig('app:fileUpload'),
|
|
|
|
|
+ useOnlyEnvVarsForIsBulkExportPagesEnabled: configManager.getConfig(
|
|
|
|
|
+ 'env:useOnlyEnvVars:app:isBulkExportPagesEnabled',
|
|
|
|
|
+ ),
|
|
|
|
|
+ isV5Compatible: configManager.getConfig('app:isV5Compatible'),
|
|
|
|
|
+ siteUrl: configManager.getConfig('app:siteUrl'),
|
|
|
|
|
+ siteUrlUseOnlyEnvVars: configManager.getConfig(
|
|
|
|
|
+ 'env:useOnlyEnvVars:app:siteUrl',
|
|
|
|
|
+ ),
|
|
|
|
|
+ envSiteUrl: configManager.getConfig('app:siteUrl', ConfigSource.env),
|
|
|
|
|
+ isMailerSetup: crowi.mailService.isMailerSetup,
|
|
|
|
|
+ fromAddress: configManager.getConfig('mail:from'),
|
|
|
|
|
+
|
|
|
|
|
+ transmissionMethod: configManager.getConfig('mail:transmissionMethod'),
|
|
|
|
|
+ smtpHost: configManager.getConfig('mail:smtpHost'),
|
|
|
|
|
+ smtpPort: configManager.getConfig('mail:smtpPort'),
|
|
|
|
|
+ smtpUser: configManager.getConfig('mail:smtpUser'),
|
|
|
|
|
+ smtpPassword: configManager.getConfig('mail:smtpPassword'),
|
|
|
|
|
+ sesAccessKeyId: configManager.getConfig('mail:sesAccessKeyId'),
|
|
|
|
|
+ sesSecretAccessKey: configManager.getConfig('mail:sesSecretAccessKey'),
|
|
|
|
|
+
|
|
|
|
|
+ fileUploadType: configManager.getConfig('app:fileUploadType'),
|
|
|
|
|
+ envFileUploadType: configManager.getConfig(
|
|
|
|
|
+ 'app:fileUploadType',
|
|
|
|
|
+ ConfigSource.env,
|
|
|
|
|
+ ),
|
|
|
|
|
+ useOnlyEnvVarForFileUploadType: configManager.getConfig(
|
|
|
|
|
+ 'env:useOnlyEnvVars:app:fileUploadType',
|
|
|
|
|
+ ),
|
|
|
|
|
+
|
|
|
|
|
+ s3Region: configManager.getConfig('aws:s3Region'),
|
|
|
|
|
+ s3CustomEndpoint: configManager.getConfig('aws:s3CustomEndpoint'),
|
|
|
|
|
+ s3Bucket: configManager.getConfig('aws:s3Bucket'),
|
|
|
|
|
+ s3AccessKeyId: configManager.getConfig('aws:s3AccessKeyId'),
|
|
|
|
|
+ s3ReferenceFileWithRelayMode: configManager.getConfig(
|
|
|
|
|
+ 'aws:referenceFileWithRelayMode',
|
|
|
|
|
+ ),
|
|
|
|
|
+
|
|
|
|
|
+ gcsUseOnlyEnvVars: configManager.getConfig('env:useOnlyEnvVars:gcs'),
|
|
|
|
|
+ gcsApiKeyJsonPath: configManager.getConfig('gcs:apiKeyJsonPath'),
|
|
|
|
|
+ gcsBucket: configManager.getConfig('gcs:bucket'),
|
|
|
|
|
+ gcsUploadNamespace: configManager.getConfig('gcs:uploadNamespace'),
|
|
|
|
|
+ gcsReferenceFileWithRelayMode: configManager.getConfig(
|
|
|
|
|
+ 'gcs:referenceFileWithRelayMode',
|
|
|
|
|
+ ),
|
|
|
|
|
+
|
|
|
|
|
+ envGcsApiKeyJsonPath: configManager.getConfig(
|
|
|
|
|
+ 'gcs:apiKeyJsonPath',
|
|
|
|
|
+ ConfigSource.env,
|
|
|
|
|
+ ),
|
|
|
|
|
+ envGcsBucket: configManager.getConfig('gcs:bucket', ConfigSource.env),
|
|
|
|
|
+ envGcsUploadNamespace: configManager.getConfig(
|
|
|
|
|
+ 'gcs:uploadNamespace',
|
|
|
|
|
+ ConfigSource.env,
|
|
|
|
|
+ ),
|
|
|
|
|
+
|
|
|
|
|
+ azureUseOnlyEnvVars: configManager.getConfig(
|
|
|
|
|
+ 'env:useOnlyEnvVars:azure',
|
|
|
|
|
+ ),
|
|
|
|
|
+ azureTenantId: configManager.getConfig(
|
|
|
|
|
+ 'azure:tenantId',
|
|
|
|
|
+ ConfigSource.db,
|
|
|
|
|
+ ),
|
|
|
|
|
+ azureClientId: configManager.getConfig(
|
|
|
|
|
+ 'azure:clientId',
|
|
|
|
|
+ ConfigSource.db,
|
|
|
|
|
+ ),
|
|
|
|
|
+ azureClientSecret: configManager.getConfig(
|
|
|
|
|
+ 'azure:clientSecret',
|
|
|
|
|
+ ConfigSource.db,
|
|
|
|
|
+ ),
|
|
|
|
|
+ azureStorageAccountName: configManager.getConfig(
|
|
|
|
|
+ 'azure:storageAccountName',
|
|
|
|
|
+ ConfigSource.db,
|
|
|
|
|
+ ),
|
|
|
|
|
+ azureStorageContainerName: configManager.getConfig(
|
|
|
|
|
+ 'azure:storageContainerName',
|
|
|
|
|
+ ConfigSource.db,
|
|
|
|
|
+ ),
|
|
|
|
|
+ azureReferenceFileWithRelayMode: configManager.getConfig(
|
|
|
|
|
+ 'azure:referenceFileWithRelayMode',
|
|
|
|
|
+ ),
|
|
|
|
|
+
|
|
|
|
|
+ envAzureTenantId: configManager.getConfig(
|
|
|
|
|
+ 'azure:tenantId',
|
|
|
|
|
+ ConfigSource.env,
|
|
|
|
|
+ ),
|
|
|
|
|
+ envAzureClientId: configManager.getConfig(
|
|
|
|
|
+ 'azure:clientId',
|
|
|
|
|
+ ConfigSource.env,
|
|
|
|
|
+ ),
|
|
|
|
|
+ envAzureClientSecret: configManager.getConfig(
|
|
|
|
|
+ 'azure:clientSecret',
|
|
|
|
|
+ ConfigSource.env,
|
|
|
|
|
+ ),
|
|
|
|
|
+ envAzureStorageAccountName: configManager.getConfig(
|
|
|
|
|
+ 'azure:storageAccountName',
|
|
|
|
|
+ ConfigSource.env,
|
|
|
|
|
+ ),
|
|
|
|
|
+ envAzureStorageContainerName: configManager.getConfig(
|
|
|
|
|
+ 'azure:storageContainerName',
|
|
|
|
|
+ ConfigSource.env,
|
|
|
|
|
+ ),
|
|
|
|
|
+
|
|
|
|
|
+ isMaintenanceMode: configManager.getConfig('app:isMaintenanceMode'),
|
|
|
|
|
+
|
|
|
|
|
+ isBulkExportPagesEnabled: configManager.getConfig(
|
|
|
|
|
+ 'app:isBulkExportPagesEnabled',
|
|
|
|
|
+ ),
|
|
|
|
|
+ envIsBulkExportPagesEnabled: configManager.getConfig(
|
|
|
|
|
+ 'app:isBulkExportPagesEnabled',
|
|
|
|
|
+ ),
|
|
|
|
|
+ bulkExportDownloadExpirationSeconds: configManager.getConfig(
|
|
|
|
|
+ 'app:bulkExportDownloadExpirationSeconds',
|
|
|
|
|
+ ),
|
|
|
|
|
+ };
|
|
|
|
|
+ return res.apiv3({ appSettingsParams });
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @swagger
|
|
* @swagger
|
|
@@ -477,14 +549,21 @@ module.exports = (crowi) => {
|
|
|
* type: object
|
|
* type: object
|
|
|
* $ref: '#/components/schemas/AppSettingPutParams'
|
|
* $ref: '#/components/schemas/AppSettingPutParams'
|
|
|
*/
|
|
*/
|
|
|
- router.put('/app-setting', accessTokenParser([SCOPE.WRITE.ADMIN.APP]), loginRequiredStrictly, adminRequired, addActivity,
|
|
|
|
|
- validator.appSetting, apiV3FormValidator,
|
|
|
|
|
- async(req, res) => {
|
|
|
|
|
|
|
+ router.put(
|
|
|
|
|
+ '/app-setting',
|
|
|
|
|
+ accessTokenParser([SCOPE.WRITE.ADMIN.APP]),
|
|
|
|
|
+ loginRequiredStrictly,
|
|
|
|
|
+ adminRequired,
|
|
|
|
|
+ addActivity,
|
|
|
|
|
+ validator.appSetting,
|
|
|
|
|
+ apiV3FormValidator,
|
|
|
|
|
+ async (req, res) => {
|
|
|
const requestAppSettingParams = {
|
|
const requestAppSettingParams = {
|
|
|
'app:title': req.body.title,
|
|
'app:title': req.body.title,
|
|
|
'app:confidential': req.body.confidential,
|
|
'app:confidential': req.body.confidential,
|
|
|
'app:globalLang': req.body.globalLang,
|
|
'app:globalLang': req.body.globalLang,
|
|
|
- 'customize:isEmailPublishedForNewUser': req.body.isEmailPublishedForNewUser,
|
|
|
|
|
|
|
+ 'customize:isEmailPublishedForNewUser':
|
|
|
|
|
+ req.body.isEmailPublishedForNewUser,
|
|
|
'app:fileUpload': req.body.fileUpload,
|
|
'app:fileUpload': req.body.fileUpload,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -494,22 +573,25 @@ module.exports = (crowi) => {
|
|
|
title: configManager.getConfig('app:title'),
|
|
title: configManager.getConfig('app:title'),
|
|
|
confidential: configManager.getConfig('app:confidential'),
|
|
confidential: configManager.getConfig('app:confidential'),
|
|
|
globalLang: configManager.getConfig('app:globalLang'),
|
|
globalLang: configManager.getConfig('app:globalLang'),
|
|
|
- isEmailPublishedForNewUser: configManager.getConfig('customize:isEmailPublishedForNewUser'),
|
|
|
|
|
|
|
+ isEmailPublishedForNewUser: configManager.getConfig(
|
|
|
|
|
+ 'customize:isEmailPublishedForNewUser',
|
|
|
|
|
+ ),
|
|
|
fileUpload: configManager.getConfig('app:fileUpload'),
|
|
fileUpload: configManager.getConfig('app:fileUpload'),
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const parameters = { action: SupportedAction.ACTION_ADMIN_APP_SETTINGS_UPDATE };
|
|
|
|
|
|
|
+ const parameters = {
|
|
|
|
|
+ action: SupportedAction.ACTION_ADMIN_APP_SETTINGS_UPDATE,
|
|
|
|
|
+ };
|
|
|
activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
|
|
|
|
|
|
return res.apiv3({ appSettingParams });
|
|
return res.apiv3({ appSettingParams });
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
|
|
+ } catch (err) {
|
|
|
const msg = 'Error occurred in updating app setting';
|
|
const msg = 'Error occurred in updating app setting';
|
|
|
logger.error('Error', err);
|
|
logger.error('Error', err);
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'update-appSetting-failed'));
|
|
return res.apiv3Err(new ErrorV3(msg, 'update-appSetting-failed'));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @swagger
|
|
* @swagger
|
|
@@ -543,14 +625,24 @@ module.exports = (crowi) => {
|
|
|
* description: Site URL. e.g. https://example.com, https://example.com:3000
|
|
* description: Site URL. e.g. https://example.com, https://example.com:3000
|
|
|
* example: 'http://localhost:3000'
|
|
* example: 'http://localhost:3000'
|
|
|
*/
|
|
*/
|
|
|
- router.put('/site-url-setting', accessTokenParser([SCOPE.WRITE.ADMIN.APP]), loginRequiredStrictly, adminRequired, addActivity,
|
|
|
|
|
- validator.siteUrlSetting, apiV3FormValidator,
|
|
|
|
|
- async(req, res) => {
|
|
|
|
|
- const useOnlyEnvVars = configManager.getConfig('env:useOnlyEnvVars:app:siteUrl');
|
|
|
|
|
|
|
+ router.put(
|
|
|
|
|
+ '/site-url-setting',
|
|
|
|
|
+ accessTokenParser([SCOPE.WRITE.ADMIN.APP]),
|
|
|
|
|
+ loginRequiredStrictly,
|
|
|
|
|
+ adminRequired,
|
|
|
|
|
+ addActivity,
|
|
|
|
|
+ validator.siteUrlSetting,
|
|
|
|
|
+ apiV3FormValidator,
|
|
|
|
|
+ async (req, res) => {
|
|
|
|
|
+ const useOnlyEnvVars = configManager.getConfig(
|
|
|
|
|
+ 'env:useOnlyEnvVars:app:siteUrl',
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
if (useOnlyEnvVars) {
|
|
if (useOnlyEnvVars) {
|
|
|
const msg = 'Updating the Site URL is prohibited on this system.';
|
|
const msg = 'Updating the Site URL is prohibited on this system.';
|
|
|
- return res.apiv3Err(new ErrorV3(msg, 'update-siteUrlSetting-prohibited'));
|
|
|
|
|
|
|
+ return res.apiv3Err(
|
|
|
|
|
+ new ErrorV3(msg, 'update-siteUrlSetting-prohibited'),
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const requestSiteUrlSettingParams = {
|
|
const requestSiteUrlSettingParams = {
|
|
@@ -563,17 +655,18 @@ module.exports = (crowi) => {
|
|
|
siteUrl: configManager.getConfig('app:siteUrl'),
|
|
siteUrl: configManager.getConfig('app:siteUrl'),
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const parameters = { action: SupportedAction.ACTION_ADMIN_SITE_URL_UPDATE };
|
|
|
|
|
|
|
+ const parameters = {
|
|
|
|
|
+ action: SupportedAction.ACTION_ADMIN_SITE_URL_UPDATE,
|
|
|
|
|
+ };
|
|
|
activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
|
return res.apiv3({ siteUrlSettingParams });
|
|
return res.apiv3({ siteUrlSettingParams });
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
|
|
+ } catch (err) {
|
|
|
const msg = 'Error occurred in updating site url setting';
|
|
const msg = 'Error occurred in updating site url setting';
|
|
|
logger.error('Error', err);
|
|
logger.error('Error', err);
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'update-siteUrlSetting-failed'));
|
|
return res.apiv3Err(new ErrorV3(msg, 'update-siteUrlSetting-failed'));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* send mail (Promise wrapper)
|
|
* send mail (Promise wrapper)
|
|
@@ -583,8 +676,7 @@ module.exports = (crowi) => {
|
|
|
smtpClient.sendMail(options, (err, res) => {
|
|
smtpClient.sendMail(options, (err, res) => {
|
|
|
if (err) {
|
|
if (err) {
|
|
|
reject(err);
|
|
reject(err);
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
|
|
+ } else {
|
|
|
resolve(res);
|
|
resolve(res);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -595,7 +687,6 @@ module.exports = (crowi) => {
|
|
|
* validate mail setting send test mail
|
|
* validate mail setting send test mail
|
|
|
*/
|
|
*/
|
|
|
async function sendTestEmail(destinationAddress) {
|
|
async function sendTestEmail(destinationAddress) {
|
|
|
-
|
|
|
|
|
const { mailService } = crowi;
|
|
const { mailService } = crowi;
|
|
|
|
|
|
|
|
if (!mailService.isMailerSetup) {
|
|
if (!mailService.isMailerSetup) {
|
|
@@ -645,13 +736,13 @@ module.exports = (crowi) => {
|
|
|
await sendMailPromiseWrapper(smtpClient, mailOptions);
|
|
await sendMailPromiseWrapper(smtpClient, mailOptions);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const updateMailSettinConfig = async function(requestMailSettingParams) {
|
|
|
|
|
- const {
|
|
|
|
|
- mailService,
|
|
|
|
|
- } = crowi;
|
|
|
|
|
|
|
+ const updateMailSettinConfig = async (requestMailSettingParams) => {
|
|
|
|
|
+ const { mailService } = crowi;
|
|
|
|
|
|
|
|
// update config without publishing S2sMessage
|
|
// update config without publishing S2sMessage
|
|
|
- await configManager.updateConfigs(requestMailSettingParams, { skipPubsub: true });
|
|
|
|
|
|
|
+ await configManager.updateConfigs(requestMailSettingParams, {
|
|
|
|
|
+ skipPubsub: true,
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
await mailService.initialize();
|
|
await mailService.initialize();
|
|
|
mailService.publishUpdatedMessage();
|
|
mailService.publishUpdatedMessage();
|
|
@@ -696,9 +787,15 @@ module.exports = (crowi) => {
|
|
|
* type: object
|
|
* type: object
|
|
|
* $ref: '#/components/schemas/SmtpSettingResponseParams'
|
|
* $ref: '#/components/schemas/SmtpSettingResponseParams'
|
|
|
*/
|
|
*/
|
|
|
- router.put('/smtp-setting', accessTokenParser([SCOPE.WRITE.ADMIN.APP]), loginRequiredStrictly, adminRequired, addActivity,
|
|
|
|
|
- validator.smtpSetting, apiV3FormValidator,
|
|
|
|
|
- async(req, res) => {
|
|
|
|
|
|
|
+ router.put(
|
|
|
|
|
+ '/smtp-setting',
|
|
|
|
|
+ accessTokenParser([SCOPE.WRITE.ADMIN.APP]),
|
|
|
|
|
+ loginRequiredStrictly,
|
|
|
|
|
+ adminRequired,
|
|
|
|
|
+ addActivity,
|
|
|
|
|
+ validator.smtpSetting,
|
|
|
|
|
+ apiV3FormValidator,
|
|
|
|
|
+ async (req, res) => {
|
|
|
const requestMailSettingParams = {
|
|
const requestMailSettingParams = {
|
|
|
'mail:from': req.body.fromAddress,
|
|
'mail:from': req.body.fromAddress,
|
|
|
'mail:transmissionMethod': req.body.transmissionMethod,
|
|
'mail:transmissionMethod': req.body.transmissionMethod,
|
|
@@ -709,17 +806,21 @@ module.exports = (crowi) => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- const mailSettingParams = await updateMailSettinConfig(requestMailSettingParams);
|
|
|
|
|
- const parameters = { action: SupportedAction.ACTION_ADMIN_MAIL_SMTP_UPDATE };
|
|
|
|
|
|
|
+ const mailSettingParams = await updateMailSettinConfig(
|
|
|
|
|
+ requestMailSettingParams,
|
|
|
|
|
+ );
|
|
|
|
|
+ const parameters = {
|
|
|
|
|
+ action: SupportedAction.ACTION_ADMIN_MAIL_SMTP_UPDATE,
|
|
|
|
|
+ };
|
|
|
activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
|
return res.apiv3({ mailSettingParams });
|
|
return res.apiv3({ mailSettingParams });
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
|
|
+ } catch (err) {
|
|
|
const msg = 'Error occurred in updating smtp setting';
|
|
const msg = 'Error occurred in updating smtp setting';
|
|
|
logger.error('Error', err);
|
|
logger.error('Error', err);
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'update-smtpSetting-failed'));
|
|
return res.apiv3Err(new ErrorV3(msg, 'update-smtpSetting-failed'));
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @swagger
|
|
* @swagger
|
|
@@ -740,22 +841,30 @@ module.exports = (crowi) => {
|
|
|
* type: object
|
|
* type: object
|
|
|
* description: Empty object
|
|
* description: Empty object
|
|
|
*/
|
|
*/
|
|
|
- router.post('/smtp-test', accessTokenParser([SCOPE.WRITE.ADMIN.APP]), loginRequiredStrictly, adminRequired, addActivity, async(req, res) => {
|
|
|
|
|
- const { t } = await getTranslation({ lang: req.user.lang });
|
|
|
|
|
|
|
+ router.post(
|
|
|
|
|
+ '/smtp-test',
|
|
|
|
|
+ accessTokenParser([SCOPE.WRITE.ADMIN.APP]),
|
|
|
|
|
+ loginRequiredStrictly,
|
|
|
|
|
+ adminRequired,
|
|
|
|
|
+ addActivity,
|
|
|
|
|
+ async (req, res) => {
|
|
|
|
|
+ const { t } = await getTranslation({ lang: req.user.lang });
|
|
|
|
|
|
|
|
- try {
|
|
|
|
|
- await sendTestEmail(req.user.email);
|
|
|
|
|
- const parameters = { action: SupportedAction.ACTION_ADMIN_MAIL_TEST_SUBMIT };
|
|
|
|
|
- activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
|
|
|
- return res.apiv3({});
|
|
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
- const msg = t('validation.failed_to_send_a_test_email');
|
|
|
|
|
- logger.error('Error', err);
|
|
|
|
|
- logger.debug('Error validate mail setting: ', err);
|
|
|
|
|
- return res.apiv3Err(new ErrorV3(msg, 'send-email-with-smtp-failed'));
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ await sendTestEmail(req.user.email);
|
|
|
|
|
+ const parameters = {
|
|
|
|
|
+ action: SupportedAction.ACTION_ADMIN_MAIL_TEST_SUBMIT,
|
|
|
|
|
+ };
|
|
|
|
|
+ activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
|
|
|
+ return res.apiv3({});
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ const msg = t('validation.failed_to_send_a_test_email');
|
|
|
|
|
+ logger.error('Error', err);
|
|
|
|
|
+ logger.debug('Error validate mail setting: ', err);
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'send-email-with-smtp-failed'));
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @swagger
|
|
* @swagger
|
|
@@ -781,9 +890,15 @@ module.exports = (crowi) => {
|
|
|
* schema:
|
|
* schema:
|
|
|
* $ref: '#/components/schemas/SesSettingResponseParams'
|
|
* $ref: '#/components/schemas/SesSettingResponseParams'
|
|
|
*/
|
|
*/
|
|
|
- router.put('/ses-setting', accessTokenParser([SCOPE.WRITE.ADMIN.APP]), loginRequiredStrictly, adminRequired, addActivity,
|
|
|
|
|
- validator.sesSetting, apiV3FormValidator,
|
|
|
|
|
- async(req, res) => {
|
|
|
|
|
|
|
+ router.put(
|
|
|
|
|
+ '/ses-setting',
|
|
|
|
|
+ accessTokenParser([SCOPE.WRITE.ADMIN.APP]),
|
|
|
|
|
+ loginRequiredStrictly,
|
|
|
|
|
+ adminRequired,
|
|
|
|
|
+ addActivity,
|
|
|
|
|
+ validator.sesSetting,
|
|
|
|
|
+ apiV3FormValidator,
|
|
|
|
|
+ async (req, res) => {
|
|
|
const { mailService } = crowi;
|
|
const { mailService } = crowi;
|
|
|
|
|
|
|
|
const requestSesSettingParams = {
|
|
const requestSesSettingParams = {
|
|
@@ -793,11 +908,12 @@ module.exports = (crowi) => {
|
|
|
'mail:sesSecretAccessKey': req.body.sesSecretAccessKey,
|
|
'mail:sesSecretAccessKey': req.body.sesSecretAccessKey,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- let mailSettingParams;
|
|
|
|
|
|
|
+ let mailSettingParams: Awaited<ReturnType<typeof updateMailSettinConfig>>;
|
|
|
try {
|
|
try {
|
|
|
- mailSettingParams = await updateMailSettinConfig(requestSesSettingParams);
|
|
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
|
|
+ mailSettingParams = await updateMailSettinConfig(
|
|
|
|
|
+ requestSesSettingParams,
|
|
|
|
|
+ );
|
|
|
|
|
+ } catch (err) {
|
|
|
const msg = 'Error occurred in updating ses setting';
|
|
const msg = 'Error occurred in updating ses setting';
|
|
|
logger.error('Error', err);
|
|
logger.error('Error', err);
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'update-ses-setting-failed'));
|
|
return res.apiv3Err(new ErrorV3(msg, 'update-ses-setting-failed'));
|
|
@@ -805,41 +921,57 @@ module.exports = (crowi) => {
|
|
|
|
|
|
|
|
await mailService.initialize();
|
|
await mailService.initialize();
|
|
|
mailService.publishUpdatedMessage();
|
|
mailService.publishUpdatedMessage();
|
|
|
- const parameters = { action: SupportedAction.ACTION_ADMIN_MAIL_SES_UPDATE };
|
|
|
|
|
|
|
+ const parameters = {
|
|
|
|
|
+ action: SupportedAction.ACTION_ADMIN_MAIL_SES_UPDATE,
|
|
|
|
|
+ };
|
|
|
activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
|
return res.apiv3({ mailSettingParams });
|
|
return res.apiv3({ mailSettingParams });
|
|
|
- });
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
router.use('/file-upload-setting', require('./file-upload-setting')(crowi));
|
|
router.use('/file-upload-setting', require('./file-upload-setting')(crowi));
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- router.put('/page-bulk-export-settings',
|
|
|
|
|
- accessTokenParser([SCOPE.WRITE.ADMIN.APP]), loginRequiredStrictly, adminRequired, addActivity, validator.pageBulkExportSettings, apiV3FormValidator,
|
|
|
|
|
- async(req, res) => {
|
|
|
|
|
|
|
+ router.put(
|
|
|
|
|
+ '/page-bulk-export-settings',
|
|
|
|
|
+ accessTokenParser([SCOPE.WRITE.ADMIN.APP]),
|
|
|
|
|
+ loginRequiredStrictly,
|
|
|
|
|
+ adminRequired,
|
|
|
|
|
+ addActivity,
|
|
|
|
|
+ validator.pageBulkExportSettings,
|
|
|
|
|
+ apiV3FormValidator,
|
|
|
|
|
+ async (req, res) => {
|
|
|
const requestParams = {
|
|
const requestParams = {
|
|
|
'app:isBulkExportPagesEnabled': req.body.isBulkExportPagesEnabled,
|
|
'app:isBulkExportPagesEnabled': req.body.isBulkExportPagesEnabled,
|
|
|
- 'app:bulkExportDownloadExpirationSeconds': req.body.bulkExportDownloadExpirationSeconds,
|
|
|
|
|
|
|
+ 'app:bulkExportDownloadExpirationSeconds':
|
|
|
|
|
+ req.body.bulkExportDownloadExpirationSeconds,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
await configManager.updateConfigs(requestParams, { skipPubsub: true });
|
|
await configManager.updateConfigs(requestParams, { skipPubsub: true });
|
|
|
const responseParams = {
|
|
const responseParams = {
|
|
|
- isBulkExportPagesEnabled: configManager.getConfig('app:isBulkExportPagesEnabled'),
|
|
|
|
|
- bulkExportDownloadExpirationSeconds: configManager.getConfig('app:bulkExportDownloadExpirationSeconds'),
|
|
|
|
|
|
|
+ isBulkExportPagesEnabled: configManager.getConfig(
|
|
|
|
|
+ 'app:isBulkExportPagesEnabled',
|
|
|
|
|
+ ),
|
|
|
|
|
+ bulkExportDownloadExpirationSeconds: configManager.getConfig(
|
|
|
|
|
+ 'app:bulkExportDownloadExpirationSeconds',
|
|
|
|
|
+ ),
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const parameters = { action: SupportedAction.ACTION_ADMIN_APP_SETTINGS_UPDATE };
|
|
|
|
|
|
|
+ const parameters = {
|
|
|
|
|
+ action: SupportedAction.ACTION_ADMIN_APP_SETTINGS_UPDATE,
|
|
|
|
|
+ };
|
|
|
activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
|
|
|
|
|
|
return res.apiv3({ responseParams });
|
|
return res.apiv3({ responseParams });
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
|
|
+ } catch (err) {
|
|
|
const msg = 'Error occurred in updating page bulk export settings';
|
|
const msg = 'Error occurred in updating page bulk export settings';
|
|
|
logger.error('Error', err);
|
|
logger.error('Error', err);
|
|
|
- return res.apiv3Err(new ErrorV3(msg, 'update-page-bulk-export-settings-failed'));
|
|
|
|
|
|
|
+ return res.apiv3Err(
|
|
|
|
|
+ new ErrorV3(msg, 'update-page-bulk-export-settings-failed'),
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @swagger
|
|
* @swagger
|
|
@@ -865,27 +997,39 @@ module.exports = (crowi) => {
|
|
|
* description: is V5 compatible, or not
|
|
* description: is V5 compatible, or not
|
|
|
* example: true
|
|
* example: true
|
|
|
*/
|
|
*/
|
|
|
- router.post('/v5-schema-migration',
|
|
|
|
|
- accessTokenParser([SCOPE.WRITE.ADMIN.APP], { acceptLegacy: true }), loginRequiredStrictly, adminRequired, async(req, res) => {
|
|
|
|
|
|
|
+ router.post(
|
|
|
|
|
+ '/v5-schema-migration',
|
|
|
|
|
+ accessTokenParser([SCOPE.WRITE.ADMIN.APP], { acceptLegacy: true }),
|
|
|
|
|
+ loginRequiredStrictly,
|
|
|
|
|
+ adminRequired,
|
|
|
|
|
+ async (req, res) => {
|
|
|
const isMaintenanceMode = crowi.appService.isMaintenanceMode();
|
|
const isMaintenanceMode = crowi.appService.isMaintenanceMode();
|
|
|
if (!isMaintenanceMode) {
|
|
if (!isMaintenanceMode) {
|
|
|
- return res.apiv3Err(new ErrorV3('GROWI is not maintenance mode. To import data, please activate the maintenance mode first.', 'not_maintenance_mode'));
|
|
|
|
|
|
|
+ return res.apiv3Err(
|
|
|
|
|
+ new ErrorV3(
|
|
|
|
|
+ 'GROWI is not maintenance mode. To import data, please activate the maintenance mode first.',
|
|
|
|
|
+ 'not_maintenance_mode',
|
|
|
|
|
+ ),
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const isV5Compatible = configManager.getConfig('app:isV5Compatible');
|
|
const isV5Compatible = configManager.getConfig('app:isV5Compatible');
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
if (!isV5Compatible) {
|
|
if (!isV5Compatible) {
|
|
|
- // This method throws and emit socketIo event when error occurs
|
|
|
|
|
|
|
+ // This method throws and emit socketIo event when error occurs
|
|
|
crowi.pageService.normalizeAllPublicPages();
|
|
crowi.pageService.normalizeAllPublicPages();
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
- return res.apiv3Err(new ErrorV3(`Failed to migrate pages: ${err.message}`), 500);
|
|
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ return res.apiv3Err(
|
|
|
|
|
+ new ErrorV3(`Failed to migrate pages: ${err.message}`),
|
|
|
|
|
+ 500,
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return res.apiv3({ isV5Compatible });
|
|
return res.apiv3({ isV5Compatible });
|
|
|
- });
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @swagger
|
|
* @swagger
|
|
@@ -920,28 +1064,47 @@ module.exports = (crowi) => {
|
|
|
* description: true if maintenance mode is enabled
|
|
* description: true if maintenance mode is enabled
|
|
|
* example: true
|
|
* example: true
|
|
|
*/
|
|
*/
|
|
|
- router.post('/maintenance-mode',
|
|
|
|
|
|
|
+ router.post(
|
|
|
|
|
+ '/maintenance-mode',
|
|
|
accessTokenParser([SCOPE.WRITE.ADMIN.APP], { acceptLegacy: true }),
|
|
accessTokenParser([SCOPE.WRITE.ADMIN.APP], { acceptLegacy: true }),
|
|
|
- loginRequiredStrictly, adminRequired, addActivity, validator.maintenanceMode, apiV3FormValidator, async(req, res) => {
|
|
|
|
|
|
|
+ loginRequiredStrictly,
|
|
|
|
|
+ adminRequired,
|
|
|
|
|
+ addActivity,
|
|
|
|
|
+ validator.maintenanceMode,
|
|
|
|
|
+ apiV3FormValidator,
|
|
|
|
|
+ async (req, res) => {
|
|
|
const { flag } = req.body;
|
|
const { flag } = req.body;
|
|
|
const parameters = {};
|
|
const parameters = {};
|
|
|
try {
|
|
try {
|
|
|
if (flag) {
|
|
if (flag) {
|
|
|
await crowi.appService.startMaintenanceMode();
|
|
await crowi.appService.startMaintenanceMode();
|
|
|
- Object.assign(parameters, { action: SupportedAction.ACTION_ADMIN_MAINTENANCEMODE_ENABLED });
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
|
|
+ Object.assign(parameters, {
|
|
|
|
|
+ action: SupportedAction.ACTION_ADMIN_MAINTENANCEMODE_ENABLED,
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
await crowi.appService.endMaintenanceMode();
|
|
await crowi.appService.endMaintenanceMode();
|
|
|
- Object.assign(parameters, { action: SupportedAction.ACTION_ADMIN_MAINTENANCEMODE_DISABLED });
|
|
|
|
|
|
|
+ Object.assign(parameters, {
|
|
|
|
|
+ action: SupportedAction.ACTION_ADMIN_MAINTENANCEMODE_DISABLED,
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
|
|
+ } catch (err) {
|
|
|
logger.error(err);
|
|
logger.error(err);
|
|
|
if (flag) {
|
|
if (flag) {
|
|
|
- res.apiv3Err(new ErrorV3('Failed to start maintenance mode', 'failed_to_start_maintenance_mode'), 500);
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- res.apiv3Err(new ErrorV3('Failed to end maintenance mode', 'failed_to_end_maintenance_mode'), 500);
|
|
|
|
|
|
|
+ res.apiv3Err(
|
|
|
|
|
+ new ErrorV3(
|
|
|
|
|
+ 'Failed to start maintenance mode',
|
|
|
|
|
+ 'failed_to_start_maintenance_mode',
|
|
|
|
|
+ ),
|
|
|
|
|
+ 500,
|
|
|
|
|
+ );
|
|
|
|
|
+ } else {
|
|
|
|
|
+ res.apiv3Err(
|
|
|
|
|
+ new ErrorV3(
|
|
|
|
|
+ 'Failed to end maintenance mode',
|
|
|
|
|
+ 'failed_to_end_maintenance_mode',
|
|
|
|
|
+ ),
|
|
|
|
|
+ 500,
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -950,7 +1113,8 @@ module.exports = (crowi) => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
res.apiv3({ flag });
|
|
res.apiv3({ flag });
|
|
|
- });
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
return router;
|
|
return router;
|
|
|
};
|
|
};
|