plugin-git-manager 1.2.23 → 1.2.26

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.
Files changed (53) hide show
  1. package/dist/client/900.acf7d1fa22f95e71.js +10 -0
  2. package/dist/client/index.js +1 -1
  3. package/dist/client-v2/900.f32b9dc85249fc0a.js +10 -0
  4. package/dist/client-v2/index.js +1 -1
  5. package/dist/externalVersion.js +8 -8
  6. package/dist/locale/en-US.json +4 -3
  7. package/dist/locale/vi-VN.json +4 -3
  8. package/dist/locale/zh-CN.json +4 -3
  9. package/dist/server/actions/git-actions.js +21 -8
  10. package/dist/server/actions/gitlab-api.js +5 -8
  11. package/dist/server/actions/poller.js +2 -1
  12. package/dist/server/actions/review.js +50 -13
  13. package/dist/server/actions/role-permissions.js +109 -16
  14. package/dist/server/actions/subtree.js +4 -8
  15. package/dist/server/migrations/20260730000000-migrate-legacy-repository-permissions.js +23 -7
  16. package/dist/server/plugin.js +42 -19
  17. package/dist/server/repository-access.js +505 -27
  18. package/dist/server/services/registry-content-service.js +149 -32
  19. package/dist/server/utils/get-repo-account.js +5 -2
  20. package/dist/server/utils/gitlab-url.js +2 -0
  21. package/dist/server/utils/redact.js +51 -5
  22. package/dist/server/utils/url-security.js +109 -0
  23. package/package.json +4 -2
  24. package/src/client/components/RunReviewButton.tsx +437 -436
  25. package/src/client/index.tsx +2 -1
  26. package/src/locale/en-US.json +4 -3
  27. package/src/locale/vi-VN.json +4 -3
  28. package/src/locale/zh-CN.json +4 -3
  29. package/src/server/__tests__/git-actions.test.ts +24 -0
  30. package/src/server/__tests__/plugin-url-security.test.ts +17 -0
  31. package/src/server/__tests__/poller.test.ts +37 -0
  32. package/src/server/__tests__/repository-access.test.ts +695 -1
  33. package/src/server/__tests__/review.test.ts +137 -0
  34. package/src/server/__tests__/role-permissions.test.ts +123 -2
  35. package/src/server/actions/git-actions.ts +33 -10
  36. package/src/server/actions/gitlab-api.ts +5 -8
  37. package/src/server/actions/poller.ts +2 -1
  38. package/src/server/actions/review.ts +74 -15
  39. package/src/server/actions/role-permissions.ts +136 -14
  40. package/src/server/actions/subtree.ts +4 -8
  41. package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +23 -8
  42. package/src/server/plugin.ts +46 -25
  43. package/src/server/repository-access.ts +737 -28
  44. package/src/server/services/__tests__/registry-content-service.test.ts +209 -13
  45. package/src/server/services/registry-content-service.ts +473 -315
  46. package/src/server/utils/__tests__/redact.test.ts +56 -0
  47. package/src/server/utils/__tests__/url-security.test.ts +85 -0
  48. package/src/server/utils/get-repo-account.ts +22 -4
  49. package/src/server/utils/gitlab-url.ts +3 -0
  50. package/src/server/utils/redact.ts +68 -5
  51. package/src/server/utils/url-security.ts +95 -0
  52. package/dist/client/900.ee2fa037aff389e2.js +0 -10
  53. package/dist/client-v2/900.bef1c41d267e50c5.js +0 -10
@@ -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 = getActionParams(ctx);
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: baseValues
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({ values: baseValues });
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: message.userId ?? metadata.userId ?? null
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 = getActionParams(ctx);
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 = getActionParams(ctx);
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 == null ? void 0 : role.name).filter((name) => typeof name === "string" && !!name);
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((mapping) => mapping == null ? void 0 : mapping.roleName).filter((name) => typeof name === "string" && !!name);
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
- return ["admin"];
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,
@@ -30,6 +30,8 @@ __export(role_permissions_exports, {
30
30
  GIT_WRITE_ACTIONS: () => GIT_WRITE_ACTIONS,
31
31
  REPOSITORY_READ_ACTIONS: () => REPOSITORY_READ_ACTIONS,
32
32
  getRepositoryPermissionIds: () => getRepositoryPermissionIds,
33
+ getRepositoryPermissionScope: () => getRepositoryPermissionScope,
34
+ repositoryPermissionIdsForDisplay: () => repositoryPermissionIdsForDisplay,
33
35
  rolePermissions: () => rolePermissions,
34
36
  syncScopedActions: () => syncScopedActions,
35
37
  updateRolePermissions: () => updateRolePermissions
@@ -68,20 +70,95 @@ const GIT_WRITE_ACTIONS = [
68
70
  "pollNow",
69
71
  "subtreeRun"
70
72
  ];
71
- function getRepositoryPermissionIds(actions, names) {
72
- var _a, _b, _c;
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) {
73
137
  const ids = /* @__PURE__ */ new Set();
138
+ let unrestricted = false;
74
139
  for (const action of actions) {
75
140
  const actionData = action.toJSON();
76
141
  if (typeof actionData.name !== "string" || !names.includes(actionData.name)) continue;
77
- const scopeRow = actionData.scope;
78
- const scope = (scopeRow == null ? void 0 : scopeRow.scope) || scopeRow;
79
- const scopedIds = (_c = (_b = (_a = scope == null ? void 0 : scope.$and) == null ? void 0 : _a[0]) == null ? void 0 : _b.id) == null ? void 0 : _c.$in;
80
- if (Array.isArray(scopedIds)) scopedIds.forEach((id) => ids.add(id));
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));
81
152
  }
82
- return [...ids];
153
+ return { ids: [...ids], unrestricted, supported: true };
154
+ }
155
+ function getRepositoryPermissionIds(actions, names) {
156
+ return getRepositoryPermissionScope(actions, names).ids;
83
157
  }
84
- async function syncScopedActions(db, resource, actionNames, ids) {
158
+ function repositoryPermissionIdsForDisplay(scope, repositoryIds) {
159
+ return scope.unrestricted ? repositoryIds : scope.ids;
160
+ }
161
+ async function syncScopedActions(db, resource, actionNames, ids, options = {}) {
85
162
  const rolesResourceId = getRecordValue(resource, "id");
86
163
  const actionsRepo = db.getRepository("rolesResourcesActions");
87
164
  for (const storedActionName of actionNames) {
@@ -89,12 +166,12 @@ async function syncScopedActions(db, resource, actionNames, ids) {
89
166
  filter: { rolesResourceId, name: storedActionName },
90
167
  appends: ["scope"]
91
168
  });
92
- if (ids.length === 0) {
93
- if (action) await action.destroy();
94
- continue;
95
- }
96
- const scopeJson = { $and: [{ id: { $in: ids } }] };
97
169
  if (action) {
170
+ if (options.unrestricted) {
171
+ await action.update({ scopeId: null });
172
+ continue;
173
+ }
174
+ const scopeJson = { $and: [{ id: { $in: ids } }] };
98
175
  const actionData = action.toJSON();
99
176
  const actionScopeId = getRecordValue(actionData.scope, "id") || actionData.scopeId || getRecordValue(action, "scopeId");
100
177
  if (actionScopeId) {
@@ -107,6 +184,13 @@ async function syncScopedActions(db, resource, actionNames, ids) {
107
184
  await action.update({ scopeId: getRecordValue(newScope, "id") });
108
185
  }
109
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 } }] };
110
194
  const newScope = await db.getRepository("rolesResourcesScopes").create({ values: { scope: scopeJson } });
111
195
  await actionsRepo.create({
112
196
  values: { rolesResourceId, name: storedActionName, scopeId: getRecordValue(newScope, "id") }
@@ -141,12 +225,19 @@ async function rolePermissions(ctx, _next) {
141
225
  filter: { rolesResourceId: getRecordValue(gitManagerResource, "id") },
142
226
  appends: ["scope"]
143
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
+ ) : [];
144
235
  const result = {
145
- read: getRepositoryPermissionIds(actions, [...REPOSITORY_READ_ACTIONS, "read"]),
236
+ read: repositoryPermissionIdsForDisplay(readScope, repositoryIds),
146
237
  write: [
147
238
  .../* @__PURE__ */ new Set([
148
- ...getRepositoryPermissionIds(gitManagerActions, GIT_WRITE_ACTIONS),
149
- ...getRepositoryPermissionIds(actions, ["write"])
239
+ ...repositoryPermissionIdsForDisplay(gitWriteScope, repositoryIds),
240
+ ...repositoryPermissionIdsForDisplay(repositoryWriteScope, repositoryIds)
150
241
  ])
151
242
  ]
152
243
  };
@@ -209,6 +300,8 @@ async function updateRolePermissions(ctx, _next) {
209
300
  GIT_WRITE_ACTIONS,
210
301
  REPOSITORY_READ_ACTIONS,
211
302
  getRepositoryPermissionIds,
303
+ getRepositoryPermissionScope,
304
+ repositoryPermissionIdsForDisplay,
212
305
  rolePermissions,
213
306
  syncScopedActions,
214
307
  updateRolePermissions
@@ -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 = getActionParams(ctx);
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 = getActionParams(ctx);
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 = getActionParams(ctx);
367
+ const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
372
368
  const runParams = {
373
369
  configId: params.configId,
374
370
  policy: validateSubtreePolicy(params.policy),
@@ -39,6 +39,7 @@ function getRecordValue(record, key) {
39
39
  class MigrateLegacyRepositoryPermissions extends import_server.Migration {
40
40
  on = "afterLoad";
41
41
  async up() {
42
+ var _a;
42
43
  const resourceRepo = this.db.getRepository("rolesResources");
43
44
  const actionsRepo = this.db.getRepository("rolesResourcesActions");
44
45
  const repositoryResources = await resourceRepo.find({ filter: { name: "gitRepositories" } });
@@ -53,11 +54,22 @@ class MigrateLegacyRepositoryPermissions extends import_server.Migration {
53
54
  const legacyRead = actions.filter((action) => getRecordValue(action, "name") === "read");
54
55
  const legacyWrite = actions.filter((action) => getRecordValue(action, "name") === "write");
55
56
  if (legacyRead.length === 0 && legacyWrite.length === 0) continue;
56
- const readIds = (0, import_role_permissions.getRepositoryPermissionIds)(legacyRead, ["read"]);
57
- const writeIds = (0, import_role_permissions.getRepositoryPermissionIds)(legacyWrite, ["write"]);
58
- const effectiveReadIds = [.../* @__PURE__ */ new Set([...readIds, ...writeIds])];
59
- if (effectiveReadIds.length === 0 && writeIds.length === 0) continue;
60
- await (0, import_role_permissions.syncScopedActions)(this.db, repositoryResource, import_role_permissions.REPOSITORY_READ_ACTIONS, effectiveReadIds);
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
+ });
61
73
  let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: "gitManager" } });
62
74
  if (!gitManagerResource) {
63
75
  gitManagerResource = await resourceRepo.create({
@@ -66,8 +78,12 @@ class MigrateLegacyRepositoryPermissions extends import_server.Migration {
66
78
  } else if (!getRecordValue(gitManagerResource, "usingActionsConfig")) {
67
79
  await gitManagerResource.update({ usingActionsConfig: true });
68
80
  }
69
- await (0, import_role_permissions.syncScopedActions)(this.db, gitManagerResource, import_role_permissions.GIT_READ_ACTIONS, effectiveReadIds);
70
- await (0, import_role_permissions.syncScopedActions)(this.db, gitManagerResource, import_role_permissions.GIT_WRITE_ACTIONS, writeIds);
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
+ });
71
87
  for (const action of [...legacyRead, ...legacyWrite]) {
72
88
  await action.destroy();
73
89
  }
@@ -38,7 +38,8 @@ var plugin_exports = {};
38
38
  __export(plugin_exports, {
39
39
  PluginGitManagerServer: () => PluginGitManagerServer,
40
40
  default: () => plugin_default,
41
- ensureAutoReviewFlowSchema: () => ensureAutoReviewFlowSchema
41
+ ensureAutoReviewFlowSchema: () => ensureAutoReviewFlowSchema,
42
+ isGitConfigurationUrlMutation: () => isGitConfigurationUrlMutation
42
43
  });
43
44
  module.exports = __toCommonJS(plugin_exports);
44
45
  var import_server = require("@nocobase/server");
@@ -55,10 +56,26 @@ var import_ai_tools = require("./ai-tools");
55
56
  var import_poller = require("./poller");
56
57
  var import_registry_content_service = require("./services/registry-content-service");
57
58
  var import_repository_access = require("./repository-access");
59
+ var import_redact = require("./utils/redact");
60
+ var import_url_security = require("./utils/url-security");
61
+ const GIT_CONFIGURATION_URL_FIELDS = /* @__PURE__ */ new Set(["repoUrl", "baseUrl"]);
62
+ function isGitConfigurationUrlMutation(resourceName, actionName) {
63
+ return typeof actionName === "string" && ["create", "update"].includes(actionName) && (0, import_redact.isGitManagerResourceResponse)(resourceName);
64
+ }
58
65
  class PluginGitManagerServer extends import_server.Plugin {
59
66
  registryContentService;
67
+ skillHubContentService;
60
68
  async afterAdd() {
61
- this.registryContentService = new import_registry_content_service.RegistryGitContentService(this.db);
69
+ this.registryContentService = new import_registry_content_service.RegistryGitContentService(
70
+ this.db,
71
+ void 0,
72
+ this.app.acl
73
+ );
74
+ this.skillHubContentService = new import_registry_content_service.SkillHubGitContentService(
75
+ this.db,
76
+ void 0,
77
+ this.app.acl
78
+ );
62
79
  }
63
80
  async beforeLoad() {
64
81
  await this.app.db.import({
@@ -108,6 +125,7 @@ class PluginGitManagerServer extends import_server.Plugin {
108
125
  }
109
126
  });
110
127
  this.app.resourceManager.use(import_repository_access.enforceRepositoryAccess);
128
+ this.app.resourceManager.use(import_repository_access.enforceRepositoryCollectionAccess);
111
129
  this.app.use(async (ctx, next) => {
112
130
  if (ctx.logger && ctx.logger.warn) {
113
131
  const originalWarn = ctx.logger.warn.bind(ctx.logger);
@@ -229,7 +247,7 @@ class PluginGitManagerServer extends import_server.Plugin {
229
247
  ]
230
248
  });
231
249
  this.app.resourceManager.use(async (ctx, next) => {
232
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
250
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
233
251
  const resource = (_a = ctx.action) == null ? void 0 : _a.resourceName;
234
252
  if (resource === "gitSubtreeConfigs" && ["create", "update"].includes((_b = ctx.action) == null ? void 0 : _b.actionName) && ((_c = ctx.action.params) == null ? void 0 : _c.values)) {
235
253
  try {
@@ -264,33 +282,37 @@ class PluginGitManagerServer extends import_server.Plugin {
264
282
  }
265
283
  }
266
284
  }
267
- if ((resource === "gitRepositories" || resource === "gitAccounts") && ["create", "update"].includes((_g = ctx.action) == null ? void 0 : _g.actionName)) {
268
- if (((_i = (_h = ctx.action.params) == null ? void 0 : _h.values) == null ? void 0 : _i.pat) === "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022") {
285
+ if (isGitConfigurationUrlMutation(resource, (_g = ctx.action) == null ? void 0 : _g.actionName)) {
286
+ const actionParams = (_h = ctx.action) == null ? void 0 : _h.params;
287
+ const requestBody = (_i = ctx.request) == null ? void 0 : _i.body;
288
+ const hasCredentialBearingUrl = [
289
+ actionParams,
290
+ actionParams == null ? void 0 : actionParams.values,
291
+ requestBody,
292
+ requestBody == null ? void 0 : requestBody.values,
293
+ ctx.query,
294
+ (_j = ctx.request) == null ? void 0 : _j.query
295
+ ].some((source) => (0, import_url_security.containsCredentialBearingUrlField)(source, GIT_CONFIGURATION_URL_FIELDS));
296
+ if (hasCredentialBearingUrl) {
297
+ ctx.throw(400, ctx.t(import_url_security.URL_USERINFO_NOT_ALLOWED, { ns: this.name }));
298
+ }
299
+ if (((_l = (_k = ctx.action.params) == null ? void 0 : _k.values) == null ? void 0 : _l.pat) === "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022") {
269
300
  delete ctx.action.params.values.pat;
270
301
  }
271
- if (((_j = ctx.request.body) == null ? void 0 : _j.pat) === "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022") {
302
+ if (((_m = ctx.request.body) == null ? void 0 : _m.pat) === "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022") {
272
303
  delete ctx.request.body.pat;
273
304
  }
274
305
  }
275
306
  return next();
276
307
  });
277
308
  this.app.resourceManager.use(async (ctx, next) => {
278
- var _a, _b;
309
+ var _a;
279
310
  const resource = (_a = ctx.action) == null ? void 0 : _a.resourceName;
280
- if (resource !== "gitRepositories" && resource !== "gitAccounts") {
311
+ if (!(0, import_redact.isGitManagerResourceResponse)(resource)) {
281
312
  return next();
282
313
  }
283
314
  await next();
284
- if (ctx.body) {
285
- const items = Array.isArray(ctx.body) ? ctx.body : ((_b = ctx.body) == null ? void 0 : _b.data) ? Array.isArray(ctx.body.data) ? ctx.body.data : [ctx.body.data] : [ctx.body];
286
- items.forEach((item) => {
287
- var _a2;
288
- if (item && typeof item === "object") {
289
- if (item.pat) item.pat = "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";
290
- if ((_a2 = item.dataValues) == null ? void 0 : _a2.pat) item.dataValues.pat = "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";
291
- }
292
- });
293
- }
315
+ (0, import_redact.redactCredentialFields)(ctx.body);
294
316
  });
295
317
  }
296
318
  async install() {
@@ -336,5 +358,6 @@ var plugin_default = PluginGitManagerServer;
336
358
  // Annotate the CommonJS export names for ESM import in node:
337
359
  0 && (module.exports = {
338
360
  PluginGitManagerServer,
339
- ensureAutoReviewFlowSchema
361
+ ensureAutoReviewFlowSchema,
362
+ isGitConfigurationUrlMutation
340
363
  });