plugin-git-manager 1.2.27 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +151 -108
- package/client-v2.d.ts +2 -2
- package/client-v2.js +1 -1
- package/client.d.ts +3 -3
- package/client.js +1 -1
- package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
- package/dist/client/941.1793e67472872992.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
- package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
- package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
- package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
- package/dist/client-v2/941.b0d55429cd053f32.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +9 -8
- package/dist/locale/en-US.json +396 -297
- package/dist/locale/vi-VN.json +384 -292
- package/dist/locale/zh-CN.json +150 -51
- package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/index.cjs +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/git-actions.js +90 -36
- package/dist/server/actions/gitlab-api.js +4 -2
- package/dist/server/actions/poller.js +5 -2
- package/dist/server/actions/review-cutover.js +137 -0
- package/dist/server/actions/review.js +150 -51
- package/dist/server/actions/role-permissions.js +1 -0
- package/dist/server/ai-tools.js +8 -9
- package/dist/server/collections/gitCodeReviews.js +10 -0
- package/dist/server/collections/gitReviewCutover.js +44 -0
- package/dist/server/collections/gitReviewFlows.js +3 -0
- package/dist/server/collections/gitReviewInbox.js +51 -0
- package/dist/server/collections/gitReviewProjects.js +43 -0
- package/dist/server/collections/gitReviewRequests.js +56 -0
- package/dist/server/index.js +8 -2
- package/dist/server/plugin.js +57 -20
- package/dist/server/poller.js +95 -74
- package/dist/server/repository-access.js +23 -5
- package/dist/server/request-method-policy.js +76 -0
- package/dist/server/review-control-access.js +79 -0
- package/dist/server/services/legacy-post-service.js +412 -0
- package/dist/server/services/registry-content-service.js +4 -3
- package/dist/server/services/review-service.js +1451 -0
- package/dist/server/services/review-source.js +325 -0
- package/dist/server/utils/get-repo-account.js +3 -2
- package/dist/server/utils/url-security.js +24 -0
- package/package.json +61 -43
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/src/client/__tests__/CommitHistory.test.tsx +79 -0
- package/src/client/__tests__/ReviewHistory.test.tsx +126 -0
- package/src/client/__tests__/RunReviewButton.test.tsx +84 -0
- package/src/client/__tests__/workflowRoutes.test.ts +65 -0
- package/src/client/ai-context.tsx +114 -114
- package/src/client/components/AIEmployeeSelect.tsx +63 -63
- package/src/client/components/CommitHistory.tsx +429 -374
- package/src/client/components/FileExplorer.tsx +386 -386
- package/src/client/components/GitAccounts.tsx +179 -179
- package/src/client/components/GitManagerSettings.tsx +160 -160
- package/src/client/components/GitOperations.tsx +220 -220
- package/src/client/components/LLMModelSelect.tsx +63 -63
- package/src/client/components/LLMServiceSelect.tsx +58 -58
- package/src/client/components/MarkdownView.tsx +80 -80
- package/src/client/components/MergeRequests.tsx +790 -790
- package/src/client/components/PollingStatus.tsx +225 -225
- package/src/client/components/RepositoryConfig.tsx +335 -335
- package/src/client/components/RepositoryPermissions.tsx +123 -123
- package/src/client/components/ReviewFlows.tsx +352 -303
- package/src/client/components/ReviewHistory.tsx +796 -566
- package/src/client/components/RunReviewButton.tsx +57 -173
- package/src/client/context/GitManagerContext.tsx +92 -92
- package/src/client/index.tsx +91 -82
- package/src/client/locale.ts +9 -9
- package/src/client/promptTemplates.ts +31 -31
- package/src/client/workflowRoutes.ts +42 -0
- package/src/client-v2/ai-context.tsx +99 -0
- package/src/client-v2/components/SubtreeSplits.tsx +547 -547
- package/src/client-v2/index.tsx +1 -1
- package/src/client-v2/locale.ts +8 -8
- package/src/client-v2/plugin.tsx +67 -39
- package/src/index.ts +2 -2
- package/src/locale/en-US.json +396 -297
- package/src/locale/vi-VN.json +384 -292
- package/src/locale/zh-CN.json +150 -51
- package/src/server/__tests__/git-actions.test.ts +24 -24
- package/src/server/__tests__/git-security.test.ts +170 -0
- package/src/server/__tests__/plugin-url-security.test.ts +17 -17
- package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
- package/src/server/__tests__/poller.test.ts +37 -37
- package/src/server/__tests__/repository-access.test.ts +760 -752
- package/src/server/__tests__/review-service.integration.test.ts +1263 -0
- package/src/server/__tests__/review.test.ts +76 -137
- package/src/server/__tests__/role-permissions.test.ts +147 -147
- package/src/server/__tests__/smoke.test.ts +139 -17
- package/src/server/__tests__/subtree.test.ts +85 -85
- package/src/server/actions/git-actions.ts +540 -480
- package/src/server/actions/gitlab-api.ts +422 -411
- package/src/server/actions/poller.ts +39 -27
- package/src/server/actions/review-cutover.ts +121 -0
- package/src/server/actions/review.ts +1498 -1369
- package/src/server/actions/role-permissions.ts +331 -321
- package/src/server/actions/subtree.ts +508 -508
- package/src/server/ai-tools.ts +334 -319
- package/src/server/collections/gitAccounts.ts +56 -56
- package/src/server/collections/gitCodeReviews.ts +218 -199
- package/src/server/collections/gitRepositories.ts +87 -87
- package/src/server/collections/gitReviewCutover.ts +23 -0
- package/src/server/collections/gitReviewFlows.ts +120 -108
- package/src/server/collections/gitReviewInbox.ts +30 -0
- package/src/server/collections/gitReviewProjects.ts +22 -0
- package/src/server/collections/gitReviewRequests.ts +35 -0
- package/src/server/collections/gitSubtreeConfigs.ts +38 -38
- package/src/server/collections/gitSubtreeRuns.ts +30 -30
- package/src/server/index.ts +14 -2
- package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
- package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
- package/src/server/plugin.ts +409 -361
- package/src/server/poller.ts +365 -352
- package/src/server/repository-access.ts +803 -773
- package/src/server/request-method-policy.ts +56 -0
- package/src/server/review-control-access.ts +71 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
- package/src/server/services/__tests__/review-source.test.ts +226 -0
- package/src/server/services/legacy-post-service.ts +550 -0
- package/src/server/services/registry-content-service.ts +495 -484
- package/src/server/services/review-service.ts +1899 -0
- package/src/server/services/review-source.ts +359 -0
- package/src/server/utils/__tests__/redact.test.ts +56 -56
- package/src/server/utils/__tests__/url-security.test.ts +85 -85
- package/src/server/utils/get-repo-account.ts +51 -41
- package/src/server/utils/gitlab-url.ts +38 -38
- package/src/server/utils/redact.ts +87 -87
- package/src/server/utils/url-security.ts +128 -95
- package/dist/client/900.acf7d1fa22f95e71.js +0 -10
- package/dist/client-v2/434.7a27051db18526c0.js +0 -10
- package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
|
@@ -1,137 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const reviewId = await triggerReviewInternal(app, {
|
|
78
|
-
flowId: 8,
|
|
79
|
-
repositoryId: 20,
|
|
80
|
-
targetType: 'branch',
|
|
81
|
-
branch: 'main',
|
|
82
|
-
userId: 7,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
expect(reviewId).toBe(99);
|
|
86
|
-
expect(repositoriesRepository.findOne).toHaveBeenCalledWith({ filterByTk: 20 });
|
|
87
|
-
expect(reviewsRepository.create).toHaveBeenCalledWith({
|
|
88
|
-
values: expect.objectContaining({ flowId: 8, repositoryId: 20, createdById: 7 }),
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('uses the immutable creator field instead of review metadata for worker identity', () => {
|
|
93
|
-
expect(resolveImmutableReviewActorId(record({ createdById: 7, metadata: { userId: 1 } }))).toBe(7);
|
|
94
|
-
expect(resolveImmutableReviewActorId(record({ createdById: null, metadata: { userId: 1 } }))).toBeNull();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('fails closed when a manual review actor has no resolvable roles', async () => {
|
|
98
|
-
const db = {
|
|
99
|
-
getRepository: vi.fn().mockReturnValue({ find: vi.fn().mockResolvedValue([]) }),
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
await expect(resolveBackgroundReviewRoles(db, 7)).rejects.toThrow('Unable to resolve roles for review actor');
|
|
103
|
-
await expect(resolveBackgroundReviewRoles(db, null)).resolves.toEqual(['admin']);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it.each(['completed', 'failed'])(
|
|
107
|
-
'refreshes the immutable actor when a different user requeues a %s review',
|
|
108
|
-
async (status) => {
|
|
109
|
-
const { app, reviewsRepository } = createReviewApp(null, {
|
|
110
|
-
id: 99,
|
|
111
|
-
status,
|
|
112
|
-
latestSha: null,
|
|
113
|
-
createdById: 1,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
await triggerReviewInternal(app, {
|
|
117
|
-
flowId: 8,
|
|
118
|
-
repositoryId: 20,
|
|
119
|
-
targetType: 'branch',
|
|
120
|
-
branch: 'main',
|
|
121
|
-
triggeredBy: 'manual',
|
|
122
|
-
userId: 7,
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
expect(reviewsRepository.update).toHaveBeenCalledWith({
|
|
126
|
-
filterByTk: 99,
|
|
127
|
-
values: expect.objectContaining({
|
|
128
|
-
createdById: 7,
|
|
129
|
-
triggeredBy: 'manual',
|
|
130
|
-
status: 'pending',
|
|
131
|
-
metadata: expect.objectContaining({ userId: 7 }),
|
|
132
|
-
}),
|
|
133
|
-
});
|
|
134
|
-
expect(reviewsRepository.create).not.toHaveBeenCalled();
|
|
135
|
-
},
|
|
136
|
-
);
|
|
137
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Application } from '@nocobase/server';
|
|
11
|
+
import { vi } from 'vitest';
|
|
12
|
+
|
|
13
|
+
import { resolveBackgroundReviewRoles, resolveImmutableReviewActorId, triggerReviewInternal } from '../actions/review';
|
|
14
|
+
|
|
15
|
+
function record(values: Record<string, unknown>) {
|
|
16
|
+
return {
|
|
17
|
+
get(attribute: string) {
|
|
18
|
+
return values[attribute];
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function createApp(enqueue?: (input: Record<string, unknown>) => Promise<number>) {
|
|
24
|
+
const reviewService = enqueue ? { enqueue } : undefined;
|
|
25
|
+
return {
|
|
26
|
+
pm: {
|
|
27
|
+
get: vi.fn((name: string) => (name === 'git-manager' ? { reviewService } : undefined)),
|
|
28
|
+
},
|
|
29
|
+
} as unknown as Application;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('Git Manager review admission adapter', () => {
|
|
33
|
+
it('delegates the selected manual request to the durable review service', async () => {
|
|
34
|
+
const enqueue = vi.fn(async () => 99);
|
|
35
|
+
const app = createApp(enqueue);
|
|
36
|
+
const input = {
|
|
37
|
+
flowId: 8,
|
|
38
|
+
repositoryId: 20,
|
|
39
|
+
targetType: 'commit' as const,
|
|
40
|
+
commitSha: 'a'.repeat(40),
|
|
41
|
+
triggeredBy: 'manual' as const,
|
|
42
|
+
userId: 7,
|
|
43
|
+
actorRoles: ['root'],
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
await expect(triggerReviewInternal(app, input)).resolves.toBe(99);
|
|
47
|
+
expect(app.pm.get).toHaveBeenCalledWith('git-manager');
|
|
48
|
+
expect(enqueue).toHaveBeenCalledWith(input);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('fails closed when the durable review service is not registered', async () => {
|
|
52
|
+
await expect(
|
|
53
|
+
triggerReviewInternal(createApp(), {
|
|
54
|
+
repositoryId: 20,
|
|
55
|
+
targetType: 'branch',
|
|
56
|
+
branch: 'main',
|
|
57
|
+
userId: 7,
|
|
58
|
+
actorRoles: ['root'],
|
|
59
|
+
}),
|
|
60
|
+
).rejects.toThrow('Git review workflow service is unavailable');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('uses the immutable creator field instead of review metadata for worker identity', () => {
|
|
64
|
+
expect(resolveImmutableReviewActorId(record({ createdById: 7, metadata: { userId: 1 } }))).toBe(7);
|
|
65
|
+
expect(resolveImmutableReviewActorId(record({ createdById: null, metadata: { userId: 1 } }))).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('fails closed when a manual review actor has no resolvable roles', async () => {
|
|
69
|
+
const db = {
|
|
70
|
+
getRepository: vi.fn().mockReturnValue({ find: vi.fn().mockResolvedValue([]) }),
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
await expect(resolveBackgroundReviewRoles(db, 7)).rejects.toThrow('Unable to resolve roles for review actor');
|
|
74
|
+
await expect(resolveBackgroundReviewRoles(db, null)).resolves.toEqual(['admin']);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
import type { Database, Model } from '@nocobase/database';
|
|
2
|
-
import { vi } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
getRepositoryPermissionIds,
|
|
6
|
-
getRepositoryPermissionScope,
|
|
7
|
-
repositoryPermissionIdsForDisplay,
|
|
8
|
-
syncScopedActions,
|
|
9
|
-
} from '../actions/role-permissions';
|
|
10
|
-
|
|
11
|
-
function permissionAction(name: string, repositoryIds: Array<number | string>) {
|
|
12
|
-
return {
|
|
13
|
-
toJSON: () => ({
|
|
14
|
-
name,
|
|
15
|
-
scope: { scope: { $and: [{ id: { $in: repositoryIds } }] } },
|
|
16
|
-
}),
|
|
17
|
-
} as unknown as Model;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
describe('Git Manager role permissions', () => {
|
|
21
|
-
it('reads repository IDs from legacy scoped actions', () => {
|
|
22
|
-
const actions = [permissionAction('read', [1]), permissionAction('write', [1, 2])];
|
|
23
|
-
|
|
24
|
-
expect(getRepositoryPermissionIds(actions, ['read', 'write'])).toEqual([1, 2]);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('does not include repository IDs from unrelated actions', () => {
|
|
28
|
-
const actions = [permissionAction('destroy', [3]), permissionAction('write', [1])];
|
|
29
|
-
|
|
30
|
-
expect(getRepositoryPermissionIds(actions, ['write'])).toEqual([1]);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('preserves direct and equality repository scopes from legacy roles', () => {
|
|
34
|
-
const directScope = {
|
|
35
|
-
toJSON: () => ({
|
|
36
|
-
name: 'read',
|
|
37
|
-
scope: { scope: { $and: [{ id: 42 }] } },
|
|
38
|
-
}),
|
|
39
|
-
} as unknown as Model;
|
|
40
|
-
const equalityScope = {
|
|
41
|
-
toJSON: () => ({
|
|
42
|
-
name: 'write',
|
|
43
|
-
scope: { scope: { $or: [{ id: { $eq: '43' } }, { id: { $in: [44] } }] } },
|
|
44
|
-
}),
|
|
45
|
-
} as unknown as Model;
|
|
46
|
-
|
|
47
|
-
expect(getRepositoryPermissionIds([directScope, equalityScope], ['read', 'write'])).toEqual([42, '43', 44]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('recognizes an unscoped legacy permission as access to every repository', () => {
|
|
51
|
-
const unscopedAction = {
|
|
52
|
-
toJSON: () => ({ name: 'read' }),
|
|
53
|
-
} as unknown as Model;
|
|
54
|
-
|
|
55
|
-
expect(getRepositoryPermissionScope([unscopedAction], ['read'])).toEqual({
|
|
56
|
-
ids: [],
|
|
57
|
-
unrestricted: true,
|
|
58
|
-
supported: true,
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('expands an unrestricted scope to the repository IDs shown by the role editor', () => {
|
|
63
|
-
expect(repositoryPermissionIdsForDisplay({ ids: [], unrestricted: true, supported: true }, [1, 2])).toEqual([1, 2]);
|
|
64
|
-
expect(repositoryPermissionIdsForDisplay({ ids: [], unrestricted: false, supported: true }, [1, 2])).toEqual([]);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('does not widen a legacy scope whose repository conditions intersect', () => {
|
|
68
|
-
const intersectingScope = {
|
|
69
|
-
toJSON: () => ({
|
|
70
|
-
name: 'read',
|
|
71
|
-
scope: { scope: { $and: [{ id: { $in: [1, 2] } }, { id: { $in: [2, 3] } }] } },
|
|
72
|
-
}),
|
|
73
|
-
} as unknown as Model;
|
|
74
|
-
|
|
75
|
-
expect(getRepositoryPermissionScope([intersectingScope], ['read'])).toEqual({
|
|
76
|
-
ids: [2],
|
|
77
|
-
unrestricted: false,
|
|
78
|
-
supported: true,
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('marks unsupported legacy scopes as unsafe to migrate', () => {
|
|
83
|
-
const unsupportedScope = {
|
|
84
|
-
toJSON: () => ({
|
|
85
|
-
name: 'read',
|
|
86
|
-
scope: { scope: { $and: [{ id: { $in: [1] } }, { status: 'active' }] } },
|
|
87
|
-
}),
|
|
88
|
-
} as unknown as Model;
|
|
89
|
-
|
|
90
|
-
expect(getRepositoryPermissionScope([unsupportedScope], ['read'])).toEqual({
|
|
91
|
-
ids: [],
|
|
92
|
-
unrestricted: false,
|
|
93
|
-
supported: false,
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('creates unscoped v2 actions when migrating an unrestricted legacy permission', async () => {
|
|
98
|
-
const actionsRepository = {
|
|
99
|
-
findOne: vi.fn().mockResolvedValue(null),
|
|
100
|
-
create: vi.fn().mockResolvedValue(undefined),
|
|
101
|
-
};
|
|
102
|
-
const db = {
|
|
103
|
-
getRepository: vi.fn((name: string) => {
|
|
104
|
-
if (name === 'rolesResourcesActions') return actionsRepository;
|
|
105
|
-
throw new Error(`Unexpected repository ${name}`);
|
|
106
|
-
}),
|
|
107
|
-
} as unknown as Database;
|
|
108
|
-
const resource = {
|
|
109
|
-
get: (attribute: string) => (attribute === 'id' ? 1 : undefined),
|
|
110
|
-
} as unknown as Model;
|
|
111
|
-
|
|
112
|
-
await syncScopedActions(db, resource, ['fileContent'], [], { unrestricted: true });
|
|
113
|
-
|
|
114
|
-
expect(actionsRepository.create).toHaveBeenCalledWith({
|
|
115
|
-
values: { rolesResourceId: 1, name: 'fileContent' },
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('persists a deny-all scope instead of deleting a zero-selection action', async () => {
|
|
120
|
-
const actionsRepository = {
|
|
121
|
-
findOne: vi.fn().mockResolvedValue(null),
|
|
122
|
-
create: vi.fn().mockResolvedValue(undefined),
|
|
123
|
-
};
|
|
124
|
-
const scopesRepository = {
|
|
125
|
-
create: vi.fn().mockResolvedValue({ get: (attribute: string) => (attribute === 'id' ? 99 : undefined) }),
|
|
126
|
-
};
|
|
127
|
-
const db = {
|
|
128
|
-
getRepository: vi.fn((name: string) => {
|
|
129
|
-
if (name === 'rolesResourcesActions') return actionsRepository;
|
|
130
|
-
if (name === 'rolesResourcesScopes') return scopesRepository;
|
|
131
|
-
throw new Error(`Unexpected repository ${name}`);
|
|
132
|
-
}),
|
|
133
|
-
} as unknown as Database;
|
|
134
|
-
const resource = {
|
|
135
|
-
get: (attribute: string) => (attribute === 'id' ? 1 : undefined),
|
|
136
|
-
} as unknown as Model;
|
|
137
|
-
|
|
138
|
-
await syncScopedActions(db, resource, ['fileContent'], []);
|
|
139
|
-
|
|
140
|
-
expect(scopesRepository.create).toHaveBeenCalledWith({
|
|
141
|
-
values: { scope: { $and: [{ id: { $in: [] } }] } },
|
|
142
|
-
});
|
|
143
|
-
expect(actionsRepository.create).toHaveBeenCalledWith({
|
|
144
|
-
values: { rolesResourceId: 1, name: 'fileContent', scopeId: 99 },
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
});
|
|
1
|
+
import type { Database, Model } from '@nocobase/database';
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
getRepositoryPermissionIds,
|
|
6
|
+
getRepositoryPermissionScope,
|
|
7
|
+
repositoryPermissionIdsForDisplay,
|
|
8
|
+
syncScopedActions,
|
|
9
|
+
} from '../actions/role-permissions';
|
|
10
|
+
|
|
11
|
+
function permissionAction(name: string, repositoryIds: Array<number | string>) {
|
|
12
|
+
return {
|
|
13
|
+
toJSON: () => ({
|
|
14
|
+
name,
|
|
15
|
+
scope: { scope: { $and: [{ id: { $in: repositoryIds } }] } },
|
|
16
|
+
}),
|
|
17
|
+
} as unknown as Model;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('Git Manager role permissions', () => {
|
|
21
|
+
it('reads repository IDs from legacy scoped actions', () => {
|
|
22
|
+
const actions = [permissionAction('read', [1]), permissionAction('write', [1, 2])];
|
|
23
|
+
|
|
24
|
+
expect(getRepositoryPermissionIds(actions, ['read', 'write'])).toEqual([1, 2]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('does not include repository IDs from unrelated actions', () => {
|
|
28
|
+
const actions = [permissionAction('destroy', [3]), permissionAction('write', [1])];
|
|
29
|
+
|
|
30
|
+
expect(getRepositoryPermissionIds(actions, ['write'])).toEqual([1]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('preserves direct and equality repository scopes from legacy roles', () => {
|
|
34
|
+
const directScope = {
|
|
35
|
+
toJSON: () => ({
|
|
36
|
+
name: 'read',
|
|
37
|
+
scope: { scope: { $and: [{ id: 42 }] } },
|
|
38
|
+
}),
|
|
39
|
+
} as unknown as Model;
|
|
40
|
+
const equalityScope = {
|
|
41
|
+
toJSON: () => ({
|
|
42
|
+
name: 'write',
|
|
43
|
+
scope: { scope: { $or: [{ id: { $eq: '43' } }, { id: { $in: [44] } }] } },
|
|
44
|
+
}),
|
|
45
|
+
} as unknown as Model;
|
|
46
|
+
|
|
47
|
+
expect(getRepositoryPermissionIds([directScope, equalityScope], ['read', 'write'])).toEqual([42, '43', 44]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('recognizes an unscoped legacy permission as access to every repository', () => {
|
|
51
|
+
const unscopedAction = {
|
|
52
|
+
toJSON: () => ({ name: 'read' }),
|
|
53
|
+
} as unknown as Model;
|
|
54
|
+
|
|
55
|
+
expect(getRepositoryPermissionScope([unscopedAction], ['read'])).toEqual({
|
|
56
|
+
ids: [],
|
|
57
|
+
unrestricted: true,
|
|
58
|
+
supported: true,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('expands an unrestricted scope to the repository IDs shown by the role editor', () => {
|
|
63
|
+
expect(repositoryPermissionIdsForDisplay({ ids: [], unrestricted: true, supported: true }, [1, 2])).toEqual([1, 2]);
|
|
64
|
+
expect(repositoryPermissionIdsForDisplay({ ids: [], unrestricted: false, supported: true }, [1, 2])).toEqual([]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('does not widen a legacy scope whose repository conditions intersect', () => {
|
|
68
|
+
const intersectingScope = {
|
|
69
|
+
toJSON: () => ({
|
|
70
|
+
name: 'read',
|
|
71
|
+
scope: { scope: { $and: [{ id: { $in: [1, 2] } }, { id: { $in: [2, 3] } }] } },
|
|
72
|
+
}),
|
|
73
|
+
} as unknown as Model;
|
|
74
|
+
|
|
75
|
+
expect(getRepositoryPermissionScope([intersectingScope], ['read'])).toEqual({
|
|
76
|
+
ids: [2],
|
|
77
|
+
unrestricted: false,
|
|
78
|
+
supported: true,
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('marks unsupported legacy scopes as unsafe to migrate', () => {
|
|
83
|
+
const unsupportedScope = {
|
|
84
|
+
toJSON: () => ({
|
|
85
|
+
name: 'read',
|
|
86
|
+
scope: { scope: { $and: [{ id: { $in: [1] } }, { status: 'active' }] } },
|
|
87
|
+
}),
|
|
88
|
+
} as unknown as Model;
|
|
89
|
+
|
|
90
|
+
expect(getRepositoryPermissionScope([unsupportedScope], ['read'])).toEqual({
|
|
91
|
+
ids: [],
|
|
92
|
+
unrestricted: false,
|
|
93
|
+
supported: false,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('creates unscoped v2 actions when migrating an unrestricted legacy permission', async () => {
|
|
98
|
+
const actionsRepository = {
|
|
99
|
+
findOne: vi.fn().mockResolvedValue(null),
|
|
100
|
+
create: vi.fn().mockResolvedValue(undefined),
|
|
101
|
+
};
|
|
102
|
+
const db = {
|
|
103
|
+
getRepository: vi.fn((name: string) => {
|
|
104
|
+
if (name === 'rolesResourcesActions') return actionsRepository;
|
|
105
|
+
throw new Error(`Unexpected repository ${name}`);
|
|
106
|
+
}),
|
|
107
|
+
} as unknown as Database;
|
|
108
|
+
const resource = {
|
|
109
|
+
get: (attribute: string) => (attribute === 'id' ? 1 : undefined),
|
|
110
|
+
} as unknown as Model;
|
|
111
|
+
|
|
112
|
+
await syncScopedActions(db, resource, ['fileContent'], [], { unrestricted: true });
|
|
113
|
+
|
|
114
|
+
expect(actionsRepository.create).toHaveBeenCalledWith({
|
|
115
|
+
values: { rolesResourceId: 1, name: 'fileContent' },
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('persists a deny-all scope instead of deleting a zero-selection action', async () => {
|
|
120
|
+
const actionsRepository = {
|
|
121
|
+
findOne: vi.fn().mockResolvedValue(null),
|
|
122
|
+
create: vi.fn().mockResolvedValue(undefined),
|
|
123
|
+
};
|
|
124
|
+
const scopesRepository = {
|
|
125
|
+
create: vi.fn().mockResolvedValue({ get: (attribute: string) => (attribute === 'id' ? 99 : undefined) }),
|
|
126
|
+
};
|
|
127
|
+
const db = {
|
|
128
|
+
getRepository: vi.fn((name: string) => {
|
|
129
|
+
if (name === 'rolesResourcesActions') return actionsRepository;
|
|
130
|
+
if (name === 'rolesResourcesScopes') return scopesRepository;
|
|
131
|
+
throw new Error(`Unexpected repository ${name}`);
|
|
132
|
+
}),
|
|
133
|
+
} as unknown as Database;
|
|
134
|
+
const resource = {
|
|
135
|
+
get: (attribute: string) => (attribute === 'id' ? 1 : undefined),
|
|
136
|
+
} as unknown as Model;
|
|
137
|
+
|
|
138
|
+
await syncScopedActions(db, resource, ['fileContent'], []);
|
|
139
|
+
|
|
140
|
+
expect(scopesRepository.create).toHaveBeenCalledWith({
|
|
141
|
+
values: { scope: { $and: [{ id: { $in: [] } }] } },
|
|
142
|
+
});
|
|
143
|
+
expect(actionsRepository.create).toHaveBeenCalledWith({
|
|
144
|
+
values: { rolesResourceId: 1, name: 'fileContent', scopeId: 99 },
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
@@ -1,17 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { execFileSync } from 'child_process';
|
|
11
|
+
import { mkdtempSync, mkdirSync, rmSync, symlinkSync, unlinkSync } from 'fs';
|
|
12
|
+
import { tmpdir } from 'os';
|
|
13
|
+
import { join } from 'path';
|
|
14
|
+
import { createMockServer, type MockServer } from '@nocobase/test';
|
|
15
|
+
import PluginGitManagerServer from '../plugin';
|
|
16
|
+
|
|
17
|
+
describe('Git Manager HTTP integration', () => {
|
|
18
|
+
let app: MockServer;
|
|
19
|
+
let agent: ReturnType<MockServer['agent']>;
|
|
20
|
+
let fixture: string;
|
|
21
|
+
let repoPath: string;
|
|
22
|
+
let repositoryId: number;
|
|
23
|
+
const originalBase = process.env.GIT_REPOS_BASE_PATH;
|
|
24
|
+
|
|
25
|
+
beforeAll(async () => {
|
|
26
|
+
fixture = mkdtempSync(join(tmpdir(), 'git-manager-http-'));
|
|
27
|
+
repoPath = join(fixture, 'repository');
|
|
28
|
+
mkdirSync(repoPath);
|
|
29
|
+
process.env.GIT_REPOS_BASE_PATH = fixture;
|
|
30
|
+
execFileSync('git', ['init', '-b', 'main', repoPath], { stdio: 'ignore' });
|
|
31
|
+
execFileSync(
|
|
32
|
+
'git',
|
|
33
|
+
[
|
|
34
|
+
'-C',
|
|
35
|
+
repoPath,
|
|
36
|
+
'-c',
|
|
37
|
+
'user.name=Test',
|
|
38
|
+
'-c',
|
|
39
|
+
'user.email=test@example.invalid',
|
|
40
|
+
'commit',
|
|
41
|
+
'--allow-empty',
|
|
42
|
+
'-m',
|
|
43
|
+
'fixture',
|
|
44
|
+
],
|
|
45
|
+
{ stdio: 'ignore' },
|
|
46
|
+
);
|
|
47
|
+
execFileSync('git', ['-C', repoPath, 'branch', 'marker'], { stdio: 'ignore' });
|
|
48
|
+
app = await createMockServer({
|
|
49
|
+
acl: true,
|
|
50
|
+
registerActions: true,
|
|
51
|
+
plugins: [
|
|
52
|
+
'field-sort',
|
|
53
|
+
'system-settings',
|
|
54
|
+
'users',
|
|
55
|
+
'auth',
|
|
56
|
+
'acl',
|
|
57
|
+
'data-source-manager',
|
|
58
|
+
'data-source-main',
|
|
59
|
+
'error-handler',
|
|
60
|
+
[PluginGitManagerServer, { name: 'plugin-git-manager' }],
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
const repository = await app.db.getRepository('gitRepositories').create({
|
|
64
|
+
values: { name: 'fixture', localPath: 'repository', repoUrl: 'https://gitlab.com/team/fixture.git' },
|
|
65
|
+
});
|
|
66
|
+
repositoryId = repository.get('id');
|
|
67
|
+
agent = await app.agent().login(await app.db.getRepository('users').findOne());
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
afterAll(async () => {
|
|
71
|
+
await app?.destroy();
|
|
72
|
+
if (originalBase === undefined) delete process.env.GIT_REPOS_BASE_PATH;
|
|
73
|
+
else process.env.GIT_REPOS_BASE_PATH = originalBase;
|
|
74
|
+
if (fixture) rmSync(fixture, { recursive: true, force: true });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('loads the actual plugin, collection and resource handler', async () => {
|
|
78
|
+
expect(app.pm.get('plugin-git-manager')).toBeInstanceOf(PluginGitManagerServer);
|
|
79
|
+
expect(app.db.getCollection('gitRepositories')).toBeTruthy();
|
|
80
|
+
const response = await agent.get('/gitManager:pollerStatus');
|
|
81
|
+
expect(response.status).toBe(200);
|
|
82
|
+
expect(response.body.data).toBeTruthy();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it.each([
|
|
86
|
+
'clone',
|
|
87
|
+
'pull',
|
|
88
|
+
'push',
|
|
89
|
+
'fetch',
|
|
90
|
+
'checkout',
|
|
91
|
+
'triggerReview',
|
|
92
|
+
'reviewApprovePost',
|
|
93
|
+
'reviewReject',
|
|
94
|
+
'pollNow',
|
|
95
|
+
'updateRolePermissions',
|
|
96
|
+
'subtreePreview',
|
|
97
|
+
'subtreeOptions',
|
|
98
|
+
'subtreeRun',
|
|
99
|
+
'subtreeReplace',
|
|
100
|
+
])('rejects GET on %s before executing it', async (action) => {
|
|
101
|
+
const response = await agent.get(`/gitManager:${action}`).query({ repositoryId, branch: 'marker' });
|
|
102
|
+
expect(response.status).toBe(405);
|
|
103
|
+
expect(response.headers.allow).toBe('POST');
|
|
104
|
+
expect(execFileSync('git', ['-C', repoPath, 'branch', '--show-current'], { encoding: 'utf8' }).trim()).toBe('main');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('rejects a junction escaping the configured root through the real POST handler', async () => {
|
|
108
|
+
const confinedBase = join(fixture, 'confined');
|
|
109
|
+
mkdirSync(confinedBase);
|
|
110
|
+
const alias = join(confinedBase, 'alias');
|
|
111
|
+
symlinkSync(repoPath, alias, 'junction');
|
|
112
|
+
process.env.GIT_REPOS_BASE_PATH = confinedBase;
|
|
113
|
+
try {
|
|
114
|
+
const escaped = await app.db.getRepository('gitRepositories').create({
|
|
115
|
+
values: { name: 'escaped', localPath: 'alias', repoUrl: 'https://gitlab.com/team/fixture.git' },
|
|
116
|
+
});
|
|
117
|
+
const response = await agent
|
|
118
|
+
.post('/gitManager:checkout')
|
|
119
|
+
.send({ repositoryId: escaped.get('id'), branch: 'marker' });
|
|
120
|
+
expect(response.status).toBe(400);
|
|
121
|
+
expect(execFileSync('git', ['-C', repoPath, 'branch', '--show-current'], { encoding: 'utf8' }).trim()).toBe(
|
|
122
|
+
'main',
|
|
123
|
+
);
|
|
124
|
+
} finally {
|
|
125
|
+
process.env.GIT_REPOS_BASE_PATH = fixture;
|
|
126
|
+
unlinkSync(alias);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('rejects HEAD and still allows authorized POST checkout', async () => {
|
|
131
|
+
const head = await agent.head('/gitManager:checkout').query({ repositoryId, branch: 'marker' });
|
|
132
|
+
expect(head.status).toBe(405);
|
|
133
|
+
const post = await agent.post('/gitManager:checkout').send({ repositoryId, branch: 'marker' });
|
|
134
|
+
expect(post.status).toBe(200);
|
|
135
|
+
expect(execFileSync('git', ['-C', repoPath, 'branch', '--show-current'], { encoding: 'utf8' }).trim()).toBe(
|
|
136
|
+
'marker',
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
});
|