feat: team permission refine (#4494) (#4498)

* feat: team permission refine (#4402)

* chore: team permission extend

* feat: manage team permission

* chore: api auth

* fix: i18n

* feat: add initv493

* fix: test, org auth manager

* test: app test for refined permission

* update init sh

* fix: add/remove manage permission (#4427)

* fix: add/remove manage permission

* fix: github action fastgpt-test

* fix: mock create model

* fix: team write permission

* fix: ts

* account permission

---------

Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com>
This commit is contained in:
Archer
2025-04-10 11:11:54 +08:00
committed by GitHub
parent 80f41dd2a9
commit 199f454b6b
51 changed files with 1116 additions and 460 deletions

View File

@@ -1,38 +0,0 @@
import { MongoApp } from '@fastgpt/service/core/app/schema';
import { MongoAppVersion } from '@fastgpt/service/core/app/version/schema';
import { getRootUser } from '@test/datas/users';
import { Call } from '@test/utils/request';
import { describe, expect, it } from 'vitest';
import handler, {
type versionListBody,
type versionListResponse
} from '@/pages/api/core/app/version/list';
describe('app version list test', () => {
it('should return app version list', async () => {
const root = await getRootUser();
const app = await MongoApp.create({
name: 'test',
tmbId: root.tmbId,
teamId: root.teamId
});
await MongoAppVersion.create(
[...Array(10).keys()].map((i) => ({
tmbId: root.tmbId,
appId: app._id,
versionName: `v${i}`
}))
);
const res = await Call<versionListBody, {}, versionListResponse>(handler, {
auth: root,
body: {
pageSize: 10,
offset: 0,
appId: app._id
}
});
expect(res.code).toBe(200);
expect(res.data.total).toBe(10);
expect(res.data.list.length).toBe(10);
});
});

View File

@@ -1,87 +0,0 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { getDatasetCollectionPaths } from '@/pages/api/core/dataset/collection/paths';
import { MongoDatasetCollection } from '@fastgpt/service/core/dataset/collection/schema';
vi.mock('@fastgpt/service/core/dataset/collection/schema', () => ({
MongoDatasetCollection: {
findOne: vi.fn()
},
DatasetColCollectionName: 'dataset_collections'
}));
describe('getDatasetCollectionPaths', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('should return empty array for empty parentId', async () => {
const result = await getDatasetCollectionPaths({});
expect(result).toEqual([]);
});
it('should return empty array if collection not found', async () => {
vi.mocked(MongoDatasetCollection.findOne).mockResolvedValueOnce(null);
const result = await getDatasetCollectionPaths({ parentId: 'nonexistent-id' });
expect(result).toEqual([]);
});
it('should return single path for collection without parent', async () => {
vi.mocked(MongoDatasetCollection.findOne).mockResolvedValueOnce({
_id: 'col1',
name: 'Collection 1',
parentId: ''
});
const result = await getDatasetCollectionPaths({ parentId: 'col1' });
expect(result).toEqual([{ parentId: 'col1', parentName: 'Collection 1' }]);
});
it('should return full path for nested collections', async () => {
vi.mocked(MongoDatasetCollection.findOne)
.mockResolvedValueOnce({
_id: 'col3',
name: 'Collection 3',
parentId: 'col2'
})
.mockResolvedValueOnce({
_id: 'col2',
name: 'Collection 2',
parentId: 'col1'
})
.mockResolvedValueOnce({
_id: 'col1',
name: 'Collection 1',
parentId: ''
});
const result = await getDatasetCollectionPaths({ parentId: 'col3' });
expect(result).toEqual([
{ parentId: 'col1', parentName: 'Collection 1' },
{ parentId: 'col2', parentName: 'Collection 2' },
{ parentId: 'col3', parentName: 'Collection 3' }
]);
});
it('should handle circular references gracefully', async () => {
vi.mocked(MongoDatasetCollection.findOne)
.mockResolvedValueOnce({
_id: 'col1',
name: 'Collection 1',
parentId: 'col2'
})
.mockResolvedValueOnce({
_id: 'col2',
name: 'Collection 2',
parentId: 'col1'
});
const result = await getDatasetCollectionPaths({ parentId: 'col1' });
expect(result).toEqual([
{ parentId: 'col2', parentName: 'Collection 2' },
{ parentId: 'col1', parentName: 'Collection 1' }
]);
});
});

View File

@@ -1,83 +0,0 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { getParents } from '@/pages/api/core/dataset/paths';
import { MongoDataset } from '@fastgpt/service/core/dataset/schema';
vi.mock('@fastgpt/service/core/dataset/schema', () => ({
MongoDataset: {
findById: vi.fn()
},
ChunkSettings: {},
DatasetCollectionName: 'datasets'
}));
describe('getParents', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('should return empty array if parentId is undefined', async () => {
const result = await getParents(undefined);
expect(result).toEqual([]);
});
it('should return empty array if parent not found', async () => {
vi.mocked(MongoDataset.findById).mockResolvedValueOnce(null);
const result = await getParents('non-existent-id');
expect(result).toEqual([]);
});
it('should return single parent path if no further parents', async () => {
vi.mocked(MongoDataset.findById).mockResolvedValueOnce({
name: 'Parent1',
parentId: undefined
});
const result = await getParents('parent1-id');
expect(result).toEqual([{ parentId: 'parent1-id', parentName: 'Parent1' }]);
});
it('should return full parent path for nested parents', async () => {
vi.mocked(MongoDataset.findById)
.mockResolvedValueOnce({
name: 'Child',
parentId: 'parent1-id'
})
.mockResolvedValueOnce({
name: 'Parent1',
parentId: 'parent2-id'
})
.mockResolvedValueOnce({
name: 'Parent2',
parentId: undefined
});
const result = await getParents('child-id');
expect(result).toEqual([
{ parentId: 'parent2-id', parentName: 'Parent2' },
{ parentId: 'parent1-id', parentName: 'Parent1' },
{ parentId: 'child-id', parentName: 'Child' }
]);
});
it('should handle circular references gracefully', async () => {
vi.mocked(MongoDataset.findById)
.mockResolvedValueOnce({
name: 'Node1',
parentId: 'node2-id'
})
.mockResolvedValueOnce({
name: 'Node2',
parentId: 'node1-id' // Circular reference
});
const result = await getParents('node1-id');
expect(result).toEqual([
{ parentId: 'node2-id', parentName: 'Node2' },
{ parentId: 'node1-id', parentName: 'Node1' }
]);
});
});

View File

@@ -1,6 +1,6 @@
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { it, expect, vi } from 'vitest';
import { dispatchWorkFlow } from '@fastgpt/service/core/workflow/dispatch';
import {
getWorkflowEntryNodeIds,
@@ -29,8 +29,9 @@ vi.mock(import('@fastgpt/service/support/wallet/usage/utils'), async (importOrig
});
const testWorkflow = async (path: string) => {
const workflowStr = readFileSync(resolve(path), 'utf-8');
const workflow = JSON.parse(workflowStr);
const fileContent = readFileSync(resolve(process.cwd(), path), 'utf-8');
const workflow = JSON.parse(fileContent);
console.log(workflow, 111);
const { nodes, edges, chatConfig } = workflow;
let runtimeNodes = storeNodes2RuntimeNodes(nodes, getWorkflowEntryNodeIds(nodes));
const variables = {};
@@ -74,9 +75,9 @@ const testWorkflow = async (path: string) => {
it('Workflow test: simple workflow', async () => {
// create a simple app
await testWorkflow('test/cases/workflow/simple.json');
// await testWorkflow('test/cases/service/core/app/workflow/loopTest.json');
});
it('Workflow test: output test', async () => {
console.log(await testWorkflow('test/cases/workflow/loopTest.json'));
// console.log(await testWorkflow('@/test/cases/workflow/loopTest.json'));
});