mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-18 10:03:55 +00:00

* add admin audit (#5041) * Test audit (#5058) * feat: operation index * fix: delete update vector * perf: Clear invalid data * perf: index * perf: cleare invalid data * index * perf: audit event * fix: schema enum * add audit.svg (#5060) Co-authored-by: dreamer6680 <146868355@qq.com> * update package * perf: audit * perf: code move * eslint * doc --------- Co-authored-by: gggaaallleee <91131304+gggaaallleee@users.noreply.github.com> Co-authored-by: dreamer6680 <1468683855@qq.com> Co-authored-by: dreamer6680 <146868355@qq.com>
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { Schema, getMongoLogModel } from '../../../common/mongo';
|
|
import { type OperationLogSchema } from '@fastgpt/global/support/user/audit/type';
|
|
import { AdminAuditEventEnum, AuditEventEnum } from '@fastgpt/global/support/user/audit/constants';
|
|
import {
|
|
TeamCollectionName,
|
|
TeamMemberCollectionName
|
|
} from '@fastgpt/global/support/user/team/constant';
|
|
|
|
export const OperationLogCollectionName = 'operationLogs';
|
|
|
|
const OperationLogSchema = new Schema({
|
|
tmbId: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: TeamMemberCollectionName,
|
|
required: true
|
|
},
|
|
teamId: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: TeamCollectionName,
|
|
required: true
|
|
},
|
|
timestamp: {
|
|
type: Date,
|
|
default: () => new Date()
|
|
},
|
|
event: {
|
|
type: String,
|
|
enum: [...Object.values(AuditEventEnum), ...Object.values(AdminAuditEventEnum)],
|
|
required: true
|
|
},
|
|
metadata: {
|
|
type: Object,
|
|
default: {}
|
|
}
|
|
});
|
|
|
|
OperationLogSchema.index({ teamId: 1, tmbId: 1, event: 1 });
|
|
OperationLogSchema.index({ timestamp: 1 }, { expireAfterSeconds: 14 * 24 * 60 * 60 }); // Auto delete after 14 days
|
|
|
|
export const MongoOperationLog = getMongoLogModel<OperationLogSchema>(
|
|
OperationLogCollectionName,
|
|
OperationLogSchema
|
|
);
|