strapi-plugin-bulk-updater 1.6.11 → 1.7.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.
- package/dist/_chunks/{BulkUpdater-CFStXO-q.mjs → BulkUpdater-BQnhVw0j.mjs} +75 -44
- package/dist/_chunks/BulkUpdater-BQnhVw0j.mjs.map +1 -0
- package/dist/_chunks/{BulkUpdater-BSlEEUTV.js → BulkUpdater-BrBWtCjS.js} +75 -44
- package/dist/_chunks/BulkUpdater-BrBWtCjS.js.map +1 -0
- package/dist/_chunks/{SettingsPage-BrfS4_qy.mjs → SettingsPage-DYD6M988.mjs} +2 -2
- package/dist/_chunks/{SettingsPage-BrfS4_qy.mjs.map → SettingsPage-DYD6M988.mjs.map} +1 -1
- package/dist/_chunks/{SettingsPage-BgEO2BNP.js → SettingsPage-DsKfbhNd.js} +2 -2
- package/dist/_chunks/{SettingsPage-BgEO2BNP.js.map → SettingsPage-DsKfbhNd.js.map} +1 -1
- package/dist/_chunks/{ValidationRulesTab-BslJyrBj.mjs → ValidationRulesTab-BzS4_gcN.mjs} +43 -3
- package/dist/_chunks/ValidationRulesTab-BzS4_gcN.mjs.map +1 -0
- package/dist/_chunks/{ValidationRulesTab-Cs0YDlMx.js → ValidationRulesTab-DZw6CujQ.js} +43 -3
- package/dist/_chunks/ValidationRulesTab-DZw6CujQ.js.map +1 -0
- package/dist/_chunks/{index-CjR6IZqM.js → index-BCOsNd1S.js} +16 -4
- package/dist/_chunks/index-BCOsNd1S.js.map +1 -0
- package/dist/_chunks/{index-4eNIGyGu.mjs → index-CjbxZZjb.mjs} +16 -4
- package/dist/_chunks/index-CjbxZZjb.mjs.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +475 -282
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +475 -282
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/_chunks/BulkUpdater-BSlEEUTV.js.map +0 -1
- package/dist/_chunks/BulkUpdater-CFStXO-q.mjs.map +0 -1
- package/dist/_chunks/ValidationRulesTab-BslJyrBj.mjs.map +0 -1
- package/dist/_chunks/ValidationRulesTab-Cs0YDlMx.js.map +0 -1
- package/dist/_chunks/index-4eNIGyGu.mjs.map +0 -1
- package/dist/_chunks/index-CjR6IZqM.js.map +0 -1
package/dist/server/index.mjs
CHANGED
|
@@ -9,9 +9,17 @@ 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`,
|
|
19
|
+
csvSubmitForChecker: `plugin::${PLUGIN_ID}.csv.submit-for-checker`,
|
|
20
|
+
csvForceRunNow: `plugin::${PLUGIN_ID}.csv.force-run-now`,
|
|
21
|
+
csvQueueForOffPeak: `plugin::${PLUGIN_ID}.csv.queue-for-off-peak`,
|
|
22
|
+
csvPreFlightDryRun: `plugin::${PLUGIN_ID}.csv.pre-flight-dry-run`,
|
|
15
23
|
// Audit Trail
|
|
16
24
|
auditView: `plugin::${PLUGIN_ID}.audit.view`,
|
|
17
25
|
auditDetails: `plugin::${PLUGIN_ID}.audit.details`,
|
|
@@ -56,6 +64,34 @@ const BULK_UPDATER_PERMISSION_ACTIONS = [
|
|
|
56
64
|
pluginName: PLUGIN_ID,
|
|
57
65
|
subCategory: "Workspace"
|
|
58
66
|
},
|
|
67
|
+
{
|
|
68
|
+
section: "plugins",
|
|
69
|
+
displayName: "Submit For Checker",
|
|
70
|
+
uid: "workspace.submit-for-checker",
|
|
71
|
+
pluginName: PLUGIN_ID,
|
|
72
|
+
subCategory: "Workspace"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
section: "plugins",
|
|
76
|
+
displayName: "Force Run Now",
|
|
77
|
+
uid: "workspace.force-run-now",
|
|
78
|
+
pluginName: PLUGIN_ID,
|
|
79
|
+
subCategory: "Workspace"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
section: "plugins",
|
|
83
|
+
displayName: "Queue For Off-Peak",
|
|
84
|
+
uid: "workspace.queue-for-off-peak",
|
|
85
|
+
pluginName: PLUGIN_ID,
|
|
86
|
+
subCategory: "Workspace"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
section: "plugins",
|
|
90
|
+
displayName: "Proceed to Execute",
|
|
91
|
+
uid: "workspace.proceed-to-execute",
|
|
92
|
+
pluginName: PLUGIN_ID,
|
|
93
|
+
subCategory: "Workspace"
|
|
94
|
+
},
|
|
59
95
|
{
|
|
60
96
|
section: "plugins",
|
|
61
97
|
displayName: "Export CSV & Templates",
|
|
@@ -70,6 +106,34 @@ const BULK_UPDATER_PERMISSION_ACTIONS = [
|
|
|
70
106
|
pluginName: PLUGIN_ID,
|
|
71
107
|
subCategory: "CSV Management"
|
|
72
108
|
},
|
|
109
|
+
{
|
|
110
|
+
section: "plugins",
|
|
111
|
+
displayName: "CSV Submit For Checker",
|
|
112
|
+
uid: "csv.submit-for-checker",
|
|
113
|
+
pluginName: PLUGIN_ID,
|
|
114
|
+
subCategory: "CSV Management"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
section: "plugins",
|
|
118
|
+
displayName: "CSV Force Run Now",
|
|
119
|
+
uid: "csv.force-run-now",
|
|
120
|
+
pluginName: PLUGIN_ID,
|
|
121
|
+
subCategory: "CSV Management"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
section: "plugins",
|
|
125
|
+
displayName: "CSV Queue For Off-Peak",
|
|
126
|
+
uid: "csv.queue-for-off-peak",
|
|
127
|
+
pluginName: PLUGIN_ID,
|
|
128
|
+
subCategory: "CSV Management"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
section: "plugins",
|
|
132
|
+
displayName: "CSV Run Pre-Flight Dry Run",
|
|
133
|
+
uid: "csv.pre-flight-dry-run",
|
|
134
|
+
pluginName: PLUGIN_ID,
|
|
135
|
+
subCategory: "CSV Management"
|
|
136
|
+
},
|
|
73
137
|
{
|
|
74
138
|
section: "plugins",
|
|
75
139
|
displayName: "View Audit History",
|
|
@@ -141,6 +205,151 @@ const BULK_UPDATER_PERMISSION_ACTIONS = [
|
|
|
141
205
|
subCategory: "Settings"
|
|
142
206
|
}
|
|
143
207
|
];
|
|
208
|
+
const BATCH_UPDATE_POLICY_CONFIG = {
|
|
209
|
+
actions: [
|
|
210
|
+
PERMISSIONS.workspaceExecute,
|
|
211
|
+
PERMISSIONS.workspaceSubmitForChecker,
|
|
212
|
+
PERMISSIONS.workspaceForceRunNow,
|
|
213
|
+
PERMISSIONS.workspaceQueueForOffPeak,
|
|
214
|
+
PERMISSIONS.workspaceProceedToExecute
|
|
215
|
+
],
|
|
216
|
+
mode: "any",
|
|
217
|
+
enforceBatchUpdateExecutionMode: true
|
|
218
|
+
};
|
|
219
|
+
const CSV_SUBMIT_BATCH_POLICY_CONFIG = {
|
|
220
|
+
actions: [
|
|
221
|
+
PERMISSIONS.csvImport,
|
|
222
|
+
PERMISSIONS.csvSubmitForChecker,
|
|
223
|
+
PERMISSIONS.csvForceRunNow,
|
|
224
|
+
PERMISSIONS.csvQueueForOffPeak
|
|
225
|
+
],
|
|
226
|
+
mode: "any",
|
|
227
|
+
enforceCsvSubmitExecutionMode: true
|
|
228
|
+
};
|
|
229
|
+
const WORKSPACE_MODE_PERMISSIONS = {
|
|
230
|
+
maker_checker: PERMISSIONS.workspaceSubmitForChecker,
|
|
231
|
+
queue_offpeak: PERMISSIONS.workspaceQueueForOffPeak,
|
|
232
|
+
immediate: PERMISSIONS.workspaceForceRunNow
|
|
233
|
+
};
|
|
234
|
+
const CSV_MODE_PERMISSIONS = {
|
|
235
|
+
maker_checker: PERMISSIONS.csvSubmitForChecker,
|
|
236
|
+
queue_offpeak: PERMISSIONS.csvQueueForOffPeak,
|
|
237
|
+
immediate: PERMISSIONS.csvForceRunNow
|
|
238
|
+
};
|
|
239
|
+
function resolveExecutionModeRequiredPermissions(body, modePermissionMap, checkPreviewOrigin) {
|
|
240
|
+
const rawMode = body?.executionMode;
|
|
241
|
+
const effectiveMode = rawMode === void 0 ? "immediate" : rawMode;
|
|
242
|
+
if (typeof effectiveMode !== "string" || !["maker_checker", "queue_offpeak", "immediate"].includes(effectiveMode)) {
|
|
243
|
+
return {
|
|
244
|
+
valid: false,
|
|
245
|
+
actions: [],
|
|
246
|
+
reason: `Unsupported or unauthorized execution mode "${String(rawMode)}".`
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
const required = [
|
|
250
|
+
modePermissionMap[effectiveMode]
|
|
251
|
+
];
|
|
252
|
+
if (checkPreviewOrigin) {
|
|
253
|
+
const isPreviewInitiated = body?.initiatedFromPreview === true || body?.initiatedFromPreview === "true" || body?.source === "preview" || body?.executionSource === "preview";
|
|
254
|
+
if (isPreviewInitiated) {
|
|
255
|
+
required.push(PERMISSIONS.workspaceProceedToExecute);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return { valid: true, actions: required };
|
|
259
|
+
}
|
|
260
|
+
function resolveBatchUpdateRequiredPermissions(body) {
|
|
261
|
+
return resolveExecutionModeRequiredPermissions(body, WORKSPACE_MODE_PERMISSIONS, true);
|
|
262
|
+
}
|
|
263
|
+
function resolveCsvSubmitRequiredPermissions(body) {
|
|
264
|
+
return resolveExecutionModeRequiredPermissions(body, CSV_MODE_PERMISSIONS, false);
|
|
265
|
+
}
|
|
266
|
+
function setForbiddenResponse(ctx, message = "You do not have permission to perform this action.") {
|
|
267
|
+
if (ctx) {
|
|
268
|
+
ctx.status = 403;
|
|
269
|
+
ctx.body = {
|
|
270
|
+
data: null,
|
|
271
|
+
error: {
|
|
272
|
+
status: 403,
|
|
273
|
+
name: "ForbiddenError",
|
|
274
|
+
message
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const hasPermissionsPolicy = (policyContext, config, { strapi } = {}) => {
|
|
280
|
+
const ctx = policyContext?.isSelect ? policyContext : policyContext?.context || policyContext;
|
|
281
|
+
let actions = [];
|
|
282
|
+
let mode = "all";
|
|
283
|
+
let enforceBatchMode = false;
|
|
284
|
+
let enforceCsvMode = false;
|
|
285
|
+
if (Array.isArray(config)) {
|
|
286
|
+
actions = config;
|
|
287
|
+
} else if (config && typeof config === "object") {
|
|
288
|
+
actions = Array.isArray(config.actions) ? config.actions : [];
|
|
289
|
+
if (config.mode === "any") {
|
|
290
|
+
mode = "any";
|
|
291
|
+
}
|
|
292
|
+
enforceBatchMode = Boolean(config.enforceBatchUpdateExecutionMode);
|
|
293
|
+
enforceCsvMode = Boolean(config.enforceCsvSubmitExecutionMode);
|
|
294
|
+
} else if (typeof config === "string") {
|
|
295
|
+
actions = [config];
|
|
296
|
+
}
|
|
297
|
+
const user = ctx?.state?.user;
|
|
298
|
+
const userAbility = ctx?.state?.userAbility;
|
|
299
|
+
const isSuperAdmin = Boolean(
|
|
300
|
+
user?.isSuperAdmin === true || Array.isArray(user?.roles) && user.roles.some((r) => r?.code === "strapi-super-admin" || r?.name === "Super Admin")
|
|
301
|
+
);
|
|
302
|
+
if (isSuperAdmin) {
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
let batchModeActions = null;
|
|
306
|
+
if (enforceBatchMode || enforceCsvMode) {
|
|
307
|
+
const resolved = enforceCsvMode ? resolveCsvSubmitRequiredPermissions(ctx?.request?.body) : resolveBatchUpdateRequiredPermissions(ctx?.request?.body);
|
|
308
|
+
if (!resolved.valid) {
|
|
309
|
+
setForbiddenResponse(ctx, resolved.reason || "You do not have permission to perform this action.");
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
batchModeActions = resolved.actions;
|
|
313
|
+
}
|
|
314
|
+
if ((!actions || actions.length === 0) && (!batchModeActions || batchModeActions.length === 0)) {
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
const evaluateActions = (reqActions, evalMode) => {
|
|
318
|
+
if (!reqActions || reqActions.length === 0) return true;
|
|
319
|
+
if (userAbility && typeof userAbility.can === "function") {
|
|
320
|
+
if (userAbility.can("manage", "all") || userAbility.can("*")) {
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
return evalMode === "any" ? reqActions.some((act) => userAbility.can(act)) : reqActions.every((act) => userAbility.can(act));
|
|
324
|
+
}
|
|
325
|
+
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) : [];
|
|
326
|
+
if (permissions.includes("*") || permissions.includes("admin::all")) {
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
return evalMode === "any" ? reqActions.some((act) => permissions.includes(act)) : reqActions.every((act) => permissions.includes(act));
|
|
330
|
+
};
|
|
331
|
+
const baseAllowed = evaluateActions(actions, mode);
|
|
332
|
+
if (!baseAllowed) {
|
|
333
|
+
setForbiddenResponse(ctx);
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
if (batchModeActions && !evaluateActions(batchModeActions, "all")) {
|
|
337
|
+
setForbiddenResponse(
|
|
338
|
+
ctx,
|
|
339
|
+
`You do not have permission to perform this batch update action (required: ${batchModeActions.join(", ")}).`
|
|
340
|
+
);
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
return true;
|
|
344
|
+
};
|
|
345
|
+
const CSV_READ_PERMISSIONS = [
|
|
346
|
+
PERMISSIONS.csvExport,
|
|
347
|
+
PERMISSIONS.csvImport,
|
|
348
|
+
PERMISSIONS.csvSubmitForChecker,
|
|
349
|
+
PERMISSIONS.csvForceRunNow,
|
|
350
|
+
PERMISSIONS.csvQueueForOffPeak,
|
|
351
|
+
PERMISSIONS.csvPreFlightDryRun
|
|
352
|
+
];
|
|
144
353
|
function requirePermissions(actions, mode = "all") {
|
|
145
354
|
return [
|
|
146
355
|
{
|
|
@@ -164,8 +373,7 @@ const routes = {
|
|
|
164
373
|
policies: requirePermissions(
|
|
165
374
|
[
|
|
166
375
|
PERMISSIONS.workspaceView,
|
|
167
|
-
|
|
168
|
-
PERMISSIONS.csvImport,
|
|
376
|
+
...CSV_READ_PERMISSIONS,
|
|
169
377
|
PERMISSIONS.validationView
|
|
170
378
|
],
|
|
171
379
|
"any"
|
|
@@ -178,7 +386,7 @@ const routes = {
|
|
|
178
386
|
handler: "bulkUpdater.getCollectionEntries",
|
|
179
387
|
config: {
|
|
180
388
|
policies: requirePermissions(
|
|
181
|
-
[PERMISSIONS.workspaceView,
|
|
389
|
+
[PERMISSIONS.workspaceView, ...CSV_READ_PERMISSIONS],
|
|
182
390
|
"any"
|
|
183
391
|
)
|
|
184
392
|
}
|
|
@@ -189,7 +397,7 @@ const routes = {
|
|
|
189
397
|
handler: "bulkUpdater.getRelationOptions",
|
|
190
398
|
config: {
|
|
191
399
|
policies: requirePermissions(
|
|
192
|
-
[PERMISSIONS.workspaceView,
|
|
400
|
+
[PERMISSIONS.workspaceView, ...CSV_READ_PERMISSIONS],
|
|
193
401
|
"any"
|
|
194
402
|
)
|
|
195
403
|
}
|
|
@@ -200,7 +408,7 @@ const routes = {
|
|
|
200
408
|
handler: "bulkUpdater.getMediaOptions",
|
|
201
409
|
config: {
|
|
202
410
|
policies: requirePermissions(
|
|
203
|
-
[PERMISSIONS.workspaceView,
|
|
411
|
+
[PERMISSIONS.workspaceView, ...CSV_READ_PERMISSIONS],
|
|
204
412
|
"any"
|
|
205
413
|
)
|
|
206
414
|
}
|
|
@@ -210,7 +418,12 @@ const routes = {
|
|
|
210
418
|
path: "/batch-update",
|
|
211
419
|
handler: "bulkUpdater.batchUpdate",
|
|
212
420
|
config: {
|
|
213
|
-
policies:
|
|
421
|
+
policies: [
|
|
422
|
+
{
|
|
423
|
+
name: "plugin::bulk-updater.hasPermissions",
|
|
424
|
+
config: BATCH_UPDATE_POLICY_CONFIG
|
|
425
|
+
}
|
|
426
|
+
]
|
|
214
427
|
}
|
|
215
428
|
},
|
|
216
429
|
{
|
|
@@ -282,6 +495,9 @@ const routes = {
|
|
|
282
495
|
PERMISSIONS.workspaceView,
|
|
283
496
|
PERMISSIONS.workspaceExecute,
|
|
284
497
|
PERMISSIONS.csvImport,
|
|
498
|
+
PERMISSIONS.csvSubmitForChecker,
|
|
499
|
+
PERMISSIONS.csvForceRunNow,
|
|
500
|
+
PERMISSIONS.csvQueueForOffPeak,
|
|
285
501
|
PERMISSIONS.auditView,
|
|
286
502
|
PERMISSIONS.approvalView
|
|
287
503
|
],
|
|
@@ -374,7 +590,7 @@ const routes = {
|
|
|
374
590
|
path: "/csv/template/:uid",
|
|
375
591
|
handler: "csv.getTemplate",
|
|
376
592
|
config: {
|
|
377
|
-
policies: requirePermissions(
|
|
593
|
+
policies: requirePermissions(CSV_READ_PERMISSIONS, "any")
|
|
378
594
|
}
|
|
379
595
|
},
|
|
380
596
|
{
|
|
@@ -414,7 +630,7 @@ const routes = {
|
|
|
414
630
|
path: "/csv/import",
|
|
415
631
|
handler: "csv.importCsv",
|
|
416
632
|
config: {
|
|
417
|
-
policies: requirePermissions(PERMISSIONS.
|
|
633
|
+
policies: requirePermissions(PERMISSIONS.csvForceRunNow)
|
|
418
634
|
}
|
|
419
635
|
},
|
|
420
636
|
{
|
|
@@ -422,7 +638,7 @@ const routes = {
|
|
|
422
638
|
path: "/csv/import-chunk",
|
|
423
639
|
handler: "csv.importChunk",
|
|
424
640
|
config: {
|
|
425
|
-
policies: requirePermissions(PERMISSIONS.
|
|
641
|
+
policies: requirePermissions(PERMISSIONS.csvForceRunNow)
|
|
426
642
|
}
|
|
427
643
|
},
|
|
428
644
|
{
|
|
@@ -430,7 +646,7 @@ const routes = {
|
|
|
430
646
|
path: "/csv/validate-preflight",
|
|
431
647
|
handler: "csv.validatePreflight",
|
|
432
648
|
config: {
|
|
433
|
-
policies: requirePermissions(PERMISSIONS.
|
|
649
|
+
policies: requirePermissions(PERMISSIONS.csvPreFlightDryRun)
|
|
434
650
|
}
|
|
435
651
|
},
|
|
436
652
|
{
|
|
@@ -438,81 +654,19 @@ const routes = {
|
|
|
438
654
|
path: "/csv/submit-batch",
|
|
439
655
|
handler: "csv.submitBatch",
|
|
440
656
|
config: {
|
|
441
|
-
policies:
|
|
657
|
+
policies: [
|
|
658
|
+
{
|
|
659
|
+
name: "plugin::bulk-updater.hasPermissions",
|
|
660
|
+
config: CSV_SUBMIT_BATCH_POLICY_CONFIG
|
|
661
|
+
}
|
|
662
|
+
]
|
|
442
663
|
}
|
|
443
664
|
}
|
|
444
665
|
]
|
|
445
666
|
}
|
|
446
667
|
};
|
|
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
668
|
const policies = {
|
|
515
|
-
hasPermissions
|
|
669
|
+
hasPermissions: hasPermissionsPolicy
|
|
516
670
|
};
|
|
517
671
|
const auditLog = {
|
|
518
672
|
collectionName: "bulk_updater_audit_logs",
|
|
@@ -586,7 +740,15 @@ const contentTypes = {
|
|
|
586
740
|
schema: auditLog
|
|
587
741
|
}
|
|
588
742
|
};
|
|
743
|
+
const { AsyncLocalStorage } = require("async_hooks");
|
|
589
744
|
const CRASH_GUARD_SYMBOL = Symbol.for("strapi-plugin-bulk-updater.undiciCrashGuardInstalled");
|
|
745
|
+
const rollbackContextStorage = new AsyncLocalStorage();
|
|
746
|
+
function runInRollbackContext(fn) {
|
|
747
|
+
return rollbackContextStorage.run(true, fn);
|
|
748
|
+
}
|
|
749
|
+
function isRollbackContext() {
|
|
750
|
+
return rollbackContextStorage.getStore() === true;
|
|
751
|
+
}
|
|
590
752
|
let activeBulkOperations = 0;
|
|
591
753
|
function getActiveBulkOperationCount() {
|
|
592
754
|
return activeBulkOperations;
|
|
@@ -789,6 +951,12 @@ const bulkUpdaterController = ({ strapi }) => ({
|
|
|
789
951
|
try {
|
|
790
952
|
const service = strapi.plugin("bulk-updater").service("bulkUpdater");
|
|
791
953
|
const currentUser = ctx.state.user;
|
|
954
|
+
const hasAuthContext = Boolean(
|
|
955
|
+
ctx?.state?.userAbility || Array.isArray(ctx?.state?.permissions) || Array.isArray(ctx?.state?.user?.permissions) || ctx?.state?.user?.isSuperAdmin !== void 0
|
|
956
|
+
);
|
|
957
|
+
if (hasAuthContext && !hasPermissionsPolicy(ctx, BATCH_UPDATE_POLICY_CONFIG, { strapi })) {
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
792
960
|
const result = await service.batchUpdate(ctx.request.body || {}, currentUser);
|
|
793
961
|
ctx.body = result;
|
|
794
962
|
} catch (err) {
|
|
@@ -1027,6 +1195,13 @@ const validationRulesController = ({ strapi }) => ({
|
|
|
1027
1195
|
}
|
|
1028
1196
|
}
|
|
1029
1197
|
});
|
|
1198
|
+
function ensureCsvAuthorized(ctx, policyConfig, strapi) {
|
|
1199
|
+
const hasAuthContext = Boolean(
|
|
1200
|
+
ctx?.state?.userAbility || Array.isArray(ctx?.state?.permissions) || Array.isArray(ctx?.state?.user?.permissions) || ctx?.state?.user?.isSuperAdmin !== void 0
|
|
1201
|
+
);
|
|
1202
|
+
if (!hasAuthContext) return true;
|
|
1203
|
+
return hasPermissionsPolicy(ctx, policyConfig, { strapi });
|
|
1204
|
+
}
|
|
1030
1205
|
const csvController = ({ strapi }) => ({
|
|
1031
1206
|
async getTemplate(ctx) {
|
|
1032
1207
|
try {
|
|
@@ -1135,6 +1310,9 @@ const csvController = ({ strapi }) => ({
|
|
|
1135
1310
|
},
|
|
1136
1311
|
async importCsv(ctx) {
|
|
1137
1312
|
try {
|
|
1313
|
+
if (!ensureCsvAuthorized(ctx, { actions: [PERMISSIONS.csvForceRunNow] }, strapi)) {
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1138
1316
|
const { uid, csvText, mode, publish, publishStrategy, unreviewedConsent } = ctx.request.body;
|
|
1139
1317
|
if (!uid) {
|
|
1140
1318
|
ctx.status = 400;
|
|
@@ -1164,6 +1342,9 @@ const csvController = ({ strapi }) => ({
|
|
|
1164
1342
|
},
|
|
1165
1343
|
async importChunk(ctx) {
|
|
1166
1344
|
try {
|
|
1345
|
+
if (!ensureCsvAuthorized(ctx, { actions: [PERMISSIONS.csvForceRunNow] }, strapi)) {
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1167
1348
|
const { uid, rows, batchId, isFirstChunk, isLastChunk, startRowNumber, mode, publish, publishStrategy, unreviewedConsent, originalHeaders } = ctx.request.body;
|
|
1168
1349
|
if (!uid) {
|
|
1169
1350
|
ctx.status = 400;
|
|
@@ -1198,6 +1379,9 @@ const csvController = ({ strapi }) => ({
|
|
|
1198
1379
|
},
|
|
1199
1380
|
async validatePreflight(ctx) {
|
|
1200
1381
|
try {
|
|
1382
|
+
if (!ensureCsvAuthorized(ctx, { actions: [PERMISSIONS.csvPreFlightDryRun] }, strapi)) {
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1201
1385
|
const { uid, rows, mode } = ctx.request.body;
|
|
1202
1386
|
if (!uid) {
|
|
1203
1387
|
ctx.status = 400;
|
|
@@ -1221,6 +1405,9 @@ const csvController = ({ strapi }) => ({
|
|
|
1221
1405
|
},
|
|
1222
1406
|
async submitBatch(ctx) {
|
|
1223
1407
|
try {
|
|
1408
|
+
if (!ensureCsvAuthorized(ctx, CSV_SUBMIT_BATCH_POLICY_CONFIG, strapi)) {
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1224
1411
|
const { uid, rows, executionMode, makerNotes, forceImmediate, mode, publish, publishStrategy, unreviewedConsent, unreviewedCount } = ctx.request.body;
|
|
1225
1412
|
if (!uid) {
|
|
1226
1413
|
ctx.status = 400;
|
|
@@ -9464,236 +9651,239 @@ const auditService = ({ strapi }) => ({
|
|
|
9464
9651
|
* Helper to revert diff items back to original values
|
|
9465
9652
|
*/
|
|
9466
9653
|
async revertDiffItems(diffs, userId) {
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9475
|
-
|
|
9476
|
-
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
9482
|
-
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
|
|
9511
|
-
|
|
9512
|
-
|
|
9513
|
-
|
|
9514
|
-
const
|
|
9515
|
-
|
|
9516
|
-
|
|
9517
|
-
|
|
9518
|
-
|
|
9519
|
-
|
|
9520
|
-
|
|
9521
|
-
|
|
9522
|
-
|
|
9523
|
-
|
|
9524
|
-
|
|
9525
|
-
|
|
9526
|
-
|
|
9527
|
-
|
|
9528
|
-
|
|
9529
|
-
|
|
9530
|
-
|
|
9531
|
-
|
|
9532
|
-
|
|
9533
|
-
if (reverted.errors.length > 0) {
|
|
9534
|
-
throw new Error(reverted.errors.join("; "));
|
|
9535
|
-
}
|
|
9536
|
-
restoredRoot = reverted.updateData[rootKey];
|
|
9537
|
-
} else {
|
|
9538
|
-
let workingRoot = existingRoot;
|
|
9539
|
-
for (const dzDiff of item.dynamicZoneDiffs) {
|
|
9540
|
-
const parsedDz = parseDynamicZonePath(dzDiff.attribute || item.attribute);
|
|
9541
|
-
const dzParts = parsedDz.cleanPath.split(".").slice(1);
|
|
9542
|
-
const targetIndexes = dzDiff.index !== void 0 ? [dzDiff.index] : parsedDz.targetIndex !== void 0 ? [parsedDz.targetIndex] : void 0;
|
|
9543
|
-
workingRoot = setDeepProperty(workingRoot, dzParts, dzDiff.oldValue ?? null, {
|
|
9544
|
-
targetIndexes,
|
|
9545
|
-
targetComponentUid: dzDiff.componentUid || parsedDz.targetComponentUid,
|
|
9546
|
-
strapi
|
|
9654
|
+
return runInRollbackContext(async () => {
|
|
9655
|
+
const revertedEntryKeys = /* @__PURE__ */ new Set();
|
|
9656
|
+
const rollbackDetails = [];
|
|
9657
|
+
for (const item of diffs) {
|
|
9658
|
+
if (item.status === "updated" && item.uid && item.documentId && item.attribute) {
|
|
9659
|
+
try {
|
|
9660
|
+
const ct = strapi.contentTypes[item.uid];
|
|
9661
|
+
if (!ct) {
|
|
9662
|
+
throw new Error(`Content type "${item.uid}" does not exist in schema.`);
|
|
9663
|
+
}
|
|
9664
|
+
const isRel = item.oldValue && typeof item.oldValue === "object" && item.oldValue.isRelation;
|
|
9665
|
+
let rollbackPayload;
|
|
9666
|
+
if (isRel) {
|
|
9667
|
+
const oldDocIds = Array.isArray(item.oldValue.documentIds) ? item.oldValue.documentIds : [];
|
|
9668
|
+
rollbackPayload = { set: oldDocIds };
|
|
9669
|
+
} else {
|
|
9670
|
+
rollbackPayload = item.oldValue ?? null;
|
|
9671
|
+
}
|
|
9672
|
+
const parsed = parseDynamicZonePath(item.attribute);
|
|
9673
|
+
const rootKey = parsed.rootKey;
|
|
9674
|
+
const rootAttrDef = ct.attributes?.[rootKey];
|
|
9675
|
+
const isComponent = rootAttrDef?.type === "component";
|
|
9676
|
+
const isDynamicZone = rootAttrDef?.type === "dynamiczone";
|
|
9677
|
+
const isNested = item.attribute.includes(".") || item.attribute.includes("[") || isComponent || isDynamicZone || isDeepComponentField(ct, strapi.components, item.attribute);
|
|
9678
|
+
const isLocalized = Boolean(ct?.pluginOptions?.i18n?.localized) && item.locale && item.locale !== "null" && item.locale !== "undefined";
|
|
9679
|
+
const isDraftAndPublish = Boolean(ct?.options?.draftAndPublish ?? item.isDraftAndPublish);
|
|
9680
|
+
const populateOption = isNested ? buildDeepPopulate(ct.attributes, strapi.components) : void 0;
|
|
9681
|
+
const findOneArgs = { documentId: item.documentId };
|
|
9682
|
+
if (populateOption) {
|
|
9683
|
+
findOneArgs.populate = populateOption;
|
|
9684
|
+
}
|
|
9685
|
+
if (isLocalized) {
|
|
9686
|
+
findOneArgs.locale = item.locale;
|
|
9687
|
+
}
|
|
9688
|
+
const currentDoc = await strapi.documents(item.uid).findOne(findOneArgs);
|
|
9689
|
+
if (!currentDoc) {
|
|
9690
|
+
throw new Error(`Document "${item.documentId}" not found in collection "${item.uid}".`);
|
|
9691
|
+
}
|
|
9692
|
+
if (isNested && (isComponent || isDynamicZone || rootAttrDef)) {
|
|
9693
|
+
const isRootDz = isDynamicZone;
|
|
9694
|
+
const existingRoot = currentDoc?.[rootKey] || (isRootDz ? [] : {});
|
|
9695
|
+
let restoredRoot;
|
|
9696
|
+
if (Array.isArray(item.dynamicZoneDiffs) && item.dynamicZoneDiffs.length > 0) {
|
|
9697
|
+
const hasStructuredSegments = item.dynamicZoneDiffs.some(
|
|
9698
|
+
(dz) => Array.isArray(dz?.segments) && dz.segments.length > 0
|
|
9699
|
+
);
|
|
9700
|
+
if (hasStructuredSegments) {
|
|
9701
|
+
const occUpdates = item.dynamicZoneDiffs.map((dzDiff) => {
|
|
9702
|
+
const isRelDiff = dzDiff.oldValue && typeof dzDiff.oldValue === "object" && dzDiff.oldValue.isRelation;
|
|
9703
|
+
const val = isRelDiff ? { mode: "set", documentIds: Array.isArray(dzDiff.oldValue.documentIds) ? dzDiff.oldValue.documentIds : [] } : dzDiff.oldValue ?? null;
|
|
9704
|
+
return {
|
|
9705
|
+
occurrenceKey: dzDiff.occurrenceKey,
|
|
9706
|
+
segments: dzDiff.segments,
|
|
9707
|
+
dynamicZoneIndex: dzDiff.index,
|
|
9708
|
+
componentId: dzDiff.componentId,
|
|
9709
|
+
componentUid: dzDiff.componentUid,
|
|
9710
|
+
value: val
|
|
9711
|
+
};
|
|
9712
|
+
});
|
|
9713
|
+
const reverted = await applyOccurrenceUpdatesToDocument({
|
|
9714
|
+
strapi,
|
|
9715
|
+
contentType: ct,
|
|
9716
|
+
allComponents: strapi.components,
|
|
9717
|
+
currentDoc,
|
|
9718
|
+
attribute: item.attribute,
|
|
9719
|
+
updates: occUpdates
|
|
9547
9720
|
});
|
|
9721
|
+
if (reverted.errors.length > 0) {
|
|
9722
|
+
throw new Error(reverted.errors.join("; "));
|
|
9723
|
+
}
|
|
9724
|
+
restoredRoot = reverted.updateData[rootKey];
|
|
9725
|
+
} else {
|
|
9726
|
+
let workingRoot = existingRoot;
|
|
9727
|
+
for (const dzDiff of item.dynamicZoneDiffs) {
|
|
9728
|
+
const parsedDz = parseDynamicZonePath(dzDiff.attribute || item.attribute);
|
|
9729
|
+
const dzParts = parsedDz.cleanPath.split(".").slice(1);
|
|
9730
|
+
const targetIndexes = dzDiff.index !== void 0 ? [dzDiff.index] : parsedDz.targetIndex !== void 0 ? [parsedDz.targetIndex] : void 0;
|
|
9731
|
+
workingRoot = setDeepProperty(workingRoot, dzParts, dzDiff.oldValue ?? null, {
|
|
9732
|
+
targetIndexes,
|
|
9733
|
+
targetComponentUid: dzDiff.componentUid || parsedDz.targetComponentUid,
|
|
9734
|
+
strapi
|
|
9735
|
+
});
|
|
9736
|
+
}
|
|
9737
|
+
restoredRoot = workingRoot;
|
|
9548
9738
|
}
|
|
9549
|
-
|
|
9739
|
+
} else {
|
|
9740
|
+
const parts = parsed.cleanPath.split(".");
|
|
9741
|
+
const pathParts = parts.slice(1);
|
|
9742
|
+
const targetIndexes = parsed.targetIndex !== void 0 ? [parsed.targetIndex] : void 0;
|
|
9743
|
+
const targetComponentUid = parsed.targetComponentUid;
|
|
9744
|
+
restoredRoot = setDeepProperty(existingRoot, pathParts, rollbackPayload, {
|
|
9745
|
+
targetIndexes,
|
|
9746
|
+
targetComponentUid,
|
|
9747
|
+
strapi
|
|
9748
|
+
});
|
|
9550
9749
|
}
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
|
|
9554
|
-
|
|
9555
|
-
|
|
9556
|
-
|
|
9557
|
-
targetIndexes,
|
|
9558
|
-
targetComponentUid,
|
|
9559
|
-
strapi
|
|
9750
|
+
await strapi.documents(item.uid).update({
|
|
9751
|
+
documentId: item.documentId,
|
|
9752
|
+
...isLocalized ? { locale: item.locale } : {},
|
|
9753
|
+
data: {
|
|
9754
|
+
[rootKey]: restoredRoot
|
|
9755
|
+
}
|
|
9560
9756
|
});
|
|
9561
|
-
}
|
|
9562
|
-
|
|
9563
|
-
|
|
9564
|
-
|
|
9565
|
-
|
|
9566
|
-
|
|
9567
|
-
}
|
|
9568
|
-
});
|
|
9569
|
-
} else {
|
|
9570
|
-
await strapi.documents(item.uid).update({
|
|
9571
|
-
documentId: item.documentId,
|
|
9572
|
-
...isLocalized ? { locale: item.locale } : {},
|
|
9573
|
-
data: {
|
|
9574
|
-
[item.attribute]: rollbackPayload
|
|
9575
|
-
}
|
|
9576
|
-
});
|
|
9577
|
-
}
|
|
9578
|
-
let targetStatus = void 0;
|
|
9579
|
-
if (item.previousStatus === "published" || item.previousStatus === "modified" || item.previousStatus === "draft") {
|
|
9580
|
-
targetStatus = item.previousStatus;
|
|
9581
|
-
} else if (item.hadPublishedVersion === false) {
|
|
9582
|
-
targetStatus = "draft";
|
|
9583
|
-
} else if (item.hadPublishedVersion === true) {
|
|
9584
|
-
targetStatus = "published";
|
|
9585
|
-
}
|
|
9586
|
-
if (isDraftAndPublish && !targetStatus) {
|
|
9587
|
-
let publishedCounterpart = null;
|
|
9588
|
-
try {
|
|
9589
|
-
const docSvc = strapi.documents(item.uid);
|
|
9590
|
-
if (typeof docSvc.findMany === "function") {
|
|
9591
|
-
const pubs = await docSvc.findMany({
|
|
9592
|
-
status: "published",
|
|
9593
|
-
filters: { documentId: item.documentId },
|
|
9594
|
-
fields: ["documentId", "publishedAt"],
|
|
9595
|
-
limit: 1,
|
|
9596
|
-
...isLocalized ? { locale: item.locale } : {}
|
|
9597
|
-
});
|
|
9598
|
-
if (pubs && pubs.length > 0) {
|
|
9599
|
-
publishedCounterpart = pubs[0];
|
|
9757
|
+
} else {
|
|
9758
|
+
await strapi.documents(item.uid).update({
|
|
9759
|
+
documentId: item.documentId,
|
|
9760
|
+
...isLocalized ? { locale: item.locale } : {},
|
|
9761
|
+
data: {
|
|
9762
|
+
[item.attribute]: rollbackPayload
|
|
9600
9763
|
}
|
|
9601
|
-
}
|
|
9602
|
-
} catch {
|
|
9764
|
+
});
|
|
9603
9765
|
}
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9766
|
+
let targetStatus = void 0;
|
|
9767
|
+
if (item.previousStatus === "published" || item.previousStatus === "modified" || item.previousStatus === "draft") {
|
|
9768
|
+
targetStatus = item.previousStatus;
|
|
9769
|
+
} else if (item.hadPublishedVersion === false) {
|
|
9607
9770
|
targetStatus = "draft";
|
|
9771
|
+
} else if (item.hadPublishedVersion === true) {
|
|
9772
|
+
targetStatus = "published";
|
|
9608
9773
|
}
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
const docSvc = strapi.documents(item.uid);
|
|
9612
|
-
if (targetStatus === "published") {
|
|
9774
|
+
if (isDraftAndPublish && !targetStatus) {
|
|
9775
|
+
let publishedCounterpart = null;
|
|
9613
9776
|
try {
|
|
9614
|
-
|
|
9615
|
-
|
|
9616
|
-
|
|
9777
|
+
const docSvc = strapi.documents(item.uid);
|
|
9778
|
+
if (typeof docSvc.findMany === "function") {
|
|
9779
|
+
const pubs = await docSvc.findMany({
|
|
9780
|
+
status: "published",
|
|
9781
|
+
filters: { documentId: item.documentId },
|
|
9782
|
+
fields: ["documentId", "publishedAt"],
|
|
9783
|
+
limit: 1,
|
|
9617
9784
|
...isLocalized ? { locale: item.locale } : {}
|
|
9618
9785
|
});
|
|
9786
|
+
if (pubs && pubs.length > 0) {
|
|
9787
|
+
publishedCounterpart = pubs[0];
|
|
9788
|
+
}
|
|
9619
9789
|
}
|
|
9620
|
-
} catch
|
|
9621
|
-
strapi.log.warn(
|
|
9622
|
-
`[bulk-updater] Failed to auto-publish rollback for ${item.uid}/${item.documentId}:`,
|
|
9623
|
-
publishErr?.message
|
|
9624
|
-
);
|
|
9790
|
+
} catch {
|
|
9625
9791
|
}
|
|
9626
|
-
|
|
9627
|
-
|
|
9628
|
-
|
|
9629
|
-
|
|
9630
|
-
|
|
9631
|
-
|
|
9632
|
-
|
|
9633
|
-
|
|
9634
|
-
|
|
9635
|
-
|
|
9792
|
+
if (publishedCounterpart?.publishedAt || currentDoc?.publishedAt) {
|
|
9793
|
+
targetStatus = "published";
|
|
9794
|
+
} else {
|
|
9795
|
+
targetStatus = "draft";
|
|
9796
|
+
}
|
|
9797
|
+
}
|
|
9798
|
+
if (isDraftAndPublish) {
|
|
9799
|
+
const docSvc = strapi.documents(item.uid);
|
|
9800
|
+
if (targetStatus === "published") {
|
|
9801
|
+
try {
|
|
9802
|
+
if (typeof docSvc.publish === "function") {
|
|
9803
|
+
await docSvc.publish({
|
|
9804
|
+
documentId: item.documentId,
|
|
9636
9805
|
...isLocalized ? { locale: item.locale } : {}
|
|
9637
9806
|
});
|
|
9638
|
-
|
|
9807
|
+
}
|
|
9808
|
+
} catch (publishErr) {
|
|
9809
|
+
strapi.log.warn(
|
|
9810
|
+
`[bulk-updater] Failed to auto-publish rollback for ${item.uid}/${item.documentId}:`,
|
|
9811
|
+
publishErr?.message
|
|
9812
|
+
);
|
|
9813
|
+
}
|
|
9814
|
+
} else if (targetStatus === "draft") {
|
|
9815
|
+
try {
|
|
9816
|
+
if (typeof docSvc.unpublish === "function") {
|
|
9817
|
+
let hasPublished = false;
|
|
9818
|
+
if (typeof docSvc.findMany === "function") {
|
|
9819
|
+
const pubs = await docSvc.findMany({
|
|
9820
|
+
status: "published",
|
|
9821
|
+
filters: { documentId: item.documentId },
|
|
9822
|
+
fields: ["documentId", "publishedAt"],
|
|
9823
|
+
limit: 1,
|
|
9824
|
+
...isLocalized ? { locale: item.locale } : {}
|
|
9825
|
+
});
|
|
9826
|
+
if (pubs && pubs.length > 0) {
|
|
9827
|
+
hasPublished = true;
|
|
9828
|
+
}
|
|
9829
|
+
} else if (currentDoc?.publishedAt) {
|
|
9639
9830
|
hasPublished = true;
|
|
9640
9831
|
}
|
|
9641
|
-
|
|
9642
|
-
|
|
9643
|
-
|
|
9644
|
-
|
|
9645
|
-
|
|
9646
|
-
|
|
9647
|
-
...isLocalized ? { locale: item.locale } : {}
|
|
9648
|
-
});
|
|
9832
|
+
if (hasPublished) {
|
|
9833
|
+
await docSvc.unpublish({
|
|
9834
|
+
documentId: item.documentId,
|
|
9835
|
+
...isLocalized ? { locale: item.locale } : {}
|
|
9836
|
+
});
|
|
9837
|
+
}
|
|
9649
9838
|
}
|
|
9839
|
+
} catch (unpubErr) {
|
|
9840
|
+
strapi.log.warn(
|
|
9841
|
+
`[bulk-updater] Failed to unpublish rollback for ${item.uid}/${item.documentId}:`,
|
|
9842
|
+
unpubErr?.message
|
|
9843
|
+
);
|
|
9650
9844
|
}
|
|
9651
|
-
} catch (unpubErr) {
|
|
9652
|
-
strapi.log.warn(
|
|
9653
|
-
`[bulk-updater] Failed to unpublish rollback for ${item.uid}/${item.documentId}:`,
|
|
9654
|
-
unpubErr?.message
|
|
9655
|
-
);
|
|
9656
9845
|
}
|
|
9657
9846
|
}
|
|
9658
|
-
|
|
9659
|
-
|
|
9660
|
-
|
|
9847
|
+
try {
|
|
9848
|
+
await recordContentHistoryVersion(strapi, {
|
|
9849
|
+
uid: item.uid,
|
|
9850
|
+
documentId: item.documentId,
|
|
9851
|
+
userId,
|
|
9852
|
+
statusOverride: isDraftAndPublish ? targetStatus : "published"
|
|
9853
|
+
});
|
|
9854
|
+
} catch {
|
|
9855
|
+
}
|
|
9856
|
+
try {
|
|
9857
|
+
const bulkService = strapi.plugin("bulk-updater").service("bulkUpdater");
|
|
9858
|
+
if (bulkService?.invalidateCache) {
|
|
9859
|
+
bulkService.invalidateCache(item.uid);
|
|
9860
|
+
}
|
|
9861
|
+
} catch {
|
|
9862
|
+
}
|
|
9863
|
+
const entryKey = `${item.uid}@@@${item.documentId}@@@${isLocalized ? item.locale : ""}`;
|
|
9864
|
+
revertedEntryKeys.add(entryKey);
|
|
9865
|
+
rollbackDetails.push({
|
|
9661
9866
|
uid: item.uid,
|
|
9662
9867
|
documentId: item.documentId,
|
|
9663
|
-
|
|
9664
|
-
|
|
9868
|
+
label: item.label,
|
|
9869
|
+
attribute: item.attribute,
|
|
9870
|
+
revertedTo: item.oldValue,
|
|
9871
|
+
status: "reverted",
|
|
9872
|
+
restoredLifecycleStatus: isDraftAndPublish ? targetStatus : "published"
|
|
9873
|
+
});
|
|
9874
|
+
} catch (err) {
|
|
9875
|
+
rollbackDetails.push({
|
|
9876
|
+
uid: item.uid,
|
|
9877
|
+
documentId: item.documentId,
|
|
9878
|
+
label: item.label,
|
|
9879
|
+
status: "error",
|
|
9880
|
+
message: err.message
|
|
9665
9881
|
});
|
|
9666
|
-
} catch {
|
|
9667
|
-
}
|
|
9668
|
-
try {
|
|
9669
|
-
const bulkService = strapi.plugin("bulk-updater").service("bulkUpdater");
|
|
9670
|
-
if (bulkService?.invalidateCache) {
|
|
9671
|
-
bulkService.invalidateCache(item.uid);
|
|
9672
|
-
}
|
|
9673
|
-
} catch {
|
|
9674
9882
|
}
|
|
9675
|
-
revertedCount++;
|
|
9676
|
-
rollbackDetails.push({
|
|
9677
|
-
uid: item.uid,
|
|
9678
|
-
documentId: item.documentId,
|
|
9679
|
-
label: item.label,
|
|
9680
|
-
attribute: item.attribute,
|
|
9681
|
-
revertedTo: item.oldValue,
|
|
9682
|
-
status: "reverted",
|
|
9683
|
-
restoredLifecycleStatus: isDraftAndPublish ? targetStatus : "published"
|
|
9684
|
-
});
|
|
9685
|
-
} catch (err) {
|
|
9686
|
-
rollbackDetails.push({
|
|
9687
|
-
uid: item.uid,
|
|
9688
|
-
documentId: item.documentId,
|
|
9689
|
-
label: item.label,
|
|
9690
|
-
status: "error",
|
|
9691
|
-
message: err.message
|
|
9692
|
-
});
|
|
9693
9883
|
}
|
|
9694
9884
|
}
|
|
9695
|
-
|
|
9696
|
-
|
|
9885
|
+
return { revertedCount: revertedEntryKeys.size, rollbackDetails };
|
|
9886
|
+
});
|
|
9697
9887
|
},
|
|
9698
9888
|
/**
|
|
9699
9889
|
* Performs deterministic rollback of a batch.
|
|
@@ -12569,6 +12759,9 @@ const index = {
|
|
|
12569
12759
|
}
|
|
12570
12760
|
});
|
|
12571
12761
|
strapi.documents.use(async (context, next) => {
|
|
12762
|
+
if (isRollbackContext()) {
|
|
12763
|
+
return await next();
|
|
12764
|
+
}
|
|
12572
12765
|
if (typeof context.uid === "string" && context.uid.startsWith("plugin::bulk-updater.")) {
|
|
12573
12766
|
return await next();
|
|
12574
12767
|
}
|