|
@@ -340,7 +340,7 @@ module.exports = (crowi) => {
|
|
|
.trim()
|
|
.trim()
|
|
|
.if((value) => value !== '')
|
|
.if((value) => value !== '')
|
|
|
.isEmail(),
|
|
.isEmail(),
|
|
|
- body('transmissionMethod').isIn(['smtp', 'ses']),
|
|
|
|
|
|
|
+ body('transmissionMethod').isIn(['smtp', 'ses', 'oauth2']),
|
|
|
],
|
|
],
|
|
|
smtpSetting: [
|
|
smtpSetting: [
|
|
|
body('smtpHost').trim(),
|
|
body('smtpHost').trim(),
|
|
@@ -358,6 +358,15 @@ module.exports = (crowi) => {
|
|
|
.matches(/^[\da-zA-Z]+$/),
|
|
.matches(/^[\da-zA-Z]+$/),
|
|
|
body('sesSecretAccessKey').trim(),
|
|
body('sesSecretAccessKey').trim(),
|
|
|
],
|
|
],
|
|
|
|
|
+ oauth2Setting: [
|
|
|
|
|
+ body('oauth2ClientId').trim(),
|
|
|
|
|
+ body('oauth2ClientSecret').trim(),
|
|
|
|
|
+ body('oauth2RefreshToken').trim(),
|
|
|
|
|
+ body('oauth2User')
|
|
|
|
|
+ .trim()
|
|
|
|
|
+ .if((value) => value !== '')
|
|
|
|
|
+ .isEmail(),
|
|
|
|
|
+ ],
|
|
|
pageBulkExportSettings: [
|
|
pageBulkExportSettings: [
|
|
|
body('isBulkExportPagesEnabled').isBoolean(),
|
|
body('isBulkExportPagesEnabled').isBoolean(),
|
|
|
body('bulkExportDownloadExpirationSeconds').isInt(),
|
|
body('bulkExportDownloadExpirationSeconds').isInt(),
|
|
@@ -422,6 +431,10 @@ module.exports = (crowi) => {
|
|
|
smtpPassword: configManager.getConfig('mail:smtpPassword'),
|
|
smtpPassword: configManager.getConfig('mail:smtpPassword'),
|
|
|
sesAccessKeyId: configManager.getConfig('mail:sesAccessKeyId'),
|
|
sesAccessKeyId: configManager.getConfig('mail:sesAccessKeyId'),
|
|
|
sesSecretAccessKey: configManager.getConfig('mail:sesSecretAccessKey'),
|
|
sesSecretAccessKey: configManager.getConfig('mail:sesSecretAccessKey'),
|
|
|
|
|
+ oauth2ClientId: configManager.getConfig('mail:oauth2ClientId'),
|
|
|
|
|
+ oauth2ClientSecret: configManager.getConfig('mail:oauth2ClientSecret'),
|
|
|
|
|
+ oauth2RefreshToken: configManager.getConfig('mail:oauth2RefreshToken'),
|
|
|
|
|
+ oauth2User: configManager.getConfig('mail:oauth2User'),
|
|
|
|
|
|
|
|
fileUploadType: configManager.getConfig('app:fileUploadType'),
|
|
fileUploadType: configManager.getConfig('app:fileUploadType'),
|
|
|
envFileUploadType: configManager.getConfig(
|
|
envFileUploadType: configManager.getConfig(
|
|
@@ -759,6 +772,10 @@ module.exports = (crowi) => {
|
|
|
smtpPassword: configManager.getConfig('mail:smtpPassword'),
|
|
smtpPassword: configManager.getConfig('mail:smtpPassword'),
|
|
|
sesAccessKeyId: configManager.getConfig('mail:sesAccessKeyId'),
|
|
sesAccessKeyId: configManager.getConfig('mail:sesAccessKeyId'),
|
|
|
sesSecretAccessKey: configManager.getConfig('mail:sesSecretAccessKey'),
|
|
sesSecretAccessKey: configManager.getConfig('mail:sesSecretAccessKey'),
|
|
|
|
|
+ oauth2ClientId: configManager.getConfig('mail:oauth2ClientId'),
|
|
|
|
|
+ oauth2ClientSecret: configManager.getConfig('mail:oauth2ClientSecret'),
|
|
|
|
|
+ oauth2RefreshToken: configManager.getConfig('mail:oauth2RefreshToken'),
|
|
|
|
|
+ oauth2User: configManager.getConfig('mail:oauth2User'),
|
|
|
};
|
|
};
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -932,6 +949,95 @@ module.exports = (crowi) => {
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @swagger
|
|
|
|
|
+ *
|
|
|
|
|
+ * /app-settings/oauth2-setting:
|
|
|
|
|
+ * put:
|
|
|
|
|
+ * tags: [AppSettings]
|
|
|
|
|
+ * security:
|
|
|
|
|
+ * - cookieAuth: []
|
|
|
|
|
+ * summary: /app-settings/oauth2-setting
|
|
|
|
|
+ * description: Update OAuth 2.0 setting for email
|
|
|
|
|
+ * requestBody:
|
|
|
|
|
+ * required: true
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * properties:
|
|
|
|
|
+ * fromAddress:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: e-mail address used as from address
|
|
|
|
|
+ * example: 'info@growi.org'
|
|
|
|
|
+ * transmissionMethod:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: transmission method
|
|
|
|
|
+ * example: 'oauth2'
|
|
|
|
|
+ * oauth2ClientId:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: OAuth 2.0 Client ID
|
|
|
|
|
+ * oauth2ClientSecret:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: OAuth 2.0 Client Secret
|
|
|
|
|
+ * oauth2RefreshToken:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: OAuth 2.0 Refresh Token
|
|
|
|
|
+ * oauth2User:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: Email address of the authorized account
|
|
|
|
|
+ * responses:
|
|
|
|
|
+ * 200:
|
|
|
|
|
+ * description: Succeeded to update OAuth 2.0 setting
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * properties:
|
|
|
|
|
+ * mailSettingParams:
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ */
|
|
|
|
|
+ router.put(
|
|
|
|
|
+ '/oauth2-setting',
|
|
|
|
|
+ accessTokenParser([SCOPE.WRITE.ADMIN.APP]),
|
|
|
|
|
+ loginRequiredStrictly,
|
|
|
|
|
+ adminRequired,
|
|
|
|
|
+ addActivity,
|
|
|
|
|
+ validator.oauth2Setting,
|
|
|
|
|
+ apiV3FormValidator,
|
|
|
|
|
+ async (req, res) => {
|
|
|
|
|
+ const { mailService } = crowi;
|
|
|
|
|
+
|
|
|
|
|
+ const requestOAuth2SettingParams = {
|
|
|
|
|
+ 'mail:from': req.body.fromAddress,
|
|
|
|
|
+ 'mail:transmissionMethod': req.body.transmissionMethod,
|
|
|
|
|
+ 'mail:oauth2ClientId': req.body.oauth2ClientId,
|
|
|
|
|
+ 'mail:oauth2ClientSecret': req.body.oauth2ClientSecret,
|
|
|
|
|
+ 'mail:oauth2RefreshToken': req.body.oauth2RefreshToken,
|
|
|
|
|
+ 'mail:oauth2User': req.body.oauth2User,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ let mailSettingParams: Awaited<ReturnType<typeof updateMailSettinConfig>>;
|
|
|
|
|
+ try {
|
|
|
|
|
+ mailSettingParams = await updateMailSettinConfig(
|
|
|
|
|
+ requestOAuth2SettingParams,
|
|
|
|
|
+ );
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ const msg = 'Error occurred in updating OAuth 2.0 setting';
|
|
|
|
|
+ logger.error('Error', err);
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'update-oauth2-setting-failed'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ await mailService.initialize();
|
|
|
|
|
+ mailService.publishUpdatedMessage();
|
|
|
|
|
+ const parameters = {
|
|
|
|
|
+ action: SupportedAction.ACTION_ADMIN_MAIL_OAUTH2_UPDATE,
|
|
|
|
|
+ };
|
|
|
|
|
+ activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
|
|
|
+ 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(
|
|
router.put(
|