strapi-plugin-bulk-updater 1.6.11 → 1.7.0

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 (28) hide show
  1. package/dist/_chunks/{BulkUpdater-CFStXO-q.mjs → BulkUpdater-CV49TvOV.mjs} +46 -21
  2. package/dist/_chunks/BulkUpdater-CV49TvOV.mjs.map +1 -0
  3. package/dist/_chunks/{BulkUpdater-BSlEEUTV.js → BulkUpdater-Cnzgw4UH.js} +46 -21
  4. package/dist/_chunks/BulkUpdater-Cnzgw4UH.js.map +1 -0
  5. package/dist/_chunks/{SettingsPage-BrfS4_qy.mjs → SettingsPage-DXRWLRp_.mjs} +2 -2
  6. package/dist/_chunks/{SettingsPage-BrfS4_qy.mjs.map → SettingsPage-DXRWLRp_.mjs.map} +1 -1
  7. package/dist/_chunks/{SettingsPage-BgEO2BNP.js → SettingsPage-w_Lz-N0V.js} +2 -2
  8. package/dist/_chunks/{SettingsPage-BgEO2BNP.js.map → SettingsPage-w_Lz-N0V.js.map} +1 -1
  9. package/dist/_chunks/{ValidationRulesTab-BslJyrBj.mjs → ValidationRulesTab-eN_vH3TB.mjs} +22 -2
  10. package/dist/_chunks/ValidationRulesTab-eN_vH3TB.mjs.map +1 -0
  11. package/dist/_chunks/{ValidationRulesTab-Cs0YDlMx.js → ValidationRulesTab-of8bIzre.js} +22 -2
  12. package/dist/_chunks/ValidationRulesTab-of8bIzre.js.map +1 -0
  13. package/dist/_chunks/{index-4eNIGyGu.mjs → index-2DodYa70.mjs} +7 -3
  14. package/dist/_chunks/index-2DodYa70.mjs.map +1 -0
  15. package/dist/_chunks/{index-CjR6IZqM.js → index-C2HoRm23.js} +7 -3
  16. package/dist/_chunks/{index-4eNIGyGu.mjs.map → index-C2HoRm23.js.map} +1 -1
  17. package/dist/admin/index.js +1 -1
  18. package/dist/admin/index.mjs +1 -1
  19. package/dist/server/index.js +157 -69
  20. package/dist/server/index.js.map +1 -1
  21. package/dist/server/index.mjs +157 -69
  22. package/dist/server/index.mjs.map +1 -1
  23. package/package.json +1 -1
  24. package/dist/_chunks/BulkUpdater-BSlEEUTV.js.map +0 -1
  25. package/dist/_chunks/BulkUpdater-CFStXO-q.mjs.map +0 -1
  26. package/dist/_chunks/ValidationRulesTab-BslJyrBj.mjs.map +0 -1
  27. package/dist/_chunks/ValidationRulesTab-Cs0YDlMx.js.map +0 -1
  28. package/dist/_chunks/index-CjR6IZqM.js.map +0 -1
@@ -9,6 +9,10 @@ const PERMISSIONS = {
9
9
  workspaceView: `plugin::${PLUGIN_ID}.workspace.view`,
10
10
  workspaceExecute: `plugin::${PLUGIN_ID}.workspace.execute`,
11
11
  workspacePublish: `plugin::${PLUGIN_ID}.workspace.publish`,
12
+ workspaceSubmitForChecker: `plugin::${PLUGIN_ID}.workspace.submit-for-checker`,
13
+ workspaceForceRunNow: `plugin::${PLUGIN_ID}.workspace.force-run-now`,
14
+ workspaceQueueForOffPeak: `plugin::${PLUGIN_ID}.workspace.queue-for-off-peak`,
15
+ workspaceProceedToExecute: `plugin::${PLUGIN_ID}.workspace.proceed-to-execute`,
12
16
  // CSV Management
13
17
  csvExport: `plugin::${PLUGIN_ID}.csv.export`,
14
18
  csvImport: `plugin::${PLUGIN_ID}.csv.import`,
@@ -56,6 +60,34 @@ const BULK_UPDATER_PERMISSION_ACTIONS = [
56
60
  pluginName: PLUGIN_ID,
57
61
  subCategory: "Workspace"
58
62
  },
63
+ {
64
+ section: "plugins",
65
+ displayName: "Submit For Checker",
66
+ uid: "workspace.submit-for-checker",
67
+ pluginName: PLUGIN_ID,
68
+ subCategory: "Workspace"
69
+ },
70
+ {
71
+ section: "plugins",
72
+ displayName: "Force Run Now",
73
+ uid: "workspace.force-run-now",
74
+ pluginName: PLUGIN_ID,
75
+ subCategory: "Workspace"
76
+ },
77
+ {
78
+ section: "plugins",
79
+ displayName: "Queue For Off-Peak",
80
+ uid: "workspace.queue-for-off-peak",
81
+ pluginName: PLUGIN_ID,
82
+ subCategory: "Workspace"
83
+ },
84
+ {
85
+ section: "plugins",
86
+ displayName: "Proceed to Execute",
87
+ uid: "workspace.proceed-to-execute",
88
+ pluginName: PLUGIN_ID,
89
+ subCategory: "Workspace"
90
+ },
59
91
  {
60
92
  section: "plugins",
61
93
  displayName: "Export CSV & Templates",
@@ -141,6 +173,118 @@ const BULK_UPDATER_PERMISSION_ACTIONS = [
141
173
  subCategory: "Settings"
142
174
  }
143
175
  ];
176
+ const BATCH_UPDATE_POLICY_CONFIG = {
177
+ actions: [
178
+ PERMISSIONS.workspaceExecute,
179
+ PERMISSIONS.workspaceSubmitForChecker,
180
+ PERMISSIONS.workspaceForceRunNow,
181
+ PERMISSIONS.workspaceQueueForOffPeak,
182
+ PERMISSIONS.workspaceProceedToExecute
183
+ ],
184
+ mode: "any",
185
+ enforceBatchUpdateExecutionMode: true
186
+ };
187
+ function resolveBatchUpdateRequiredPermissions(body) {
188
+ const rawMode = body?.executionMode;
189
+ const effectiveMode = rawMode === void 0 ? "immediate" : rawMode;
190
+ if (typeof effectiveMode !== "string" || !["maker_checker", "queue_offpeak", "immediate"].includes(effectiveMode)) {
191
+ return {
192
+ valid: false,
193
+ actions: [],
194
+ reason: `Unsupported or unauthorized execution mode "${String(rawMode)}".`
195
+ };
196
+ }
197
+ const required = [];
198
+ if (effectiveMode === "maker_checker") {
199
+ required.push(PERMISSIONS.workspaceSubmitForChecker);
200
+ } else if (effectiveMode === "queue_offpeak") {
201
+ required.push(PERMISSIONS.workspaceQueueForOffPeak);
202
+ } else {
203
+ required.push(PERMISSIONS.workspaceForceRunNow);
204
+ }
205
+ const isPreviewInitiated = body?.initiatedFromPreview === true || body?.initiatedFromPreview === "true" || body?.source === "preview" || body?.executionSource === "preview";
206
+ if (isPreviewInitiated) {
207
+ required.push(PERMISSIONS.workspaceProceedToExecute);
208
+ }
209
+ return { valid: true, actions: required };
210
+ }
211
+ function setForbiddenResponse(ctx, message = "You do not have permission to perform this action.") {
212
+ if (ctx) {
213
+ ctx.status = 403;
214
+ ctx.body = {
215
+ data: null,
216
+ error: {
217
+ status: 403,
218
+ name: "ForbiddenError",
219
+ message
220
+ }
221
+ };
222
+ }
223
+ }
224
+ const hasPermissionsPolicy = (policyContext, config, { strapi } = {}) => {
225
+ const ctx = policyContext?.isSelect ? policyContext : policyContext?.context || policyContext;
226
+ let actions = [];
227
+ let mode = "all";
228
+ let enforceBatchMode = false;
229
+ if (Array.isArray(config)) {
230
+ actions = config;
231
+ } else if (config && typeof config === "object") {
232
+ actions = Array.isArray(config.actions) ? config.actions : [];
233
+ if (config.mode === "any") {
234
+ mode = "any";
235
+ }
236
+ enforceBatchMode = Boolean(config.enforceBatchUpdateExecutionMode);
237
+ } else if (typeof config === "string") {
238
+ actions = [config];
239
+ }
240
+ const user = ctx?.state?.user;
241
+ const userAbility = ctx?.state?.userAbility;
242
+ const isSuperAdmin = Boolean(
243
+ user?.isSuperAdmin === true || Array.isArray(user?.roles) && user.roles.some((r) => r?.code === "strapi-super-admin" || r?.name === "Super Admin")
244
+ );
245
+ if (isSuperAdmin) {
246
+ return true;
247
+ }
248
+ let batchModeActions = null;
249
+ if (enforceBatchMode) {
250
+ const resolved = resolveBatchUpdateRequiredPermissions(ctx?.request?.body);
251
+ if (!resolved.valid) {
252
+ setForbiddenResponse(ctx, resolved.reason || "You do not have permission to perform this action.");
253
+ return false;
254
+ }
255
+ batchModeActions = resolved.actions;
256
+ }
257
+ if ((!actions || actions.length === 0) && (!batchModeActions || batchModeActions.length === 0)) {
258
+ return true;
259
+ }
260
+ const evaluateActions = (reqActions, evalMode) => {
261
+ if (!reqActions || reqActions.length === 0) return true;
262
+ if (userAbility && typeof userAbility.can === "function") {
263
+ if (userAbility.can("manage", "all") || userAbility.can("*")) {
264
+ return true;
265
+ }
266
+ return evalMode === "any" ? reqActions.some((act) => userAbility.can(act)) : reqActions.every((act) => userAbility.can(act));
267
+ }
268
+ const permissions = Array.isArray(ctx?.state?.permissions) ? ctx.state.permissions : Array.isArray(user?.permissions) ? user.permissions.map((p) => typeof p === "string" ? p : p?.action).filter(Boolean) : [];
269
+ if (permissions.includes("*") || permissions.includes("admin::all")) {
270
+ return true;
271
+ }
272
+ return evalMode === "any" ? reqActions.some((act) => permissions.includes(act)) : reqActions.every((act) => permissions.includes(act));
273
+ };
274
+ const baseAllowed = evaluateActions(actions, mode);
275
+ if (!baseAllowed) {
276
+ setForbiddenResponse(ctx);
277
+ return false;
278
+ }
279
+ if (batchModeActions && !evaluateActions(batchModeActions, "all")) {
280
+ setForbiddenResponse(
281
+ ctx,
282
+ `You do not have permission to perform this batch update action (required: ${batchModeActions.join(", ")}).`
283
+ );
284
+ return false;
285
+ }
286
+ return true;
287
+ };
144
288
  function requirePermissions(actions, mode = "all") {
145
289
  return [
146
290
  {
@@ -210,7 +354,12 @@ const routes = {
210
354
  path: "/batch-update",
211
355
  handler: "bulkUpdater.batchUpdate",
212
356
  config: {
213
- policies: requirePermissions(PERMISSIONS.workspaceExecute)
357
+ policies: [
358
+ {
359
+ name: "plugin::bulk-updater.hasPermissions",
360
+ config: BATCH_UPDATE_POLICY_CONFIG
361
+ }
362
+ ]
214
363
  }
215
364
  },
216
365
  {
@@ -444,75 +593,8 @@ const routes = {
444
593
  ]
445
594
  }
446
595
  };
447
- const hasPermissions = (policyContext, config, { strapi } = {}) => {
448
- const ctx = policyContext?.isSelect ? policyContext : policyContext?.context || policyContext;
449
- let actions = [];
450
- let mode = "all";
451
- if (Array.isArray(config)) {
452
- actions = config;
453
- } else if (config && typeof config === "object") {
454
- actions = Array.isArray(config.actions) ? config.actions : [];
455
- if (config.mode === "any") {
456
- mode = "any";
457
- }
458
- } else if (typeof config === "string") {
459
- actions = [config];
460
- }
461
- if (!actions || actions.length === 0) {
462
- return true;
463
- }
464
- const user = ctx?.state?.user;
465
- const userAbility = ctx?.state?.userAbility;
466
- const isSuperAdmin = Boolean(
467
- user?.isSuperAdmin === true || Array.isArray(user?.roles) && user.roles.some((r) => r?.code === "strapi-super-admin" || r?.name === "Super Admin")
468
- );
469
- if (isSuperAdmin) {
470
- return true;
471
- }
472
- if (userAbility && typeof userAbility.can === "function") {
473
- if (userAbility.can("manage", "all") || userAbility.can("*")) {
474
- return true;
475
- }
476
- const isAllowed2 = mode === "any" ? actions.some((act) => userAbility.can(act)) : actions.every((act) => userAbility.can(act));
477
- if (isAllowed2) {
478
- return true;
479
- }
480
- if (ctx) {
481
- ctx.status = 403;
482
- ctx.body = {
483
- data: null,
484
- error: {
485
- status: 403,
486
- name: "ForbiddenError",
487
- message: "You do not have permission to perform this action."
488
- }
489
- };
490
- }
491
- return false;
492
- }
493
- const permissions = Array.isArray(ctx?.state?.permissions) ? ctx.state.permissions : Array.isArray(user?.permissions) ? user.permissions.map((p) => typeof p === "string" ? p : p?.action).filter(Boolean) : [];
494
- if (permissions.includes("*") || permissions.includes("admin::all")) {
495
- return true;
496
- }
497
- const isAllowed = mode === "any" ? actions.some((act) => permissions.includes(act)) : actions.every((act) => permissions.includes(act));
498
- if (isAllowed) {
499
- return true;
500
- }
501
- if (ctx) {
502
- ctx.status = 403;
503
- ctx.body = {
504
- data: null,
505
- error: {
506
- status: 403,
507
- name: "ForbiddenError",
508
- message: "You do not have permission to perform this action."
509
- }
510
- };
511
- }
512
- return false;
513
- };
514
596
  const policies = {
515
- hasPermissions
597
+ hasPermissions: hasPermissionsPolicy
516
598
  };
517
599
  const auditLog = {
518
600
  collectionName: "bulk_updater_audit_logs",
@@ -789,6 +871,12 @@ const bulkUpdaterController = ({ strapi }) => ({
789
871
  try {
790
872
  const service = strapi.plugin("bulk-updater").service("bulkUpdater");
791
873
  const currentUser = ctx.state.user;
874
+ const hasAuthContext = Boolean(
875
+ ctx?.state?.userAbility || Array.isArray(ctx?.state?.permissions) || Array.isArray(ctx?.state?.user?.permissions) || ctx?.state?.user?.isSuperAdmin !== void 0
876
+ );
877
+ if (hasAuthContext && !hasPermissionsPolicy(ctx, BATCH_UPDATE_POLICY_CONFIG, { strapi })) {
878
+ return;
879
+ }
792
880
  const result = await service.batchUpdate(ctx.request.body || {}, currentUser);
793
881
  ctx.body = result;
794
882
  } catch (err) {