plugin-git-manager 1.3.1 → 1.3.3
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/LICENSE +201 -0
- package/dist/client/317.17ed0018e3e7db00.js +10 -0
- package/dist/client/453.fc3042c9740d8fab.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/317.d2466574d00f94d0.js +10 -0
- package/dist/client-v2/453.5e507c94c59277b1.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +2 -2
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/review-cutover.js +121 -7
- package/dist/server/plugin.js +90 -9
- package/dist/server/repository-access.js +41 -3
- package/dist/server/services/legacy-post-service.js +10 -6
- package/dist/server/services/review-service.js +30 -7
- package/dist/server/services/review-source.js +7 -4
- package/package.json +2 -2
- package/src/client/__tests__/CommitHistory.test.tsx +1 -8
- package/src/client/__tests__/ReviewHistory.test.tsx +1 -8
- package/src/client/__tests__/RunReviewButton.test.tsx +1 -8
- package/src/client/__tests__/workflowRoutes.test.ts +3 -10
- package/src/client/components/CommitHistory.tsx +1 -8
- package/src/client/components/ReviewFlows.tsx +53 -19
- package/src/client/components/ReviewHistory.tsx +1 -8
- package/src/client/components/RunReviewButton.tsx +1 -8
- package/src/client/index.tsx +11 -8
- package/src/client/workflowRoutes.ts +3 -18
- package/src/client-v2/plugin.tsx +11 -0
- package/src/server/__tests__/git-security.test.ts +1 -8
- package/src/server/__tests__/poller-lifecycle.test.ts +1 -8
- package/src/server/__tests__/repository-access.test.ts +1 -8
- package/src/server/__tests__/review-service.integration.test.ts +1 -8
- package/src/server/__tests__/review.test.ts +1 -8
- package/src/server/__tests__/smoke.test.ts +1 -8
- package/src/server/actions/git-actions.ts +1 -8
- package/src/server/actions/gitlab-api.ts +1 -8
- package/src/server/actions/poller.ts +1 -8
- package/src/server/actions/review-cutover.ts +135 -15
- package/src/server/actions/review.ts +1 -8
- package/src/server/actions/role-permissions.ts +1 -8
- package/src/server/ai-tools.ts +1 -8
- package/src/server/collections/gitCodeReviews.ts +1 -8
- package/src/server/collections/gitReviewCutover.ts +1 -8
- package/src/server/collections/gitReviewFlows.ts +1 -8
- package/src/server/collections/gitReviewInbox.ts +1 -8
- package/src/server/collections/gitReviewProjects.ts +1 -8
- package/src/server/collections/gitReviewRequests.ts +1 -8
- package/src/server/index.ts +1 -8
- package/src/server/plugin.ts +88 -8
- package/src/server/poller.ts +1 -8
- package/src/server/repository-access.ts +36 -9
- package/src/server/request-method-policy.ts +1 -8
- package/src/server/review-control-access.ts +1 -8
- package/src/server/services/__tests__/registry-content-service.test.ts +1 -8
- package/src/server/services/__tests__/review-source.test.ts +33 -8
- package/src/server/services/legacy-post-service.ts +11 -14
- package/src/server/services/registry-content-service.ts +1 -8
- package/src/server/services/review-service.ts +35 -21
- package/src/server/services/review-source.ts +8 -12
- package/src/server/utils/get-repo-account.ts +1 -8
- package/src/server/utils/url-security.ts +1 -8
- package/dist/client/941.1793e67472872992.js +0 -10
- package/dist/client-v2/941.b0d55429cd053f32.js +0 -10
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { reviewApprovalHref, workflowHref } from '../workflowRoutes';
|
|
11
4
|
|
|
@@ -40,7 +33,7 @@ describe('Git review workflow route resolution', () => {
|
|
|
40
33
|
else routeWindow.__nocobase_modern_client_prefix__ = originalModernPrefix;
|
|
41
34
|
});
|
|
42
35
|
|
|
43
|
-
it('keeps workflow links in the legacy shell
|
|
36
|
+
it('keeps workflow and approval task links in the legacy shell without forcing a modern prefix', () => {
|
|
44
37
|
routeWindow.__nocobase_modern_client_prefix__ = 'v3-custom';
|
|
45
38
|
routeWindow.__nocobase_public_path__ = '/tenant/app/v3-custom/';
|
|
46
39
|
window.history.replaceState({}, '', '/tenant/app/admin/settings/workflow');
|
|
@@ -48,7 +41,7 @@ describe('Git review workflow route resolution', () => {
|
|
|
48
41
|
|
|
49
42
|
expect(workflowHref(app, 'workflow', 'flow/42')).toBe('/tenant/app/admin/settings/workflow/workflows/flow%2F42');
|
|
50
43
|
expect(workflowHref(app, 'execution', 73)).toBe('/tenant/app/admin/settings/workflow/executions/73');
|
|
51
|
-
expect(reviewApprovalHref(app)).toBe('/tenant/app/
|
|
44
|
+
expect(reviewApprovalHref(app)).toBe('/tenant/app/admin/workflow/tasks/git-review-approval/pending');
|
|
52
45
|
});
|
|
53
46
|
|
|
54
47
|
it('uses the effective modern basename and custom modern prefix for v2 workflow links', () => {
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import React, { useEffect, useState, useCallback, memo } from 'react';
|
|
11
4
|
import { Table, Empty, Spin, Typography, Tag, Drawer, List, Button, Space, Select, Input, theme } from 'antd';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
11
4
|
import {
|
|
@@ -25,8 +18,8 @@ import {
|
|
|
25
18
|
Alert,
|
|
26
19
|
} from 'antd';
|
|
27
20
|
import { PlusOutlined, EditOutlined, DeleteOutlined, BranchesOutlined } from '@ant-design/icons';
|
|
28
|
-
import { useApp } from '@nocobase/client-v2';
|
|
29
|
-
import { useGitManager } from '../context/GitManagerContext';
|
|
21
|
+
import { createAclSnippetAllow, useACLContext, useACLRoleContext, useApp } from '@nocobase/client-v2';
|
|
22
|
+
import { GitManagerProvider, useGitManager } from '../context/GitManagerContext';
|
|
30
23
|
import { AIEmployeeSelect } from './AIEmployeeSelect';
|
|
31
24
|
import { LLMServiceSelect } from './LLMServiceSelect';
|
|
32
25
|
import { LLMModelSelect } from './LLMModelSelect';
|
|
@@ -51,6 +44,25 @@ export const ReviewFlows: React.FC = () => {
|
|
|
51
44
|
const app = useApp();
|
|
52
45
|
const api = app.apiClient;
|
|
53
46
|
const { repos } = useGitManager();
|
|
47
|
+
const aclContext = useACLContext();
|
|
48
|
+
const { parseAction, snippets, allowAll, resources } = useACLRoleContext();
|
|
49
|
+
const snippetAllowed = createAclSnippetAllow(snippets, allowAll);
|
|
50
|
+
const canAct = (action: string) => {
|
|
51
|
+
if (!aclContext) return true;
|
|
52
|
+
const gitWrite = Boolean(parseAction('gitManager:triggerReview'));
|
|
53
|
+
if (resources?.includes('gitManager') && !gitWrite) return false;
|
|
54
|
+
const explicit = Boolean(parseAction(`gitReviewFlows:${action}`));
|
|
55
|
+
if (resources?.includes('gitReviewFlows')) return explicit;
|
|
56
|
+
return (
|
|
57
|
+
explicit ||
|
|
58
|
+
gitWrite ||
|
|
59
|
+
snippetAllowed('pm.plugin-git-manager.write') ||
|
|
60
|
+
snippetAllowed('pm.plugin-git-manager.manage')
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
const canCreate = canAct('create');
|
|
64
|
+
const canUpdate = canAct('update');
|
|
65
|
+
const canDestroy = canAct('destroy');
|
|
54
66
|
const [flows, setFlows] = useState<any[]>([]);
|
|
55
67
|
const [loading, setLoading] = useState(false);
|
|
56
68
|
const [editing, setEditing] = useState<any | null>(null);
|
|
@@ -183,12 +195,16 @@ export const ReviewFlows: React.FC = () => {
|
|
|
183
195
|
width: 100,
|
|
184
196
|
render: (_: any, record: any) => (
|
|
185
197
|
<Space>
|
|
186
|
-
|
|
187
|
-
<
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
198
|
+
{canUpdate && (
|
|
199
|
+
<Tooltip title={t('Edit')}>
|
|
200
|
+
<Button size="small" icon={<EditOutlined />} onClick={() => openEdit(record)} />
|
|
201
|
+
</Tooltip>
|
|
202
|
+
)}
|
|
203
|
+
{canDestroy && (
|
|
204
|
+
<Popconfirm title={t('Delete this flow?')} onConfirm={() => handleDelete(record.id)}>
|
|
205
|
+
<Button size="small" danger icon={<DeleteOutlined />} />
|
|
206
|
+
</Popconfirm>
|
|
207
|
+
)}
|
|
192
208
|
</Space>
|
|
193
209
|
),
|
|
194
210
|
},
|
|
@@ -197,9 +213,11 @@ export const ReviewFlows: React.FC = () => {
|
|
|
197
213
|
return (
|
|
198
214
|
<div>
|
|
199
215
|
<div style={{ marginBottom: 12, display: 'flex', justifyContent: 'space-between' }}>
|
|
200
|
-
|
|
201
|
-
{
|
|
202
|
-
|
|
216
|
+
{canCreate && (
|
|
217
|
+
<Button type="primary" icon={<PlusOutlined />} onClick={openCreate}>
|
|
218
|
+
{t('Add Review Flow')}
|
|
219
|
+
</Button>
|
|
220
|
+
)}
|
|
203
221
|
<Button onClick={load} loading={loading}>
|
|
204
222
|
{t('Refresh')}
|
|
205
223
|
</Button>
|
|
@@ -350,3 +368,19 @@ export const ReviewFlows: React.FC = () => {
|
|
|
350
368
|
</div>
|
|
351
369
|
);
|
|
352
370
|
};
|
|
371
|
+
|
|
372
|
+
function ReviewFlowsPageContent() {
|
|
373
|
+
const { refreshRepos } = useGitManager();
|
|
374
|
+
useEffect(() => {
|
|
375
|
+
refreshRepos();
|
|
376
|
+
}, [refreshRepos]);
|
|
377
|
+
return <ReviewFlows />;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export function ReviewFlowsSettings() {
|
|
381
|
+
return (
|
|
382
|
+
<GitManagerProvider>
|
|
383
|
+
<ReviewFlowsPageContent />
|
|
384
|
+
</GitManagerProvider>
|
|
385
|
+
);
|
|
386
|
+
}
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
11
4
|
import {
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
11
4
|
import { Button, Dropdown, Modal, Form, Select, Input, message, Space, Tooltip, Tag, Alert } from 'antd';
|
package/src/client/index.tsx
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { Plugin } from '@nocobase/client';
|
|
11
4
|
import type PluginAIClientV2 from '@nocobase/plugin-ai/client-v2';
|
|
@@ -16,6 +9,10 @@ const GitManagerSettings = React.lazy(() =>
|
|
|
16
9
|
import('./components/GitManagerSettings').then((m) => ({ default: m.GitManagerSettings })),
|
|
17
10
|
);
|
|
18
11
|
|
|
12
|
+
const ReviewFlowsSettings = React.lazy(() =>
|
|
13
|
+
import('./components/ReviewFlows').then((m) => ({ default: m.ReviewFlowsSettings })),
|
|
14
|
+
);
|
|
15
|
+
|
|
19
16
|
const RepositoryConfig = React.lazy(() =>
|
|
20
17
|
import('./components/RepositoryConfig').then((m) => ({ default: m.RepositoryConfigSettings })),
|
|
21
18
|
);
|
|
@@ -59,6 +56,12 @@ export class PluginGitManagerClient extends Plugin {
|
|
|
59
56
|
aclSnippet: `pm.plugin-git-manager.write`,
|
|
60
57
|
});
|
|
61
58
|
|
|
59
|
+
this.app.pluginSettingsManager.add('git-manager.review-flows', {
|
|
60
|
+
title: this.t('Review Flows'),
|
|
61
|
+
Component: ReviewFlowsSettings,
|
|
62
|
+
aclSnippet: 'pm.plugin-git-manager.read',
|
|
63
|
+
});
|
|
64
|
+
|
|
62
65
|
// Full management — requires full plugin permission
|
|
63
66
|
this.app.pluginSettingsManager.add('git-manager.manage', {
|
|
64
67
|
title: (this as any).t('Manage'),
|
|
@@ -1,18 +1,6 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
|
-
import {
|
|
11
|
-
getModernClientPrefix,
|
|
12
|
-
getRouteRuntimeVersion,
|
|
13
|
-
getV2EffectiveBasePath,
|
|
14
|
-
stripModernClientPrefix,
|
|
15
|
-
} from '@nocobase/client-v2';
|
|
3
|
+
import { getRouteRuntimeVersion, getV2EffectiveBasePath, stripModernClientPrefix } from '@nocobase/client-v2';
|
|
16
4
|
|
|
17
5
|
type App = Parameters<typeof getV2EffectiveBasePath>[0];
|
|
18
6
|
|
|
@@ -34,9 +22,6 @@ export function workflowHref(app: App, type: 'workflow' | 'execution', id: strin
|
|
|
34
22
|
}
|
|
35
23
|
|
|
36
24
|
export function reviewApprovalHref(app: App) {
|
|
37
|
-
const base =
|
|
38
|
-
getRouteRuntimeVersion() === 'modern'
|
|
39
|
-
? getV2EffectiveBasePath(app)
|
|
40
|
-
: join(legacyBase(app), getModernClientPrefix());
|
|
25
|
+
const base = getRouteRuntimeVersion() === 'modern' ? getV2EffectiveBasePath(app) : legacyBase(app);
|
|
41
26
|
return join(base, '/admin/workflow/tasks/git-review-approval/pending');
|
|
42
27
|
}
|
package/src/client-v2/plugin.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
1
3
|
import { Plugin, Application } from '@nocobase/client-v2';
|
|
2
4
|
import type PluginAIClientV2 from '@nocobase/plugin-ai/client-v2';
|
|
3
5
|
import type PluginAclClientV2 from '@nocobase/plugin-acl/client-v2';
|
|
@@ -53,6 +55,15 @@ export class PluginGitManagerClient extends Plugin<Record<string, never>, Applic
|
|
|
53
55
|
import('../client/components/RepositoryConfig').then((m) => ({ default: m.RepositoryConfigSettings })),
|
|
54
56
|
});
|
|
55
57
|
|
|
58
|
+
this.pluginSettingsManager.addPageTabItem({
|
|
59
|
+
menuKey: 'git-manager',
|
|
60
|
+
key: 'review-flows',
|
|
61
|
+
title: this.t('Review Flows'),
|
|
62
|
+
aclSnippet: 'pm.plugin-git-manager.read',
|
|
63
|
+
componentLoader: () =>
|
|
64
|
+
import('../client/components/ReviewFlows').then((m) => ({ default: m.ReviewFlowsSettings })),
|
|
65
|
+
});
|
|
66
|
+
|
|
56
67
|
this.pluginSettingsManager.addPageTabItem({
|
|
57
68
|
menuKey: 'git-manager',
|
|
58
69
|
key: 'manage',
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { execFileSync } from 'child_process';
|
|
11
4
|
import { mkdtempSync, mkdirSync, readFileSync, rmSync, symlinkSync, unlinkSync } from 'fs';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import type { Application } from '@nocobase/server';
|
|
11
4
|
import { getPollerStatus, pollAllRepos, startPoller, stopPoller } from '../poller';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { enforceRepositoryAccess, enforceRepositoryCollectionAccess } from '../repository-access';
|
|
11
4
|
import { vi } from 'vitest';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { execFileSync } from 'child_process';
|
|
11
4
|
import { createHash } from 'crypto';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import type { Application } from '@nocobase/server';
|
|
11
4
|
import { vi } from 'vitest';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { execFileSync } from 'child_process';
|
|
11
4
|
import { mkdtempSync, mkdirSync, rmSync, symlinkSync, unlinkSync } from 'fs';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import simpleGit, { SimpleGit } from 'simple-git';
|
|
11
4
|
import { Context } from '@nocobase/actions';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { Context } from '@nocobase/actions';
|
|
11
4
|
import { getEffectiveActionParams } from '../repository-access';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { Context } from '@nocobase/actions';
|
|
11
4
|
import { pollAllRepos, pollOneRepo, getPollerStatus } from '../poller';
|
|
@@ -1,20 +1,14 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import type { Context } from '@nocobase/actions';
|
|
11
4
|
import type { GitReviewService } from '../services/review-service';
|
|
12
|
-
import { getEffectiveActionParams } from '../repository-access';
|
|
5
|
+
import { getEffectiveActionParams, hasRepositoryAccess, hasUnrestrictedRepositoryAccess } from '../repository-access';
|
|
6
|
+
|
|
7
|
+
type ID = string | number;
|
|
8
|
+
type ReviewCollection = 'gitCodeReviews' | 'gitReviewInbox' | 'gitReviewRequests';
|
|
13
9
|
|
|
14
10
|
function service(ctx: Context): GitReviewService {
|
|
15
|
-
|
|
16
|
-
if (!Array.isArray(roles) || !roles.includes('root') || !ctx.state?.currentUser?.id)
|
|
17
|
-
ctx.throw(403, 'Permission denied');
|
|
11
|
+
if (!ctx.state?.currentUser?.id) ctx.throw(403, ctx.t('Permission denied', { ns: 'plugin-git-manager' }));
|
|
18
12
|
const plugin = (ctx.app.pm.get('plugin-git-manager') || ctx.app.pm.get('git-manager')) as unknown as {
|
|
19
13
|
reviewService?: GitReviewService;
|
|
20
14
|
};
|
|
@@ -22,18 +16,134 @@ function service(ctx: Context): GitReviewService {
|
|
|
22
16
|
return plugin.reviewService;
|
|
23
17
|
}
|
|
24
18
|
|
|
19
|
+
function roles(ctx: Context): string[] {
|
|
20
|
+
const current = ctx.state?.currentRoles;
|
|
21
|
+
return Array.isArray(current) && current.every((role) => typeof role === 'string') ? current : [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function allowed(ctx: Context, repositoryId: unknown, action: string) {
|
|
25
|
+
if (typeof repositoryId !== 'string' && typeof repositoryId !== 'number') {
|
|
26
|
+
return hasUnrestrictedRepositoryAccess({ acl: ctx.app.acl, roles: roles(ctx), action });
|
|
27
|
+
}
|
|
28
|
+
return hasRepositoryAccess({ acl: ctx.app.acl, roles: roles(ctx), repositoryId, action });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function repositoryId(ctx: Context, collection: ReviewCollection, id: ID): Promise<ID | null> {
|
|
32
|
+
const row = await ctx.db.getRepository(collection).findOne({ filterByTk: id });
|
|
33
|
+
const value: unknown = row?.repositoryId;
|
|
34
|
+
return typeof value === 'string' || typeof value === 'number' ? value : null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function requireRecordAccess(ctx: Context, collection: ReviewCollection, id: unknown, action: string) {
|
|
38
|
+
if (typeof id !== 'string' && typeof id !== 'number') return;
|
|
39
|
+
const repoId = await repositoryId(ctx, collection, id);
|
|
40
|
+
if (repoId == null || !(await allowed(ctx, repoId, action))) {
|
|
41
|
+
ctx.throw(403, ctx.t('Permission denied', { ns: 'plugin-git-manager' }));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
25
45
|
export async function reviewCutoverStatus(ctx: Context, next: () => Promise<void>) {
|
|
26
|
-
|
|
46
|
+
const unrestricted = await hasUnrestrictedRepositoryAccess({
|
|
47
|
+
acl: ctx.app.acl,
|
|
48
|
+
roles: roles(ctx),
|
|
49
|
+
action: 'reviewCutoverStatus',
|
|
50
|
+
});
|
|
51
|
+
const status = await service(ctx).cutoverStatus(
|
|
52
|
+
unrestricted ? undefined : (repositoryId) => allowed(ctx, repositoryId, 'reviewCutoverStatus'),
|
|
53
|
+
);
|
|
54
|
+
const repositoryCache = new Map<string, ID | null>();
|
|
55
|
+
const findRepository = async (collection: ReviewCollection, id: ID) => {
|
|
56
|
+
const key = `${collection}:${id}`;
|
|
57
|
+
if (!repositoryCache.has(key)) repositoryCache.set(key, await repositoryId(ctx, collection, id));
|
|
58
|
+
return repositoryCache.get(key) ?? null;
|
|
59
|
+
};
|
|
60
|
+
const visible = async <T>(
|
|
61
|
+
items: T[],
|
|
62
|
+
getRepositoryId: (item: T) => Promise<ID | null>,
|
|
63
|
+
action: string,
|
|
64
|
+
): Promise<Array<T & { canWrite: boolean }>> => {
|
|
65
|
+
const result: Array<T & { canWrite: boolean }> = [];
|
|
66
|
+
for (const item of items) {
|
|
67
|
+
const repoId = await getRepositoryId(item);
|
|
68
|
+
if (!(await allowed(ctx, repoId, 'reviewCutoverStatus'))) continue;
|
|
69
|
+
result.push({ ...item, canWrite: await allowed(ctx, repoId, action) });
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const legacyPendingReviews = await visible(
|
|
75
|
+
status.legacyPendingReviews,
|
|
76
|
+
async (item) => item.repositoryId,
|
|
77
|
+
'reviewCancelLegacy',
|
|
78
|
+
);
|
|
79
|
+
const legacyRunningReviews = await visible(
|
|
80
|
+
status.legacyRunningReviews,
|
|
81
|
+
(item) => findRepository('gitCodeReviews', item.legacyReviewId),
|
|
82
|
+
'reviewRecover',
|
|
83
|
+
);
|
|
84
|
+
const legacyUncertainReviews = await visible(
|
|
85
|
+
status.legacyUncertainReviews,
|
|
86
|
+
async (item) => item.repositoryId,
|
|
87
|
+
'reviewRecover',
|
|
88
|
+
);
|
|
89
|
+
const quarantined = await visible(
|
|
90
|
+
status.quarantined,
|
|
91
|
+
(item) => findRepository('gitReviewRequests', item.requestId),
|
|
92
|
+
'reviewRecover',
|
|
93
|
+
);
|
|
94
|
+
const orphaned = await visible(
|
|
95
|
+
status.orphaned,
|
|
96
|
+
(item) => findRepository('gitReviewInbox', item.inboxId),
|
|
97
|
+
'reviewRecover',
|
|
98
|
+
);
|
|
99
|
+
const postUnknownReviews = await visible(
|
|
100
|
+
status.postUnknownReviews,
|
|
101
|
+
(item) => findRepository('gitCodeReviews', item.reviewId),
|
|
102
|
+
'reviewResetPostClaim',
|
|
103
|
+
);
|
|
104
|
+
const legacyPublicationHolds = await visible(
|
|
105
|
+
status.legacyPublicationHolds,
|
|
106
|
+
async (item) => item.repositoryId,
|
|
107
|
+
'reviewLegacyReleaseHold',
|
|
108
|
+
);
|
|
109
|
+
const queuedBlockedReviews = await visible(
|
|
110
|
+
status.queuedBlockedReviews,
|
|
111
|
+
async (item) => item.repositoryId,
|
|
112
|
+
'reviewCancelQueued',
|
|
113
|
+
);
|
|
114
|
+
ctx.body = {
|
|
115
|
+
success: true,
|
|
116
|
+
data: {
|
|
117
|
+
...status,
|
|
118
|
+
legacyPendingReviews,
|
|
119
|
+
legacyRunningReviews,
|
|
120
|
+
legacyUncertainReviews,
|
|
121
|
+
quarantined,
|
|
122
|
+
orphaned,
|
|
123
|
+
postUnknownReviews,
|
|
124
|
+
legacyPublicationHolds,
|
|
125
|
+
queuedBlockedReviews,
|
|
126
|
+
canConfirmCutover: await hasUnrestrictedRepositoryAccess({
|
|
127
|
+
acl: ctx.app.acl,
|
|
128
|
+
roles: roles(ctx),
|
|
129
|
+
action: 'reviewConfirmCutover',
|
|
130
|
+
}),
|
|
131
|
+
},
|
|
132
|
+
};
|
|
27
133
|
await next();
|
|
28
134
|
}
|
|
29
135
|
|
|
30
136
|
export async function reviewConfirmCutover(ctx: Context, next: () => Promise<void>) {
|
|
31
137
|
const reviewService = service(ctx);
|
|
138
|
+
if (
|
|
139
|
+
!(await hasUnrestrictedRepositoryAccess({ acl: ctx.app.acl, roles: roles(ctx), action: 'reviewConfirmCutover' }))
|
|
140
|
+
) {
|
|
141
|
+
ctx.throw(403, ctx.t('Permission denied', { ns: 'plugin-git-manager' }));
|
|
142
|
+
}
|
|
32
143
|
if (getEffectiveActionParams(ctx).confirmation !== 'OLD_WORKERS_AND_AI_STOPPED')
|
|
33
144
|
ctx.throw(400, ctx.t('Worker and AI stop confirmation is required', { ns: 'plugin-git-manager' }));
|
|
34
145
|
await reviewService.confirmCutover(ctx.state.currentUser.id);
|
|
35
|
-
ctx
|
|
36
|
-
await next();
|
|
146
|
+
await reviewCutoverStatus(ctx, next);
|
|
37
147
|
}
|
|
38
148
|
|
|
39
149
|
export async function reviewCancelLegacy(ctx: Context, next: () => Promise<void>) {
|
|
@@ -43,6 +153,7 @@ export async function reviewCancelLegacy(ctx: Context, next: () => Promise<void>
|
|
|
43
153
|
ctx.throw(400, ctx.t('Legacy review cancellation confirmation is required', { ns: 'plugin-git-manager' }));
|
|
44
154
|
if (typeof legacyReviewId !== 'string' && typeof legacyReviewId !== 'number')
|
|
45
155
|
ctx.throw(400, ctx.t('Legacy review identifier is required', { ns: 'plugin-git-manager' }));
|
|
156
|
+
await requireRecordAccess(ctx, 'gitCodeReviews', legacyReviewId, 'reviewCancelLegacy');
|
|
46
157
|
await reviewService.cancelLegacy(legacyReviewId, ctx.state.currentUser.id);
|
|
47
158
|
ctx.body = { success: true };
|
|
48
159
|
await next();
|
|
@@ -53,6 +164,13 @@ export async function reviewRecover(ctx: Context, next: () => Promise<void>) {
|
|
|
53
164
|
const { confirmation, requestId, executionId, legacyReviewId, inboxId } = getEffectiveActionParams(ctx);
|
|
54
165
|
if (confirmation !== 'AI_STOPPED')
|
|
55
166
|
ctx.throw(400, ctx.t('AI stop confirmation is required', { ns: 'plugin-git-manager' }));
|
|
167
|
+
if (typeof legacyReviewId === 'string' || typeof legacyReviewId === 'number') {
|
|
168
|
+
await requireRecordAccess(ctx, 'gitCodeReviews', legacyReviewId, 'reviewRecover');
|
|
169
|
+
} else if (typeof inboxId === 'string' || typeof inboxId === 'number') {
|
|
170
|
+
await requireRecordAccess(ctx, 'gitReviewInbox', inboxId, 'reviewRecover');
|
|
171
|
+
} else {
|
|
172
|
+
await requireRecordAccess(ctx, 'gitReviewRequests', requestId, 'reviewRecover');
|
|
173
|
+
}
|
|
56
174
|
try {
|
|
57
175
|
if (typeof legacyReviewId === 'string' || typeof legacyReviewId === 'number') {
|
|
58
176
|
await reviewService.recoverLegacy(legacyReviewId, ctx.state.currentUser.id);
|
|
@@ -89,6 +207,7 @@ export async function reviewResetPostClaim(ctx: Context, next: () => Promise<voi
|
|
|
89
207
|
if (confirmation !== 'OUTBOUND_POST_STOPPED')
|
|
90
208
|
ctx.throw(400, ctx.t('Outbound post stop confirmation is required', { ns: 'plugin-git-manager' }));
|
|
91
209
|
if (typeof reviewId !== 'string' && typeof reviewId !== 'number') ctx.throw(400, 'reviewId is required');
|
|
210
|
+
await requireRecordAccess(ctx, 'gitCodeReviews', reviewId, 'reviewResetPostClaim');
|
|
92
211
|
if (
|
|
93
212
|
!Object.prototype.hasOwnProperty.call(params, 'expectedAttempt') ||
|
|
94
213
|
(expectedAttempt !== null && typeof expectedAttempt !== 'string')
|
|
@@ -115,6 +234,7 @@ export async function reviewCancelQueued(ctx: Context, next: () => Promise<void>
|
|
|
115
234
|
if (confirmation !== 'CANCEL_QUEUED_REVIEW')
|
|
116
235
|
ctx.throw(400, ctx.t('Queued review cancellation confirmation is required', { ns: 'plugin-git-manager' }));
|
|
117
236
|
if (typeof inboxId !== 'string' && typeof inboxId !== 'number') ctx.throw(400, 'inboxId is required');
|
|
237
|
+
await requireRecordAccess(ctx, 'gitReviewInbox', inboxId, 'reviewCancelQueued');
|
|
118
238
|
await reviewService.cancelQueued(inboxId, ctx.state.currentUser.id);
|
|
119
239
|
ctx.body = { success: true };
|
|
120
240
|
await next();
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { Context } from '@nocobase/actions';
|
|
11
4
|
import type { Application } from '@nocobase/server';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import type { Database, Model } from '@nocobase/database';
|
|
11
4
|
|
package/src/server/ai-tools.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { z } from 'zod';
|
|
11
4
|
import type { Application } from '@nocobase/server';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { defineCollection } from '@nocobase/database';
|
|
11
4
|
|