Просмотр исходного кода

Merge pull request #6206 from weseek/feat/auditlog-98553

feat: Add activity for notifications
ryoji-s 3 лет назад
Родитель
Сommit
b3bd791ff8

+ 21 - 0
packages/app/src/interfaces/activity.ts

@@ -115,6 +115,13 @@ const ACTION_ADMIN_CUSTOM_SCRIPT_UPDATE = 'ADMIN_CUSTOM_SCRIPT_UPDATE';
 const ACTION_ADMIN_ARCHIVE_DATA_UPLOAD = 'ADMIN_ARCHIVE_DATA_UPLOAD';
 const ACTION_ADMIN_ARCHIVE_DATA_CREATE = 'ADMIN_ARCHIVE_DATA_CREATE';
 const ACTION_ADMIN_USER_NOTIFICATION_SETTINGS_ADD = 'ADMIN_USER_NOTIFICATION_SETTINGS_ADD';
+const ACTION_ADMIN_USER_NOTIFICATION_SETTINGS_DELETE = 'ADMIN_USER_NOTIFICATION_SETTINGS_DELETE';
+const ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_ADD = 'ADMIN_GLOBAL_NOTIFICATION_SETTINGS_ADD';
+const ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_UPDATE = 'ADMIN_GLOBAL_NOTIFICATION_SETTINGS_UPDATE';
+const ACTION_ADMIN_NOTIFICATION_GRANT_SETTINGS_UPDATE = 'ADMIN_NOTIFICATION_GRANT_SETTINGS_UPDATE';
+const ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_ENABLED = 'ADMIN_GLOBAL_NOTIFICATION_SETTINGS_ENABLED';
+const ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_DISABLED = 'ADMIN_GLOBAL_NOTIFICATION_SETTINGS_DISABLED';
+const ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_DELETE = 'ADMIN_GLOBAL_NOTIFICATION_SETTINGS_DELETE';
 const ACTION_ADMIN_SLACK_WORKSPACE_CREATE = 'ADMIN_SLACK_WORKSPACE_CREATE';
 const ACTION_ADMIN_SLACK_CONFIGURATION_SETTING_UPDATE = 'ADMIN_SLACK_CONFIGURATION_SETTING_UPDATE';
 const ACTION_ADMIN_USERS_INVITE = 'ADMIN_USERS_INVITE';
@@ -255,6 +262,13 @@ export const SupportedAction = {
   ACTION_ADMIN_ARCHIVE_DATA_UPLOAD,
   ACTION_ADMIN_ARCHIVE_DATA_CREATE,
   ACTION_ADMIN_USER_NOTIFICATION_SETTINGS_ADD,
+  ACTION_ADMIN_USER_NOTIFICATION_SETTINGS_DELETE,
+  ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_ADD,
+  ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_UPDATE,
+  ACTION_ADMIN_NOTIFICATION_GRANT_SETTINGS_UPDATE,
+  ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_ENABLED,
+  ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_DISABLED,
+  ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_DELETE,
   ACTION_ADMIN_SLACK_WORKSPACE_CREATE,
   ACTION_ADMIN_SLACK_CONFIGURATION_SETTING_UPDATE,
   ACTION_ADMIN_USERS_INVITE,
@@ -397,6 +411,13 @@ export const LargeActionGroup = {
   ACTION_ADMIN_ARCHIVE_DATA_UPLOAD,
   ACTION_ADMIN_ARCHIVE_DATA_CREATE,
   ACTION_ADMIN_USER_NOTIFICATION_SETTINGS_ADD,
+  ACTION_ADMIN_USER_NOTIFICATION_SETTINGS_DELETE,
+  ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_ADD,
+  ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_UPDATE,
+  ACTION_ADMIN_NOTIFICATION_GRANT_SETTINGS_UPDATE,
+  ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_ENABLED,
+  ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_DISABLED,
+  ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_DELETE,
   ACTION_ADMIN_SLACK_WORKSPACE_CREATE,
   ACTION_ADMIN_SLACK_CONFIGURATION_SETTING_UPDATE,
   ACTION_ADMIN_USERS_INVITE,

+ 38 - 7
packages/app/src/server/routes/apiv3/notification-setting.js

@@ -213,11 +213,15 @@ module.exports = (crowi) => {
    *                      type: object
    *                      description: deleted notification
    */
-  router.delete('/user-notification/:id', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
+  router.delete('/user-notification/:id', loginRequiredStrictly, adminRequired, csrf, addActivity, async(req, res) => {
     const { id } = req.params;
 
     try {
       const deletedNotificaton = await UpdatePost.findOneAndRemove({ _id: id });
+
+      const parameters = { action: SupportedAction.ACTION_ADMIN_USER_NOTIFICATION_SETTINGS_DELETE };
+      activityEvent.emit('update', res.locals.activity._id, parameters);
+
       return res.apiv3(deletedNotificaton);
     }
     catch (err) {
@@ -253,7 +257,8 @@ module.exports = (crowi) => {
    *                      type: object
    *                      description: notification param created
    */
-  router.post('/global-notification', loginRequiredStrictly, adminRequired, csrf, validator.globalNotification, apiV3FormValidator, async(req, res) => {
+  // eslint-disable-next-line max-len
+  router.post('/global-notification', loginRequiredStrictly, adminRequired, csrf, addActivity, validator.globalNotification, apiV3FormValidator, async(req, res) => {
 
     const {
       notifyToType, toEmail, slackChannels, triggerPath, triggerEvents,
@@ -275,6 +280,10 @@ module.exports = (crowi) => {
 
     try {
       const createdNotification = await notification.save();
+
+      const parameters = { action: SupportedAction.ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_ADD };
+      activityEvent.emit('update', res.locals.activity._id, parameters);
+
       return res.apiv3({ createdNotification }, 201);
     }
     catch (err) {
@@ -316,7 +325,8 @@ module.exports = (crowi) => {
    *                      type: object
    *                      description: notification param updated
    */
-  router.put('/global-notification/:id', loginRequiredStrictly, adminRequired, csrf, validator.globalNotification, apiV3FormValidator, async(req, res) => {
+  // eslint-disable-next-line max-len
+  router.put('/global-notification/:id', loginRequiredStrictly, adminRequired, csrf, addActivity, validator.globalNotification, apiV3FormValidator, async(req, res) => {
     const { id } = req.params;
     const {
       notifyToType, toEmail, slackChannels, triggerPath, triggerEvents,
@@ -355,6 +365,10 @@ module.exports = (crowi) => {
       setting.triggerEvents = triggerEvents || [];
 
       const createdNotification = await setting.save();
+
+      const parameters = { action: SupportedAction.ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_UPDATE };
+      activityEvent.emit('update', res.locals.activity._id, parameters);
+
       return res.apiv3({ createdNotification });
     }
     catch (err) {
@@ -387,7 +401,8 @@ module.exports = (crowi) => {
    *                schema:
    *                  $ref: '#/components/schemas/NotifyForPageGrant'
    */
-  router.put('/notify-for-page-grant', loginRequiredStrictly, adminRequired, csrf, validator.notifyForPageGrant, apiV3FormValidator, async(req, res) => {
+  // eslint-disable-next-line max-len
+  router.put('/notify-for-page-grant', loginRequiredStrictly, adminRequired, csrf, addActivity, validator.notifyForPageGrant, apiV3FormValidator, async(req, res) => {
 
     let requestParams = {
       'notification:owner-page:isEnabled': req.body.isNotificationForOwnerPageEnabled,
@@ -402,6 +417,10 @@ module.exports = (crowi) => {
         isNotificationForOwnerPageEnabled: await crowi.configManager.getConfig('notification', 'notification:owner-page:isEnabled'),
         isNotificationForGroupPageEnabled: await crowi.configManager.getConfig('notification', 'notification:group-page:isEnabled'),
       };
+
+      const parameters = { action: SupportedAction.ACTION_ADMIN_NOTIFICATION_GRANT_SETTINGS_UPDATE };
+      activityEvent.emit('update', res.locals.activity._id, parameters);
+
       return res.apiv3({ responseParams });
     }
     catch (err) {
@@ -409,7 +428,9 @@ module.exports = (crowi) => {
       logger.error('Error', err);
       return res.apiv3Err(new ErrorV3(msg, 'update-notify-for-page-grant-failed'));
     }
+
   });
+
   /**
    * @swagger
    *
@@ -444,7 +465,7 @@ module.exports = (crowi) => {
    *                      type: object
    *                      description: notification id for updated
    */
-  router.put('/global-notification/:id/enabled', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
+  router.put('/global-notification/:id/enabled', loginRequiredStrictly, adminRequired, csrf, addActivity, async(req, res) => {
     const { id } = req.params;
     const { isEnabled } = req.body;
 
@@ -456,6 +477,13 @@ module.exports = (crowi) => {
         await GlobalNotificationSetting.disable(id);
       }
 
+      const parameters = {
+        action: isEnabled
+          ? SupportedAction.ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_ENABLED
+          : SupportedAction.ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_DISABLED,
+      };
+      activityEvent.emit('update', res.locals.activity._id, parameters);
+
       return res.apiv3({ id });
 
     }
@@ -492,11 +520,15 @@ module.exports = (crowi) => {
   *                      type: object
   *                      description: deleted notification
   */
-  router.delete('/global-notification/:id', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
+  router.delete('/global-notification/:id', loginRequiredStrictly, adminRequired, csrf, addActivity, async(req, res) => {
     const { id } = req.params;
 
     try {
       const deletedNotificaton = await GlobalNotificationSetting.findOneAndRemove({ _id: id });
+
+      const parameters = { action: SupportedAction.ACTION_ADMIN_GLOBAL_NOTIFICATION_SETTINGS_DELETE };
+      activityEvent.emit('update', res.locals.activity._id, parameters);
+
       return res.apiv3(deletedNotificaton);
     }
     catch (err) {
@@ -505,7 +537,6 @@ module.exports = (crowi) => {
       return res.apiv3Err(new ErrorV3(msg, 'delete-globalNotification-failed'));
     }
 
-
   });
 
   return router;