plugin-git-manager 1.2.27 → 1.2.28
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 +133 -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/900.a48beac7e2ebee7d.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/900.e6155002a9c97e7f.js +10 -0
- package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +9 -8
- package/dist/locale/en-US.json +307 -297
- package/dist/locale/vi-VN.json +295 -292
- package/dist/locale/zh-CN.json +61 -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.js +20 -10
- package/dist/server/plugin.js +6 -4
- package/dist/server/poller.js +46 -45
- package/dist/server/request-method-policy.js +75 -0
- package/dist/server/services/registry-content-service.js +4 -3
- 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__/RunReviewButton.test.tsx +73 -0
- package/src/client/ai-context.tsx +114 -114
- package/src/client/components/AIEmployeeSelect.tsx +63 -63
- package/src/client/components/CommitHistory.tsx +374 -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 +303 -303
- package/src/client/components/ReviewHistory.tsx +566 -566
- package/src/client/components/RunReviewButton.tsx +63 -55
- 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-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 +307 -297
- package/src/locale/vi-VN.json +295 -292
- package/src/locale/zh-CN.json +61 -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 +752 -752
- package/src/server/__tests__/review.test.ts +137 -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.ts +1388 -1369
- package/src/server/actions/role-permissions.ts +321 -321
- package/src/server/actions/subtree.ts +508 -508
- package/src/server/ai-tools.ts +319 -319
- package/src/server/collections/gitAccounts.ts +56 -56
- package/src/server/collections/gitCodeReviews.ts +199 -199
- package/src/server/collections/gitRepositories.ts +87 -87
- package/src/server/collections/gitReviewFlows.ts +108 -108
- package/src/server/collections/gitSubtreeConfigs.ts +38 -38
- package/src/server/collections/gitSubtreeRuns.ts +30 -30
- package/src/server/index.ts +2 -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 +372 -361
- package/src/server/poller.ts +351 -352
- package/src/server/repository-access.ts +773 -773
- package/src/server/request-method-policy.ts +55 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
- package/src/server/services/registry-content-service.ts +495 -484
- 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,198 +1,198 @@
|
|
|
1
|
-
import { Migration } from '@nocobase/server';
|
|
2
|
-
import { DataTypes, QueryTypes } from 'sequelize';
|
|
3
|
-
|
|
4
|
-
interface LegacyRepositoryCredential {
|
|
5
|
-
id: number;
|
|
6
|
-
repoUrl: string | null;
|
|
7
|
-
username: string | null;
|
|
8
|
-
pat: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface AccountCredential {
|
|
12
|
-
id: number;
|
|
13
|
-
username: string;
|
|
14
|
-
pat: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default class AddGitAccountsMigration extends Migration {
|
|
18
|
-
on = 'afterSync';
|
|
19
|
-
|
|
20
|
-
async up() {
|
|
21
|
-
const queryInterface = (this as any).db.sequelize.getQueryInterface();
|
|
22
|
-
const sequelize = (this as any).db.sequelize;
|
|
23
|
-
const tablePrefix = (this as any).db.options?.tablePrefix || '';
|
|
24
|
-
const repoTable = `${tablePrefix}gitRepositories`;
|
|
25
|
-
const accountsTable = `${tablePrefix}gitAccounts`;
|
|
26
|
-
|
|
27
|
-
const quoteTable = (tableName: string) => queryInterface.queryGenerator.quoteTable(tableName);
|
|
28
|
-
const quoteIdentifier = (identifier: string) => queryInterface.queryGenerator.quoteIdentifier(identifier);
|
|
29
|
-
const quotedRepoTable = quoteTable(repoTable);
|
|
30
|
-
const quotedAccountsTable = quoteTable(accountsTable);
|
|
31
|
-
|
|
32
|
-
const repoInfo = await queryInterface.describeTable(repoTable).catch(() => null);
|
|
33
|
-
if (!repoInfo) return;
|
|
34
|
-
|
|
35
|
-
// 1. Create gitAccounts table
|
|
36
|
-
const accountsExists = await queryInterface.describeTable(accountsTable).catch(() => null);
|
|
37
|
-
if (!accountsExists) {
|
|
38
|
-
await queryInterface.createTable(accountsTable, {
|
|
39
|
-
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
|
40
|
-
name: { type: DataTypes.STRING, allowNull: false },
|
|
41
|
-
provider: { type: DataTypes.STRING, allowNull: false, defaultValue: 'gitlab' },
|
|
42
|
-
baseUrl: { type: DataTypes.STRING, allowNull: true },
|
|
43
|
-
username: { type: DataTypes.STRING, allowNull: false },
|
|
44
|
-
pat: { type: DataTypes.STRING, allowNull: false },
|
|
45
|
-
createdAt: { type: DataTypes.DATE, allowNull: false },
|
|
46
|
-
updatedAt: { type: DataTypes.DATE, allowNull: false },
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// 2. Add gitAccountId column to gitRepositories
|
|
51
|
-
if (!repoInfo.gitAccountId) {
|
|
52
|
-
await queryInterface.addColumn(repoTable, 'gitAccountId', {
|
|
53
|
-
type: DataTypes.BIGINT,
|
|
54
|
-
allowNull: true,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// 3. Migrate existing data: deduplicate by (host, username, pat)
|
|
59
|
-
if (repoInfo.username && repoInfo.pat) {
|
|
60
|
-
const rows = (await sequelize.query(
|
|
61
|
-
`SELECT ${quoteIdentifier('id')}, ${quoteIdentifier('repoUrl')}, ${quoteIdentifier(
|
|
62
|
-
'username',
|
|
63
|
-
)}, ${quoteIdentifier('pat')}
|
|
64
|
-
FROM ${quotedRepoTable}
|
|
65
|
-
WHERE ${quoteIdentifier('pat')} IS NOT NULL AND ${quoteIdentifier('pat')} != ''`,
|
|
66
|
-
{ type: QueryTypes.SELECT },
|
|
67
|
-
)) as LegacyRepositoryCredential[];
|
|
68
|
-
|
|
69
|
-
if (rows.length > 0) {
|
|
70
|
-
const now = new Date();
|
|
71
|
-
|
|
72
|
-
// Group by host + username + pat to deduplicate
|
|
73
|
-
const groups = new Map<string, { host: string; username: string; pat: string; repoIds: number[] }>();
|
|
74
|
-
for (const row of rows) {
|
|
75
|
-
let host = '';
|
|
76
|
-
try {
|
|
77
|
-
host = row.repoUrl ? new URL(row.repoUrl).host : '';
|
|
78
|
-
} catch {
|
|
79
|
-
/* keep empty */
|
|
80
|
-
}
|
|
81
|
-
const username = row.username || '';
|
|
82
|
-
const key = `${host}::${username}::${row.pat}`;
|
|
83
|
-
if (!groups.has(key)) {
|
|
84
|
-
groups.set(key, { host, username, pat: row.pat, repoIds: [] });
|
|
85
|
-
}
|
|
86
|
-
const group = groups.get(key);
|
|
87
|
-
if (group) group.repoIds.push(row.id);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
for (const [, group] of groups) {
|
|
91
|
-
const name = group.host ? `${group.host} (${group.username})` : `${group.username}`;
|
|
92
|
-
const baseUrl = group.host ? `https://${group.host}` : null;
|
|
93
|
-
|
|
94
|
-
const provider = group.host.toLowerCase().includes('github') ? 'github' : 'gitlab';
|
|
95
|
-
const accountsRepository = (this as any).db.getRepository('gitAccounts');
|
|
96
|
-
const existingAccount = await accountsRepository.findOne({
|
|
97
|
-
filter: { provider, baseUrl, username: group.username, pat: group.pat },
|
|
98
|
-
});
|
|
99
|
-
const account =
|
|
100
|
-
existingAccount ||
|
|
101
|
-
(await accountsRepository.create({
|
|
102
|
-
values: {
|
|
103
|
-
name,
|
|
104
|
-
provider,
|
|
105
|
-
baseUrl,
|
|
106
|
-
username: group.username,
|
|
107
|
-
pat: group.pat,
|
|
108
|
-
createdAt: now,
|
|
109
|
-
updatedAt: now,
|
|
110
|
-
},
|
|
111
|
-
}));
|
|
112
|
-
const accountId = account.get('id') as number;
|
|
113
|
-
|
|
114
|
-
if (accountId) {
|
|
115
|
-
for (const repoId of group.repoIds) {
|
|
116
|
-
await sequelize.query(
|
|
117
|
-
`UPDATE ${quotedRepoTable}
|
|
118
|
-
SET ${quoteIdentifier('gitAccountId')} = :accountId
|
|
119
|
-
WHERE ${quoteIdentifier('id')} = :repoId`,
|
|
120
|
-
{ replacements: { accountId, repoId } },
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// 4. Remove old username and pat columns
|
|
129
|
-
if (repoInfo.username) {
|
|
130
|
-
await queryInterface.removeColumn(repoTable, 'username');
|
|
131
|
-
}
|
|
132
|
-
if (repoInfo.pat) {
|
|
133
|
-
await queryInterface.removeColumn(repoTable, 'pat');
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async down() {
|
|
138
|
-
const queryInterface = (this as any).db.sequelize.getQueryInterface();
|
|
139
|
-
const sequelize = (this as any).db.sequelize;
|
|
140
|
-
const tablePrefix = (this as any).db.options?.tablePrefix || '';
|
|
141
|
-
const repoTable = `${tablePrefix}gitRepositories`;
|
|
142
|
-
const accountsTable = `${tablePrefix}gitAccounts`;
|
|
143
|
-
|
|
144
|
-
const quoteTable = (tableName: string) => queryInterface.queryGenerator.quoteTable(tableName);
|
|
145
|
-
const quoteIdentifier = (identifier: string) => queryInterface.queryGenerator.quoteIdentifier(identifier);
|
|
146
|
-
const quotedRepoTable = quoteTable(repoTable);
|
|
147
|
-
const quotedAccountsTable = quoteTable(accountsTable);
|
|
148
|
-
|
|
149
|
-
const repoInfo = await queryInterface.describeTable(repoTable).catch(() => null);
|
|
150
|
-
if (!repoInfo) return;
|
|
151
|
-
|
|
152
|
-
// Restore username and pat columns
|
|
153
|
-
if (!repoInfo.username) {
|
|
154
|
-
await queryInterface.addColumn(repoTable, 'username', {
|
|
155
|
-
type: DataTypes.STRING,
|
|
156
|
-
allowNull: true,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
if (!repoInfo.pat) {
|
|
160
|
-
await queryInterface.addColumn(repoTable, 'pat', {
|
|
161
|
-
type: DataTypes.STRING,
|
|
162
|
-
allowNull: true,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const accountsExists = await queryInterface.describeTable(accountsTable).catch(() => null);
|
|
167
|
-
if (repoInfo.gitAccountId && accountsExists) {
|
|
168
|
-
const credentials = (await sequelize.query(
|
|
169
|
-
`SELECT r.${quoteIdentifier('id')} AS ${quoteIdentifier('id')},
|
|
170
|
-
a.${quoteIdentifier('username')} AS ${quoteIdentifier('username')},
|
|
171
|
-
a.${quoteIdentifier('pat')} AS ${quoteIdentifier('pat')}
|
|
172
|
-
FROM ${quotedRepoTable} r
|
|
173
|
-
INNER JOIN ${quotedAccountsTable} a
|
|
174
|
-
ON r.${quoteIdentifier('gitAccountId')} = a.${quoteIdentifier('id')}`,
|
|
175
|
-
{ type: QueryTypes.SELECT },
|
|
176
|
-
)) as AccountCredential[];
|
|
177
|
-
|
|
178
|
-
for (const credential of credentials) {
|
|
179
|
-
await sequelize.query(
|
|
180
|
-
`UPDATE ${quotedRepoTable}
|
|
181
|
-
SET ${quoteIdentifier('username')} = :username, ${quoteIdentifier('pat')} = :pat
|
|
182
|
-
WHERE ${quoteIdentifier('id')} = :id`,
|
|
183
|
-
{ replacements: credential },
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Drop gitAccountId column
|
|
189
|
-
if (repoInfo.gitAccountId) {
|
|
190
|
-
await queryInterface.removeColumn(repoTable, 'gitAccountId');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Drop gitAccounts table
|
|
194
|
-
if (accountsExists) {
|
|
195
|
-
await queryInterface.dropTable(accountsTable);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
1
|
+
import { Migration } from '@nocobase/server';
|
|
2
|
+
import { DataTypes, QueryTypes } from 'sequelize';
|
|
3
|
+
|
|
4
|
+
interface LegacyRepositoryCredential {
|
|
5
|
+
id: number;
|
|
6
|
+
repoUrl: string | null;
|
|
7
|
+
username: string | null;
|
|
8
|
+
pat: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface AccountCredential {
|
|
12
|
+
id: number;
|
|
13
|
+
username: string;
|
|
14
|
+
pat: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default class AddGitAccountsMigration extends Migration {
|
|
18
|
+
on = 'afterSync';
|
|
19
|
+
|
|
20
|
+
async up() {
|
|
21
|
+
const queryInterface = (this as any).db.sequelize.getQueryInterface();
|
|
22
|
+
const sequelize = (this as any).db.sequelize;
|
|
23
|
+
const tablePrefix = (this as any).db.options?.tablePrefix || '';
|
|
24
|
+
const repoTable = `${tablePrefix}gitRepositories`;
|
|
25
|
+
const accountsTable = `${tablePrefix}gitAccounts`;
|
|
26
|
+
|
|
27
|
+
const quoteTable = (tableName: string) => queryInterface.queryGenerator.quoteTable(tableName);
|
|
28
|
+
const quoteIdentifier = (identifier: string) => queryInterface.queryGenerator.quoteIdentifier(identifier);
|
|
29
|
+
const quotedRepoTable = quoteTable(repoTable);
|
|
30
|
+
const quotedAccountsTable = quoteTable(accountsTable);
|
|
31
|
+
|
|
32
|
+
const repoInfo = await queryInterface.describeTable(repoTable).catch(() => null);
|
|
33
|
+
if (!repoInfo) return;
|
|
34
|
+
|
|
35
|
+
// 1. Create gitAccounts table
|
|
36
|
+
const accountsExists = await queryInterface.describeTable(accountsTable).catch(() => null);
|
|
37
|
+
if (!accountsExists) {
|
|
38
|
+
await queryInterface.createTable(accountsTable, {
|
|
39
|
+
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
|
40
|
+
name: { type: DataTypes.STRING, allowNull: false },
|
|
41
|
+
provider: { type: DataTypes.STRING, allowNull: false, defaultValue: 'gitlab' },
|
|
42
|
+
baseUrl: { type: DataTypes.STRING, allowNull: true },
|
|
43
|
+
username: { type: DataTypes.STRING, allowNull: false },
|
|
44
|
+
pat: { type: DataTypes.STRING, allowNull: false },
|
|
45
|
+
createdAt: { type: DataTypes.DATE, allowNull: false },
|
|
46
|
+
updatedAt: { type: DataTypes.DATE, allowNull: false },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 2. Add gitAccountId column to gitRepositories
|
|
51
|
+
if (!repoInfo.gitAccountId) {
|
|
52
|
+
await queryInterface.addColumn(repoTable, 'gitAccountId', {
|
|
53
|
+
type: DataTypes.BIGINT,
|
|
54
|
+
allowNull: true,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 3. Migrate existing data: deduplicate by (host, username, pat)
|
|
59
|
+
if (repoInfo.username && repoInfo.pat) {
|
|
60
|
+
const rows = (await sequelize.query(
|
|
61
|
+
`SELECT ${quoteIdentifier('id')}, ${quoteIdentifier('repoUrl')}, ${quoteIdentifier(
|
|
62
|
+
'username',
|
|
63
|
+
)}, ${quoteIdentifier('pat')}
|
|
64
|
+
FROM ${quotedRepoTable}
|
|
65
|
+
WHERE ${quoteIdentifier('pat')} IS NOT NULL AND ${quoteIdentifier('pat')} != ''`,
|
|
66
|
+
{ type: QueryTypes.SELECT },
|
|
67
|
+
)) as LegacyRepositoryCredential[];
|
|
68
|
+
|
|
69
|
+
if (rows.length > 0) {
|
|
70
|
+
const now = new Date();
|
|
71
|
+
|
|
72
|
+
// Group by host + username + pat to deduplicate
|
|
73
|
+
const groups = new Map<string, { host: string; username: string; pat: string; repoIds: number[] }>();
|
|
74
|
+
for (const row of rows) {
|
|
75
|
+
let host = '';
|
|
76
|
+
try {
|
|
77
|
+
host = row.repoUrl ? new URL(row.repoUrl).host : '';
|
|
78
|
+
} catch {
|
|
79
|
+
/* keep empty */
|
|
80
|
+
}
|
|
81
|
+
const username = row.username || '';
|
|
82
|
+
const key = `${host}::${username}::${row.pat}`;
|
|
83
|
+
if (!groups.has(key)) {
|
|
84
|
+
groups.set(key, { host, username, pat: row.pat, repoIds: [] });
|
|
85
|
+
}
|
|
86
|
+
const group = groups.get(key);
|
|
87
|
+
if (group) group.repoIds.push(row.id);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for (const [, group] of groups) {
|
|
91
|
+
const name = group.host ? `${group.host} (${group.username})` : `${group.username}`;
|
|
92
|
+
const baseUrl = group.host ? `https://${group.host}` : null;
|
|
93
|
+
|
|
94
|
+
const provider = group.host.toLowerCase().includes('github') ? 'github' : 'gitlab';
|
|
95
|
+
const accountsRepository = (this as any).db.getRepository('gitAccounts');
|
|
96
|
+
const existingAccount = await accountsRepository.findOne({
|
|
97
|
+
filter: { provider, baseUrl, username: group.username, pat: group.pat },
|
|
98
|
+
});
|
|
99
|
+
const account =
|
|
100
|
+
existingAccount ||
|
|
101
|
+
(await accountsRepository.create({
|
|
102
|
+
values: {
|
|
103
|
+
name,
|
|
104
|
+
provider,
|
|
105
|
+
baseUrl,
|
|
106
|
+
username: group.username,
|
|
107
|
+
pat: group.pat,
|
|
108
|
+
createdAt: now,
|
|
109
|
+
updatedAt: now,
|
|
110
|
+
},
|
|
111
|
+
}));
|
|
112
|
+
const accountId = account.get('id') as number;
|
|
113
|
+
|
|
114
|
+
if (accountId) {
|
|
115
|
+
for (const repoId of group.repoIds) {
|
|
116
|
+
await sequelize.query(
|
|
117
|
+
`UPDATE ${quotedRepoTable}
|
|
118
|
+
SET ${quoteIdentifier('gitAccountId')} = :accountId
|
|
119
|
+
WHERE ${quoteIdentifier('id')} = :repoId`,
|
|
120
|
+
{ replacements: { accountId, repoId } },
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 4. Remove old username and pat columns
|
|
129
|
+
if (repoInfo.username) {
|
|
130
|
+
await queryInterface.removeColumn(repoTable, 'username');
|
|
131
|
+
}
|
|
132
|
+
if (repoInfo.pat) {
|
|
133
|
+
await queryInterface.removeColumn(repoTable, 'pat');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async down() {
|
|
138
|
+
const queryInterface = (this as any).db.sequelize.getQueryInterface();
|
|
139
|
+
const sequelize = (this as any).db.sequelize;
|
|
140
|
+
const tablePrefix = (this as any).db.options?.tablePrefix || '';
|
|
141
|
+
const repoTable = `${tablePrefix}gitRepositories`;
|
|
142
|
+
const accountsTable = `${tablePrefix}gitAccounts`;
|
|
143
|
+
|
|
144
|
+
const quoteTable = (tableName: string) => queryInterface.queryGenerator.quoteTable(tableName);
|
|
145
|
+
const quoteIdentifier = (identifier: string) => queryInterface.queryGenerator.quoteIdentifier(identifier);
|
|
146
|
+
const quotedRepoTable = quoteTable(repoTable);
|
|
147
|
+
const quotedAccountsTable = quoteTable(accountsTable);
|
|
148
|
+
|
|
149
|
+
const repoInfo = await queryInterface.describeTable(repoTable).catch(() => null);
|
|
150
|
+
if (!repoInfo) return;
|
|
151
|
+
|
|
152
|
+
// Restore username and pat columns
|
|
153
|
+
if (!repoInfo.username) {
|
|
154
|
+
await queryInterface.addColumn(repoTable, 'username', {
|
|
155
|
+
type: DataTypes.STRING,
|
|
156
|
+
allowNull: true,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
if (!repoInfo.pat) {
|
|
160
|
+
await queryInterface.addColumn(repoTable, 'pat', {
|
|
161
|
+
type: DataTypes.STRING,
|
|
162
|
+
allowNull: true,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const accountsExists = await queryInterface.describeTable(accountsTable).catch(() => null);
|
|
167
|
+
if (repoInfo.gitAccountId && accountsExists) {
|
|
168
|
+
const credentials = (await sequelize.query(
|
|
169
|
+
`SELECT r.${quoteIdentifier('id')} AS ${quoteIdentifier('id')},
|
|
170
|
+
a.${quoteIdentifier('username')} AS ${quoteIdentifier('username')},
|
|
171
|
+
a.${quoteIdentifier('pat')} AS ${quoteIdentifier('pat')}
|
|
172
|
+
FROM ${quotedRepoTable} r
|
|
173
|
+
INNER JOIN ${quotedAccountsTable} a
|
|
174
|
+
ON r.${quoteIdentifier('gitAccountId')} = a.${quoteIdentifier('id')}`,
|
|
175
|
+
{ type: QueryTypes.SELECT },
|
|
176
|
+
)) as AccountCredential[];
|
|
177
|
+
|
|
178
|
+
for (const credential of credentials) {
|
|
179
|
+
await sequelize.query(
|
|
180
|
+
`UPDATE ${quotedRepoTable}
|
|
181
|
+
SET ${quoteIdentifier('username')} = :username, ${quoteIdentifier('pat')} = :pat
|
|
182
|
+
WHERE ${quoteIdentifier('id')} = :id`,
|
|
183
|
+
{ replacements: credential },
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Drop gitAccountId column
|
|
189
|
+
if (repoInfo.gitAccountId) {
|
|
190
|
+
await queryInterface.removeColumn(repoTable, 'gitAccountId');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Drop gitAccounts table
|
|
194
|
+
if (accountsExists) {
|
|
195
|
+
await queryInterface.dropTable(accountsTable);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import { Migration } from '@nocobase/server';
|
|
2
|
-
import type { Model } from '@nocobase/database';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
GIT_READ_ACTIONS,
|
|
6
|
-
GIT_WRITE_ACTIONS,
|
|
7
|
-
REPOSITORY_READ_ACTIONS,
|
|
8
|
-
getRepositoryPermissionScope,
|
|
9
|
-
syncScopedActions,
|
|
10
|
-
} from '../actions/role-permissions';
|
|
11
|
-
|
|
12
|
-
function getRecordValue(record: unknown, key: string) {
|
|
13
|
-
if (!record || typeof record !== 'object') return undefined;
|
|
14
|
-
const model = record as { get?: (attribute: string) => unknown } & Record<string, unknown>;
|
|
15
|
-
return typeof model.get === 'function' ? model.get(key) : model[key];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default class MigrateLegacyRepositoryPermissions extends Migration {
|
|
19
|
-
on = 'afterLoad';
|
|
20
|
-
|
|
21
|
-
async up() {
|
|
22
|
-
const resourceRepo = this.db.getRepository('rolesResources');
|
|
23
|
-
const actionsRepo = this.db.getRepository('rolesResourcesActions');
|
|
24
|
-
const repositoryResources = await resourceRepo.find({ filter: { name: 'gitRepositories' } });
|
|
25
|
-
|
|
26
|
-
for (const repositoryResource of repositoryResources) {
|
|
27
|
-
const rolesResourceId = getRecordValue(repositoryResource, 'id');
|
|
28
|
-
const roleName = getRecordValue(repositoryResource, 'roleName');
|
|
29
|
-
if (!rolesResourceId || !roleName) continue;
|
|
30
|
-
|
|
31
|
-
const actions = await actionsRepo.find({
|
|
32
|
-
filter: { rolesResourceId },
|
|
33
|
-
appends: ['scope'],
|
|
34
|
-
});
|
|
35
|
-
const legacyRead = actions.filter((action) => getRecordValue(action, 'name') === 'read') as Model[];
|
|
36
|
-
const legacyWrite = actions.filter((action) => getRecordValue(action, 'name') === 'write') as Model[];
|
|
37
|
-
if (legacyRead.length === 0 && legacyWrite.length === 0) continue;
|
|
38
|
-
|
|
39
|
-
const readPermission = getRepositoryPermissionScope(legacyRead, ['read']);
|
|
40
|
-
const writePermission = getRepositoryPermissionScope(legacyWrite, ['write']);
|
|
41
|
-
if (!readPermission.supported || !writePermission.supported) {
|
|
42
|
-
this.app.log?.warn(
|
|
43
|
-
`[git-manager] skipped repository permission migration for role ${String(
|
|
44
|
-
roleName,
|
|
45
|
-
)} because its legacy scope cannot be represented safely`,
|
|
46
|
-
);
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
const effectiveReadIds = [...new Set([...readPermission.ids, ...writePermission.ids])];
|
|
50
|
-
const effectiveReadUnrestricted = readPermission.unrestricted || writePermission.unrestricted;
|
|
51
|
-
if (effectiveReadIds.length === 0 && !effectiveReadUnrestricted && !writePermission.unrestricted) continue;
|
|
52
|
-
|
|
53
|
-
await syncScopedActions(this.db, repositoryResource, REPOSITORY_READ_ACTIONS, effectiveReadIds, {
|
|
54
|
-
unrestricted: effectiveReadUnrestricted,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: 'gitManager' } });
|
|
58
|
-
if (!gitManagerResource) {
|
|
59
|
-
gitManagerResource = await resourceRepo.create({
|
|
60
|
-
values: { roleName, name: 'gitManager', usingActionsConfig: true },
|
|
61
|
-
});
|
|
62
|
-
} else if (!getRecordValue(gitManagerResource, 'usingActionsConfig')) {
|
|
63
|
-
await gitManagerResource.update({ usingActionsConfig: true });
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
await syncScopedActions(this.db, gitManagerResource, GIT_READ_ACTIONS, effectiveReadIds, {
|
|
67
|
-
unrestricted: effectiveReadUnrestricted,
|
|
68
|
-
});
|
|
69
|
-
await syncScopedActions(this.db, gitManagerResource, GIT_WRITE_ACTIONS, writePermission.ids, {
|
|
70
|
-
unrestricted: writePermission.unrestricted,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
for (const action of [...legacyRead, ...legacyWrite]) {
|
|
74
|
-
await action.destroy();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
await repositoryResource.writeToACL({ acl: this.app.acl });
|
|
78
|
-
await gitManagerResource.writeToACL({ acl: this.app.acl });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
1
|
+
import { Migration } from '@nocobase/server';
|
|
2
|
+
import type { Model } from '@nocobase/database';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
GIT_READ_ACTIONS,
|
|
6
|
+
GIT_WRITE_ACTIONS,
|
|
7
|
+
REPOSITORY_READ_ACTIONS,
|
|
8
|
+
getRepositoryPermissionScope,
|
|
9
|
+
syncScopedActions,
|
|
10
|
+
} from '../actions/role-permissions';
|
|
11
|
+
|
|
12
|
+
function getRecordValue(record: unknown, key: string) {
|
|
13
|
+
if (!record || typeof record !== 'object') return undefined;
|
|
14
|
+
const model = record as { get?: (attribute: string) => unknown } & Record<string, unknown>;
|
|
15
|
+
return typeof model.get === 'function' ? model.get(key) : model[key];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default class MigrateLegacyRepositoryPermissions extends Migration {
|
|
19
|
+
on = 'afterLoad';
|
|
20
|
+
|
|
21
|
+
async up() {
|
|
22
|
+
const resourceRepo = this.db.getRepository('rolesResources');
|
|
23
|
+
const actionsRepo = this.db.getRepository('rolesResourcesActions');
|
|
24
|
+
const repositoryResources = await resourceRepo.find({ filter: { name: 'gitRepositories' } });
|
|
25
|
+
|
|
26
|
+
for (const repositoryResource of repositoryResources) {
|
|
27
|
+
const rolesResourceId = getRecordValue(repositoryResource, 'id');
|
|
28
|
+
const roleName = getRecordValue(repositoryResource, 'roleName');
|
|
29
|
+
if (!rolesResourceId || !roleName) continue;
|
|
30
|
+
|
|
31
|
+
const actions = await actionsRepo.find({
|
|
32
|
+
filter: { rolesResourceId },
|
|
33
|
+
appends: ['scope'],
|
|
34
|
+
});
|
|
35
|
+
const legacyRead = actions.filter((action) => getRecordValue(action, 'name') === 'read') as Model[];
|
|
36
|
+
const legacyWrite = actions.filter((action) => getRecordValue(action, 'name') === 'write') as Model[];
|
|
37
|
+
if (legacyRead.length === 0 && legacyWrite.length === 0) continue;
|
|
38
|
+
|
|
39
|
+
const readPermission = getRepositoryPermissionScope(legacyRead, ['read']);
|
|
40
|
+
const writePermission = getRepositoryPermissionScope(legacyWrite, ['write']);
|
|
41
|
+
if (!readPermission.supported || !writePermission.supported) {
|
|
42
|
+
this.app.log?.warn(
|
|
43
|
+
`[git-manager] skipped repository permission migration for role ${String(
|
|
44
|
+
roleName,
|
|
45
|
+
)} because its legacy scope cannot be represented safely`,
|
|
46
|
+
);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const effectiveReadIds = [...new Set([...readPermission.ids, ...writePermission.ids])];
|
|
50
|
+
const effectiveReadUnrestricted = readPermission.unrestricted || writePermission.unrestricted;
|
|
51
|
+
if (effectiveReadIds.length === 0 && !effectiveReadUnrestricted && !writePermission.unrestricted) continue;
|
|
52
|
+
|
|
53
|
+
await syncScopedActions(this.db, repositoryResource, REPOSITORY_READ_ACTIONS, effectiveReadIds, {
|
|
54
|
+
unrestricted: effectiveReadUnrestricted,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: 'gitManager' } });
|
|
58
|
+
if (!gitManagerResource) {
|
|
59
|
+
gitManagerResource = await resourceRepo.create({
|
|
60
|
+
values: { roleName, name: 'gitManager', usingActionsConfig: true },
|
|
61
|
+
});
|
|
62
|
+
} else if (!getRecordValue(gitManagerResource, 'usingActionsConfig')) {
|
|
63
|
+
await gitManagerResource.update({ usingActionsConfig: true });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
await syncScopedActions(this.db, gitManagerResource, GIT_READ_ACTIONS, effectiveReadIds, {
|
|
67
|
+
unrestricted: effectiveReadUnrestricted,
|
|
68
|
+
});
|
|
69
|
+
await syncScopedActions(this.db, gitManagerResource, GIT_WRITE_ACTIONS, writePermission.ids, {
|
|
70
|
+
unrestricted: writePermission.unrestricted,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
for (const action of [...legacyRead, ...legacyWrite]) {
|
|
74
|
+
await action.destroy();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
await repositoryResource.writeToACL({ acl: this.app.acl });
|
|
78
|
+
await gitManagerResource.writeToACL({ acl: this.app.acl });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|