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

consider "additonalActions" and "excludeActions"

Shun Miyazawa 3 лет назад
Родитель
Сommit
04a2323251
1 измененных файлов с 23 добавлено и 4 удалено
  1. 23 4
      packages/app/src/server/service/activity.ts

+ 23 - 4
packages/app/src/server/service/activity.ts

@@ -1,3 +1,4 @@
+import { differenceWith } from 'lodash';
 import mongoose from 'mongoose';
 
 import {
@@ -12,6 +13,14 @@ import Crowi from '../crowi';
 
 const logger = loggerFactory('growi:service:ActivityService');
 
+const parseActionString = (actionsString: SupportedActionType): SupportedActionType[] => {
+  if (actionsString == null) {
+    return [];
+  }
+
+  return (actionsString as string).split(',').map(value => value.trim()) as SupportedActionType[];
+};
+
 class ActivityService {
 
   crowi!: Crowi;
@@ -49,11 +58,20 @@ class ActivityService {
 
   getAvailableActions = function(): SupportedActionType[] {
     const auditLogActionGroupSize = this.crowi.configManager.getConfig('crowi', 'app:auditLogActionGroupSize') || ActionGroupSize.Small;
+    const auditLogAdditonalActions = this.crowi.configManager.getConfig('crowi', 'app:auditLogAdditonalActions');
+    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"
+    let additonalActions: SupportedActionType[] = [];
+    if (auditLogAdditonalActions != null) {
+      additonalActions = parseActionString(auditLogAdditonalActions);
+    }
+
+    let excludeActions: SupportedActionType[] = [];
+    if (auditLogExcludeActions != null) {
+      excludeActions = parseActionString(auditLogExcludeActions);
+    }
 
-    const availableActions: SupportedActionType[] = [...AllSupportedActionToNotified];
+    const availableActions: SupportedActionType[] = [...AllSupportedActionToNotified, ...additonalActions];
 
     switch (auditLogActionGroupSize) {
       case ActionGroupSize.Small:
@@ -67,7 +85,8 @@ class ActivityService {
         break;
     }
 
-    return Array.from(new Set(availableActions));
+    // availableActions - excludeActions
+    return differenceWith(Array.from(new Set(availableActions)), excludeActions);
   }
 
   shoudUpdateActivity = function(action: SupportedActionType): boolean {