plugin-git-manager 1.2.21 → 1.2.24
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/dist/client/{434.1d19d4d6acc114f1.js → 434.b2eeaaef33aae6e0.js} +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client-v2/{434.f8836ea116648de1.js → 434.7a27051db18526c0.js} +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +8 -8
- package/dist/locale/en-US.json +4 -3
- package/dist/locale/vi-VN.json +4 -3
- package/dist/locale/zh-CN.json +4 -3
- package/dist/server/actions/git-actions.js +21 -8
- package/dist/server/actions/gitlab-api.js +5 -8
- package/dist/server/actions/poller.js +2 -1
- package/dist/server/actions/review.js +50 -13
- package/dist/server/actions/role-permissions.js +217 -54
- package/dist/server/actions/subtree.js +4 -8
- package/dist/server/migrations/20260730000000-migrate-legacy-repository-permissions.js +94 -0
- package/dist/server/plugin.js +44 -19
- package/dist/server/repository-access.js +570 -0
- package/dist/server/services/registry-content-service.js +137 -22
- package/dist/server/utils/get-repo-account.js +5 -2
- package/dist/server/utils/gitlab-url.js +2 -0
- package/dist/server/utils/redact.js +51 -5
- package/dist/server/utils/url-security.js +109 -0
- package/package.json +1 -1
- package/src/client/components/RepositoryConfig.tsx +4 -1
- package/src/locale/en-US.json +4 -3
- package/src/locale/vi-VN.json +4 -3
- package/src/locale/zh-CN.json +4 -3
- package/src/server/__tests__/git-actions.test.ts +24 -0
- package/src/server/__tests__/plugin-url-security.test.ts +17 -0
- package/src/server/__tests__/poller.test.ts +37 -0
- package/src/server/__tests__/repository-access.test.ts +752 -0
- package/src/server/__tests__/review.test.ts +137 -0
- package/src/server/__tests__/role-permissions.test.ts +147 -0
- package/src/server/actions/git-actions.ts +33 -10
- package/src/server/actions/gitlab-api.ts +5 -8
- package/src/server/actions/poller.ts +2 -1
- package/src/server/actions/review.ts +74 -15
- package/src/server/actions/role-permissions.ts +251 -59
- package/src/server/actions/subtree.ts +4 -8
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -0
- package/src/server/plugin.ts +48 -24
- package/src/server/repository-access.ts +773 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +209 -13
- package/src/server/services/registry-content-service.ts +184 -30
- package/src/server/utils/__tests__/redact.test.ts +56 -0
- package/src/server/utils/__tests__/url-security.test.ts +85 -0
- package/src/server/utils/get-repo-account.ts +22 -4
- package/src/server/utils/gitlab-url.ts +3 -0
- package/src/server/utils/redact.ts +68 -5
- package/src/server/utils/url-security.ts +95 -0
|
@@ -31,6 +31,8 @@ __export(review_exports, {
|
|
|
31
31
|
pickFlowMatchingBranch: () => pickFlowMatchingBranch,
|
|
32
32
|
recoverStuckReviews: () => recoverStuckReviews,
|
|
33
33
|
registerReviewQueue: () => registerReviewQueue,
|
|
34
|
+
resolveBackgroundReviewRoles: () => resolveBackgroundReviewRoles,
|
|
35
|
+
resolveImmutableReviewActorId: () => resolveImmutableReviewActorId,
|
|
34
36
|
reviewApprovePost: () => reviewApprovePost,
|
|
35
37
|
reviewReject: () => reviewReject,
|
|
36
38
|
triggerReview: () => triggerReview,
|
|
@@ -38,6 +40,7 @@ __export(review_exports, {
|
|
|
38
40
|
unregisterReviewQueue: () => unregisterReviewQueue
|
|
39
41
|
});
|
|
40
42
|
module.exports = __toCommonJS(review_exports);
|
|
43
|
+
var import_repository_access = require("../repository-access");
|
|
41
44
|
var import_gitlab_url = require("../utils/gitlab-url");
|
|
42
45
|
var import_redact = require("../utils/redact");
|
|
43
46
|
var import_get_repo_account = require("../utils/get-repo-account");
|
|
@@ -63,10 +66,6 @@ let reviewQueueTimer = null;
|
|
|
63
66
|
let reviewQueueKickTimer = null;
|
|
64
67
|
let reviewQueueProcessing = false;
|
|
65
68
|
let reviewWakeHandler = null;
|
|
66
|
-
function getActionParams(ctx) {
|
|
67
|
-
var _a, _b;
|
|
68
|
-
return { ...ctx.action.params, ...(_a = ctx.action.params) == null ? void 0 : _a.values, ...((_b = ctx.request) == null ? void 0 : _b.body) || {} };
|
|
69
|
-
}
|
|
70
69
|
function targetKey(args) {
|
|
71
70
|
if (args.targetType === "mr") return `${args.repositoryId}:mr:${args.mrIid}`;
|
|
72
71
|
if (args.targetType === "commit") return `${args.repositoryId}:commit:${args.commitSha}`;
|
|
@@ -82,7 +81,7 @@ async function withTriggerLock(app, key, fn) {
|
|
|
82
81
|
}
|
|
83
82
|
async function triggerReview(ctx, next) {
|
|
84
83
|
var _a, _b;
|
|
85
|
-
const params =
|
|
84
|
+
const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
|
|
86
85
|
const { flowId, repositoryId, targetType, mrIid, commitSha, branch, folderPath, extraInstructions } = params;
|
|
87
86
|
if (!repositoryId) ctx.throw(400, "repositoryId is required");
|
|
88
87
|
if (!targetType) ctx.throw(400, "targetType is required");
|
|
@@ -125,6 +124,10 @@ async function triggerReviewInternalLocked(app, args) {
|
|
|
125
124
|
flow = await flowsRepo.findOne({ filterByTk: args.flowId });
|
|
126
125
|
if (!flow) throwHttp(404, "Review flow not found");
|
|
127
126
|
if (!flow.get("enabled")) throwHttp(400, "Review flow is disabled");
|
|
127
|
+
const flowRepositoryId = flow.get("repositoryId");
|
|
128
|
+
if (flowRepositoryId != null && String(flowRepositoryId) !== String(args.repositoryId)) {
|
|
129
|
+
throwHttp(400, "Review flow does not belong to this repository");
|
|
130
|
+
}
|
|
128
131
|
} else {
|
|
129
132
|
const candidates = await flowsRepo.find({
|
|
130
133
|
filter: {
|
|
@@ -161,6 +164,7 @@ async function triggerReviewInternalLocked(app, args) {
|
|
|
161
164
|
}
|
|
162
165
|
const existing = await reviewsRepo.findOne({ filter: targetFilter });
|
|
163
166
|
const existingLatestSha = existing == null ? void 0 : existing.get("latestSha");
|
|
167
|
+
const queuedActorId = args.triggeredBy === "poll" ? null : args.userId ?? null;
|
|
164
168
|
const baseValues = {
|
|
165
169
|
flowId: flow.get("id"),
|
|
166
170
|
repositoryId: args.repositoryId,
|
|
@@ -196,11 +200,21 @@ async function triggerReviewInternalLocked(app, args) {
|
|
|
196
200
|
}
|
|
197
201
|
await reviewsRepo.update({
|
|
198
202
|
filterByTk: existing.get("id"),
|
|
199
|
-
values:
|
|
203
|
+
values: {
|
|
204
|
+
...baseValues,
|
|
205
|
+
createdById: queuedActorId
|
|
206
|
+
}
|
|
200
207
|
});
|
|
201
208
|
reviewId = existing.get("id");
|
|
202
209
|
} else {
|
|
203
|
-
const review = await reviewsRepo.create({
|
|
210
|
+
const review = await reviewsRepo.create({
|
|
211
|
+
values: {
|
|
212
|
+
...baseValues,
|
|
213
|
+
// The worker later derives its acting user from this server-owned
|
|
214
|
+
// field rather than mutable review metadata.
|
|
215
|
+
createdById: queuedActorId
|
|
216
|
+
}
|
|
217
|
+
});
|
|
204
218
|
reviewId = review.get("id");
|
|
205
219
|
}
|
|
206
220
|
await enqueueReview(app, {
|
|
@@ -420,6 +434,16 @@ function getQueuedReviewMetadata(review) {
|
|
|
420
434
|
}
|
|
421
435
|
return typeof raw === "object" ? raw : {};
|
|
422
436
|
}
|
|
437
|
+
function resolveImmutableReviewActorId(review) {
|
|
438
|
+
const createdById = review.get("createdById");
|
|
439
|
+
if (typeof createdById === "number" && Number.isFinite(createdById)) {
|
|
440
|
+
return createdById;
|
|
441
|
+
}
|
|
442
|
+
if (typeof createdById === "string" && createdById.trim()) {
|
|
443
|
+
return createdById;
|
|
444
|
+
}
|
|
445
|
+
return null;
|
|
446
|
+
}
|
|
423
447
|
function toNullableNumber(value) {
|
|
424
448
|
if (value === null || value === void 0 || value === "") return null;
|
|
425
449
|
const parsed = Number(value);
|
|
@@ -521,6 +545,10 @@ async function processQueuedReview(app, message) {
|
|
|
521
545
|
const metadata = getQueuedReviewMetadata(review);
|
|
522
546
|
const targetType = message.targetType || review.get("targetType");
|
|
523
547
|
try {
|
|
548
|
+
const actorUserId = resolveImmutableReviewActorId(review);
|
|
549
|
+
if (actorUserId == null && review.get("triggeredBy") !== "poll") {
|
|
550
|
+
throw new Error("Manual review has no immutable triggering user");
|
|
551
|
+
}
|
|
524
552
|
const repo = await db.getRepository("gitRepositories").findOne({
|
|
525
553
|
filterByTk: message.repositoryId || review.get("repositoryId")
|
|
526
554
|
});
|
|
@@ -529,6 +557,11 @@ async function processQueuedReview(app, message) {
|
|
|
529
557
|
const storedFlow = await db.getRepository("gitReviewFlows").findOne({
|
|
530
558
|
filterByTk: (flowSnapshot == null ? void 0 : flowSnapshot.id) || review.get("flowId")
|
|
531
559
|
});
|
|
560
|
+
if (!storedFlow) throw new Error("Review flow not found");
|
|
561
|
+
const flowRepositoryId = storedFlow.get("repositoryId");
|
|
562
|
+
if (flowRepositoryId != null && String(flowRepositoryId) !== String(repo.get("id"))) {
|
|
563
|
+
throw new Error("Review flow does not belong to this repository");
|
|
564
|
+
}
|
|
532
565
|
const flow = createFlowFromSnapshot(flowSnapshot, storedFlow);
|
|
533
566
|
const aiEmployeeUsername = message.aiEmployeeUsername || metadata.aiEmployeeUsername || flow.get("aiEmployeeUsername");
|
|
534
567
|
if (!aiEmployeeUsername) throw new Error("Flow has no AI employee configured");
|
|
@@ -544,7 +577,7 @@ async function processQueuedReview(app, message) {
|
|
|
544
577
|
headSha: message.headSha || review.get("headSha"),
|
|
545
578
|
aiEmployeeUsername,
|
|
546
579
|
extraInstructions: message.extraInstructions ?? metadata.extraInstructions ?? void 0,
|
|
547
|
-
userId:
|
|
580
|
+
userId: actorUserId
|
|
548
581
|
});
|
|
549
582
|
} catch (err) {
|
|
550
583
|
(_f = (_e = app.log) == null ? void 0 : _e.error) == null ? void 0 : _f.call(_e, "git review queue: failed before review execution", err);
|
|
@@ -554,7 +587,7 @@ async function processQueuedReview(app, message) {
|
|
|
554
587
|
}
|
|
555
588
|
async function reviewApprovePost(ctx, next) {
|
|
556
589
|
var _a, _b;
|
|
557
|
-
const params =
|
|
590
|
+
const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
|
|
558
591
|
const { reviewId, editedMarkdown } = params;
|
|
559
592
|
if (!reviewId) ctx.throw(400, "reviewId is required");
|
|
560
593
|
const reviewsRepo = ctx.db.getRepository("gitCodeReviews");
|
|
@@ -586,7 +619,7 @@ async function reviewApprovePost(ctx, next) {
|
|
|
586
619
|
}
|
|
587
620
|
async function reviewReject(ctx, next) {
|
|
588
621
|
var _a, _b;
|
|
589
|
-
const params =
|
|
622
|
+
const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
|
|
590
623
|
const { reviewId, reason } = params;
|
|
591
624
|
if (!reviewId) ctx.throw(400, "reviewId is required");
|
|
592
625
|
const reviewsRepo = ctx.db.getRepository("gitCodeReviews");
|
|
@@ -800,7 +833,7 @@ async function resolveBackgroundReviewRoles(db, userId) {
|
|
|
800
833
|
if (!userId) return ["admin"];
|
|
801
834
|
try {
|
|
802
835
|
const roles = await db.getRepository("users.roles", userId).find({ raw: true });
|
|
803
|
-
const roleNames = (Array.isArray(roles) ? roles : []).map((role) => role
|
|
836
|
+
const roleNames = (Array.isArray(roles) ? roles : []).map((role) => role && typeof role === "object" ? role.name : void 0).filter((name) => typeof name === "string" && !!name);
|
|
804
837
|
if (roleNames.length) return roleNames;
|
|
805
838
|
} catch {
|
|
806
839
|
}
|
|
@@ -809,11 +842,13 @@ async function resolveBackgroundReviewRoles(db, userId) {
|
|
|
809
842
|
filter: { userId },
|
|
810
843
|
raw: true
|
|
811
844
|
});
|
|
812
|
-
const roleNames = (Array.isArray(mappings) ? mappings : []).map(
|
|
845
|
+
const roleNames = (Array.isArray(mappings) ? mappings : []).map(
|
|
846
|
+
(mapping) => mapping && typeof mapping === "object" ? mapping.roleName : void 0
|
|
847
|
+
).filter((name) => typeof name === "string" && !!name);
|
|
813
848
|
if (roleNames.length) return roleNames;
|
|
814
849
|
} catch {
|
|
815
850
|
}
|
|
816
|
-
|
|
851
|
+
throw new Error("Unable to resolve roles for review actor");
|
|
817
852
|
}
|
|
818
853
|
function buildReviewPrompt(args) {
|
|
819
854
|
const lines = [];
|
|
@@ -1089,6 +1124,8 @@ async function recoverStuckReviews(app) {
|
|
|
1089
1124
|
pickFlowMatchingBranch,
|
|
1090
1125
|
recoverStuckReviews,
|
|
1091
1126
|
registerReviewQueue,
|
|
1127
|
+
resolveBackgroundReviewRoles,
|
|
1128
|
+
resolveImmutableReviewActorId,
|
|
1092
1129
|
reviewApprovePost,
|
|
1093
1130
|
reviewReject,
|
|
1094
1131
|
triggerReview,
|
|
@@ -26,12 +26,177 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
26
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
27
|
var role_permissions_exports = {};
|
|
28
28
|
__export(role_permissions_exports, {
|
|
29
|
+
GIT_READ_ACTIONS: () => GIT_READ_ACTIONS,
|
|
30
|
+
GIT_WRITE_ACTIONS: () => GIT_WRITE_ACTIONS,
|
|
31
|
+
REPOSITORY_READ_ACTIONS: () => REPOSITORY_READ_ACTIONS,
|
|
32
|
+
getRepositoryPermissionIds: () => getRepositoryPermissionIds,
|
|
33
|
+
getRepositoryPermissionScope: () => getRepositoryPermissionScope,
|
|
34
|
+
repositoryPermissionIdsForDisplay: () => repositoryPermissionIdsForDisplay,
|
|
29
35
|
rolePermissions: () => rolePermissions,
|
|
36
|
+
syncScopedActions: () => syncScopedActions,
|
|
30
37
|
updateRolePermissions: () => updateRolePermissions
|
|
31
38
|
});
|
|
32
39
|
module.exports = __toCommonJS(role_permissions_exports);
|
|
33
40
|
function getRecordValue(record, key) {
|
|
34
|
-
|
|
41
|
+
if (!record || typeof record !== "object") return void 0;
|
|
42
|
+
const model = record;
|
|
43
|
+
return typeof model.get === "function" ? model.get(key) : model[key];
|
|
44
|
+
}
|
|
45
|
+
const REPOSITORY_READ_ACTIONS = ["list", "get"];
|
|
46
|
+
const GIT_READ_ACTIONS = [
|
|
47
|
+
"status",
|
|
48
|
+
"log",
|
|
49
|
+
"branches",
|
|
50
|
+
"diff",
|
|
51
|
+
"fileTree",
|
|
52
|
+
"fileContent",
|
|
53
|
+
"commitDetail",
|
|
54
|
+
"mergeRequests",
|
|
55
|
+
"mergeRequestDetail",
|
|
56
|
+
"mergeRequestNotes",
|
|
57
|
+
"pollerStatus",
|
|
58
|
+
"subtreePreview",
|
|
59
|
+
"subtreeOptions"
|
|
60
|
+
];
|
|
61
|
+
const GIT_WRITE_ACTIONS = [
|
|
62
|
+
"clone",
|
|
63
|
+
"pull",
|
|
64
|
+
"push",
|
|
65
|
+
"fetch",
|
|
66
|
+
"checkout",
|
|
67
|
+
"triggerReview",
|
|
68
|
+
"reviewApprovePost",
|
|
69
|
+
"reviewReject",
|
|
70
|
+
"pollNow",
|
|
71
|
+
"subtreeRun"
|
|
72
|
+
];
|
|
73
|
+
function supportedIds(ids) {
|
|
74
|
+
return { ids: new Set(ids), unrestricted: false, supported: true };
|
|
75
|
+
}
|
|
76
|
+
function unsupportedScope() {
|
|
77
|
+
return { ids: /* @__PURE__ */ new Set(), unrestricted: false, supported: false };
|
|
78
|
+
}
|
|
79
|
+
function combineScopeBranches(operator, branches) {
|
|
80
|
+
const resolutions = branches.map(resolveRepositoryScope);
|
|
81
|
+
if (resolutions.some((resolution) => !resolution.supported)) return unsupportedScope();
|
|
82
|
+
if (operator === "$or") {
|
|
83
|
+
if (resolutions.some((resolution) => resolution.unrestricted)) {
|
|
84
|
+
return { ids: /* @__PURE__ */ new Set(), unrestricted: true, supported: true };
|
|
85
|
+
}
|
|
86
|
+
return supportedIds(resolutions.flatMap((resolution) => [...resolution.ids]));
|
|
87
|
+
}
|
|
88
|
+
const restricted = resolutions.filter((resolution) => !resolution.unrestricted);
|
|
89
|
+
if (restricted.length === 0) {
|
|
90
|
+
return { ids: /* @__PURE__ */ new Set(), unrestricted: true, supported: true };
|
|
91
|
+
}
|
|
92
|
+
const [first, ...rest] = restricted;
|
|
93
|
+
const ids = new Set([...first.ids].filter((id) => rest.every((resolution) => resolution.ids.has(id))));
|
|
94
|
+
return supportedIds(ids);
|
|
95
|
+
}
|
|
96
|
+
function resolveRepositoryScope(scope) {
|
|
97
|
+
if (scope == null) {
|
|
98
|
+
return { ids: /* @__PURE__ */ new Set(), unrestricted: true, supported: true };
|
|
99
|
+
}
|
|
100
|
+
if (typeof scope !== "object" || Array.isArray(scope)) return unsupportedScope();
|
|
101
|
+
const condition = scope;
|
|
102
|
+
const keys = Object.keys(condition);
|
|
103
|
+
if (keys.length === 0) {
|
|
104
|
+
return { ids: /* @__PURE__ */ new Set(), unrestricted: true, supported: true };
|
|
105
|
+
}
|
|
106
|
+
const operator = keys.find((key) => key === "$and" || key === "$or");
|
|
107
|
+
if (operator) {
|
|
108
|
+
if (keys.length !== 1 || !Array.isArray(condition[operator])) return unsupportedScope();
|
|
109
|
+
return combineScopeBranches(operator, condition[operator]);
|
|
110
|
+
}
|
|
111
|
+
if (keys.length !== 1 || !("id" in condition)) return unsupportedScope();
|
|
112
|
+
const id = condition.id;
|
|
113
|
+
if (typeof id === "number" || typeof id === "string") {
|
|
114
|
+
return supportedIds([id]);
|
|
115
|
+
}
|
|
116
|
+
if (!id || typeof id !== "object" || Array.isArray(id)) return unsupportedScope();
|
|
117
|
+
const idCondition = id;
|
|
118
|
+
const idKeys = Object.keys(idCondition);
|
|
119
|
+
if (idKeys.length !== 1) return unsupportedScope();
|
|
120
|
+
const equal = idCondition.$eq;
|
|
121
|
+
if (typeof equal === "number" || typeof equal === "string") {
|
|
122
|
+
return supportedIds([equal]);
|
|
123
|
+
}
|
|
124
|
+
const included = idCondition.$in;
|
|
125
|
+
if (Array.isArray(included) && included.every((value) => typeof value === "number" || typeof value === "string")) {
|
|
126
|
+
return supportedIds(included);
|
|
127
|
+
}
|
|
128
|
+
return unsupportedScope();
|
|
129
|
+
}
|
|
130
|
+
function actionScope(actionData) {
|
|
131
|
+
const scopeRow = actionData.scope;
|
|
132
|
+
if (!scopeRow || typeof scopeRow !== "object") return void 0;
|
|
133
|
+
const scopeRecord = scopeRow;
|
|
134
|
+
return "scope" in scopeRecord ? scopeRecord.scope : scopeRecord;
|
|
135
|
+
}
|
|
136
|
+
function getRepositoryPermissionScope(actions, names) {
|
|
137
|
+
const ids = /* @__PURE__ */ new Set();
|
|
138
|
+
let unrestricted = false;
|
|
139
|
+
for (const action of actions) {
|
|
140
|
+
const actionData = action.toJSON();
|
|
141
|
+
if (typeof actionData.name !== "string" || !names.includes(actionData.name)) continue;
|
|
142
|
+
const scope = actionScope(actionData);
|
|
143
|
+
const resolution = resolveRepositoryScope(scope);
|
|
144
|
+
if (!resolution.supported) {
|
|
145
|
+
return { ids: [], unrestricted: false, supported: false };
|
|
146
|
+
}
|
|
147
|
+
if (resolution.unrestricted) {
|
|
148
|
+
unrestricted = true;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
resolution.ids.forEach((id) => ids.add(id));
|
|
152
|
+
}
|
|
153
|
+
return { ids: [...ids], unrestricted, supported: true };
|
|
154
|
+
}
|
|
155
|
+
function getRepositoryPermissionIds(actions, names) {
|
|
156
|
+
return getRepositoryPermissionScope(actions, names).ids;
|
|
157
|
+
}
|
|
158
|
+
function repositoryPermissionIdsForDisplay(scope, repositoryIds) {
|
|
159
|
+
return scope.unrestricted ? repositoryIds : scope.ids;
|
|
160
|
+
}
|
|
161
|
+
async function syncScopedActions(db, resource, actionNames, ids, options = {}) {
|
|
162
|
+
const rolesResourceId = getRecordValue(resource, "id");
|
|
163
|
+
const actionsRepo = db.getRepository("rolesResourcesActions");
|
|
164
|
+
for (const storedActionName of actionNames) {
|
|
165
|
+
const action = await actionsRepo.findOne({
|
|
166
|
+
filter: { rolesResourceId, name: storedActionName },
|
|
167
|
+
appends: ["scope"]
|
|
168
|
+
});
|
|
169
|
+
if (action) {
|
|
170
|
+
if (options.unrestricted) {
|
|
171
|
+
await action.update({ scopeId: null });
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const scopeJson = { $and: [{ id: { $in: ids } }] };
|
|
175
|
+
const actionData = action.toJSON();
|
|
176
|
+
const actionScopeId = getRecordValue(actionData.scope, "id") || actionData.scopeId || getRecordValue(action, "scopeId");
|
|
177
|
+
if (actionScopeId) {
|
|
178
|
+
await db.getRepository("rolesResourcesScopes").update({
|
|
179
|
+
filterByTk: actionScopeId,
|
|
180
|
+
values: { scope: scopeJson }
|
|
181
|
+
});
|
|
182
|
+
} else {
|
|
183
|
+
const newScope = await db.getRepository("rolesResourcesScopes").create({ values: { scope: scopeJson } });
|
|
184
|
+
await action.update({ scopeId: getRecordValue(newScope, "id") });
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
if (options.unrestricted) {
|
|
188
|
+
await actionsRepo.create({
|
|
189
|
+
values: { rolesResourceId, name: storedActionName }
|
|
190
|
+
});
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const scopeJson = { $and: [{ id: { $in: ids } }] };
|
|
194
|
+
const newScope = await db.getRepository("rolesResourcesScopes").create({ values: { scope: scopeJson } });
|
|
195
|
+
await actionsRepo.create({
|
|
196
|
+
values: { rolesResourceId, name: storedActionName, scopeId: getRecordValue(newScope, "id") }
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
35
200
|
}
|
|
36
201
|
async function rolePermissions(ctx, _next) {
|
|
37
202
|
var _a;
|
|
@@ -53,25 +218,29 @@ async function rolePermissions(ctx, _next) {
|
|
|
53
218
|
filter: { rolesResourceId: getRecordValue(resource, "id") },
|
|
54
219
|
appends: ["scope"]
|
|
55
220
|
});
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
221
|
+
const gitManagerResource = await ctx.db.getRepository("rolesResources").findOne({
|
|
222
|
+
filter: { roleName, name: "gitManager" }
|
|
223
|
+
});
|
|
224
|
+
const gitManagerActions = gitManagerResource ? await ctx.db.getRepository("rolesResourcesActions").find({
|
|
225
|
+
filter: { rolesResourceId: getRecordValue(gitManagerResource, "id") },
|
|
226
|
+
appends: ["scope"]
|
|
227
|
+
}) : [];
|
|
228
|
+
const readScope = getRepositoryPermissionScope(actions, [...REPOSITORY_READ_ACTIONS, "read"]);
|
|
229
|
+
const gitWriteScope = getRepositoryPermissionScope(gitManagerActions, GIT_WRITE_ACTIONS);
|
|
230
|
+
const repositoryWriteScope = getRepositoryPermissionScope(actions, ["write"]);
|
|
231
|
+
const requiresRepositoryList = readScope.unrestricted || gitWriteScope.unrestricted || repositoryWriteScope.unrestricted;
|
|
232
|
+
const repositoryIds = requiresRepositoryList ? (await ctx.db.getRepository("gitRepositories").find({ fields: ["id"] })).map(
|
|
233
|
+
(repository) => getRecordValue(repository, "id")
|
|
234
|
+
) : [];
|
|
235
|
+
const result = {
|
|
236
|
+
read: repositoryPermissionIdsForDisplay(readScope, repositoryIds),
|
|
237
|
+
write: [
|
|
238
|
+
.../* @__PURE__ */ new Set([
|
|
239
|
+
...repositoryPermissionIdsForDisplay(gitWriteScope, repositoryIds),
|
|
240
|
+
...repositoryPermissionIdsForDisplay(repositoryWriteScope, repositoryIds)
|
|
241
|
+
])
|
|
242
|
+
]
|
|
243
|
+
};
|
|
75
244
|
ctx.body = result;
|
|
76
245
|
}
|
|
77
246
|
async function updateRolePermissions(ctx, _next) {
|
|
@@ -94,45 +263,32 @@ async function updateRolePermissions(ctx, _next) {
|
|
|
94
263
|
} else if (!getRecordValue(resource, "usingActionsConfig")) {
|
|
95
264
|
await resource.update({ usingActionsConfig: true });
|
|
96
265
|
}
|
|
97
|
-
const rolesResourceId = getRecordValue(resource, "id");
|
|
98
266
|
const actionsRepo = ctx.db.getRepository("rolesResourcesActions");
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
267
|
+
const readIds = permissions.read || [];
|
|
268
|
+
const writeIds = permissions.write || [];
|
|
269
|
+
const effectiveReadIds = [.../* @__PURE__ */ new Set([...readIds, ...writeIds])];
|
|
270
|
+
await syncScopedActions(ctx.db, resource, REPOSITORY_READ_ACTIONS, effectiveReadIds);
|
|
271
|
+
let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: "gitManager" } });
|
|
272
|
+
if (!gitManagerResource) {
|
|
273
|
+
gitManagerResource = await resourceRepo.create({
|
|
274
|
+
values: { roleName, name: "gitManager", usingActionsConfig: true }
|
|
104
275
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
} else {
|
|
108
|
-
const scopeJson = { $and: [{ id: { $in: ids } }] };
|
|
109
|
-
if (action) {
|
|
110
|
-
const actionData = action.toJSON ? action.toJSON() : action;
|
|
111
|
-
const actionScope = actionData.scope;
|
|
112
|
-
const actionScopeId = getRecordValue(actionScope, "id") || actionData.scopeId || getRecordValue(action, "scopeId");
|
|
113
|
-
if (actionScopeId) {
|
|
114
|
-
await ctx.db.getRepository("rolesResourcesScopes").update({
|
|
115
|
-
filterByTk: actionScopeId,
|
|
116
|
-
values: { scope: scopeJson }
|
|
117
|
-
});
|
|
118
|
-
} else {
|
|
119
|
-
const newScope = await ctx.db.getRepository("rolesResourcesScopes").create({
|
|
120
|
-
values: { scope: scopeJson }
|
|
121
|
-
});
|
|
122
|
-
await action.update({ scopeId: getRecordValue(newScope, "id") });
|
|
123
|
-
}
|
|
124
|
-
} else {
|
|
125
|
-
const newScope = await ctx.db.getRepository("rolesResourcesScopes").create({
|
|
126
|
-
values: { scope: scopeJson }
|
|
127
|
-
});
|
|
128
|
-
await actionsRepo.create({
|
|
129
|
-
values: { rolesResourceId, name: actionName, scopeId: getRecordValue(newScope, "id") }
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
276
|
+
} else if (!getRecordValue(gitManagerResource, "usingActionsConfig")) {
|
|
277
|
+
await gitManagerResource.update({ usingActionsConfig: true });
|
|
133
278
|
}
|
|
279
|
+
await syncScopedActions(ctx.db, gitManagerResource, GIT_READ_ACTIONS, effectiveReadIds);
|
|
280
|
+
await syncScopedActions(ctx.db, gitManagerResource, GIT_WRITE_ACTIONS, writeIds);
|
|
281
|
+
const legacyReadAction = await actionsRepo.findOne({
|
|
282
|
+
filter: { rolesResourceId: getRecordValue(resource, "id"), name: "read" }
|
|
283
|
+
});
|
|
284
|
+
if (legacyReadAction) await legacyReadAction.destroy();
|
|
285
|
+
const legacyWriteAction = await actionsRepo.findOne({
|
|
286
|
+
filter: { rolesResourceId: getRecordValue(resource, "id"), name: "write" }
|
|
287
|
+
});
|
|
288
|
+
if (legacyWriteAction) await legacyWriteAction.destroy();
|
|
134
289
|
try {
|
|
135
290
|
await resource.writeToACL({ acl: ctx.app.acl });
|
|
291
|
+
await gitManagerResource.writeToACL({ acl: ctx.app.acl });
|
|
136
292
|
} catch (e) {
|
|
137
293
|
(_c = (_b = ctx.logger) == null ? void 0 : _b.warn) == null ? void 0 : _c.call(_b, "[git-manager] Failed to write resource to ACL memory cache:", e);
|
|
138
294
|
}
|
|
@@ -140,6 +296,13 @@ async function updateRolePermissions(ctx, _next) {
|
|
|
140
296
|
}
|
|
141
297
|
// Annotate the CommonJS export names for ESM import in node:
|
|
142
298
|
0 && (module.exports = {
|
|
299
|
+
GIT_READ_ACTIONS,
|
|
300
|
+
GIT_WRITE_ACTIONS,
|
|
301
|
+
REPOSITORY_READ_ACTIONS,
|
|
302
|
+
getRepositoryPermissionIds,
|
|
303
|
+
getRepositoryPermissionScope,
|
|
304
|
+
repositoryPermissionIdsForDisplay,
|
|
143
305
|
rolePermissions,
|
|
306
|
+
syncScopedActions,
|
|
144
307
|
updateRolePermissions
|
|
145
308
|
});
|
|
@@ -53,14 +53,10 @@ var fs = __toESM(require("fs"));
|
|
|
53
53
|
var os = __toESM(require("os"));
|
|
54
54
|
var path = __toESM(require("path"));
|
|
55
55
|
var import_git_actions = require("./git-actions");
|
|
56
|
+
var import_repository_access = require("../repository-access");
|
|
56
57
|
var import_get_repo_account = require("../utils/get-repo-account");
|
|
57
58
|
var import_redact = require("../utils/redact");
|
|
58
59
|
const SUBTREE_EXECUTION_MODE = "app";
|
|
59
|
-
function getActionParams(ctx) {
|
|
60
|
-
var _a, _b;
|
|
61
|
-
const requestBody = ((_a = ctx.request) == null ? void 0 : _a.body) || {};
|
|
62
|
-
return { ...ctx.action.params, ...(_b = ctx.action.params) == null ? void 0 : _b.values, ...requestBody };
|
|
63
|
-
}
|
|
64
60
|
function stringValue(value, fallback = "") {
|
|
65
61
|
return typeof value === "string" ? value.trim() : fallback;
|
|
66
62
|
}
|
|
@@ -292,7 +288,7 @@ async function loadConfigAndRepository(ctx, configId) {
|
|
|
292
288
|
return { configRecord, config, repo, account };
|
|
293
289
|
}
|
|
294
290
|
async function subtreeOptions(ctx, next) {
|
|
295
|
-
const params =
|
|
291
|
+
const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
|
|
296
292
|
const repositoryId = params.repositoryId;
|
|
297
293
|
if (!repositoryId) ctx.throw(400, "repositoryId is required");
|
|
298
294
|
const remoteName = validateRemoteName(stringValue(params.remoteName, "origin") || "origin");
|
|
@@ -342,7 +338,7 @@ async function subtreeOptions(ctx, next) {
|
|
|
342
338
|
await next();
|
|
343
339
|
}
|
|
344
340
|
async function subtreePreview(ctx, next) {
|
|
345
|
-
const params =
|
|
341
|
+
const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
|
|
346
342
|
const configId = params.configId;
|
|
347
343
|
if (!configId) ctx.throw(400, "configId is required");
|
|
348
344
|
const { config, repo, account } = await loadConfigAndRepository(ctx, configId);
|
|
@@ -368,7 +364,7 @@ async function subtreePreview(ctx, next) {
|
|
|
368
364
|
}
|
|
369
365
|
async function subtreeRunOnAppProcess(ctx, next) {
|
|
370
366
|
var _a, _b;
|
|
371
|
-
const params =
|
|
367
|
+
const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
|
|
372
368
|
const runParams = {
|
|
373
369
|
configId: params.configId,
|
|
374
370
|
policy: validateSubtreePolicy(params.policy),
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var migrate_legacy_repository_permissions_exports = {};
|
|
28
|
+
__export(migrate_legacy_repository_permissions_exports, {
|
|
29
|
+
default: () => MigrateLegacyRepositoryPermissions
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(migrate_legacy_repository_permissions_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
var import_role_permissions = require("../actions/role-permissions");
|
|
34
|
+
function getRecordValue(record, key) {
|
|
35
|
+
if (!record || typeof record !== "object") return void 0;
|
|
36
|
+
const model = record;
|
|
37
|
+
return typeof model.get === "function" ? model.get(key) : model[key];
|
|
38
|
+
}
|
|
39
|
+
class MigrateLegacyRepositoryPermissions extends import_server.Migration {
|
|
40
|
+
on = "afterLoad";
|
|
41
|
+
async up() {
|
|
42
|
+
var _a;
|
|
43
|
+
const resourceRepo = this.db.getRepository("rolesResources");
|
|
44
|
+
const actionsRepo = this.db.getRepository("rolesResourcesActions");
|
|
45
|
+
const repositoryResources = await resourceRepo.find({ filter: { name: "gitRepositories" } });
|
|
46
|
+
for (const repositoryResource of repositoryResources) {
|
|
47
|
+
const rolesResourceId = getRecordValue(repositoryResource, "id");
|
|
48
|
+
const roleName = getRecordValue(repositoryResource, "roleName");
|
|
49
|
+
if (!rolesResourceId || !roleName) continue;
|
|
50
|
+
const actions = await actionsRepo.find({
|
|
51
|
+
filter: { rolesResourceId },
|
|
52
|
+
appends: ["scope"]
|
|
53
|
+
});
|
|
54
|
+
const legacyRead = actions.filter((action) => getRecordValue(action, "name") === "read");
|
|
55
|
+
const legacyWrite = actions.filter((action) => getRecordValue(action, "name") === "write");
|
|
56
|
+
if (legacyRead.length === 0 && legacyWrite.length === 0) continue;
|
|
57
|
+
const readPermission = (0, import_role_permissions.getRepositoryPermissionScope)(legacyRead, ["read"]);
|
|
58
|
+
const writePermission = (0, import_role_permissions.getRepositoryPermissionScope)(legacyWrite, ["write"]);
|
|
59
|
+
if (!readPermission.supported || !writePermission.supported) {
|
|
60
|
+
(_a = this.app.log) == null ? void 0 : _a.warn(
|
|
61
|
+
`[git-manager] skipped repository permission migration for role ${String(
|
|
62
|
+
roleName
|
|
63
|
+
)} because its legacy scope cannot be represented safely`
|
|
64
|
+
);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const effectiveReadIds = [.../* @__PURE__ */ new Set([...readPermission.ids, ...writePermission.ids])];
|
|
68
|
+
const effectiveReadUnrestricted = readPermission.unrestricted || writePermission.unrestricted;
|
|
69
|
+
if (effectiveReadIds.length === 0 && !effectiveReadUnrestricted && !writePermission.unrestricted) continue;
|
|
70
|
+
await (0, import_role_permissions.syncScopedActions)(this.db, repositoryResource, import_role_permissions.REPOSITORY_READ_ACTIONS, effectiveReadIds, {
|
|
71
|
+
unrestricted: effectiveReadUnrestricted
|
|
72
|
+
});
|
|
73
|
+
let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: "gitManager" } });
|
|
74
|
+
if (!gitManagerResource) {
|
|
75
|
+
gitManagerResource = await resourceRepo.create({
|
|
76
|
+
values: { roleName, name: "gitManager", usingActionsConfig: true }
|
|
77
|
+
});
|
|
78
|
+
} else if (!getRecordValue(gitManagerResource, "usingActionsConfig")) {
|
|
79
|
+
await gitManagerResource.update({ usingActionsConfig: true });
|
|
80
|
+
}
|
|
81
|
+
await (0, import_role_permissions.syncScopedActions)(this.db, gitManagerResource, import_role_permissions.GIT_READ_ACTIONS, effectiveReadIds, {
|
|
82
|
+
unrestricted: effectiveReadUnrestricted
|
|
83
|
+
});
|
|
84
|
+
await (0, import_role_permissions.syncScopedActions)(this.db, gitManagerResource, import_role_permissions.GIT_WRITE_ACTIONS, writePermission.ids, {
|
|
85
|
+
unrestricted: writePermission.unrestricted
|
|
86
|
+
});
|
|
87
|
+
for (const action of [...legacyRead, ...legacyWrite]) {
|
|
88
|
+
await action.destroy();
|
|
89
|
+
}
|
|
90
|
+
await repositoryResource.writeToACL({ acl: this.app.acl });
|
|
91
|
+
await gitManagerResource.writeToACL({ acl: this.app.acl });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|