Przeglądaj źródła

add grantedGroups

Shun Miyazawa 1 rok temu
rodzic
commit
b143f572b7

+ 25 - 0
apps/app/src/features/openai/server/models/ai-assistant.ts

@@ -1,3 +1,4 @@
+import { type IGrantedGroup, GroupType } from '@growi/core';
 import type mongoose from 'mongoose';
 import type mongoose from 'mongoose';
 import { type Model, type Document, Schema } from 'mongoose';
 import { type Model, type Document, Schema } from 'mongoose';
 
 
@@ -38,6 +39,7 @@ interface AiAssistant {
   instruction?: string
   instruction?: string
   vectorStoreId: string // VectorStoreId of OpenAI Specify (https://platform.openai.com/docs/api-reference/vector-stores/object)
   vectorStoreId: string // VectorStoreId of OpenAI Specify (https://platform.openai.com/docs/api-reference/vector-stores/object)
   types: AiAssistantType[]
   types: AiAssistantType[]
+  grantedGroups: IGrantedGroup[];
   pages: mongoose.Types.ObjectId[]
   pages: mongoose.Types.ObjectId[]
   sharingScope: AiAssistantSharingScope
   sharingScope: AiAssistantSharingScope
   learningScope: AiAssistantLearningScope
   learningScope: AiAssistantLearningScope
@@ -78,6 +80,29 @@ const schema = new Schema<AiAssistantDocument>(
       ref: 'Page',
       ref: 'Page',
       required: true,
       required: true,
     }],
     }],
+    grantedGroups: {
+      type: [{
+        type: {
+          type: String,
+          enum: Object.values(GroupType),
+          required: true,
+          default: 'UserGroup',
+        },
+        item: {
+          type: Schema.Types.ObjectId,
+          refPath: 'grantedGroups.type',
+          required: true,
+          index: true,
+        },
+      }],
+      validate: [function(arr: IGrantedGroup[]): boolean {
+        if (arr == null) return true;
+        const uniqueItemValues = new Set(arr.map(e => e.item));
+        return arr.length === uniqueItemValues.size;
+      }, 'grantedGroups contains non unique item'],
+      default: [],
+      required: true,
+    },
     sharingScope: {
     sharingScope: {
       type: String,
       type: String,
       enum: Object.values(AiAssistantSharingScope),
       enum: Object.values(AiAssistantSharingScope),