Quellcode durchsuchen

Merge pull request #6094 from weseek/feat/98341

feat: Create activity when user group is created
Shun Miyazawa vor 3 Jahren
Ursprung
Commit
a6ff2a8475

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

@@ -45,6 +45,7 @@ const ACTION_ADMIN_USER_NOTIFICATION_SETTINGS_ADD = 'ADMIN_USER_NOTIFICATION_SET
 const ACTION_ADMIN_SLACK_WORKSPACE_CREATE = 'ADMIN_SLACK_WORKSPACE_CREATE';
 const ACTION_ADMIN_SLACK_WORKSPACE_CREATE = 'ADMIN_SLACK_WORKSPACE_CREATE';
 const ACTION_ADMIN_SLACK_CONFIGURATION_SETTING_UPDATE = 'ACTION_ADMIN_SLACK_CONFIGURATION_SETTING_UPDATE';
 const ACTION_ADMIN_SLACK_CONFIGURATION_SETTING_UPDATE = 'ACTION_ADMIN_SLACK_CONFIGURATION_SETTING_UPDATE';
 const ACTION_ADMIN_USERS_INVITE = 'ADMIN_USERS_INVITE';
 const ACTION_ADMIN_USERS_INVITE = 'ADMIN_USERS_INVITE';
+const ACTION_ADMIN_USER_GROUP_CREATE = 'ADMIN_USER_GROUP_CREATE';
 
 
 export const SupportedTargetModel = {
 export const SupportedTargetModel = {
   MODEL_PAGE,
   MODEL_PAGE,
@@ -93,6 +94,7 @@ export const SupportedAction = {
   ACTION_ADMIN_SLACK_WORKSPACE_CREATE,
   ACTION_ADMIN_SLACK_WORKSPACE_CREATE,
   ACTION_ADMIN_SLACK_CONFIGURATION_SETTING_UPDATE,
   ACTION_ADMIN_SLACK_CONFIGURATION_SETTING_UPDATE,
   ACTION_ADMIN_USERS_INVITE,
   ACTION_ADMIN_USERS_INVITE,
+  ACTION_ADMIN_USER_GROUP_CREATE,
 } as const;
 } as const;
 
 
 export const SupportedActionToNotified = {
 export const SupportedActionToNotified = {

+ 10 - 1
packages/app/src/server/routes/apiv3/user-group.js

@@ -1,9 +1,12 @@
+import { SupportedAction } from '~/interfaces/activity';
 import UserGroup from '~/server/models/user-group';
 import UserGroup from '~/server/models/user-group';
 import { excludeTestIdsFromTargetIds } from '~/server/util/compare-objectId';
 import { excludeTestIdsFromTargetIds } from '~/server/util/compare-objectId';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 
 
+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:user-group'); // eslint-disable-line no-unused-vars
 const logger = loggerFactory('growi:routes:apiv3:user-group'); // eslint-disable-line no-unused-vars
 
 
 const express = require('express');
 const express = require('express');
@@ -31,6 +34,9 @@ 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 csrf = require('../../middlewares/csrf')(crowi);
   const csrf = require('../../middlewares/csrf')(crowi);
+  const addActivity = generateAddActivityMiddleware(crowi);
+
+  const activityEvent = crowi.event('activity');
 
 
   const {
   const {
     UserGroupRelation,
     UserGroupRelation,
@@ -222,7 +228,7 @@ module.exports = (crowi) => {
    *                      type: object
    *                      type: object
    *                      description: A result of `UserGroup.createGroupByName`
    *                      description: A result of `UserGroup.createGroupByName`
    */
    */
-  router.post('/', loginRequiredStrictly, adminRequired, csrf, validator.create, apiV3FormValidator, async(req, res) => {
+  router.post('/', loginRequiredStrictly, adminRequired, csrf, addActivity, validator.create, apiV3FormValidator, async(req, res) => {
     const { name, description = '', parentId } = req.body;
     const { name, description = '', parentId } = req.body;
 
 
     try {
     try {
@@ -230,6 +236,9 @@ module.exports = (crowi) => {
       const userGroupDescription = crowi.xss.process(description);
       const userGroupDescription = crowi.xss.process(description);
       const userGroup = await UserGroup.createGroup(userGroupName, userGroupDescription, parentId);
       const userGroup = await UserGroup.createGroup(userGroupName, userGroupDescription, parentId);
 
 
+      const parameters = { action: SupportedAction.ACTION_ADMIN_USER_GROUP_CREATE };
+      activityEvent.emit('update', res.locals.activity._id, parameters);
+
       return res.apiv3({ userGroup }, 201);
       return res.apiv3({ userGroup }, 201);
     }
     }
     catch (err) {
     catch (err) {