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

Merge pull request #6109 from weseek/feat/97983-97987-get-available-actions-implementation-considering-adding-and-excluding-actions

feat: getAvailableActions implementation considering adding and excluding actions
Haku Mizuki 3 лет назад
Родитель
Сommit
6bdb2cc120

+ 2 - 0
packages/app/.env.development

@@ -31,3 +31,5 @@ OGP_URI="http://ogp:8088"
 # GROWI_APP_ID_FOR_GROWI_CLOUD=012345
 # ACTIVITY_EXPIRATION_SECONDS=2592000
 # AUDIT_LOG_ACTION_GROUP_SIZE=SMALL
+# AUDIT_LOG_ADDITIONAL_ACTIONS=
+# AUDIT_LOG_EXCLUDE_ACTIONS=

+ 30 - 9
packages/app/src/server/service/activity.ts

@@ -1,7 +1,8 @@
 import mongoose from 'mongoose';
 
 import {
-  IActivity, SupportedActionType, ActionGroupSize, AllSmallGroupActions, AllMediumGroupActions, AllLargeGroupActions, AllSupportedActionToNotified,
+  IActivity, SupportedActionType, ActionGroupSize, AllSupportedAction,
+  AllSmallGroupActions, AllMediumGroupActions, AllLargeGroupActions, AllSupportedActionToNotified,
 } from '~/interfaces/activity';
 import { IPage } from '~/interfaces/page';
 import Activity from '~/server/models/activity';
@@ -12,6 +13,15 @@ import Crowi from '../crowi';
 
 const logger = loggerFactory('growi:service:ActivityService');
 
+const parseActionString = (actionsString: string): SupportedActionType[] => {
+  if (actionsString == null) {
+    return [];
+  }
+
+  const actions = actionsString.split(',').map(value => value.trim());
+  return actions.filter(action => (AllSupportedAction as string[]).includes(action)) as SupportedActionType[];
+};
+
 class ActivityService {
 
   crowi!: Crowi;
@@ -49,25 +59,36 @@ class ActivityService {
 
   getAvailableActions = function(): SupportedActionType[] {
     const auditLogActionGroupSize = this.crowi.configManager.getConfig('crowi', 'app:auditLogActionGroupSize') || ActionGroupSize.Small;
+    const auditLogAdditionalActions = this.crowi.configManager.getConfig('crowi', 'app:auditLogAdditionalActions');
+    const auditLogExcludeActions = this.crowi.configManager.getConfig('crowi', 'app:auditLogExcludeActions');
 
-    // TODO: 97982, 97986
-    // Update AvailableActions taking into account the values of "AUDIT_LOG_EXCLUDE_ACTIONS" and “AUDIT_LOG_ADDITONAL_ACTIONS"
-
-    const availableActions: SupportedActionType[] = [...AllSupportedActionToNotified];
+    const availableActionsSet = new Set<SupportedActionType>();
 
+    // Set base action group
     switch (auditLogActionGroupSize) {
       case ActionGroupSize.Small:
-        availableActions.push(...AllSmallGroupActions);
+        AllSmallGroupActions.forEach(action => availableActionsSet.add(action));
         break;
       case ActionGroupSize.Medium:
-        availableActions.push(...AllMediumGroupActions);
+        AllMediumGroupActions.forEach(action => availableActionsSet.add(action));
         break;
       case ActionGroupSize.Large:
-        availableActions.push(...AllLargeGroupActions);
+        AllLargeGroupActions.forEach(action => availableActionsSet.add(action));
         break;
     }
 
-    return Array.from(new Set(availableActions));
+    // Add additionalActions
+    const additionalActions = parseActionString(auditLogAdditionalActions);
+    additionalActions.forEach(action => availableActionsSet.add(action));
+
+    // Delete excludeActions
+    const excludeActions = parseActionString(auditLogExcludeActions);
+    excludeActions.forEach(action => availableActionsSet.delete(action));
+
+    // Add essentialActions
+    AllSupportedActionToNotified.forEach(action => availableActionsSet.add(action));
+
+    return Array.from(availableActionsSet);
   }
 
   shoudUpdateActivity = function(action: SupportedActionType): boolean {

+ 12 - 0
packages/app/src/server/service/config-loader.ts

@@ -634,6 +634,18 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type: ValueType.STRING,
     default: 'SMALL',
   },
+  AUDIT_LOG_ADDITIONAL_ACTIONS: {
+    ns: 'crowi',
+    key: 'app:auditLogAdditionalActions',
+    type: ValueType.STRING,
+    default: null,
+  },
+  AUDIT_LOG_EXCLUDE_ACTIONS: {
+    ns: 'crowi',
+    key: 'app:auditLogExcludeActions',
+    type: ValueType.STRING,
+    default: null,
+  },
 };