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

Merge branch 'feat/auditlog' of https://github.com/weseek/growi into feat/97283-create-activit-by-general-user-operation

Shun Miyazawa 3 лет назад
Родитель
Сommit
3eafa0fa6e
2 измененных файлов с 20 добавлено и 3 удалено
  1. 9 0
      packages/app/src/interfaces/activity.ts
  2. 11 3
      packages/app/src/server/routes/apiv3/user-group.js

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

@@ -61,6 +61,9 @@ 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';
 const ACTION_ADMIN_USER_GROUP_CREATE = 'ADMIN_USER_GROUP_CREATE';
+const ACTION_ADMIN_USER_GROUP_UPDATE = 'ADMIN_USER_GROUP_UPDATE';
+const ACTION_ADMIN_USER_GROUP_DELETE = 'ADMIN_USER_GROUP_DELETE';
+const ACTION_ADMIN_USER_GROUP_ADD_USER = 'ADMIN_USER_GROUP_ADD_USER';
 const ACTION_ADMIN_SEARCH_INDICES_NORMALIZE = 'ADMIN_SEARCH_INDICES_NORMALIZE';
 const ACTION_ADMIN_SEARCH_INDICES_NORMALIZE = 'ADMIN_SEARCH_INDICES_NORMALIZE';
 const ACTION_ADMIN_SEARCH_INDICES_REBUILD = 'ADMIN_SEARCH_INDICES_REBUILD';
 const ACTION_ADMIN_SEARCH_INDICES_REBUILD = 'ADMIN_SEARCH_INDICES_REBUILD';
 
 
@@ -128,6 +131,9 @@ export const SupportedAction = {
   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,
   ACTION_ADMIN_USER_GROUP_CREATE,
+  ACTION_ADMIN_USER_GROUP_UPDATE,
+  ACTION_ADMIN_USER_GROUP_DELETE,
+  ACTION_ADMIN_USER_GROUP_ADD_USER,
   ACTION_ADMIN_SEARCH_INDICES_NORMALIZE,
   ACTION_ADMIN_SEARCH_INDICES_NORMALIZE,
   ACTION_ADMIN_SEARCH_INDICES_REBUILD,
   ACTION_ADMIN_SEARCH_INDICES_REBUILD,
 } as const;
 } as const;
@@ -215,6 +221,9 @@ export const LargeActionGroup = {
   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,
   ACTION_ADMIN_USER_GROUP_CREATE,
+  ACTION_ADMIN_USER_GROUP_UPDATE,
+  ACTION_ADMIN_USER_GROUP_DELETE,
+  ACTION_ADMIN_USER_GROUP_ADD_USER,
   ACTION_ADMIN_SEARCH_INDICES_NORMALIZE,
   ACTION_ADMIN_SEARCH_INDICES_NORMALIZE,
   ACTION_ADMIN_SEARCH_INDICES_REBUILD,
   ACTION_ADMIN_SEARCH_INDICES_REBUILD,
 } as const;
 } as const;

+ 11 - 3
packages/app/src/server/routes/apiv3/user-group.js

@@ -429,13 +429,16 @@ module.exports = (crowi) => {
    *                      type: object
    *                      type: object
    *                      description: A result of `UserGroup.removeCompletelyById`
    *                      description: A result of `UserGroup.removeCompletelyById`
    */
    */
-  router.delete('/:id', loginRequiredStrictly, adminRequired, csrf, validator.delete, apiV3FormValidator, async(req, res) => {
+  router.delete('/:id', loginRequiredStrictly, adminRequired, csrf, validator.delete, apiV3FormValidator, addActivity, async(req, res) => {
     const { id: deleteGroupId } = req.params;
     const { id: deleteGroupId } = req.params;
     const { actionName, transferToUserGroupId } = req.query;
     const { actionName, transferToUserGroupId } = req.query;
 
 
     try {
     try {
       const userGroups = await crowi.userGroupService.removeCompletelyByRootGroupId(deleteGroupId, actionName, transferToUserGroupId, req.user);
       const userGroups = await crowi.userGroupService.removeCompletelyByRootGroupId(deleteGroupId, actionName, transferToUserGroupId, req.user);
 
 
+      const parameters = { action: SupportedAction.ACTION_ADMIN_USER_GROUP_DELETE };
+      activityEvent.emit('update', res.locals.activity._id, parameters);
+
       return res.apiv3({ userGroups });
       return res.apiv3({ userGroups });
     }
     }
     catch (err) {
     catch (err) {
@@ -473,7 +476,7 @@ module.exports = (crowi) => {
    *                      type: object
    *                      type: object
    *                      description: A result of `UserGroup.updateName`
    *                      description: A result of `UserGroup.updateName`
    */
    */
-  router.put('/:id', loginRequiredStrictly, adminRequired, csrf, validator.update, apiV3FormValidator, async(req, res) => {
+  router.put('/:id', loginRequiredStrictly, adminRequired, csrf, validator.update, apiV3FormValidator, addActivity, async(req, res) => {
     const { id } = req.params;
     const { id } = req.params;
     const {
     const {
       name, description, parentId, forceUpdateParents = false,
       name, description, parentId, forceUpdateParents = false,
@@ -482,6 +485,9 @@ module.exports = (crowi) => {
     try {
     try {
       const userGroup = await crowi.userGroupService.updateGroup(id, name, description, parentId, forceUpdateParents);
       const userGroup = await crowi.userGroupService.updateGroup(id, name, description, parentId, forceUpdateParents);
 
 
+      const parameters = { action: SupportedAction.ACTION_ADMIN_USER_GROUP_UPDATE };
+      activityEvent.emit('update', res.locals.activity._id, parameters);
+
       return res.apiv3({ userGroup });
       return res.apiv3({ userGroup });
     }
     }
     catch (err) {
     catch (err) {
@@ -639,7 +645,7 @@ module.exports = (crowi) => {
    *                      type: object
    *                      type: object
    *                      description: the associative entity between user and userGroup
    *                      description: the associative entity between user and userGroup
    */
    */
-  router.post('/:id/users/:username', loginRequiredStrictly, adminRequired, validator.users.post, apiV3FormValidator, async(req, res) => {
+  router.post('/:id/users/:username', loginRequiredStrictly, adminRequired, validator.users.post, apiV3FormValidator, addActivity, async(req, res) => {
     const { id, username } = req.params;
     const { id, username } = req.params;
 
 
     try {
     try {
@@ -660,6 +666,8 @@ module.exports = (crowi) => {
       const insertedRelations = await UserGroupRelation.createRelations(groupIdsOfRelationToCreate, user);
       const insertedRelations = await UserGroupRelation.createRelations(groupIdsOfRelationToCreate, user);
       const serializedUser = serializeUserSecurely(user);
       const serializedUser = serializeUserSecurely(user);
 
 
+      const parameters = { action: SupportedAction.ACTION_ADMIN_USER_GROUP_ADD_USER };
+      activityEvent.emit('update', res.locals.activity._id, parameters);
       return res.apiv3({ user: serializedUser, createdRelationCount: insertedRelations.length });
       return res.apiv3({ user: serializedUser, createdRelationCount: insertedRelations.length });
     }
     }
     catch (err) {
     catch (err) {