@strapi/content-releases 4.20.1 → 4.20.3
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/{App-1hHIqUoZ.js → App-C_iroyIu.js} +271 -55
- package/dist/_chunks/App-C_iroyIu.js.map +1 -0
- package/dist/_chunks/{App-U6GbyLIE.mjs → App-hWBsb1nt.mjs} +272 -57
- package/dist/_chunks/App-hWBsb1nt.mjs.map +1 -0
- package/dist/_chunks/{en-GqXgfmzl.mjs → en-UyU8mm8l.mjs} +11 -2
- package/dist/_chunks/en-UyU8mm8l.mjs.map +1 -0
- package/dist/_chunks/{en-bDhIlw-B.js → en-oj7ZfWI3.js} +11 -2
- package/dist/_chunks/en-oj7ZfWI3.js.map +1 -0
- package/dist/_chunks/{index-l-FvkQlQ.js → index-SDpSekBU.js} +73 -10
- package/dist/_chunks/index-SDpSekBU.js.map +1 -0
- package/dist/_chunks/{index-gkExFBa0.mjs → index-rEfNT9PC.mjs} +77 -14
- package/dist/_chunks/index-rEfNT9PC.mjs.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/server/index.js +470 -414
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +470 -414
- package/dist/server/index.mjs.map +1 -1
- package/package.json +11 -9
- package/dist/_chunks/App-1hHIqUoZ.js.map +0 -1
- package/dist/_chunks/App-U6GbyLIE.mjs.map +0 -1
- package/dist/_chunks/en-GqXgfmzl.mjs.map +0 -1
- package/dist/_chunks/en-bDhIlw-B.js.map +0 -1
- package/dist/_chunks/index-gkExFBa0.mjs.map +0 -1
- package/dist/_chunks/index-l-FvkQlQ.js.map +0 -1
package/dist/server/index.js
CHANGED
|
@@ -73,6 +73,9 @@ const ACTIONS = [
|
|
|
73
73
|
pluginName: "content-releases"
|
|
74
74
|
}
|
|
75
75
|
];
|
|
76
|
+
const ALLOWED_WEBHOOK_EVENTS = {
|
|
77
|
+
RELEASES_PUBLISH: "releases.publish"
|
|
78
|
+
};
|
|
76
79
|
async function deleteActionsOnDisableDraftAndPublish({
|
|
77
80
|
oldContentTypes,
|
|
78
81
|
contentTypes: contentTypes2
|
|
@@ -164,6 +167,9 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
164
167
|
);
|
|
165
168
|
throw err;
|
|
166
169
|
});
|
|
170
|
+
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
|
171
|
+
strapi2.webhookStore.addAllowedEvent(key, value);
|
|
172
|
+
});
|
|
167
173
|
}
|
|
168
174
|
}
|
|
169
175
|
};
|
|
@@ -283,464 +289,504 @@ const getGroupName = (queryValue) => {
|
|
|
283
289
|
return "contentType.displayName";
|
|
284
290
|
}
|
|
285
291
|
};
|
|
286
|
-
const createReleaseService = ({ strapi: strapi2 }) =>
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
validateScheduledAtIsLaterThanNow
|
|
293
|
-
} = getService("release-validation", { strapi: strapi2 });
|
|
294
|
-
await Promise.all([
|
|
295
|
-
validatePendingReleasesLimit(),
|
|
296
|
-
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
|
|
297
|
-
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
298
|
-
]);
|
|
299
|
-
const release2 = await strapi2.entityService.create(RELEASE_MODEL_UID, {
|
|
300
|
-
data: releaseWithCreatorFields
|
|
292
|
+
const createReleaseService = ({ strapi: strapi2 }) => {
|
|
293
|
+
const dispatchWebhook = (event, { isPublished, release: release2, error }) => {
|
|
294
|
+
strapi2.eventHub.emit(event, {
|
|
295
|
+
isPublished,
|
|
296
|
+
error,
|
|
297
|
+
release: release2
|
|
301
298
|
});
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
299
|
+
};
|
|
300
|
+
return {
|
|
301
|
+
async create(releaseData, { user }) {
|
|
302
|
+
const releaseWithCreatorFields = await utils.setCreatorFields({ user })(releaseData);
|
|
303
|
+
const {
|
|
304
|
+
validatePendingReleasesLimit,
|
|
305
|
+
validateUniqueNameForPendingRelease,
|
|
306
|
+
validateScheduledAtIsLaterThanNow
|
|
307
|
+
} = getService("release-validation", { strapi: strapi2 });
|
|
308
|
+
await Promise.all([
|
|
309
|
+
validatePendingReleasesLimit(),
|
|
310
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
|
|
311
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
312
|
+
]);
|
|
313
|
+
const release2 = await strapi2.entityService.create(RELEASE_MODEL_UID, {
|
|
314
|
+
data: releaseWithCreatorFields
|
|
315
|
+
});
|
|
316
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling") && releaseWithCreatorFields.scheduledAt) {
|
|
317
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
318
|
+
await schedulingService.set(release2.id, release2.scheduledAt);
|
|
322
319
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
320
|
+
strapi2.telemetry.send("didCreateContentRelease");
|
|
321
|
+
return release2;
|
|
322
|
+
},
|
|
323
|
+
async findOne(id, query = {}) {
|
|
324
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id, {
|
|
325
|
+
...query
|
|
326
|
+
});
|
|
327
|
+
return release2;
|
|
328
|
+
},
|
|
329
|
+
findPage(query) {
|
|
330
|
+
return strapi2.entityService.findPage(RELEASE_MODEL_UID, {
|
|
331
|
+
...query,
|
|
332
|
+
populate: {
|
|
333
|
+
actions: {
|
|
334
|
+
// @ts-expect-error Ignore missing properties
|
|
335
|
+
count: true
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
},
|
|
340
|
+
async findManyWithContentTypeEntryAttached(contentTypeUid, entryId) {
|
|
341
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
342
|
+
where: {
|
|
343
|
+
actions: {
|
|
344
|
+
target_type: contentTypeUid,
|
|
345
|
+
target_id: entryId
|
|
346
|
+
},
|
|
347
|
+
releasedAt: {
|
|
348
|
+
$null: true
|
|
349
|
+
}
|
|
331
350
|
},
|
|
332
|
-
|
|
333
|
-
|
|
351
|
+
populate: {
|
|
352
|
+
// Filter the action to get only the content type entry
|
|
353
|
+
actions: {
|
|
354
|
+
where: {
|
|
355
|
+
target_type: contentTypeUid,
|
|
356
|
+
target_id: entryId
|
|
357
|
+
}
|
|
358
|
+
}
|
|
334
359
|
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
360
|
+
});
|
|
361
|
+
return releases.map((release2) => {
|
|
362
|
+
if (release2.actions?.length) {
|
|
363
|
+
const [actionForEntry] = release2.actions;
|
|
364
|
+
delete release2.actions;
|
|
365
|
+
return {
|
|
366
|
+
...release2,
|
|
367
|
+
action: actionForEntry
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
return release2;
|
|
371
|
+
});
|
|
372
|
+
},
|
|
373
|
+
async findManyWithoutContentTypeEntryAttached(contentTypeUid, entryId) {
|
|
374
|
+
const releasesRelated = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
375
|
+
where: {
|
|
376
|
+
releasedAt: {
|
|
377
|
+
$null: true
|
|
378
|
+
},
|
|
379
|
+
actions: {
|
|
340
380
|
target_type: contentTypeUid,
|
|
341
381
|
target_id: entryId
|
|
342
382
|
}
|
|
343
383
|
}
|
|
384
|
+
});
|
|
385
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
386
|
+
where: {
|
|
387
|
+
$or: [
|
|
388
|
+
{
|
|
389
|
+
id: {
|
|
390
|
+
$notIn: releasesRelated.map((release2) => release2.id)
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
actions: null
|
|
395
|
+
}
|
|
396
|
+
],
|
|
397
|
+
releasedAt: {
|
|
398
|
+
$null: true
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
return releases.map((release2) => {
|
|
403
|
+
if (release2.actions?.length) {
|
|
404
|
+
const [actionForEntry] = release2.actions;
|
|
405
|
+
delete release2.actions;
|
|
406
|
+
return {
|
|
407
|
+
...release2,
|
|
408
|
+
action: actionForEntry
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
return release2;
|
|
412
|
+
});
|
|
413
|
+
},
|
|
414
|
+
async update(id, releaseData, { user }) {
|
|
415
|
+
const releaseWithCreatorFields = await utils.setCreatorFields({ user, isEdition: true })(
|
|
416
|
+
releaseData
|
|
417
|
+
);
|
|
418
|
+
const { validateUniqueNameForPendingRelease, validateScheduledAtIsLaterThanNow } = getService(
|
|
419
|
+
"release-validation",
|
|
420
|
+
{ strapi: strapi2 }
|
|
421
|
+
);
|
|
422
|
+
await Promise.all([
|
|
423
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name, id),
|
|
424
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
425
|
+
]);
|
|
426
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id);
|
|
427
|
+
if (!release2) {
|
|
428
|
+
throw new utils.errors.NotFoundError(`No release found for id ${id}`);
|
|
344
429
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if (release2.actions?.length) {
|
|
348
|
-
const [actionForEntry] = release2.actions;
|
|
349
|
-
delete release2.actions;
|
|
350
|
-
return {
|
|
351
|
-
...release2,
|
|
352
|
-
action: actionForEntry
|
|
353
|
-
};
|
|
430
|
+
if (release2.releasedAt) {
|
|
431
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
354
432
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
433
|
+
const updatedRelease = await strapi2.entityService.update(RELEASE_MODEL_UID, id, {
|
|
434
|
+
/*
|
|
435
|
+
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">>
|
|
436
|
+
* is not compatible with the type we are passing here: UpdateRelease.Request['body']
|
|
437
|
+
*/
|
|
438
|
+
// @ts-expect-error see above
|
|
439
|
+
data: releaseWithCreatorFields
|
|
440
|
+
});
|
|
441
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
442
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
443
|
+
if (releaseData.scheduledAt) {
|
|
444
|
+
await schedulingService.set(id, releaseData.scheduledAt);
|
|
445
|
+
} else if (release2.scheduledAt) {
|
|
446
|
+
schedulingService.cancel(id);
|
|
367
447
|
}
|
|
368
448
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
$null: true
|
|
384
|
-
}
|
|
449
|
+
strapi2.telemetry.send("didUpdateContentRelease");
|
|
450
|
+
return updatedRelease;
|
|
451
|
+
},
|
|
452
|
+
async createAction(releaseId, action) {
|
|
453
|
+
const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
|
|
454
|
+
strapi: strapi2
|
|
455
|
+
});
|
|
456
|
+
await Promise.all([
|
|
457
|
+
validateEntryContentType(action.entry.contentType),
|
|
458
|
+
validateUniqueEntry(releaseId, action)
|
|
459
|
+
]);
|
|
460
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
|
|
461
|
+
if (!release2) {
|
|
462
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
385
463
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
if (release2.actions?.length) {
|
|
389
|
-
const [actionForEntry] = release2.actions;
|
|
390
|
-
delete release2.actions;
|
|
391
|
-
return {
|
|
392
|
-
...release2,
|
|
393
|
-
action: actionForEntry
|
|
394
|
-
};
|
|
464
|
+
if (release2.releasedAt) {
|
|
465
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
395
466
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">>
|
|
419
|
-
* is not compatible with the type we are passing here: UpdateRelease.Request['body']
|
|
420
|
-
*/
|
|
421
|
-
// @ts-expect-error see above
|
|
422
|
-
data: releaseWithCreatorFields
|
|
423
|
-
});
|
|
424
|
-
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
425
|
-
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
426
|
-
if (releaseData.scheduledAt) {
|
|
427
|
-
await schedulingService.set(id, releaseData.scheduledAt);
|
|
428
|
-
} else if (release2.scheduledAt) {
|
|
429
|
-
schedulingService.cancel(id);
|
|
467
|
+
const { entry, type } = action;
|
|
468
|
+
return strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
|
|
469
|
+
data: {
|
|
470
|
+
type,
|
|
471
|
+
contentType: entry.contentType,
|
|
472
|
+
locale: entry.locale,
|
|
473
|
+
entry: {
|
|
474
|
+
id: entry.id,
|
|
475
|
+
__type: entry.contentType,
|
|
476
|
+
__pivot: { field: "entry" }
|
|
477
|
+
},
|
|
478
|
+
release: releaseId
|
|
479
|
+
},
|
|
480
|
+
populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
|
|
481
|
+
});
|
|
482
|
+
},
|
|
483
|
+
async findActions(releaseId, query) {
|
|
484
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
485
|
+
fields: ["id"]
|
|
486
|
+
});
|
|
487
|
+
if (!release2) {
|
|
488
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
430
489
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
});
|
|
438
|
-
await Promise.all([
|
|
439
|
-
validateEntryContentType(action.entry.contentType),
|
|
440
|
-
validateUniqueEntry(releaseId, action)
|
|
441
|
-
]);
|
|
442
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
|
|
443
|
-
if (!release2) {
|
|
444
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
445
|
-
}
|
|
446
|
-
if (release2.releasedAt) {
|
|
447
|
-
throw new utils.errors.ValidationError("Release already published");
|
|
448
|
-
}
|
|
449
|
-
const { entry, type } = action;
|
|
450
|
-
return strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
|
|
451
|
-
data: {
|
|
452
|
-
type,
|
|
453
|
-
contentType: entry.contentType,
|
|
454
|
-
locale: entry.locale,
|
|
455
|
-
entry: {
|
|
456
|
-
id: entry.id,
|
|
457
|
-
__type: entry.contentType,
|
|
458
|
-
__pivot: { field: "entry" }
|
|
490
|
+
return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
|
|
491
|
+
...query,
|
|
492
|
+
populate: {
|
|
493
|
+
entry: {
|
|
494
|
+
populate: "*"
|
|
495
|
+
}
|
|
459
496
|
},
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
|
|
463
|
-
});
|
|
464
|
-
},
|
|
465
|
-
async findActions(releaseId, query) {
|
|
466
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
467
|
-
fields: ["id"]
|
|
468
|
-
});
|
|
469
|
-
if (!release2) {
|
|
470
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
471
|
-
}
|
|
472
|
-
return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
|
|
473
|
-
...query,
|
|
474
|
-
populate: {
|
|
475
|
-
entry: {
|
|
476
|
-
populate: "*"
|
|
497
|
+
filters: {
|
|
498
|
+
release: releaseId
|
|
477
499
|
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
async groupActions(actions, groupBy) {
|
|
488
|
-
const contentTypeUids = actions.reduce((acc, action) => {
|
|
489
|
-
if (!acc.includes(action.contentType)) {
|
|
490
|
-
acc.push(action.contentType);
|
|
491
|
-
}
|
|
492
|
-
return acc;
|
|
493
|
-
}, []);
|
|
494
|
-
const allReleaseContentTypesDictionary = await this.getContentTypesDataForActions(
|
|
495
|
-
contentTypeUids
|
|
496
|
-
);
|
|
497
|
-
const allLocalesDictionary = await this.getLocalesDataForActions();
|
|
498
|
-
const formattedData = actions.map((action) => {
|
|
499
|
-
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
500
|
-
return {
|
|
501
|
-
...action,
|
|
502
|
-
locale: action.locale ? allLocalesDictionary[action.locale] : null,
|
|
503
|
-
contentType: {
|
|
504
|
-
displayName,
|
|
505
|
-
mainFieldValue: action.entry[mainField],
|
|
506
|
-
uid: action.contentType
|
|
500
|
+
});
|
|
501
|
+
},
|
|
502
|
+
async countActions(query) {
|
|
503
|
+
return strapi2.entityService.count(RELEASE_ACTION_MODEL_UID, query);
|
|
504
|
+
},
|
|
505
|
+
async groupActions(actions, groupBy) {
|
|
506
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
507
|
+
if (!acc.includes(action.contentType)) {
|
|
508
|
+
acc.push(action.contentType);
|
|
507
509
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
const contentTypesData = {};
|
|
526
|
-
for (const contentTypeUid of contentTypesUids) {
|
|
527
|
-
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
528
|
-
uid: contentTypeUid
|
|
510
|
+
return acc;
|
|
511
|
+
}, []);
|
|
512
|
+
const allReleaseContentTypesDictionary = await this.getContentTypesDataForActions(
|
|
513
|
+
contentTypeUids
|
|
514
|
+
);
|
|
515
|
+
const allLocalesDictionary = await this.getLocalesDataForActions();
|
|
516
|
+
const formattedData = actions.map((action) => {
|
|
517
|
+
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
518
|
+
return {
|
|
519
|
+
...action,
|
|
520
|
+
locale: action.locale ? allLocalesDictionary[action.locale] : null,
|
|
521
|
+
contentType: {
|
|
522
|
+
displayName,
|
|
523
|
+
mainFieldValue: action.entry[mainField],
|
|
524
|
+
uid: action.contentType
|
|
525
|
+
}
|
|
526
|
+
};
|
|
529
527
|
});
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
},
|
|
537
|
-
getContentTypeModelsFromActions(actions) {
|
|
538
|
-
const contentTypeUids = actions.reduce((acc, action) => {
|
|
539
|
-
if (!acc.includes(action.contentType)) {
|
|
540
|
-
acc.push(action.contentType);
|
|
528
|
+
const groupName = getGroupName(groupBy);
|
|
529
|
+
return ___default.default.groupBy(groupName)(formattedData);
|
|
530
|
+
},
|
|
531
|
+
async getLocalesDataForActions() {
|
|
532
|
+
if (!strapi2.plugin("i18n")) {
|
|
533
|
+
return {};
|
|
541
534
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
(acc, contentTypeUid) => {
|
|
546
|
-
acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
|
|
535
|
+
const allLocales = await strapi2.plugin("i18n").service("locales").find() || [];
|
|
536
|
+
return allLocales.reduce((acc, locale) => {
|
|
537
|
+
acc[locale.code] = { name: locale.name, code: locale.code };
|
|
547
538
|
return acc;
|
|
548
|
-
},
|
|
549
|
-
|
|
550
|
-
)
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
539
|
+
}, {});
|
|
540
|
+
},
|
|
541
|
+
async getContentTypesDataForActions(contentTypesUids) {
|
|
542
|
+
const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
|
|
543
|
+
const contentTypesData = {};
|
|
544
|
+
for (const contentTypeUid of contentTypesUids) {
|
|
545
|
+
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
546
|
+
uid: contentTypeUid
|
|
547
|
+
});
|
|
548
|
+
contentTypesData[contentTypeUid] = {
|
|
549
|
+
mainField: contentTypeConfig.settings.mainField,
|
|
550
|
+
displayName: strapi2.getModel(contentTypeUid).info.displayName
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
return contentTypesData;
|
|
554
|
+
},
|
|
555
|
+
getContentTypeModelsFromActions(actions) {
|
|
556
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
557
|
+
if (!acc.includes(action.contentType)) {
|
|
558
|
+
acc.push(action.contentType);
|
|
559
|
+
}
|
|
559
560
|
return acc;
|
|
560
|
-
},
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
561
|
+
}, []);
|
|
562
|
+
const contentTypeModelsMap = contentTypeUids.reduce(
|
|
563
|
+
(acc, contentTypeUid) => {
|
|
564
|
+
acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
|
|
565
|
+
return acc;
|
|
566
|
+
},
|
|
567
|
+
{}
|
|
568
|
+
);
|
|
569
|
+
return contentTypeModelsMap;
|
|
570
|
+
},
|
|
571
|
+
async getAllComponents() {
|
|
572
|
+
const contentManagerComponentsService = strapi2.plugin("content-manager").service("components");
|
|
573
|
+
const components = await contentManagerComponentsService.findAllComponents();
|
|
574
|
+
const componentsMap = components.reduce(
|
|
575
|
+
(acc, component) => {
|
|
576
|
+
acc[component.uid] = component;
|
|
577
|
+
return acc;
|
|
578
|
+
},
|
|
579
|
+
{}
|
|
580
|
+
);
|
|
581
|
+
return componentsMap;
|
|
582
|
+
},
|
|
583
|
+
async delete(releaseId) {
|
|
584
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
585
|
+
populate: {
|
|
586
|
+
actions: {
|
|
587
|
+
fields: ["id"]
|
|
588
|
+
}
|
|
570
589
|
}
|
|
590
|
+
});
|
|
591
|
+
if (!release2) {
|
|
592
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
571
593
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
where: {
|
|
582
|
-
id: {
|
|
583
|
-
$in: release2.actions.map((action) => action.id)
|
|
594
|
+
if (release2.releasedAt) {
|
|
595
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
596
|
+
}
|
|
597
|
+
await strapi2.db.transaction(async () => {
|
|
598
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
599
|
+
where: {
|
|
600
|
+
id: {
|
|
601
|
+
$in: release2.actions.map((action) => action.id)
|
|
602
|
+
}
|
|
584
603
|
}
|
|
585
|
-
}
|
|
604
|
+
});
|
|
605
|
+
await strapi2.entityService.delete(RELEASE_MODEL_UID, releaseId);
|
|
586
606
|
});
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
{
|
|
596
|
-
|
|
597
|
-
|
|
607
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling") && release2.scheduledAt) {
|
|
608
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
609
|
+
await schedulingService.cancel(release2.id);
|
|
610
|
+
}
|
|
611
|
+
strapi2.telemetry.send("didDeleteContentRelease");
|
|
612
|
+
return release2;
|
|
613
|
+
},
|
|
614
|
+
async publish(releaseId) {
|
|
615
|
+
try {
|
|
616
|
+
const releaseWithPopulatedActionEntries = await strapi2.entityService.findOne(
|
|
617
|
+
RELEASE_MODEL_UID,
|
|
618
|
+
releaseId,
|
|
619
|
+
{
|
|
598
620
|
populate: {
|
|
599
|
-
|
|
600
|
-
|
|
621
|
+
actions: {
|
|
622
|
+
populate: {
|
|
623
|
+
entry: {
|
|
624
|
+
fields: ["id"]
|
|
625
|
+
}
|
|
626
|
+
}
|
|
601
627
|
}
|
|
602
628
|
}
|
|
603
629
|
}
|
|
630
|
+
);
|
|
631
|
+
if (!releaseWithPopulatedActionEntries) {
|
|
632
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
604
633
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
if (!releaseWithPopulatedActionEntries) {
|
|
608
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
609
|
-
}
|
|
610
|
-
if (releaseWithPopulatedActionEntries.releasedAt) {
|
|
611
|
-
throw new utils.errors.ValidationError("Release already published");
|
|
612
|
-
}
|
|
613
|
-
if (releaseWithPopulatedActionEntries.actions.length === 0) {
|
|
614
|
-
throw new utils.errors.ValidationError("No entries to publish");
|
|
615
|
-
}
|
|
616
|
-
const collectionTypeActions = {};
|
|
617
|
-
const singleTypeActions = [];
|
|
618
|
-
for (const action of releaseWithPopulatedActionEntries.actions) {
|
|
619
|
-
const contentTypeUid = action.contentType;
|
|
620
|
-
if (strapi2.contentTypes[contentTypeUid].kind === "collectionType") {
|
|
621
|
-
if (!collectionTypeActions[contentTypeUid]) {
|
|
622
|
-
collectionTypeActions[contentTypeUid] = {
|
|
623
|
-
entriestoPublishIds: [],
|
|
624
|
-
entriesToUnpublishIds: []
|
|
625
|
-
};
|
|
634
|
+
if (releaseWithPopulatedActionEntries.releasedAt) {
|
|
635
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
626
636
|
}
|
|
627
|
-
if (
|
|
628
|
-
|
|
629
|
-
} else {
|
|
630
|
-
collectionTypeActions[contentTypeUid].entriesToUnpublishIds.push(action.entry.id);
|
|
637
|
+
if (releaseWithPopulatedActionEntries.actions.length === 0) {
|
|
638
|
+
throw new utils.errors.ValidationError("No entries to publish");
|
|
631
639
|
}
|
|
632
|
-
|
|
633
|
-
singleTypeActions
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
await entityManagerService.publish(entry, uid);
|
|
640
|
+
const collectionTypeActions = {};
|
|
641
|
+
const singleTypeActions = [];
|
|
642
|
+
for (const action of releaseWithPopulatedActionEntries.actions) {
|
|
643
|
+
const contentTypeUid = action.contentType;
|
|
644
|
+
if (strapi2.contentTypes[contentTypeUid].kind === "collectionType") {
|
|
645
|
+
if (!collectionTypeActions[contentTypeUid]) {
|
|
646
|
+
collectionTypeActions[contentTypeUid] = {
|
|
647
|
+
entriestoPublishIds: [],
|
|
648
|
+
entriesToUnpublishIds: []
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
if (action.type === "publish") {
|
|
652
|
+
collectionTypeActions[contentTypeUid].entriestoPublishIds.push(action.entry.id);
|
|
653
|
+
} else {
|
|
654
|
+
collectionTypeActions[contentTypeUid].entriesToUnpublishIds.push(action.entry.id);
|
|
655
|
+
}
|
|
649
656
|
} else {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
;
|
|
655
|
-
else {
|
|
656
|
-
throw error;
|
|
657
|
+
singleTypeActions.push({
|
|
658
|
+
uid: contentTypeUid,
|
|
659
|
+
action: action.type,
|
|
660
|
+
id: action.entry.id
|
|
661
|
+
});
|
|
657
662
|
}
|
|
658
663
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
664
|
+
const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
|
|
665
|
+
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
666
|
+
await strapi2.db.transaction(async () => {
|
|
667
|
+
for (const { uid, action, id } of singleTypeActions) {
|
|
668
|
+
const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
|
|
669
|
+
const entry = await strapi2.entityService.findOne(uid, id, { populate });
|
|
670
|
+
try {
|
|
671
|
+
if (action === "publish") {
|
|
672
|
+
await entityManagerService.publish(entry, uid);
|
|
673
|
+
} else {
|
|
674
|
+
await entityManagerService.unpublish(entry, uid);
|
|
669
675
|
}
|
|
670
|
-
}
|
|
671
|
-
|
|
676
|
+
} catch (error) {
|
|
677
|
+
if (error instanceof utils.errors.ApplicationError && (error.message === "already.published" || error.message === "already.draft")) {
|
|
678
|
+
} else {
|
|
679
|
+
throw error;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
672
682
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
683
|
+
for (const contentTypeUid of Object.keys(collectionTypeActions)) {
|
|
684
|
+
const populate = await populateBuilderService(contentTypeUid).populateDeep(Infinity).build();
|
|
685
|
+
const { entriestoPublishIds, entriesToUnpublishIds } = collectionTypeActions[contentTypeUid];
|
|
686
|
+
const entriesToPublish = await strapi2.entityService.findMany(
|
|
687
|
+
contentTypeUid,
|
|
688
|
+
{
|
|
689
|
+
filters: {
|
|
690
|
+
id: {
|
|
691
|
+
$in: entriestoPublishIds
|
|
692
|
+
}
|
|
693
|
+
},
|
|
694
|
+
populate
|
|
680
695
|
}
|
|
681
|
-
|
|
682
|
-
|
|
696
|
+
);
|
|
697
|
+
const entriesToUnpublish = await strapi2.entityService.findMany(
|
|
698
|
+
contentTypeUid,
|
|
699
|
+
{
|
|
700
|
+
filters: {
|
|
701
|
+
id: {
|
|
702
|
+
$in: entriesToUnpublishIds
|
|
703
|
+
}
|
|
704
|
+
},
|
|
705
|
+
populate
|
|
706
|
+
}
|
|
707
|
+
);
|
|
708
|
+
if (entriesToPublish.length > 0) {
|
|
709
|
+
await entityManagerService.publishMany(entriesToPublish, contentTypeUid);
|
|
710
|
+
}
|
|
711
|
+
if (entriesToUnpublish.length > 0) {
|
|
712
|
+
await entityManagerService.unpublishMany(entriesToUnpublish, contentTypeUid);
|
|
713
|
+
}
|
|
683
714
|
}
|
|
684
|
-
);
|
|
685
|
-
|
|
686
|
-
|
|
715
|
+
});
|
|
716
|
+
const release2 = await strapi2.entityService.update(RELEASE_MODEL_UID, releaseId, {
|
|
717
|
+
data: {
|
|
718
|
+
/*
|
|
719
|
+
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">> looks like it's wrong
|
|
720
|
+
*/
|
|
721
|
+
// @ts-expect-error see above
|
|
722
|
+
releasedAt: /* @__PURE__ */ new Date()
|
|
723
|
+
},
|
|
724
|
+
populate: {
|
|
725
|
+
actions: {
|
|
726
|
+
// @ts-expect-error is not expecting count but it is working
|
|
727
|
+
count: true
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
732
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
733
|
+
isPublished: true,
|
|
734
|
+
release: release2
|
|
735
|
+
});
|
|
687
736
|
}
|
|
688
|
-
|
|
689
|
-
|
|
737
|
+
strapi2.telemetry.send("didPublishContentRelease");
|
|
738
|
+
return release2;
|
|
739
|
+
} catch (error) {
|
|
740
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
741
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
742
|
+
isPublished: false,
|
|
743
|
+
error
|
|
744
|
+
});
|
|
690
745
|
}
|
|
746
|
+
throw error;
|
|
691
747
|
}
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
return release2;
|
|
703
|
-
},
|
|
704
|
-
async updateAction(actionId, releaseId, update) {
|
|
705
|
-
const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
706
|
-
where: {
|
|
707
|
-
id: actionId,
|
|
708
|
-
release: {
|
|
709
|
-
id: releaseId,
|
|
710
|
-
releasedAt: {
|
|
711
|
-
$null: true
|
|
748
|
+
},
|
|
749
|
+
async updateAction(actionId, releaseId, update) {
|
|
750
|
+
const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
751
|
+
where: {
|
|
752
|
+
id: actionId,
|
|
753
|
+
release: {
|
|
754
|
+
id: releaseId,
|
|
755
|
+
releasedAt: {
|
|
756
|
+
$null: true
|
|
757
|
+
}
|
|
712
758
|
}
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
759
|
+
},
|
|
760
|
+
data: update
|
|
761
|
+
});
|
|
762
|
+
if (!updatedAction) {
|
|
763
|
+
throw new utils.errors.NotFoundError(
|
|
764
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
return updatedAction;
|
|
768
|
+
},
|
|
769
|
+
async deleteAction(actionId, releaseId) {
|
|
770
|
+
const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
|
|
771
|
+
where: {
|
|
772
|
+
id: actionId,
|
|
773
|
+
release: {
|
|
774
|
+
id: releaseId,
|
|
775
|
+
releasedAt: {
|
|
776
|
+
$null: true
|
|
777
|
+
}
|
|
732
778
|
}
|
|
733
779
|
}
|
|
780
|
+
});
|
|
781
|
+
if (!deletedAction) {
|
|
782
|
+
throw new utils.errors.NotFoundError(
|
|
783
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
784
|
+
);
|
|
734
785
|
}
|
|
735
|
-
|
|
736
|
-
if (!deletedAction) {
|
|
737
|
-
throw new utils.errors.NotFoundError(
|
|
738
|
-
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
739
|
-
);
|
|
786
|
+
return deletedAction;
|
|
740
787
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
});
|
|
788
|
+
};
|
|
789
|
+
};
|
|
744
790
|
const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
745
791
|
async validateUniqueEntry(releaseId, releaseActionArgs) {
|
|
746
792
|
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
@@ -865,11 +911,21 @@ const services = {
|
|
|
865
911
|
};
|
|
866
912
|
const RELEASE_SCHEMA = yup__namespace.object().shape({
|
|
867
913
|
name: yup__namespace.string().trim().required(),
|
|
868
|
-
// scheduledAt is a date, but we always receive strings from the client
|
|
869
914
|
scheduledAt: yup__namespace.string().nullable(),
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
915
|
+
isScheduled: yup__namespace.boolean().optional(),
|
|
916
|
+
time: yup__namespace.string().when("isScheduled", {
|
|
917
|
+
is: true,
|
|
918
|
+
then: yup__namespace.string().trim().required(),
|
|
919
|
+
otherwise: yup__namespace.string().nullable()
|
|
920
|
+
}),
|
|
921
|
+
timezone: yup__namespace.string().when("isScheduled", {
|
|
922
|
+
is: true,
|
|
923
|
+
then: yup__namespace.string().required().nullable(),
|
|
924
|
+
otherwise: yup__namespace.string().nullable()
|
|
925
|
+
}),
|
|
926
|
+
date: yup__namespace.string().when("isScheduled", {
|
|
927
|
+
is: true,
|
|
928
|
+
then: yup__namespace.string().required().nullable(),
|
|
873
929
|
otherwise: yup__namespace.string().nullable()
|
|
874
930
|
})
|
|
875
931
|
}).required().noUnknown();
|