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