plugin-git-manager 1.2.28 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +58 -40
  2. package/dist/client/941.1793e67472872992.js +10 -0
  3. package/dist/client/index.js +1 -1
  4. package/dist/client-v2/941.b0d55429cd053f32.js +10 -0
  5. package/dist/client-v2/index.js +1 -1
  6. package/dist/locale/en-US.json +90 -1
  7. package/dist/locale/vi-VN.json +90 -1
  8. package/dist/locale/zh-CN.json +90 -1
  9. package/dist/node_modules/simple-git/package.json +1 -1
  10. package/dist/node_modules/zod/package.json +1 -1
  11. package/dist/server/actions/review-cutover.js +137 -0
  12. package/dist/server/actions/review.js +132 -43
  13. package/dist/server/actions/role-permissions.js +1 -0
  14. package/dist/server/ai-tools.js +8 -9
  15. package/dist/server/collections/gitCodeReviews.js +10 -0
  16. package/dist/server/collections/gitReviewCutover.js +44 -0
  17. package/dist/server/collections/gitReviewFlows.js +3 -0
  18. package/dist/server/collections/gitReviewInbox.js +51 -0
  19. package/dist/server/collections/gitReviewProjects.js +43 -0
  20. package/dist/server/collections/gitReviewRequests.js +56 -0
  21. package/dist/server/index.js +8 -2
  22. package/dist/server/plugin.js +51 -16
  23. package/dist/server/poller.js +54 -34
  24. package/dist/server/repository-access.js +23 -5
  25. package/dist/server/request-method-policy.js +2 -1
  26. package/dist/server/review-control-access.js +79 -0
  27. package/dist/server/services/legacy-post-service.js +412 -0
  28. package/dist/server/services/review-service.js +1451 -0
  29. package/dist/server/services/review-source.js +325 -0
  30. package/package.json +2 -2
  31. package/src/client/__tests__/CommitHistory.test.tsx +79 -0
  32. package/src/client/__tests__/ReviewHistory.test.tsx +126 -0
  33. package/src/client/__tests__/RunReviewButton.test.tsx +46 -35
  34. package/src/client/__tests__/workflowRoutes.test.ts +65 -0
  35. package/src/client/components/CommitHistory.tsx +61 -6
  36. package/src/client/components/ReviewFlows.tsx +90 -41
  37. package/src/client/components/ReviewHistory.tsx +245 -15
  38. package/src/client/components/RunReviewButton.tsx +12 -136
  39. package/src/client/workflowRoutes.ts +42 -0
  40. package/src/locale/en-US.json +90 -1
  41. package/src/locale/vi-VN.json +90 -1
  42. package/src/locale/zh-CN.json +90 -1
  43. package/src/server/__tests__/repository-access.test.ts +11 -3
  44. package/src/server/__tests__/review-service.integration.test.ts +1263 -0
  45. package/src/server/__tests__/review.test.ts +37 -98
  46. package/src/server/actions/review-cutover.ts +121 -0
  47. package/src/server/actions/review.ts +148 -38
  48. package/src/server/actions/role-permissions.ts +10 -0
  49. package/src/server/ai-tools.ts +23 -8
  50. package/src/server/collections/gitCodeReviews.ts +19 -0
  51. package/src/server/collections/gitReviewCutover.ts +23 -0
  52. package/src/server/collections/gitReviewFlows.ts +12 -0
  53. package/src/server/collections/gitReviewInbox.ts +30 -0
  54. package/src/server/collections/gitReviewProjects.ts +22 -0
  55. package/src/server/collections/gitReviewRequests.ts +35 -0
  56. package/src/server/index.ts +12 -0
  57. package/src/server/plugin.ts +43 -6
  58. package/src/server/poller.ts +54 -40
  59. package/src/server/repository-access.ts +32 -2
  60. package/src/server/request-method-policy.ts +1 -0
  61. package/src/server/review-control-access.ts +71 -0
  62. package/src/server/services/__tests__/review-source.test.ts +226 -0
  63. package/src/server/services/legacy-post-service.ts +550 -0
  64. package/src/server/services/review-service.ts +1899 -0
  65. package/src/server/services/review-source.ts +359 -0
  66. package/dist/client/900.a48beac7e2ebee7d.js +0 -10
  67. package/dist/client-v2/900.e6155002a9c97e7f.js +0 -10
@@ -48,6 +48,7 @@ var import_sequelize = require("sequelize");
48
48
  var gitActions = __toESM(require("./actions/git-actions"));
49
49
  var gitlabApi = __toESM(require("./actions/gitlab-api"));
50
50
  var reviewActions = __toESM(require("./actions/review"));
51
+ var reviewCutoverActions = __toESM(require("./actions/review-cutover"));
51
52
  var pollerActions = __toESM(require("./actions/poller"));
52
53
  var rolePermissionsActions = __toESM(require("./actions/role-permissions"));
53
54
  var subtreeActions = __toESM(require("./actions/subtree"));
@@ -56,6 +57,9 @@ var import_ai_tools = require("./ai-tools");
56
57
  var import_request_method_policy = require("./request-method-policy");
57
58
  var import_poller = require("./poller");
58
59
  var import_registry_content_service = require("./services/registry-content-service");
60
+ var import_review_service = require("./services/review-service");
61
+ var import_legacy_post_service = require("./services/legacy-post-service");
62
+ var import_review_control_access = require("./review-control-access");
59
63
  var import_repository_access = require("./repository-access");
60
64
  var import_redact = require("./utils/redact");
61
65
  var import_url_security = require("./utils/url-security");
@@ -66,7 +70,11 @@ function isGitConfigurationUrlMutation(resourceName, actionName) {
66
70
  class PluginGitManagerServer extends import_server.Plugin {
67
71
  registryContentService;
68
72
  skillHubContentService;
73
+ reviewService;
74
+ legacyPostService;
69
75
  async afterAdd() {
76
+ this.reviewService = new import_review_service.GitReviewService(this.app);
77
+ this.legacyPostService = new import_legacy_post_service.LegacyPostService(this.app);
70
78
  this.registryContentService = new import_registry_content_service.RegistryGitContentService(
71
79
  this.db,
72
80
  void 0,
@@ -89,6 +97,7 @@ class PluginGitManagerServer extends import_server.Plugin {
89
97
  });
90
98
  }
91
99
  async load() {
100
+ var _a;
92
101
  const dayjsLib = require("dayjs");
93
102
  const utcPlugin = require("dayjs/plugin/utc");
94
103
  const timezonePlugin = require("dayjs/plugin/timezone");
@@ -114,7 +123,17 @@ class PluginGitManagerServer extends import_server.Plugin {
114
123
  mergeRequestNotes: gitlabApi.mergeRequestNotes,
115
124
  triggerReview: reviewActions.triggerReview,
116
125
  reviewApprovePost: reviewActions.reviewApprovePost,
126
+ reviewLegacyPostStatus: reviewActions.reviewLegacyPostStatus,
127
+ reviewLegacyRetryPost: reviewActions.reviewLegacyRetryPost,
128
+ reviewLegacyReleaseHold: reviewActions.reviewLegacyReleaseHold,
117
129
  reviewReject: reviewActions.reviewReject,
130
+ reviewWorkflowRetryPost: reviewActions.reviewWorkflowRetryPost,
131
+ reviewCutoverStatus: reviewCutoverActions.reviewCutoverStatus,
132
+ reviewConfirmCutover: reviewCutoverActions.reviewConfirmCutover,
133
+ reviewCancelLegacy: reviewCutoverActions.reviewCancelLegacy,
134
+ reviewRecover: reviewCutoverActions.reviewRecover,
135
+ reviewResetPostClaim: reviewCutoverActions.reviewResetPostClaim,
136
+ reviewCancelQueued: reviewCutoverActions.reviewCancelQueued,
118
137
  pollNow: pollerActions.pollNow,
119
138
  pollerStatus: pollerActions.pollerStatus,
120
139
  rolePermissions: rolePermissionsActions.rolePermissions,
@@ -125,7 +144,18 @@ class PluginGitManagerServer extends import_server.Plugin {
125
144
  subtreeReplace: subtreeActions.subtreeRunOnAppProcess
126
145
  }
127
146
  });
147
+ const legacyApprovalAction = this.app.acl.getAvailableAction("reviewApprovePost");
148
+ const priorAliases = (_a = legacyApprovalAction == null ? void 0 : legacyApprovalAction.options) == null ? void 0 : _a.aliases;
149
+ this.app.acl.setAvailableAction("reviewApprovePost", {
150
+ ...legacyApprovalAction == null ? void 0 : legacyApprovalAction.options,
151
+ aliases: [
152
+ ...Array.isArray(priorAliases) ? priorAliases : priorAliases ? [priorAliases] : [],
153
+ "reviewLegacyPostStatus",
154
+ "reviewLegacyRetryPost"
155
+ ]
156
+ });
128
157
  this.app.resourceManager.use(import_request_method_policy.enforceGitRequestMethod);
158
+ this.app.resourceManager.use(import_review_control_access.enforceReviewControlAccess);
129
159
  this.app.resourceManager.use(import_repository_access.enforceRepositoryAccess);
130
160
  this.app.resourceManager.use(import_repository_access.enforceRepositoryCollectionAccess);
131
161
  this.app.use(async (ctx, next) => {
@@ -140,33 +170,29 @@ class PluginGitManagerServer extends import_server.Plugin {
140
170
  }
141
171
  return next();
142
172
  });
143
- (0, import_review.registerReviewQueue)(this.app);
144
173
  (0, import_ai_tools.registerGitReviewAiTools)(this.app);
145
174
  this.app.on("afterStart", async () => {
146
175
  await ensureAutoReviewFlowSchema(this.app).catch(
147
176
  (err) => {
148
- var _a, _b;
149
- return (_b = (_a = this.app.log) == null ? void 0 : _a.error) == null ? void 0 : _b.call(_a, "plugin-git-manager: ensure schema error", err);
150
- }
151
- );
152
- (0, import_review.recoverStuckReviews)(this.app).catch(
153
- (err) => {
154
- var _a, _b;
155
- return (_b = (_a = this.app.log) == null ? void 0 : _a.error) == null ? void 0 : _b.call(_a, "plugin-git-manager: recoverStuckReviews error", err);
177
+ var _a2, _b;
178
+ return (_b = (_a2 = this.app.log) == null ? void 0 : _a2.error) == null ? void 0 : _b.call(_a2, "plugin-git-manager: ensure schema error", err);
156
179
  }
157
180
  );
181
+ this.reviewService.start();
158
182
  subtreeActions.recoverStuckSubtreeRuns(this.app).catch((err) => {
159
- var _a, _b;
160
- return (_b = (_a = this.app.log) == null ? void 0 : _a.error) == null ? void 0 : _b.call(_a, "plugin-git-manager: recover subtree runs error", err);
183
+ var _a2, _b;
184
+ return (_b = (_a2 = this.app.log) == null ? void 0 : _a2.error) == null ? void 0 : _b.call(_a2, "plugin-git-manager: recover subtree runs error", err);
161
185
  });
162
186
  (0, import_poller.startPoller)(this.app);
163
187
  });
164
188
  this.app.on("beforeStop", () => {
165
189
  (0, import_review.unregisterReviewQueue)(this.app);
190
+ this.reviewService.stop();
166
191
  (0, import_poller.stopPoller)(this.app);
167
192
  });
168
193
  this.app.on("beforeDestroy", () => {
169
194
  (0, import_review.unregisterReviewQueue)(this.app);
195
+ this.reviewService.stop();
170
196
  (0, import_poller.stopPoller)(this.app);
171
197
  });
172
198
  this.app.acl.registerSnippet({
@@ -218,7 +244,10 @@ class PluginGitManagerServer extends import_server.Plugin {
218
244
  "gitManager:checkout",
219
245
  "gitManager:triggerReview",
220
246
  "gitManager:reviewApprovePost",
247
+ "gitManager:reviewLegacyPostStatus",
248
+ "gitManager:reviewLegacyRetryPost",
221
249
  "gitManager:reviewReject",
250
+ "gitManager:reviewWorkflowRetryPost",
222
251
  "gitManager:pollNow",
223
252
  "gitSubtreeConfigs:create",
224
253
  "gitSubtreeConfigs:update",
@@ -249,8 +278,8 @@ class PluginGitManagerServer extends import_server.Plugin {
249
278
  ]
250
279
  });
251
280
  this.app.resourceManager.use(async (ctx, next) => {
252
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
253
- const resource = (_a = ctx.action) == null ? void 0 : _a.resourceName;
281
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
282
+ const resource = (_a2 = ctx.action) == null ? void 0 : _a2.resourceName;
254
283
  if (resource === "gitSubtreeConfigs" && ["create", "update"].includes((_b = ctx.action) == null ? void 0 : _b.actionName) && ((_c = ctx.action.params) == null ? void 0 : _c.values)) {
255
284
  try {
256
285
  subtreeActions.validateSubtreeConfigInput(ctx.action.params.values);
@@ -308,8 +337,8 @@ class PluginGitManagerServer extends import_server.Plugin {
308
337
  return next();
309
338
  });
310
339
  this.app.resourceManager.use(async (ctx, next) => {
311
- var _a;
312
- const resource = (_a = ctx.action) == null ? void 0 : _a.resourceName;
340
+ var _a2;
341
+ const resource = (_a2 = ctx.action) == null ? void 0 : _a2.resourceName;
313
342
  if (!(0, import_redact.isGitManagerResourceResponse)(resource)) {
314
343
  return next();
315
344
  }
@@ -318,18 +347,24 @@ class PluginGitManagerServer extends import_server.Plugin {
318
347
  });
319
348
  }
320
349
  async install() {
321
- var _a, _b, _c, _d;
350
+ var _a, _b, _c, _d, _e, _f, _g, _h;
322
351
  await ((_a = this.app.db.getCollection("gitAccounts")) == null ? void 0 : _a.sync());
323
352
  await ((_b = this.app.db.getCollection("gitRepositories")) == null ? void 0 : _b.sync());
324
353
  await ((_c = this.app.db.getCollection("gitSubtreeConfigs")) == null ? void 0 : _c.sync());
325
354
  await ((_d = this.app.db.getCollection("gitSubtreeRuns")) == null ? void 0 : _d.sync());
355
+ await ((_e = this.app.db.getCollection("gitReviewProjects")) == null ? void 0 : _e.sync());
356
+ await ((_f = this.app.db.getCollection("gitReviewInbox")) == null ? void 0 : _f.sync());
357
+ await ((_g = this.app.db.getCollection("gitReviewRequests")) == null ? void 0 : _g.sync());
358
+ await ((_h = this.app.db.getCollection("gitReviewCutover")) == null ? void 0 : _h.sync());
326
359
  }
327
360
  async beforeDisable() {
328
361
  (0, import_review.unregisterReviewQueue)(this.app);
362
+ this.reviewService.stop();
329
363
  (0, import_poller.stopPoller)(this.app);
330
364
  }
331
365
  async beforeUnload() {
332
366
  (0, import_review.unregisterReviewQueue)(this.app);
367
+ this.reviewService.stop();
333
368
  (0, import_poller.stopPoller)(this.app);
334
369
  }
335
370
  }
@@ -154,7 +154,7 @@ async function pollAllRepos(app) {
154
154
  const repos = await reposRepo.find({ filter: { autoReview: true } });
155
155
  for (const repo of repos) {
156
156
  try {
157
- const result = await pollOneRepo(app, repo);
157
+ const result = await pollOneRepoUnlocked(app, repo);
158
158
  scanned += result.scanned;
159
159
  triggered += result.triggered;
160
160
  } catch (err) {
@@ -177,6 +177,23 @@ async function tick(app) {
177
177
  await pollAllRepos(app);
178
178
  }
179
179
  async function pollOneRepo(app, repo) {
180
+ const state = stateFor(app);
181
+ if (state.polling) return { scanned: 0, triggered: 0 };
182
+ state.polling = true;
183
+ let lock = null;
184
+ try {
185
+ lock = await tryAcquirePollerLock(app);
186
+ if (!lock) return { scanned: 0, triggered: 0 };
187
+ return await pollOneRepoUnlocked(app, repo);
188
+ } finally {
189
+ try {
190
+ await (lock == null ? void 0 : lock.release());
191
+ } finally {
192
+ state.polling = false;
193
+ }
194
+ }
195
+ }
196
+ async function pollOneRepoUnlocked(app, repo) {
180
197
  var _a, _b;
181
198
  const flowsRepo = app.db.getRepository("gitReviewFlows");
182
199
  const reviewsRepo = app.db.getRepository("gitCodeReviews");
@@ -195,9 +212,10 @@ async function pollOneRepo(app, repo) {
195
212
  const account = await (0, import_get_repo_account.getRepoAccount)(app.db, repo);
196
213
  const pat = (account == null ? void 0 : account.pat) || "";
197
214
  if (!pat) return { scanned: 0, triggered: 0 };
198
- const lastPolledAt = repo.get("lastPolledAt");
199
- const mrs = await listMergeRequests(repo, pat, lastPolledAt);
215
+ const pollStartedAt = /* @__PURE__ */ new Date();
216
+ const mrs = await listMergeRequests(repo, pat);
200
217
  let triggered = 0;
218
+ let failed = false;
201
219
  for (const mr of mrs) {
202
220
  const flow = primaryFlow && (0, import_review.branchMatches)(primaryFlow, mr.source_branch) ? primaryFlow : flows.find((f) => (0, import_review.branchMatches)(f, mr.source_branch));
203
221
  if (!flow) continue;
@@ -206,7 +224,8 @@ async function pollOneRepo(app, repo) {
206
224
  repositoryId: repo.get("id"),
207
225
  targetType: "mr",
208
226
  mrIid: mr.iid
209
- }
227
+ },
228
+ sort: ["-id"]
210
229
  });
211
230
  if (existing) {
212
231
  if (existing.get("latestSha") !== mr.sha) {
@@ -215,7 +234,7 @@ async function pollOneRepo(app, repo) {
215
234
  values: { latestSha: mr.sha }
216
235
  });
217
236
  }
218
- continue;
237
+ if (!flow.get("reviewOnNewCommits") || existing.get("headSha") === mr.sha) continue;
219
238
  }
220
239
  try {
221
240
  await (0, import_review.triggerReviewInternal)(app, {
@@ -225,20 +244,23 @@ async function pollOneRepo(app, repo) {
225
244
  mrIid: mr.iid,
226
245
  branch: mr.source_branch,
227
246
  headSha: mr.sha,
228
- triggeredBy: "poll"
247
+ triggeredBy: "poll",
248
+ eventType: existing ? "head_changed" : "change_opened"
229
249
  });
230
250
  triggered++;
231
251
  } catch (err) {
252
+ failed = true;
232
253
  (_b = (_a = app.log) == null ? void 0 : _a.error) == null ? void 0 : _b.call(_a, `poller: triggerReviewInternal failed for MR !${mr.iid}: ${err == null ? void 0 : err.message}`);
233
254
  }
234
255
  }
256
+ if (failed) throw new Error("One or more merge requests could not be queued");
235
257
  await reposRepo.update({
236
258
  filterByTk: repo.get("id"),
237
- values: { lastPolledAt: /* @__PURE__ */ new Date() }
259
+ values: { lastPolledAt: pollStartedAt }
238
260
  });
239
261
  return { scanned: mrs.length, triggered };
240
262
  }
241
- async function listMergeRequests(repo, pat, updatedAfter) {
263
+ async function listMergeRequests(repo, pat) {
242
264
  const repoUrl = repo.get("repoUrl");
243
265
  const isGitHub = typeof repoUrl === "string" && new URL(repoUrl).hostname === "github.com";
244
266
  if (isGitHub) {
@@ -251,21 +273,18 @@ async function listMergeRequests(repo, pat, updatedAfter) {
251
273
  });
252
274
  const headers = { Accept: "application/vnd.github.v3+json" };
253
275
  if (pat) headers["Authorization"] = `Bearer ${pat}`;
254
- const response2 = await fetch(`https://api.github.com/repos/${projectPath}/pulls?${params2.toString()}`, {
255
- headers,
256
- redirect: "error"
257
- });
258
- if (!response2.ok) {
259
- const body = await response2.text().catch(() => "");
260
- throw new Error(`GitHub API error ${response2.status}: ${body}`);
261
- }
262
- let prs = await response2.json();
263
- if (Array.isArray(prs) && updatedAfter) {
264
- const cutoff = updatedAfter.getTime() - 1e3;
265
- prs = prs.filter((pr) => {
266
- const t = (pr == null ? void 0 : pr.updated_at) ? new Date(pr.updated_at).getTime() : 0;
267
- return t >= cutoff;
276
+ const prs = [];
277
+ for (let page = 1; ; page++) {
278
+ params2.set("page", String(page));
279
+ const response = await fetch(`https://api.github.com/repos/${projectPath}/pulls?${params2.toString()}`, {
280
+ headers,
281
+ redirect: "error"
268
282
  });
283
+ if (!response.ok) throw new Error(`GitHub API error ${response.status}`);
284
+ const items = await response.json();
285
+ if (!Array.isArray(items)) throw new Error("Invalid GitHub pull request response");
286
+ prs.push(...items);
287
+ if (items.length < MR_PAGE_SIZE) break;
269
288
  }
270
289
  return (prs || []).map((pr) => {
271
290
  var _a, _b, _c;
@@ -284,19 +303,20 @@ async function listMergeRequests(repo, pat, updatedAfter) {
284
303
  order_by: "updated_at",
285
304
  sort: "desc"
286
305
  });
287
- if (updatedAfter) {
288
- const safeBound = new Date(updatedAfter.getTime() - 1e3);
289
- params.set("updated_after", safeBound.toISOString());
290
- }
291
- const response = await fetch(`${apiBase}/projects/${encodedProject}/merge_requests?${params.toString()}`, {
292
- redirect: "error",
293
- headers: { "PRIVATE-TOKEN": pat, Accept: "application/json" }
294
- });
295
- if (!response.ok) {
296
- const body = await response.text().catch(() => "");
297
- throw new Error(`GitLab API error ${response.status}: ${body}`);
306
+ const mrs = [];
307
+ for (let page = 1; ; page++) {
308
+ params.set("page", String(page));
309
+ const response = await fetch(`${apiBase}/projects/${encodedProject}/merge_requests?${params.toString()}`, {
310
+ redirect: "error",
311
+ headers: { "PRIVATE-TOKEN": pat, Accept: "application/json" }
312
+ });
313
+ if (!response.ok) throw new Error(`GitLab API error ${response.status}`);
314
+ const items = await response.json();
315
+ if (!Array.isArray(items)) throw new Error("Invalid GitLab merge request response");
316
+ mrs.push(...items);
317
+ if (items.length < MR_PAGE_SIZE) break;
298
318
  }
299
- return response.json();
319
+ return mrs;
300
320
  }
301
321
  // Annotate the CommonJS export names for ESM import in node:
302
322
  0 && (module.exports = {
@@ -54,7 +54,14 @@ const REPOSITORY_ID_ACTIONS = /* @__PURE__ */ new Set([
54
54
  "subtreeOptions"
55
55
  ]);
56
56
  const SUBTREE_CONFIG_ACTIONS = /* @__PURE__ */ new Set(["subtreePreview", "subtreeRun", "subtreeReplace"]);
57
- const REVIEW_ID_ACTIONS = /* @__PURE__ */ new Set(["reviewApprovePost", "reviewReject"]);
57
+ const REVIEW_ID_ACTIONS = /* @__PURE__ */ new Set([
58
+ "reviewApprovePost",
59
+ "reviewReject",
60
+ "reviewWorkflowRetryPost",
61
+ "reviewLegacyPostStatus",
62
+ "reviewLegacyRetryPost",
63
+ "reviewLegacyReleaseHold"
64
+ ]);
58
65
  function asRecord(value) {
59
66
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
60
67
  }
@@ -427,13 +434,25 @@ async function requireScopedRunConfigValue(ctx, values, scope, actionName) {
427
434
  }
428
435
  }
429
436
  async function enforceRepositoryCollectionAccess(ctx, next) {
430
- var _a, _b, _c;
437
+ var _a, _b, _c, _d, _e, _f;
431
438
  const collectionName = scopedCollectionName(ctx);
432
439
  if (!collectionName) {
433
440
  await next();
434
441
  return;
435
442
  }
436
443
  rejectTargetCollectionOverride(ctx, collectionName);
444
+ const actionName = (_a = ctx.action) == null ? void 0 : _a.actionName;
445
+ if (collectionName === "gitCodeReviews" && actionName && ["create", "update", "destroy"].includes(actionName)) {
446
+ ctx.throw(403, "Permission denied");
447
+ }
448
+ if (collectionName === "gitReviewFlows" && actionName && ["create", "update"].includes(actionName)) {
449
+ const bindingFields = /* @__PURE__ */ new Set(["workflowId", "workflowKey"]);
450
+ if ([(_b = ctx.action) == null ? void 0 : _b.params, (_c = ctx.request) == null ? void 0 : _c.body, ctx.query, (_d = ctx.request) == null ? void 0 : _d.query].some(
451
+ (source) => containsMutationField(source, bindingFields)
452
+ )) {
453
+ ctx.throw(403, "Permission denied");
454
+ }
455
+ }
437
456
  const roles = currentRoles(ctx);
438
457
  if (roles.includes("root")) {
439
458
  await next();
@@ -448,7 +467,7 @@ async function enforceRepositoryCollectionAccess(ctx, next) {
448
467
  await next();
449
468
  return;
450
469
  }
451
- const scope = resolveRepositoryScope((_a = repositoryPermission.params) == null ? void 0 : _a.filter);
470
+ const scope = resolveRepositoryScope((_e = repositoryPermission.params) == null ? void 0 : _e.filter);
452
471
  if (!scope.supported) {
453
472
  ctx.throw(403, "Permission denied");
454
473
  }
@@ -456,7 +475,6 @@ async function enforceRepositoryCollectionAccess(ctx, next) {
456
475
  await next();
457
476
  return;
458
477
  }
459
- const actionName = (_b = ctx.action) == null ? void 0 : _b.actionName;
460
478
  if (!actionName || !STANDARD_COLLECTION_ACTIONS.has(actionName)) {
461
479
  ctx.throw(403, "Permission denied");
462
480
  }
@@ -469,7 +487,7 @@ async function enforceRepositoryCollectionAccess(ctx, next) {
469
487
  rejectScopedCredentialAssociationRoute(ctx);
470
488
  rejectScopedRepositoryCredentialAssociationRead(ctx, actionName);
471
489
  rejectScopedBulkMutationValues(ctx, actionName);
472
- const mergeParams = (_c = ctx.action) == null ? void 0 : _c.mergeParams;
490
+ const mergeParams = (_f = ctx.action) == null ? void 0 : _f.mergeParams;
473
491
  if (!mergeParams) {
474
492
  ctx.throw(403, "Permission denied");
475
493
  }
@@ -41,7 +41,8 @@ const READ_ACTIONS = /* @__PURE__ */ new Set([
41
41
  "mergeRequestDetail",
42
42
  "mergeRequestNotes",
43
43
  "pollerStatus",
44
- "rolePermissions"
44
+ "rolePermissions",
45
+ "reviewCutoverStatus"
45
46
  ]);
46
47
  async function enforceGitRequestMethod(ctx, next) {
47
48
  var _a, _b;
@@ -0,0 +1,79 @@
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 review_control_access_exports = {};
28
+ __export(review_control_access_exports, {
29
+ enforceReviewControlAccess: () => enforceReviewControlAccess
30
+ });
31
+ module.exports = __toCommonJS(review_control_access_exports);
32
+ const CONTROL_COLLECTIONS = /* @__PURE__ */ new Set(["gitReviewProjects", "gitReviewInbox", "gitReviewRequests", "gitReviewCutover"]);
33
+ const REVIEW_COLLECTION = /* @__PURE__ */ new Set(["gitCodeReviews"]);
34
+ const ROUTE_KEYS = /* @__PURE__ */ new Set([
35
+ "resourceName",
36
+ "targetCollection",
37
+ "associatedName",
38
+ "__collection",
39
+ "appends",
40
+ "include",
41
+ "fields"
42
+ ]);
43
+ function containsCollection(value, collections = CONTROL_COLLECTIONS) {
44
+ if (typeof value === "string") return value.split(/[.[\],:/()=\s]+/).some((part) => collections.has(part));
45
+ if (Array.isArray(value)) return value.some((item) => containsCollection(item, collections));
46
+ if (value && typeof value === "object")
47
+ return Object.entries(value).some(
48
+ ([key, nested]) => containsCollection(key, collections) || containsCollection(nested, collections)
49
+ );
50
+ return false;
51
+ }
52
+ function containsRouteOverride(value, collections = CONTROL_COLLECTIONS) {
53
+ if (Array.isArray(value)) return value.some((item) => containsRouteOverride(item, collections));
54
+ if (!value || typeof value !== "object") return false;
55
+ return Object.entries(value).some(([key, nested]) => {
56
+ const keyParts = key.split(/[.[\],:/()=\s]+/);
57
+ return keyParts.some((part) => ROUTE_KEYS.has(part)) && containsCollection(nested, collections) || containsRouteOverride(nested, collections);
58
+ });
59
+ }
60
+ async function enforceReviewControlAccess(ctx, next) {
61
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
62
+ let currentTarget;
63
+ try {
64
+ const current = (_a = ctx.getCurrentRepository) == null ? void 0 : _a.call(ctx);
65
+ currentTarget = ((_b = current == null ? void 0 : current.targetCollection) == null ? void 0 : _b.name) || ((_c = current == null ? void 0 : current.collection) == null ? void 0 : _c.name);
66
+ } catch {
67
+ }
68
+ if (containsCollection((_d = ctx.action) == null ? void 0 : _d.resourceName) || containsCollection(currentTarget) || [(_e = ctx.action) == null ? void 0 : _e.params, (_f = ctx.request) == null ? void 0 : _f.body, ctx.query, (_g = ctx.request) == null ? void 0 : _g.query].some((input) => containsRouteOverride(input)))
69
+ ctx.throw(403, "Permission denied");
70
+ if (((_h = ctx.action) == null ? void 0 : _h.actionName) && !["list", "get"].includes(ctx.action.actionName) && (containsCollection(ctx.action.resourceName, REVIEW_COLLECTION) || containsCollection(currentTarget, REVIEW_COLLECTION) || [ctx.action.params, (_i = ctx.request) == null ? void 0 : _i.body, ctx.query, (_j = ctx.request) == null ? void 0 : _j.query].some(
71
+ (input) => containsRouteOverride(input, REVIEW_COLLECTION)
72
+ )))
73
+ ctx.throw(403, "Permission denied");
74
+ await next();
75
+ }
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ enforceReviewControlAccess
79
+ });