app-settings.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. const loggerFactory = require('@alias/logger');
  2. const logger = loggerFactory('growi:routes:apiv3:app-settings');
  3. const debug = require('debug')('growi:routes:admin');
  4. const express = require('express');
  5. const { listLocaleIds } = require('@commons/util/locale-utils');
  6. const router = express.Router();
  7. const { body } = require('express-validator');
  8. const ErrorV3 = require('../../models/vo/error-apiv3');
  9. /**
  10. * @swagger
  11. * tags:
  12. * name: AppSettings
  13. */
  14. /**
  15. * @swagger
  16. *
  17. * components:
  18. * schemas:
  19. * AppSettingParams:
  20. * description: AppSettingParams
  21. * type: object
  22. * properties:
  23. * title:
  24. * type: string
  25. * description: site name show on page header and tilte of HTML
  26. * confidential:
  27. * type: string
  28. * description: confidential show on page header
  29. * globalLang:
  30. * type: string
  31. * description: language set when create user
  32. * fileUpload:
  33. * type: boolean
  34. * description: enable upload file except image file
  35. * SiteUrlSettingParams:
  36. * description: SiteUrlSettingParams
  37. * type: object
  38. * properties:
  39. * siteUrl:
  40. * type: string
  41. * description: Site URL. e.g. https://example.com, https://example.com:8080
  42. * envSiteUrl:
  43. * type: string
  44. * description: environment variable 'APP_SITE_URL'
  45. * MailSetting:
  46. * description: MailSettingParams
  47. * type: object
  48. * properties:
  49. * fromAddress:
  50. * type: string
  51. * description: e-mail address used as from address of mail which sent from GROWI app
  52. * transmissionMethod:
  53. * type: string
  54. * description: transmission method
  55. * SmtpSettingParams:
  56. * description: SmtpSettingParams
  57. * type: object
  58. * properties:
  59. * smtpHost:
  60. * type: string
  61. * description: host name of client's smtp server
  62. * smtpPort:
  63. * type: string
  64. * description: port of client's smtp server
  65. * smtpUser:
  66. * type: string
  67. * description: user name of client's smtp server
  68. * smtpPassword:
  69. * type: string
  70. * description: password of client's smtp server
  71. * SesSettingParams:
  72. * description: SesSettingParams
  73. * type: object
  74. * properties:
  75. * accessKeyId:
  76. * type: string
  77. * description: accesskey id for authentification of AWS
  78. * secretAccessKey:
  79. * type: string
  80. * description: secret key for authentification of AWS
  81. * AwsSettingParams:
  82. * description: AwsSettingParams
  83. * type: object
  84. * properties:
  85. * region:
  86. * type: string
  87. * description: region of AWS S3
  88. * customEndpoint:
  89. * type: string
  90. * description: custom endpoint of AWS S3
  91. * bucket:
  92. * type: string
  93. * description: AWS S3 bucket name
  94. * accessKeyId:
  95. * type: string
  96. * description: accesskey id for authentification of AWS
  97. * secretAccessKey:
  98. * type: string
  99. * description: secret key for authentification of AWS
  100. * GcpSettingParams:
  101. * description: GcpSettingParams
  102. * type: object
  103. * properties:
  104. * gcsApiKeyJsonPath:
  105. * type: string
  106. * description: apiKeyJsonPath of gcp
  107. * gcsBucket:
  108. * type: string
  109. * description: bucket name of gcs
  110. * gcsUploadNamespace:
  111. * type: string
  112. * description: name space of gcs
  113. * envGcsApiKeyJsonPath:
  114. * type: string
  115. * description: Path of the JSON file that contains service account key to authenticate to GCP API
  116. * envGcsBucket:
  117. * type: string
  118. * description: Name of the GCS bucket
  119. * envGcsUploadNamespace:
  120. * type: string
  121. * description: Directory name to create in the bucket
  122. * PluginSettingParams:
  123. * description: PluginSettingParams
  124. * type: object
  125. * properties:
  126. * isEnabledPlugins:
  127. * type: string
  128. * description: enable use plugins
  129. */
  130. module.exports = (crowi) => {
  131. const accessTokenParser = require('../../middlewares/access-token-parser')(crowi);
  132. const loginRequired = require('../../middlewares/login-required')(crowi);
  133. const loginRequiredStrictly = require('../../middlewares/login-required')(crowi);
  134. const adminRequired = require('../../middlewares/admin-required')(crowi);
  135. const csrf = require('../../middlewares/csrf')(crowi);
  136. const apiV3FormValidator = require('../../middlewares/apiv3-form-validator')(crowi);
  137. const validator = {
  138. appSetting: [
  139. body('title').trim(),
  140. body('confidential'),
  141. body('globalLang').isIn(listLocaleIds()),
  142. body('fileUpload').isBoolean(),
  143. ],
  144. siteUrlSetting: [
  145. body('siteUrl').trim().matches(/^(https?:\/\/[^/]+|)$/).isURL({ require_tld: false }),
  146. ],
  147. mailSetting: [
  148. body('fromAddress').trim().if(value => value !== '').isEmail(),
  149. body('transmissionMethod').isIn(['smtp', 'ses']),
  150. ],
  151. smtpSetting: [
  152. body('smtpHost').trim(),
  153. body('smtpPort').trim().if(value => value !== '').isPort(),
  154. body('smtpUser').trim(),
  155. body('smtpPassword').trim(),
  156. ],
  157. sesSetting: [
  158. body('sesAccessKeyId').trim().if(value => value !== '').matches(/^[\da-zA-Z]+$/),
  159. body('sesSecretAccessKey').trim(),
  160. ],
  161. awsSetting: [
  162. body('region').trim().matches(/^[a-z]+-[a-z]+-\d+$/).withMessage((value, { req }) => req.t('validation.aws_region')),
  163. body('customEndpoint').trim().matches(/^(https?:\/\/[^/]+|)$/).withMessage((value, { req }) => req.t('validation.aws_custom_endpoint')),
  164. body('bucket').trim(),
  165. body('accessKeyId').trim().if(value => value !== '').matches(/^[\da-zA-Z]+$/),
  166. body('secretAccessKey').trim(),
  167. ],
  168. gcpSetting: [
  169. body('gcsApiKeyJsonPath').trim(),
  170. body('gcsBucket').trim(),
  171. body('gcsUploadNamespace').trim(),
  172. ],
  173. pluginSetting: [
  174. body('isEnabledPlugins').isBoolean(),
  175. ],
  176. };
  177. /**
  178. * @swagger
  179. *
  180. * /app-settings:
  181. * get:
  182. * tags: [AppSettings]
  183. * operationId: getAppSettings
  184. * summary: /app-settings
  185. * description: get app setting params
  186. * responses:
  187. * 200:
  188. * description: Resources are available
  189. * content:
  190. * application/json:
  191. * schema:
  192. * properties:
  193. * appSettingsParams:
  194. * type: object
  195. * description: app settings params
  196. */
  197. router.get('/', accessTokenParser, loginRequired, adminRequired, async(req, res) => {
  198. const appSettingsParams = {
  199. title: crowi.configManager.getConfig('crowi', 'app:title'),
  200. confidential: crowi.configManager.getConfig('crowi', 'app:confidential'),
  201. globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
  202. fileUpload: crowi.configManager.getConfig('crowi', 'app:fileUpload'),
  203. siteUrl: crowi.configManager.getConfig('crowi', 'app:siteUrl'),
  204. envSiteUrl: crowi.configManager.getConfigFromEnvVars('crowi', 'app:siteUrl'),
  205. isMailerSetup: crowi.mailService.isMailerSetup,
  206. fromAddress: crowi.configManager.getConfig('crowi', 'mail:from'),
  207. transmissionMethod: crowi.configManager.getConfig('crowi', 'mail:transmissionMethod'),
  208. smtpHost: crowi.configManager.getConfig('crowi', 'mail:smtpHost'),
  209. smtpPort: crowi.configManager.getConfig('crowi', 'mail:smtpPort'),
  210. smtpUser: crowi.configManager.getConfig('crowi', 'mail:smtpUser'),
  211. smtpPassword: crowi.configManager.getConfig('crowi', 'mail:smtpPassword'),
  212. sesAccessKeyId: crowi.configManager.getConfig('crowi', 'mail:sesAccessKeyId'),
  213. sesSecretAccessKey: crowi.configManager.getConfig('crowi', 'mail:sesSecretAccessKey'),
  214. region: crowi.configManager.getConfig('crowi', 'aws:region'),
  215. customEndpoint: crowi.configManager.getConfig('crowi', 'aws:customEndpoint'),
  216. bucket: crowi.configManager.getConfig('crowi', 'aws:bucket'),
  217. accessKeyId: crowi.configManager.getConfig('crowi', 'aws:accessKeyId'),
  218. secretAccessKey: crowi.configManager.getConfig('crowi', 'aws:secretAccessKey'),
  219. envGcsApiKeyJsonPath: crowi.configManager.getConfigFromEnvVars('crowi', 'gcs:apiKeyJsonPath'),
  220. envGcsBucket: crowi.configManager.getConfigFromEnvVars('crowi', 'gcs:bucket'),
  221. envGcsUploadNamespace: crowi.configManager.getConfigFromEnvVars('crowi', 'gcs:uploadNamespace'),
  222. isEnabledPlugins: crowi.configManager.getConfig('crowi', 'plugin:isEnabledPlugins'),
  223. };
  224. return res.apiv3({ appSettingsParams });
  225. });
  226. /**
  227. * @swagger
  228. *
  229. * /app-settings/app-setting:
  230. * put:
  231. * tags: [AppSettings]
  232. * summary: /app-settings/app-setting
  233. * operationId: updateAppSettings
  234. * description: Update app setting
  235. * requestBody:
  236. * required: true
  237. * content:
  238. * application/json:
  239. * schema:
  240. * $ref: '#/components/schemas/AppSettingParams'
  241. * responses:
  242. * 200:
  243. * description: Succeeded to update app setting
  244. * content:
  245. * application/json:
  246. * schema:
  247. * $ref: '#/components/schemas/AppSettingParams'
  248. */
  249. router.put('/app-setting', loginRequiredStrictly, adminRequired, csrf, validator.appSetting, apiV3FormValidator, async(req, res) => {
  250. const requestAppSettingParams = {
  251. 'app:title': req.body.title,
  252. 'app:confidential': req.body.confidential,
  253. 'app:globalLang': req.body.globalLang,
  254. 'app:fileUpload': req.body.fileUpload,
  255. };
  256. try {
  257. await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestAppSettingParams);
  258. const appSettingParams = {
  259. title: crowi.configManager.getConfig('crowi', 'app:title'),
  260. confidential: crowi.configManager.getConfig('crowi', 'app:confidential'),
  261. globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
  262. fileUpload: crowi.configManager.getConfig('crowi', 'app:fileUpload'),
  263. };
  264. return res.apiv3({ appSettingParams });
  265. }
  266. catch (err) {
  267. const msg = 'Error occurred in updating app setting';
  268. logger.error('Error', err);
  269. return res.apiv3Err(new ErrorV3(msg, 'update-appSetting-failed'));
  270. }
  271. });
  272. /**
  273. * @swagger
  274. *
  275. * /app-settings/site-url-setting:
  276. * put:
  277. * tags: [AppSettings]
  278. * operationId: updateAppSettingSiteUrlSetting
  279. * summary: /app-settings/site-url-setting
  280. * description: Update site url setting
  281. * requestBody:
  282. * required: true
  283. * content:
  284. * application/json:
  285. * schema:
  286. * $ref: '#/components/schemas/SiteUrlSettingParams'
  287. * responses:
  288. * 200:
  289. * description: Succeeded to update site url setting
  290. * content:
  291. * application/json:
  292. * schema:
  293. * $ref: '#/components/schemas/SiteUrlSettingParams'
  294. */
  295. router.put('/site-url-setting', loginRequiredStrictly, adminRequired, csrf, validator.siteUrlSetting, apiV3FormValidator, async(req, res) => {
  296. const requestSiteUrlSettingParams = {
  297. 'app:siteUrl': req.body.siteUrl,
  298. };
  299. try {
  300. await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestSiteUrlSettingParams);
  301. const siteUrlSettingParams = {
  302. siteUrl: crowi.configManager.getConfig('crowi', 'app:siteUrl'),
  303. };
  304. return res.apiv3({ siteUrlSettingParams });
  305. }
  306. catch (err) {
  307. const msg = 'Error occurred in updating site url setting';
  308. logger.error('Error', err);
  309. return res.apiv3Err(new ErrorV3(msg, 'update-siteUrlSetting-failed'));
  310. }
  311. });
  312. /**
  313. * send mail (Promise wrapper)
  314. */
  315. async function sendMailPromiseWrapper(smtpClient, options) {
  316. return new Promise((resolve, reject) => {
  317. smtpClient.sendMail(options, (err, res) => {
  318. if (err) {
  319. reject(err);
  320. }
  321. else {
  322. resolve(res);
  323. }
  324. });
  325. });
  326. }
  327. /**
  328. * validate mail setting send test mail
  329. */
  330. async function sendTestEmail(destinationAddress) {
  331. const { configManager, mailService } = crowi;
  332. if (!mailService.isMailerSetup) {
  333. throw Error('mailService is not setup');
  334. }
  335. const fromAddress = configManager.getConfig('crowi', 'mail:from');
  336. if (fromAddress == null) {
  337. throw Error('fromAddress is not setup');
  338. }
  339. const smtpHost = configManager.getConfig('crowi', 'mail:smtpHost');
  340. const smtpPort = configManager.getConfig('crowi', 'mail:smtpPort');
  341. const smtpUser = configManager.getConfig('crowi', 'mail:smtpUser');
  342. const smtpPassword = configManager.getConfig('crowi', 'mail:smtpPassword');
  343. const option = {
  344. host: smtpHost,
  345. port: smtpPort,
  346. };
  347. if (smtpUser && smtpPassword) {
  348. option.auth = {
  349. user: smtpUser,
  350. pass: smtpPassword,
  351. };
  352. }
  353. if (option.port === 465) {
  354. option.secure = true;
  355. }
  356. const smtpClient = mailService.createSMTPClient(option);
  357. debug('mailer setup for validate SMTP setting', smtpClient);
  358. const mailOptions = {
  359. from: fromAddress,
  360. to: destinationAddress,
  361. subject: 'Wiki管理設定のアップデートによるメール通知',
  362. text: 'このメールは、WikiのSMTP設定のアップデートにより送信されています。',
  363. };
  364. await sendMailPromiseWrapper(smtpClient, mailOptions);
  365. }
  366. const updateMailSettinConfig = async function(requestMailSettingParams) {
  367. const {
  368. configManager,
  369. mailService,
  370. } = crowi;
  371. // update config without publishing S2sMessage
  372. await configManager.updateConfigsInTheSameNamespace('crowi', requestMailSettingParams, true);
  373. await mailService.initialize();
  374. mailService.publishUpdatedMessage();
  375. return {
  376. isMailerSetup: mailService.isMailerSetup,
  377. fromAddress: configManager.getConfig('crowi', 'mail:from'),
  378. smtpHost: configManager.getConfig('crowi', 'mail:smtpHost'),
  379. smtpPort: configManager.getConfig('crowi', 'mail:smtpPort'),
  380. smtpUser: configManager.getConfig('crowi', 'mail:smtpUser'),
  381. smtpPassword: configManager.getConfig('crowi', 'mail:smtpPassword'),
  382. sesAccessKeyId: configManager.getConfig('crowi', 'mail:sesAccessKeyId'),
  383. sesSecretAccessKey: configManager.getConfig('crowi', 'mail:sesSecretAccessKey'),
  384. };
  385. };
  386. /**
  387. * @swagger
  388. *
  389. * /app-settings/smtp-setting:
  390. * put:
  391. * tags: [AppSettings]
  392. * operationId: updateAppSettingSmtpSetting
  393. * summary: /app-settings/smtp-setting
  394. * description: Update smtp setting
  395. * requestBody:
  396. * required: true
  397. * content:
  398. * application/json:
  399. * schema:
  400. * $ref: '#/components/schemas/SmtpSettingParams'
  401. * responses:
  402. * 200:
  403. * description: Succeeded to update smtp setting
  404. * content:
  405. * application/json:
  406. * schema:
  407. * $ref: '#/components/schemas/SmtpSettingParams'
  408. */
  409. router.put('/smtp-setting', loginRequiredStrictly, adminRequired, csrf, validator.smtpSetting, apiV3FormValidator, async(req, res) => {
  410. const requestMailSettingParams = {
  411. 'mail:from': req.body.fromAddress,
  412. 'mail:transmissionMethod': req.body.transmissionMethod,
  413. 'mail:smtpHost': req.body.smtpHost,
  414. 'mail:smtpPort': req.body.smtpPort,
  415. 'mail:smtpUser': req.body.smtpUser,
  416. 'mail:smtpPassword': req.body.smtpPassword,
  417. };
  418. try {
  419. const mailSettingParams = await updateMailSettinConfig(requestMailSettingParams);
  420. return res.apiv3({ mailSettingParams });
  421. }
  422. catch (err) {
  423. const msg = 'Error occurred in updating smtp setting';
  424. logger.error('Error', err);
  425. return res.apiv3Err(new ErrorV3(msg, 'update-smtpSetting-failed'));
  426. }
  427. });
  428. /**
  429. * @swagger
  430. *
  431. * /app-settings/smtp-test:
  432. * post:
  433. * tags: [AppSettings]
  434. * operationId: postSmtpTest
  435. * summary: /app-settings/smtp-setting
  436. * description: Send test mail for smtp
  437. * responses:
  438. * 200:
  439. * description: Succeeded to send test mail for smtp
  440. */
  441. router.post('/smtp-test', loginRequiredStrictly, adminRequired, async(req, res) => {
  442. try {
  443. await sendTestEmail(req.user.email);
  444. return res.apiv3({});
  445. }
  446. catch (err) {
  447. const msg = req.t('validation.failed_to_send_a_test_email');
  448. logger.error('Error', err);
  449. debug('Error validate mail setting: ', err);
  450. return res.apiv3Err(new ErrorV3(msg, 'send-email-with-smtp-failed'));
  451. }
  452. });
  453. /**
  454. * @swagger
  455. *
  456. * /app-settings/ses-setting:
  457. * put:
  458. * tags: [AppSettings]
  459. * operationId: updateAppSettingSesSetting
  460. * summary: /app-settings/ses-setting
  461. * description: Update ses setting
  462. * requestBody:
  463. * required: true
  464. * content:
  465. * application/json:
  466. * schema:
  467. * $ref: '#/components/schemas/SesSettingParams'
  468. * responses:
  469. * 200:
  470. * description: Succeeded to update ses setting
  471. * content:
  472. * application/json:
  473. * schema:
  474. * $ref: '#/components/schemas/SesSettingParams'
  475. */
  476. router.put('/ses-setting', loginRequiredStrictly, adminRequired, csrf, validator.sesSetting, apiV3FormValidator, async(req, res) => {
  477. const { mailService } = crowi;
  478. const requestSesSettingParams = {
  479. 'mail:from': req.body.fromAddress,
  480. 'mail:transmissionMethod': req.body.transmissionMethod,
  481. 'mail:sesAccessKeyId': req.body.sesAccessKeyId,
  482. 'mail:sesSecretAccessKey': req.body.sesSecretAccessKey,
  483. };
  484. let mailSettingParams;
  485. try {
  486. mailSettingParams = await updateMailSettinConfig(requestSesSettingParams);
  487. }
  488. catch (err) {
  489. const msg = 'Error occurred in updating ses setting';
  490. logger.error('Error', err);
  491. return res.apiv3Err(new ErrorV3(msg, 'update-ses-setting-failed'));
  492. }
  493. await mailService.initialize();
  494. mailService.publishUpdatedMessage();
  495. return res.apiv3({ mailSettingParams });
  496. });
  497. /**
  498. * @swagger
  499. *
  500. * /app-settings/aws-setting:
  501. * put:
  502. * tags: [AppSettings]
  503. * operationId: updateAppSettingAwsSetting
  504. * summary: /app-settings/aws-setting
  505. * description: Update aws setting
  506. * requestBody:
  507. * required: true
  508. * content:
  509. * application/json:
  510. * schema:
  511. * $ref: '#/components/schemas/AwsSettingParams'
  512. * responses:
  513. * 200:
  514. * description: Succeeded to update aws setting
  515. * content:
  516. * application/json:
  517. * schema:
  518. * $ref: '#/components/schemas/AwsSettingParams'
  519. */
  520. router.put('/aws-setting', loginRequiredStrictly, adminRequired, csrf, validator.awsSetting, apiV3FormValidator, async(req, res) => {
  521. const requestAwsSettingParams = {
  522. 'aws:region': req.body.region,
  523. 'aws:customEndpoint': req.body.customEndpoint,
  524. 'aws:bucket': req.body.bucket,
  525. 'aws:accessKeyId': req.body.accessKeyId,
  526. 'aws:secretAccessKey': req.body.secretAccessKey,
  527. };
  528. try {
  529. await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestAwsSettingParams);
  530. // TODO GW-3797 re-setup file uploader
  531. const awsSettingParams = {
  532. region: crowi.configManager.getConfig('crowi', 'aws:region'),
  533. customEndpoint: crowi.configManager.getConfig('crowi', 'aws:customEndpoint'),
  534. bucket: crowi.configManager.getConfig('crowi', 'aws:bucket'),
  535. accessKeyId: crowi.configManager.getConfig('crowi', 'aws:accessKeyId'),
  536. secretAccessKey: crowi.configManager.getConfig('crowi', 'aws:secretAccessKey'),
  537. };
  538. return res.apiv3({ awsSettingParams });
  539. }
  540. catch (err) {
  541. const msg = 'Error occurred in updating aws setting';
  542. logger.error('Error', err);
  543. return res.apiv3Err(new ErrorV3(msg, 'update-awsSetting-failed'));
  544. }
  545. });
  546. /**
  547. * @swagger
  548. *
  549. * /app-settings/gcp-setting:
  550. * put:
  551. * tags: [AppSettings]
  552. * operationId: updateAppSettingGcpSetting
  553. * summary: /app-settings/gcp-setting
  554. * description: Update gcp setting
  555. * requestBody:
  556. * required: true
  557. * content:
  558. * application/json:
  559. * schema:
  560. * $ref: '#/components/schemas/GcpSettingParams'
  561. * responses:
  562. * 200:
  563. * description: Succeeded to update gcp setting
  564. * content:
  565. * application/json:
  566. * schema:
  567. * $ref: '#/components/schemas/GcpSettingParams'
  568. */
  569. router.put('/gcp-setting', loginRequiredStrictly, adminRequired, csrf, validator.gcpSetting, apiV3FormValidator, async(req, res) => {
  570. const requestGcpSettingParams = {
  571. 'gcs:apiKeyJsonPath': req.body.gcsApiKeyJsonPath,
  572. 'gcs:bucket': req.body.gcsBucket,
  573. 'gcs:uploadNamespace': req.body.gcsUploadNamespace,
  574. };
  575. try {
  576. await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestGcpSettingParams);
  577. // TODO GW-3797 re-setup file uploader
  578. const gcpSettingParams = {
  579. gcsApiKeyJsonPath: crowi.configManager.getConfig('crowi', 'gcs:apiKeyJsonPath'),
  580. gcsBucket: crowi.configManager.getConfig('crowi', 'gcs:bucket'),
  581. gcsUploadNamespace: crowi.configManager.getConfig('crowi', 'gcs:uploadNamespace'),
  582. };
  583. return res.apiv3({ gcpSettingParams });
  584. }
  585. catch (err) {
  586. const msg = 'Error occurred in updating aws setting';
  587. logger.error('Error', err);
  588. return res.apiv3Err(new ErrorV3(msg, 'update-awsSetting-failed'));
  589. }
  590. });
  591. /**
  592. * @swagger
  593. *
  594. * /app-settings/plugin-setting:
  595. * put:
  596. * tags: [AppSettings]
  597. * operationId: updateAppSettingPluginSetting
  598. * summary: /app-settings/plugin-setting
  599. * description: Update plugin setting
  600. * requestBody:
  601. * required: true
  602. * content:
  603. * application/json:
  604. * schema:
  605. * $ref: '#/components/schemas/PluginSettingParams'
  606. * responses:
  607. * 200:
  608. * description: Succeeded to update plugin setting
  609. * content:
  610. * application/json:
  611. * schema:
  612. * $ref: '#/components/schemas/PluginSettingParams'
  613. */
  614. router.put('/plugin-setting', loginRequiredStrictly, adminRequired, csrf, validator.pluginSetting, apiV3FormValidator, async(req, res) => {
  615. const requestPluginSettingParams = {
  616. 'plugin:isEnabledPlugins': req.body.isEnabledPlugins,
  617. };
  618. try {
  619. await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestPluginSettingParams);
  620. const pluginSettingParams = {
  621. isEnabledPlugins: crowi.configManager.getConfig('crowi', 'plugin:isEnabledPlugins'),
  622. };
  623. return res.apiv3({ pluginSettingParams });
  624. }
  625. catch (err) {
  626. const msg = 'Error occurred in updating plugin setting';
  627. logger.error('Error', err);
  628. return res.apiv3Err(new ErrorV3(msg, 'update-pluginSetting-failed'));
  629. }
  630. });
  631. return router;
  632. };