@strapi/content-releases 5.0.0-beta.8 → 5.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +17 -1
  2. package/dist/_chunks/{App-D_6Y9N2F.mjs → App-6gbM0io-.mjs} +215 -255
  3. package/dist/_chunks/App-6gbM0io-.mjs.map +1 -0
  4. package/dist/_chunks/{App-DUmziQ17.js → App-zzUitryC.js} +216 -257
  5. package/dist/_chunks/App-zzUitryC.js.map +1 -0
  6. package/dist/_chunks/SettingsPage-CTOl3Qtw.js +157 -0
  7. package/dist/_chunks/SettingsPage-CTOl3Qtw.js.map +1 -0
  8. package/dist/_chunks/SettingsPage-CuSH193e.mjs +157 -0
  9. package/dist/_chunks/SettingsPage-CuSH193e.mjs.map +1 -0
  10. package/dist/_chunks/{en-DtFJ5ViE.js → en-1_1re1mc.js} +7 -2
  11. package/dist/_chunks/en-1_1re1mc.js.map +1 -0
  12. package/dist/_chunks/{en-B9Ur3VsE.mjs → en-C3sq5KNP.mjs} +7 -2
  13. package/dist/_chunks/en-C3sq5KNP.mjs.map +1 -0
  14. package/dist/_chunks/{index-C5Hc767q.js → index-BxRiXenX.js} +518 -437
  15. package/dist/_chunks/index-BxRiXenX.js.map +1 -0
  16. package/dist/_chunks/{index-BomF0-yY.mjs → index-CuchqQ4_.mjs} +525 -444
  17. package/dist/_chunks/index-CuchqQ4_.mjs.map +1 -0
  18. package/dist/_chunks/validation-schemas-C7P2rhPu.mjs +29 -0
  19. package/dist/_chunks/validation-schemas-C7P2rhPu.mjs.map +1 -0
  20. package/dist/_chunks/validation-schemas-bib1fBc7.js +47 -0
  21. package/dist/_chunks/validation-schemas-bib1fBc7.js.map +1 -0
  22. package/dist/admin/index.js +1 -1
  23. package/dist/admin/index.mjs +2 -2
  24. package/dist/admin/src/components/ReleaseActionMenu.d.ts +2 -2
  25. package/dist/admin/src/components/{CMReleasesContainer.d.ts → ReleaseActionModal.d.ts} +3 -1
  26. package/dist/admin/src/components/ReleaseModal.d.ts +2 -1
  27. package/dist/admin/src/components/ReleasesPanel.d.ts +3 -0
  28. package/dist/admin/src/pages/SettingsPage.d.ts +1 -0
  29. package/dist/admin/src/services/release.d.ts +37 -32
  30. package/dist/admin/src/utils/time.d.ts +9 -0
  31. package/dist/server/index.js +784 -600
  32. package/dist/server/index.js.map +1 -1
  33. package/dist/server/index.mjs +785 -601
  34. package/dist/server/index.mjs.map +1 -1
  35. package/dist/server/src/bootstrap.d.ts.map +1 -1
  36. package/dist/server/src/constants.d.ts +11 -2
  37. package/dist/server/src/constants.d.ts.map +1 -1
  38. package/dist/server/src/content-types/index.d.ts +3 -5
  39. package/dist/server/src/content-types/index.d.ts.map +1 -1
  40. package/dist/server/src/content-types/release-action/index.d.ts +3 -5
  41. package/dist/server/src/content-types/release-action/index.d.ts.map +1 -1
  42. package/dist/server/src/content-types/release-action/schema.d.ts +3 -5
  43. package/dist/server/src/content-types/release-action/schema.d.ts.map +1 -1
  44. package/dist/server/src/controllers/index.d.ts +6 -3
  45. package/dist/server/src/controllers/index.d.ts.map +1 -1
  46. package/dist/server/src/controllers/release-action.d.ts +0 -1
  47. package/dist/server/src/controllers/release-action.d.ts.map +1 -1
  48. package/dist/server/src/controllers/release.d.ts +7 -2
  49. package/dist/server/src/controllers/release.d.ts.map +1 -1
  50. package/dist/server/src/controllers/settings.d.ts +11 -0
  51. package/dist/server/src/controllers/settings.d.ts.map +1 -0
  52. package/dist/server/src/controllers/validation/release-action.d.ts +7 -1
  53. package/dist/server/src/controllers/validation/release-action.d.ts.map +1 -1
  54. package/dist/server/src/controllers/validation/release.d.ts +1 -0
  55. package/dist/server/src/controllers/validation/release.d.ts.map +1 -1
  56. package/dist/server/src/controllers/validation/settings.d.ts +2 -0
  57. package/dist/server/src/controllers/validation/settings.d.ts.map +1 -0
  58. package/dist/server/src/index.d.ts +66 -51
  59. package/dist/server/src/index.d.ts.map +1 -1
  60. package/dist/server/src/middlewares/documents.d.ts +6 -0
  61. package/dist/server/src/middlewares/documents.d.ts.map +1 -0
  62. package/dist/server/src/migrations/database/5.0.0-document-id-in-actions.d.ts +9 -0
  63. package/dist/server/src/migrations/database/5.0.0-document-id-in-actions.d.ts.map +1 -0
  64. package/dist/server/src/migrations/index.d.ts.map +1 -1
  65. package/dist/server/src/register.d.ts.map +1 -1
  66. package/dist/server/src/routes/index.d.ts +16 -0
  67. package/dist/server/src/routes/index.d.ts.map +1 -1
  68. package/dist/server/src/routes/release-action.d.ts.map +1 -1
  69. package/dist/server/src/routes/release.d.ts.map +1 -1
  70. package/dist/server/src/routes/settings.d.ts +18 -0
  71. package/dist/server/src/routes/settings.d.ts.map +1 -0
  72. package/dist/server/src/services/index.d.ts +38 -38
  73. package/dist/server/src/services/index.d.ts.map +1 -1
  74. package/dist/server/src/services/release-action.d.ts +36 -0
  75. package/dist/server/src/services/release-action.d.ts.map +1 -0
  76. package/dist/server/src/services/release.d.ts +6 -41
  77. package/dist/server/src/services/release.d.ts.map +1 -1
  78. package/dist/server/src/services/settings.d.ts +13 -0
  79. package/dist/server/src/services/settings.d.ts.map +1 -0
  80. package/dist/server/src/services/validation.d.ts +1 -1
  81. package/dist/server/src/services/validation.d.ts.map +1 -1
  82. package/dist/server/src/utils/index.d.ts +29 -8
  83. package/dist/server/src/utils/index.d.ts.map +1 -1
  84. package/dist/shared/contracts/release-actions.d.ts +6 -5
  85. package/dist/shared/contracts/release-actions.d.ts.map +1 -1
  86. package/dist/shared/contracts/releases.d.ts +6 -5
  87. package/dist/shared/contracts/releases.d.ts.map +1 -1
  88. package/dist/shared/contracts/settings.d.ts +39 -0
  89. package/dist/shared/contracts/settings.d.ts.map +1 -0
  90. package/dist/shared/validation-schemas.d.ts +1 -0
  91. package/dist/shared/validation-schemas.d.ts.map +1 -1
  92. package/package.json +10 -9
  93. package/dist/_chunks/App-DUmziQ17.js.map +0 -1
  94. package/dist/_chunks/App-D_6Y9N2F.mjs.map +0 -1
  95. package/dist/_chunks/en-B9Ur3VsE.mjs.map +0 -1
  96. package/dist/_chunks/en-DtFJ5ViE.js.map +0 -1
  97. package/dist/_chunks/index-BomF0-yY.mjs.map +0 -1
  98. package/dist/_chunks/index-C5Hc767q.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { contentTypes as contentTypes$1, async, setCreatorFields, errors, validateYupSchema, yup as yup$1 } from "@strapi/utils";
1
+ import { contentTypes as contentTypes$1, async, setCreatorFields, errors, yup as yup$1, validateYupSchema } from "@strapi/utils";
2
2
  import isEqual from "lodash/isEqual";
3
3
  import { difference, keys } from "lodash";
4
4
  import _ from "lodash/fp";
@@ -48,6 +48,23 @@ const ACTIONS = [
48
48
  displayName: "Add an entry to a release",
49
49
  uid: "create-action",
50
50
  pluginName: "content-releases"
51
+ },
52
+ // Settings
53
+ {
54
+ uid: "settings.read",
55
+ section: "settings",
56
+ displayName: "Read",
57
+ category: "content releases",
58
+ subCategory: "options",
59
+ pluginName: "content-releases"
60
+ },
61
+ {
62
+ uid: "settings.update",
63
+ section: "settings",
64
+ displayName: "Edit",
65
+ category: "content releases",
66
+ subCategory: "options",
67
+ pluginName: "content-releases"
51
68
  }
52
69
  ];
53
70
  const ALLOWED_WEBHOOK_EVENTS = {
@@ -56,16 +73,13 @@ const ALLOWED_WEBHOOK_EVENTS = {
56
73
  const getService = (name, { strapi: strapi2 }) => {
57
74
  return strapi2.plugin("content-releases").service(name);
58
75
  };
59
- const getPopulatedEntry = async (contentTypeUid, entryId, { strapi: strapi2 }) => {
76
+ const getDraftEntryValidStatus = async ({ contentType, documentId, locale }, { strapi: strapi2 }) => {
60
77
  const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
61
- const populate = await populateBuilderService(contentTypeUid).populateDeep(Infinity).build();
62
- const entry = await strapi2.db.query(contentTypeUid).findOne({
63
- where: { id: entryId },
64
- populate
65
- });
66
- return entry;
78
+ const populate = await populateBuilderService(contentType).populateDeep(Infinity).build();
79
+ const entry = await getEntry({ contentType, documentId, locale, populate }, { strapi: strapi2 });
80
+ return isEntryValid(contentType, entry, { strapi: strapi2 });
67
81
  };
68
- const getEntryValidStatus = async (contentTypeUid, entry, { strapi: strapi2 }) => {
82
+ const isEntryValid = async (contentTypeUid, entry, { strapi: strapi2 }) => {
69
83
  try {
70
84
  await strapi2.entityValidator.validateEntityCreation(
71
85
  strapi2.getModel(contentTypeUid),
@@ -79,6 +93,38 @@ const getEntryValidStatus = async (contentTypeUid, entry, { strapi: strapi2 }) =
79
93
  return false;
80
94
  }
81
95
  };
96
+ const getEntry = async ({
97
+ contentType,
98
+ documentId,
99
+ locale,
100
+ populate,
101
+ status = "draft"
102
+ }, { strapi: strapi2 }) => {
103
+ if (documentId) {
104
+ return strapi2.documents(contentType).findOne({ documentId, locale, populate, status });
105
+ }
106
+ return strapi2.documents(contentType).findFirst({ locale, populate, status });
107
+ };
108
+ const getEntryStatus = async (contentType, entry) => {
109
+ if (entry.publishedAt) {
110
+ return "published";
111
+ }
112
+ const publishedEntry = await strapi.documents(contentType).findOne({
113
+ documentId: entry.documentId,
114
+ locale: entry.locale,
115
+ status: "published",
116
+ fields: ["updatedAt"]
117
+ });
118
+ if (!publishedEntry) {
119
+ return "draft";
120
+ }
121
+ const entryUpdatedAt = new Date(entry.updatedAt).getTime();
122
+ const publishedEntryUpdatedAt = new Date(publishedEntry.updatedAt).getTime();
123
+ if (entryUpdatedAt > publishedEntryUpdatedAt) {
124
+ return "modified";
125
+ }
126
+ return "published";
127
+ };
82
128
  async function deleteActionsOnDisableDraftAndPublish({
83
129
  oldContentTypes,
84
130
  contentTypes: contentTypes2
@@ -124,20 +170,22 @@ async function migrateIsValidAndStatusReleases() {
124
170
  const notValidatedActions = actions.filter((action) => action.isEntryValid === null);
125
171
  for (const action of notValidatedActions) {
126
172
  if (action.entry) {
127
- const populatedEntry = await getPopulatedEntry(action.contentType, action.entry.id, {
128
- strapi
173
+ const isEntryValid2 = getDraftEntryValidStatus(
174
+ {
175
+ contentType: action.contentType,
176
+ documentId: action.entryDocumentId,
177
+ locale: action.locale
178
+ },
179
+ { strapi }
180
+ );
181
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
182
+ where: {
183
+ id: action.id
184
+ },
185
+ data: {
186
+ isEntryValid: isEntryValid2
187
+ }
129
188
  });
130
- if (populatedEntry) {
131
- const isEntryValid = getEntryValidStatus(action.contentType, populatedEntry, { strapi });
132
- await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
133
- where: {
134
- id: action.id
135
- },
136
- data: {
137
- isEntryValid
138
- }
139
- });
140
- }
141
189
  }
142
190
  }
143
191
  return getService("release", { strapi }).updateReleaseStatus(release2.id);
@@ -181,24 +229,24 @@ async function revalidateChangedContentTypes({ oldContentTypes, contentTypes: co
181
229
  }
182
230
  });
183
231
  await async.map(actions, async (action) => {
184
- if (action.entry && action.release) {
185
- const populatedEntry = await getPopulatedEntry(contentTypeUID, action.entry.id, {
186
- strapi
232
+ if (action.entry && action.release && action.type === "publish") {
233
+ const isEntryValid2 = await getDraftEntryValidStatus(
234
+ {
235
+ contentType: contentTypeUID,
236
+ documentId: action.entryDocumentId,
237
+ locale: action.locale
238
+ },
239
+ { strapi }
240
+ );
241
+ releasesAffected.add(action.release.id);
242
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
243
+ where: {
244
+ id: action.id
245
+ },
246
+ data: {
247
+ isEntryValid: isEntryValid2
248
+ }
187
249
  });
188
- if (populatedEntry) {
189
- const isEntryValid = await getEntryValidStatus(contentTypeUID, populatedEntry, {
190
- strapi
191
- });
192
- releasesAffected.add(action.release.id);
193
- await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
194
- where: {
195
- id: action.id
196
- },
197
- data: {
198
- isEntryValid
199
- }
200
- });
201
- }
202
250
  }
203
251
  });
204
252
  }
@@ -255,9 +303,38 @@ async function enableContentTypeLocalized({ oldContentTypes, contentTypes: conte
255
303
  }
256
304
  }
257
305
  }
306
+ const addEntryDocumentToReleaseActions = {
307
+ name: "content-releases::5.0.0-add-entry-document-id-to-release-actions",
308
+ async up(trx, db) {
309
+ const hasPolymorphicColumn = await trx.schema.hasColumn("strapi_release_actions", "target_id");
310
+ if (hasPolymorphicColumn) {
311
+ const hasEntryDocumentIdColumn = await trx.schema.hasColumn(
312
+ "strapi_release_actions",
313
+ "entry_document_id"
314
+ );
315
+ if (!hasEntryDocumentIdColumn) {
316
+ await trx.schema.alterTable("strapi_release_actions", (table) => {
317
+ table.string("entry_document_id");
318
+ });
319
+ }
320
+ const releaseActions = await trx.select("*").from("strapi_release_actions");
321
+ async.map(releaseActions, async (action) => {
322
+ const { target_type, target_id } = action;
323
+ const entry = await db.query(target_type).findOne({ where: { id: target_id } });
324
+ if (entry) {
325
+ await trx("strapi_release_actions").update({ entry_document_id: entry.documentId }).where("id", action.id);
326
+ }
327
+ });
328
+ }
329
+ },
330
+ async down() {
331
+ throw new Error("not implemented");
332
+ }
333
+ };
258
334
  const register = async ({ strapi: strapi2 }) => {
259
335
  if (strapi2.ee.features.isEnabled("cms-content-releases")) {
260
336
  await strapi2.service("admin::permission").actionProvider.registerMany(ACTIONS);
337
+ strapi2.db.migrations.providers.internal.register(addEntryDocumentToReleaseActions);
261
338
  strapi2.hook("strapi::content-types.beforeSync").register(disableContentTypeLocalized).register(deleteActionsOnDisableDraftAndPublish);
262
339
  strapi2.hook("strapi::content-types.afterSync").register(deleteActionsOnDeleteContentType).register(enableContentTypeLocalized).register(revalidateChangedContentTypes).register(migrateIsValidAndStatusReleases);
263
340
  }
@@ -267,6 +344,104 @@ const register = async ({ strapi: strapi2 }) => {
267
344
  graphqlExtensionService.shadowCRUD(RELEASE_ACTION_MODEL_UID).disable();
268
345
  }
269
346
  };
347
+ const updateActionsStatusAndUpdateReleaseStatus = async (contentType, entry) => {
348
+ const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
349
+ where: {
350
+ actions: {
351
+ contentType,
352
+ entryDocumentId: entry.documentId,
353
+ locale: entry.locale
354
+ }
355
+ }
356
+ });
357
+ const entryStatus = await isEntryValid(contentType, entry, { strapi });
358
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
359
+ where: {
360
+ contentType,
361
+ entryDocumentId: entry.documentId,
362
+ locale: entry.locale
363
+ },
364
+ data: {
365
+ isEntryValid: entryStatus
366
+ }
367
+ });
368
+ for (const release2 of releases) {
369
+ getService("release", { strapi }).updateReleaseStatus(release2.id);
370
+ }
371
+ };
372
+ const deleteActionsAndUpdateReleaseStatus = async (params) => {
373
+ const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
374
+ where: {
375
+ actions: params
376
+ }
377
+ });
378
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
379
+ where: params
380
+ });
381
+ for (const release2 of releases) {
382
+ getService("release", { strapi }).updateReleaseStatus(release2.id);
383
+ }
384
+ };
385
+ const deleteActionsOnDelete = async (ctx, next) => {
386
+ if (ctx.action !== "delete") {
387
+ return next();
388
+ }
389
+ if (!contentTypes$1.hasDraftAndPublish(ctx.contentType)) {
390
+ return next();
391
+ }
392
+ const contentType = ctx.contentType.uid;
393
+ const { documentId, locale } = ctx.params;
394
+ const result = await next();
395
+ if (!result) {
396
+ return result;
397
+ }
398
+ try {
399
+ deleteActionsAndUpdateReleaseStatus({
400
+ contentType,
401
+ entryDocumentId: documentId,
402
+ ...locale !== "*" && { locale }
403
+ });
404
+ } catch (error) {
405
+ strapi.log.error("Error while deleting release actions after delete", {
406
+ error
407
+ });
408
+ }
409
+ return result;
410
+ };
411
+ const updateActionsOnUpdate = async (ctx, next) => {
412
+ if (ctx.action !== "update") {
413
+ return next();
414
+ }
415
+ if (!contentTypes$1.hasDraftAndPublish(ctx.contentType)) {
416
+ return next();
417
+ }
418
+ const contentType = ctx.contentType.uid;
419
+ const result = await next();
420
+ if (!result) {
421
+ return result;
422
+ }
423
+ try {
424
+ updateActionsStatusAndUpdateReleaseStatus(contentType, result);
425
+ } catch (error) {
426
+ strapi.log.error("Error while updating release actions after update", {
427
+ error
428
+ });
429
+ }
430
+ return result;
431
+ };
432
+ const deleteReleasesActionsAndUpdateReleaseStatus = async (params) => {
433
+ const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
434
+ where: {
435
+ actions: params
436
+ }
437
+ });
438
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
439
+ where: params
440
+ });
441
+ for (const release2 of releases) {
442
+ getService("release", { strapi }).updateReleaseStatus(release2.id);
443
+ }
444
+ };
270
445
  const bootstrap = async ({ strapi: strapi2 }) => {
271
446
  if (strapi2.ee.features.isEnabled("cms-content-releases")) {
272
447
  const contentTypesWithDraftAndPublish = Object.keys(strapi2.contentTypes).filter(
@@ -274,115 +449,29 @@ const bootstrap = async ({ strapi: strapi2 }) => {
274
449
  );
275
450
  strapi2.db.lifecycles.subscribe({
276
451
  models: contentTypesWithDraftAndPublish,
277
- async afterDelete(event) {
278
- try {
279
- const { model, result } = event;
280
- if (model.kind === "collectionType" && model.options?.draftAndPublish) {
281
- const { id } = result;
282
- const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
283
- where: {
284
- actions: {
285
- target_type: model.uid,
286
- target_id: id
287
- }
288
- }
289
- });
290
- await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
291
- where: {
292
- target_type: model.uid,
293
- target_id: id
294
- }
295
- });
296
- for (const release2 of releases) {
297
- getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
298
- }
299
- }
300
- } catch (error) {
301
- strapi2.log.error("Error while deleting release actions after entry delete", { error });
302
- }
303
- },
304
452
  /**
305
- * deleteMany hook doesn't return the deleted entries ids
306
- * so we need to fetch them before deleting the entries to save the ids on our state
307
- */
308
- async beforeDeleteMany(event) {
309
- const { model, params } = event;
310
- if (model.kind === "collectionType" && model.options?.draftAndPublish) {
311
- const { where } = params;
312
- const entriesToDelete = await strapi2.db.query(model.uid).findMany({ select: ["id"], where });
313
- event.state.entriesToDelete = entriesToDelete;
314
- }
315
- },
316
- /**
317
- * We delete the release actions related to deleted entries
318
- * We make this only after deleteMany is succesfully executed to avoid errors
453
+ * deleteMany is still used outside documents service, for example when deleting a locale
319
454
  */
320
455
  async afterDeleteMany(event) {
321
456
  try {
322
- const { model, state } = event;
323
- const entriesToDelete = state.entriesToDelete;
324
- if (entriesToDelete) {
325
- const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
326
- where: {
327
- actions: {
328
- target_type: model.uid,
329
- target_id: {
330
- $in: entriesToDelete.map((entry) => entry.id)
331
- }
332
- }
333
- }
334
- });
335
- await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
336
- where: {
337
- target_type: model.uid,
338
- target_id: {
339
- $in: entriesToDelete.map((entry) => entry.id)
340
- }
341
- }
457
+ const model = strapi2.getModel(event.model.uid);
458
+ if (model.kind === "collectionType" && model.options?.draftAndPublish) {
459
+ const { where } = event.params;
460
+ deleteReleasesActionsAndUpdateReleaseStatus({
461
+ contentType: model.uid,
462
+ locale: where.locale ?? null,
463
+ ...where.documentId && { entryDocumentId: where.documentId }
342
464
  });
343
- for (const release2 of releases) {
344
- getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
345
- }
346
465
  }
347
466
  } catch (error) {
348
467
  strapi2.log.error("Error while deleting release actions after entry deleteMany", {
349
468
  error
350
469
  });
351
470
  }
352
- },
353
- async afterUpdate(event) {
354
- try {
355
- const { model, result } = event;
356
- if (model.kind === "collectionType" && model.options?.draftAndPublish) {
357
- const isEntryValid = await getEntryValidStatus(model.uid, result, {
358
- strapi: strapi2
359
- });
360
- await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
361
- where: {
362
- target_type: model.uid,
363
- target_id: result.id
364
- },
365
- data: {
366
- isEntryValid
367
- }
368
- });
369
- const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
370
- where: {
371
- actions: {
372
- target_type: model.uid,
373
- target_id: result.id
374
- }
375
- }
376
- });
377
- for (const release2 of releases) {
378
- getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
379
- }
380
- }
381
- } catch (error) {
382
- strapi2.log.error("Error while updating release actions after entry update", { error });
383
- }
384
471
  }
385
472
  });
473
+ strapi2.documents.use(deleteActionsOnDelete);
474
+ strapi2.documents.use(updateActionsOnUpdate);
386
475
  getService("scheduling", { strapi: strapi2 }).syncFromDatabase().catch((err) => {
387
476
  strapi2.log.error(
388
477
  "Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling."
@@ -474,15 +563,13 @@ const schema = {
474
563
  enum: ["publish", "unpublish"],
475
564
  required: true
476
565
  },
477
- entry: {
478
- type: "relation",
479
- relation: "morphToOne",
480
- configurable: false
481
- },
482
566
  contentType: {
483
567
  type: "string",
484
568
  required: true
485
569
  },
570
+ entryDocumentId: {
571
+ type: "string"
572
+ },
486
573
  locale: {
487
574
  type: "string"
488
575
  },
@@ -504,18 +591,6 @@ const contentTypes = {
504
591
  release: release$1,
505
592
  "release-action": releaseAction$1
506
593
  };
507
- const getGroupName = (queryValue) => {
508
- switch (queryValue) {
509
- case "contentType":
510
- return "contentType.displayName";
511
- case "action":
512
- return "type";
513
- case "locale":
514
- return _.getOr("No locale", "locale.name");
515
- default:
516
- return "contentType.displayName";
517
- }
518
- };
519
594
  const createReleaseService = ({ strapi: strapi2 }) => {
520
595
  const dispatchWebhook = (event, { isPublished, release: release2, error }) => {
521
596
  strapi2.eventHub.emit(event, {
@@ -524,93 +599,32 @@ const createReleaseService = ({ strapi: strapi2 }) => {
524
599
  release: release2
525
600
  });
526
601
  };
527
- const publishSingleTypeAction = async (uid, actionType, entryId) => {
528
- const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
529
- const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
530
- const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
531
- const entry = await strapi2.entityService.findOne(uid, entryId, { populate });
532
- try {
533
- if (actionType === "publish") {
534
- await entityManagerService.publish(entry, uid);
535
- } else {
536
- await entityManagerService.unpublish(entry, uid);
537
- }
538
- } catch (error) {
539
- if (error instanceof errors.ApplicationError && (error.message === "already.published" || error.message === "already.draft"))
540
- ;
541
- else {
542
- throw error;
543
- }
544
- }
545
- };
546
- const publishCollectionTypeAction = async (uid, entriesToPublishIds, entriestoUnpublishIds) => {
547
- const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
548
- const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
549
- const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
550
- const entriesToPublish = await strapi2.entityService.findMany(uid, {
551
- filters: {
552
- id: {
553
- $in: entriesToPublishIds
554
- }
555
- },
556
- populate
557
- });
558
- const entriesToUnpublish = await strapi2.entityService.findMany(uid, {
559
- filters: {
560
- id: {
561
- $in: entriestoUnpublishIds
562
- }
563
- },
564
- populate
565
- });
566
- if (entriesToPublish.length > 0) {
567
- await entityManagerService.publishMany(entriesToPublish, uid);
568
- }
569
- if (entriesToUnpublish.length > 0) {
570
- await entityManagerService.unpublishMany(entriesToUnpublish, uid);
571
- }
572
- };
573
602
  const getFormattedActions = async (releaseId) => {
574
603
  const actions = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findMany({
575
604
  where: {
576
605
  release: {
577
606
  id: releaseId
578
607
  }
579
- },
580
- populate: {
581
- entry: {
582
- fields: ["id"]
583
- }
584
608
  }
585
609
  });
586
610
  if (actions.length === 0) {
587
611
  throw new errors.ValidationError("No entries to publish");
588
612
  }
589
- const collectionTypeActions = {};
590
- const singleTypeActions = [];
613
+ const formattedActions = {};
591
614
  for (const action of actions) {
592
615
  const contentTypeUid = action.contentType;
593
- if (strapi2.contentTypes[contentTypeUid].kind === "collectionType") {
594
- if (!collectionTypeActions[contentTypeUid]) {
595
- collectionTypeActions[contentTypeUid] = {
596
- entriesToPublishIds: [],
597
- entriesToUnpublishIds: []
598
- };
599
- }
600
- if (action.type === "publish") {
601
- collectionTypeActions[contentTypeUid].entriesToPublishIds.push(action.entry.id);
602
- } else {
603
- collectionTypeActions[contentTypeUid].entriesToUnpublishIds.push(action.entry.id);
604
- }
605
- } else {
606
- singleTypeActions.push({
607
- uid: contentTypeUid,
608
- action: action.type,
609
- id: action.entry.id
610
- });
616
+ if (!formattedActions[contentTypeUid]) {
617
+ formattedActions[contentTypeUid] = {
618
+ publish: [],
619
+ unpublish: []
620
+ };
611
621
  }
622
+ formattedActions[contentTypeUid][action.type].push({
623
+ documentId: action.entryDocumentId,
624
+ locale: action.locale
625
+ });
612
626
  }
613
- return { collectionTypeActions, singleTypeActions };
627
+ return formattedActions;
614
628
  };
615
629
  return {
616
630
  async create(releaseData, { user }) {
@@ -657,91 +671,10 @@ const createReleaseService = ({ strapi: strapi2 }) => {
657
671
  }
658
672
  });
659
673
  },
660
- async findManyWithContentTypeEntryAttached(contentTypeUid, entriesIds) {
661
- let entries = entriesIds;
662
- if (!Array.isArray(entriesIds)) {
663
- entries = [entriesIds];
664
- }
665
- const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
666
- where: {
667
- actions: {
668
- target_type: contentTypeUid,
669
- target_id: {
670
- $in: entries
671
- }
672
- },
673
- releasedAt: {
674
- $null: true
675
- }
676
- },
677
- populate: {
678
- // Filter the action to get only the content type entry
679
- actions: {
680
- where: {
681
- target_type: contentTypeUid,
682
- target_id: {
683
- $in: entries
684
- }
685
- },
686
- populate: {
687
- entry: {
688
- select: ["id"]
689
- }
690
- }
691
- }
692
- }
693
- });
694
- return releases.map((release2) => {
695
- if (release2.actions?.length) {
696
- const actionsForEntry = release2.actions;
697
- delete release2.actions;
698
- return {
699
- ...release2,
700
- actions: actionsForEntry
701
- };
702
- }
703
- return release2;
704
- });
705
- },
706
- async findManyWithoutContentTypeEntryAttached(contentTypeUid, entryId) {
707
- const releasesRelated = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
708
- where: {
709
- releasedAt: {
710
- $null: true
711
- },
712
- actions: {
713
- target_type: contentTypeUid,
714
- target_id: entryId
715
- }
716
- }
717
- });
718
- const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
719
- where: {
720
- $or: [
721
- {
722
- id: {
723
- $notIn: releasesRelated.map((release2) => release2.id)
724
- }
725
- },
726
- {
727
- actions: null
728
- }
729
- ],
730
- releasedAt: {
731
- $null: true
732
- }
733
- }
734
- });
735
- return releases.map((release2) => {
736
- if (release2.actions?.length) {
737
- const [actionForEntry] = release2.actions;
738
- delete release2.actions;
739
- return {
740
- ...release2,
741
- action: actionForEntry
742
- };
743
- }
744
- return release2;
674
+ findMany(query) {
675
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
676
+ return strapi2.db.query(RELEASE_MODEL_UID).findMany({
677
+ ...dbQuery
745
678
  });
746
679
  },
747
680
  async update(id, releaseData, { user }) {
@@ -777,131 +710,6 @@ const createReleaseService = ({ strapi: strapi2 }) => {
777
710
  strapi2.telemetry.send("didUpdateContentRelease");
778
711
  return updatedRelease;
779
712
  },
780
- async createAction(releaseId, action) {
781
- const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
782
- strapi: strapi2
783
- });
784
- await Promise.all([
785
- validateEntryContentType(action.entry.contentType),
786
- validateUniqueEntry(releaseId, action)
787
- ]);
788
- const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id: releaseId } });
789
- if (!release2) {
790
- throw new errors.NotFoundError(`No release found for id ${releaseId}`);
791
- }
792
- if (release2.releasedAt) {
793
- throw new errors.ValidationError("Release already published");
794
- }
795
- const { entry, type } = action;
796
- const populatedEntry = await getPopulatedEntry(entry.contentType, entry.id, { strapi: strapi2 });
797
- const isEntryValid = await getEntryValidStatus(entry.contentType, populatedEntry, { strapi: strapi2 });
798
- const releaseAction2 = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).create({
799
- data: {
800
- type,
801
- contentType: entry.contentType,
802
- locale: entry.locale,
803
- isEntryValid,
804
- entry: {
805
- id: entry.id,
806
- __type: entry.contentType,
807
- __pivot: { field: "entry" }
808
- },
809
- release: releaseId
810
- },
811
- populate: { release: { select: ["id"] }, entry: { select: ["id"] } }
812
- });
813
- this.updateReleaseStatus(releaseId);
814
- return releaseAction2;
815
- },
816
- async findActions(releaseId, query) {
817
- const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
818
- where: { id: releaseId },
819
- select: ["id"]
820
- });
821
- if (!release2) {
822
- throw new errors.NotFoundError(`No release found for id ${releaseId}`);
823
- }
824
- const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
825
- return strapi2.db.query(RELEASE_ACTION_MODEL_UID).findPage({
826
- ...dbQuery,
827
- populate: {
828
- entry: {
829
- populate: "*"
830
- }
831
- },
832
- where: {
833
- release: releaseId
834
- }
835
- });
836
- },
837
- async countActions(query) {
838
- const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
839
- return strapi2.db.query(RELEASE_ACTION_MODEL_UID).count(dbQuery);
840
- },
841
- async groupActions(actions, groupBy) {
842
- const contentTypeUids = actions.reduce((acc, action) => {
843
- if (!acc.includes(action.contentType)) {
844
- acc.push(action.contentType);
845
- }
846
- return acc;
847
- }, []);
848
- const allReleaseContentTypesDictionary = await this.getContentTypesDataForActions(contentTypeUids);
849
- const allLocalesDictionary = await this.getLocalesDataForActions();
850
- const formattedData = actions.map((action) => {
851
- const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
852
- return {
853
- ...action,
854
- locale: action.locale ? allLocalesDictionary[action.locale] : null,
855
- contentType: {
856
- displayName,
857
- mainFieldValue: action.entry[mainField],
858
- uid: action.contentType
859
- }
860
- };
861
- });
862
- const groupName = getGroupName(groupBy);
863
- return _.groupBy(groupName)(formattedData);
864
- },
865
- async getLocalesDataForActions() {
866
- if (!strapi2.plugin("i18n")) {
867
- return {};
868
- }
869
- const allLocales = await strapi2.plugin("i18n").service("locales").find() || [];
870
- return allLocales.reduce((acc, locale) => {
871
- acc[locale.code] = { name: locale.name, code: locale.code };
872
- return acc;
873
- }, {});
874
- },
875
- async getContentTypesDataForActions(contentTypesUids) {
876
- const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
877
- const contentTypesData = {};
878
- for (const contentTypeUid of contentTypesUids) {
879
- const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
880
- uid: contentTypeUid
881
- });
882
- contentTypesData[contentTypeUid] = {
883
- mainField: contentTypeConfig.settings.mainField,
884
- displayName: strapi2.getModel(contentTypeUid).info.displayName
885
- };
886
- }
887
- return contentTypesData;
888
- },
889
- getContentTypeModelsFromActions(actions) {
890
- const contentTypeUids = actions.reduce((acc, action) => {
891
- if (!acc.includes(action.contentType)) {
892
- acc.push(action.contentType);
893
- }
894
- return acc;
895
- }, []);
896
- const contentTypeModelsMap = contentTypeUids.reduce(
897
- (acc, contentTypeUid) => {
898
- acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
899
- return acc;
900
- },
901
- {}
902
- );
903
- return contentTypeModelsMap;
904
- },
905
713
  async getAllComponents() {
906
714
  const contentManagerComponentsService = strapi2.plugin("content-manager").service("components");
907
715
  const components = await contentManagerComponentsService.findAllComponents();
@@ -967,20 +775,19 @@ const createReleaseService = ({ strapi: strapi2 }) => {
967
775
  }
968
776
  try {
969
777
  strapi2.log.info(`[Content Releases] Starting to publish release ${lockedRelease.name}`);
970
- const { collectionTypeActions, singleTypeActions } = await getFormattedActions(releaseId);
971
- await strapi2.db.transaction(async () => {
972
- for (const { uid, action, id } of singleTypeActions) {
973
- await publishSingleTypeAction(uid, action, id);
974
- }
975
- for (const contentTypeUid of Object.keys(collectionTypeActions)) {
976
- const uid = contentTypeUid;
977
- await publishCollectionTypeAction(
978
- uid,
979
- collectionTypeActions[uid].entriesToPublishIds,
980
- collectionTypeActions[uid].entriesToUnpublishIds
981
- );
982
- }
983
- });
778
+ const formattedActions = await getFormattedActions(releaseId);
779
+ await strapi2.db.transaction(
780
+ async () => Promise.all(
781
+ Object.keys(formattedActions).map(async (contentTypeUid) => {
782
+ const contentType = contentTypeUid;
783
+ const { publish, unpublish } = formattedActions[contentType];
784
+ return Promise.all([
785
+ ...publish.map((params) => strapi2.documents(contentType).publish(params)),
786
+ ...unpublish.map((params) => strapi2.documents(contentType).unpublish(params))
787
+ ]);
788
+ })
789
+ )
790
+ );
984
791
  const release22 = await strapi2.db.query(RELEASE_MODEL_UID).update({
985
792
  where: {
986
793
  id: releaseId
@@ -1010,13 +817,216 @@ const createReleaseService = ({ strapi: strapi2 }) => {
1010
817
  };
1011
818
  }
1012
819
  });
1013
- if (error instanceof Error) {
1014
- throw error;
820
+ if (error instanceof Error) {
821
+ throw error;
822
+ }
823
+ return release2;
824
+ },
825
+ async updateReleaseStatus(releaseId) {
826
+ const releaseActionService = getService("release-action", { strapi: strapi2 });
827
+ const [totalActions, invalidActions] = await Promise.all([
828
+ releaseActionService.countActions({
829
+ filters: {
830
+ release: releaseId
831
+ }
832
+ }),
833
+ releaseActionService.countActions({
834
+ filters: {
835
+ release: releaseId,
836
+ isEntryValid: false
837
+ }
838
+ })
839
+ ]);
840
+ if (totalActions > 0) {
841
+ if (invalidActions > 0) {
842
+ return strapi2.db.query(RELEASE_MODEL_UID).update({
843
+ where: {
844
+ id: releaseId
845
+ },
846
+ data: {
847
+ status: "blocked"
848
+ }
849
+ });
850
+ }
851
+ return strapi2.db.query(RELEASE_MODEL_UID).update({
852
+ where: {
853
+ id: releaseId
854
+ },
855
+ data: {
856
+ status: "ready"
857
+ }
858
+ });
859
+ }
860
+ return strapi2.db.query(RELEASE_MODEL_UID).update({
861
+ where: {
862
+ id: releaseId
863
+ },
864
+ data: {
865
+ status: "empty"
866
+ }
867
+ });
868
+ }
869
+ };
870
+ };
871
+ const getGroupName = (queryValue) => {
872
+ switch (queryValue) {
873
+ case "contentType":
874
+ return "contentType.displayName";
875
+ case "type":
876
+ return "type";
877
+ case "locale":
878
+ return _.getOr("No locale", "locale.name");
879
+ default:
880
+ return "contentType.displayName";
881
+ }
882
+ };
883
+ const createReleaseActionService = ({ strapi: strapi2 }) => {
884
+ const getLocalesDataForActions = async () => {
885
+ if (!strapi2.plugin("i18n")) {
886
+ return {};
887
+ }
888
+ const allLocales = await strapi2.plugin("i18n").service("locales").find() || [];
889
+ return allLocales.reduce((acc, locale) => {
890
+ acc[locale.code] = { name: locale.name, code: locale.code };
891
+ return acc;
892
+ }, {});
893
+ };
894
+ const getContentTypesDataForActions = async (contentTypesUids) => {
895
+ const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
896
+ const contentTypesData = {};
897
+ for (const contentTypeUid of contentTypesUids) {
898
+ const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
899
+ uid: contentTypeUid
900
+ });
901
+ contentTypesData[contentTypeUid] = {
902
+ mainField: contentTypeConfig.settings.mainField,
903
+ displayName: strapi2.getModel(contentTypeUid).info.displayName
904
+ };
905
+ }
906
+ return contentTypesData;
907
+ };
908
+ return {
909
+ async create(releaseId, action) {
910
+ const { validateEntryData, validateUniqueEntry } = getService("release-validation", {
911
+ strapi: strapi2
912
+ });
913
+ await Promise.all([
914
+ validateEntryData(action.contentType, action.entryDocumentId),
915
+ validateUniqueEntry(releaseId, action)
916
+ ]);
917
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id: releaseId } });
918
+ if (!release2) {
919
+ throw new errors.NotFoundError(`No release found for id ${releaseId}`);
920
+ }
921
+ if (release2.releasedAt) {
922
+ throw new errors.ValidationError("Release already published");
923
+ }
924
+ const actionStatus = action.type === "publish" ? await getDraftEntryValidStatus(
925
+ {
926
+ contentType: action.contentType,
927
+ documentId: action.entryDocumentId,
928
+ locale: action.locale
929
+ },
930
+ {
931
+ strapi: strapi2
932
+ }
933
+ ) : true;
934
+ const releaseAction2 = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).create({
935
+ data: {
936
+ ...action,
937
+ release: release2.id,
938
+ isEntryValid: actionStatus
939
+ },
940
+ populate: { release: { select: ["id"] } }
941
+ });
942
+ getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
943
+ return releaseAction2;
944
+ },
945
+ async findPage(releaseId, query) {
946
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
947
+ where: { id: releaseId },
948
+ select: ["id"]
949
+ });
950
+ if (!release2) {
951
+ throw new errors.NotFoundError(`No release found for id ${releaseId}`);
1015
952
  }
1016
- return release2;
953
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
954
+ const { results: actions, pagination } = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findPage({
955
+ ...dbQuery,
956
+ where: {
957
+ release: releaseId
958
+ }
959
+ });
960
+ const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
961
+ const actionsWithEntry = await async.map(actions, async (action) => {
962
+ const populate = await populateBuilderService(action.contentType).populateDeep(Infinity).build();
963
+ const entry = await getEntry(
964
+ {
965
+ contentType: action.contentType,
966
+ documentId: action.entryDocumentId,
967
+ locale: action.locale,
968
+ populate,
969
+ status: action.type === "publish" ? "draft" : "published"
970
+ },
971
+ { strapi: strapi2 }
972
+ );
973
+ return {
974
+ ...action,
975
+ entry,
976
+ status: entry ? await getEntryStatus(action.contentType, entry) : null
977
+ };
978
+ });
979
+ return {
980
+ results: actionsWithEntry,
981
+ pagination
982
+ };
1017
983
  },
1018
- async updateAction(actionId, releaseId, update) {
1019
- const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
984
+ async groupActions(actions, groupBy) {
985
+ const contentTypeUids = actions.reduce((acc, action) => {
986
+ if (!acc.includes(action.contentType)) {
987
+ acc.push(action.contentType);
988
+ }
989
+ return acc;
990
+ }, []);
991
+ const allReleaseContentTypesDictionary = await getContentTypesDataForActions(contentTypeUids);
992
+ const allLocalesDictionary = await getLocalesDataForActions();
993
+ const formattedData = actions.map((action) => {
994
+ const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
995
+ return {
996
+ ...action,
997
+ locale: action.locale ? allLocalesDictionary[action.locale] : null,
998
+ contentType: {
999
+ displayName,
1000
+ mainFieldValue: action.entry[mainField],
1001
+ uid: action.contentType
1002
+ }
1003
+ };
1004
+ });
1005
+ const groupName = getGroupName(groupBy);
1006
+ return _.groupBy(groupName)(formattedData);
1007
+ },
1008
+ getContentTypeModelsFromActions(actions) {
1009
+ const contentTypeUids = actions.reduce((acc, action) => {
1010
+ if (!acc.includes(action.contentType)) {
1011
+ acc.push(action.contentType);
1012
+ }
1013
+ return acc;
1014
+ }, []);
1015
+ const contentTypeModelsMap = contentTypeUids.reduce(
1016
+ (acc, contentTypeUid) => {
1017
+ acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
1018
+ return acc;
1019
+ },
1020
+ {}
1021
+ );
1022
+ return contentTypeModelsMap;
1023
+ },
1024
+ async countActions(query) {
1025
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
1026
+ return strapi2.db.query(RELEASE_ACTION_MODEL_UID).count(dbQuery);
1027
+ },
1028
+ async update(actionId, releaseId, update) {
1029
+ const action = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findOne({
1020
1030
  where: {
1021
1031
  id: actionId,
1022
1032
  release: {
@@ -1025,17 +1035,42 @@ const createReleaseService = ({ strapi: strapi2 }) => {
1025
1035
  $null: true
1026
1036
  }
1027
1037
  }
1028
- },
1029
- data: update
1038
+ }
1030
1039
  });
1031
- if (!updatedAction) {
1040
+ if (!action) {
1032
1041
  throw new errors.NotFoundError(
1033
1042
  `Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
1034
1043
  );
1035
1044
  }
1045
+ const actionStatus = update.type === "publish" ? getDraftEntryValidStatus(
1046
+ {
1047
+ contentType: action.contentType,
1048
+ documentId: action.entryDocumentId,
1049
+ locale: action.locale
1050
+ },
1051
+ {
1052
+ strapi: strapi2
1053
+ }
1054
+ ) : true;
1055
+ const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
1056
+ where: {
1057
+ id: actionId,
1058
+ release: {
1059
+ id: releaseId,
1060
+ releasedAt: {
1061
+ $null: true
1062
+ }
1063
+ }
1064
+ },
1065
+ data: {
1066
+ ...update,
1067
+ isEntryValid: actionStatus
1068
+ }
1069
+ });
1070
+ getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
1036
1071
  return updatedAction;
1037
1072
  },
1038
- async deleteAction(actionId, releaseId) {
1073
+ async delete(actionId, releaseId) {
1039
1074
  const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
1040
1075
  where: {
1041
1076
  id: actionId,
@@ -1052,51 +1087,8 @@ const createReleaseService = ({ strapi: strapi2 }) => {
1052
1087
  `Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
1053
1088
  );
1054
1089
  }
1055
- this.updateReleaseStatus(releaseId);
1090
+ getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
1056
1091
  return deletedAction;
1057
- },
1058
- async updateReleaseStatus(releaseId) {
1059
- const [totalActions, invalidActions] = await Promise.all([
1060
- this.countActions({
1061
- filters: {
1062
- release: releaseId
1063
- }
1064
- }),
1065
- this.countActions({
1066
- filters: {
1067
- release: releaseId,
1068
- isEntryValid: false
1069
- }
1070
- })
1071
- ]);
1072
- if (totalActions > 0) {
1073
- if (invalidActions > 0) {
1074
- return strapi2.db.query(RELEASE_MODEL_UID).update({
1075
- where: {
1076
- id: releaseId
1077
- },
1078
- data: {
1079
- status: "blocked"
1080
- }
1081
- });
1082
- }
1083
- return strapi2.db.query(RELEASE_MODEL_UID).update({
1084
- where: {
1085
- id: releaseId
1086
- },
1087
- data: {
1088
- status: "ready"
1089
- }
1090
- });
1091
- }
1092
- return strapi2.db.query(RELEASE_MODEL_UID).update({
1093
- where: {
1094
- id: releaseId
1095
- },
1096
- data: {
1097
- status: "empty"
1098
- }
1099
- });
1100
1092
  }
1101
1093
  };
1102
1094
  };
@@ -1112,30 +1104,35 @@ const createReleaseValidationService = ({ strapi: strapi2 }) => ({
1112
1104
  where: {
1113
1105
  id: releaseId
1114
1106
  },
1115
- populate: { actions: { populate: { entry: { select: ["id"] } } } }
1107
+ populate: {
1108
+ actions: true
1109
+ }
1116
1110
  });
1117
1111
  if (!release2) {
1118
1112
  throw new errors.NotFoundError(`No release found for id ${releaseId}`);
1119
1113
  }
1120
1114
  const isEntryInRelease = release2.actions.some(
1121
- (action) => Number(action.entry.id) === Number(releaseActionArgs.entry.id) && action.contentType === releaseActionArgs.entry.contentType
1115
+ (action) => Number(action.entryDocumentId) === Number(releaseActionArgs.entryDocumentId) && action.contentType === releaseActionArgs.contentType && action.locale === releaseActionArgs.locale
1122
1116
  );
1123
1117
  if (isEntryInRelease) {
1124
1118
  throw new AlreadyOnReleaseError(
1125
- `Entry with id ${releaseActionArgs.entry.id} and contentType ${releaseActionArgs.entry.contentType} already exists in release with id ${releaseId}`
1119
+ `Entry with documentId ${releaseActionArgs.entryDocumentId} ${releaseActionArgs.locale ? `(${releaseActionArgs.locale})` : ""} and contentType ${releaseActionArgs.contentType} already exists in release with id ${releaseId}`
1126
1120
  );
1127
1121
  }
1128
1122
  },
1129
- validateEntryContentType(contentTypeUid) {
1123
+ validateEntryData(contentTypeUid, entryDocumentId) {
1130
1124
  const contentType = strapi2.contentType(contentTypeUid);
1131
1125
  if (!contentType) {
1132
1126
  throw new errors.NotFoundError(`No content type found for uid ${contentTypeUid}`);
1133
1127
  }
1134
- if (!contentType.options?.draftAndPublish) {
1128
+ if (!contentTypes$1.hasDraftAndPublish(contentType)) {
1135
1129
  throw new errors.ValidationError(
1136
1130
  `Content type with uid ${contentTypeUid} does not have draftAndPublish enabled`
1137
1131
  );
1138
1132
  }
1133
+ if (contentType.kind === "collectionType" && !entryDocumentId) {
1134
+ throw new errors.ValidationError("Document id is required for collection type");
1135
+ }
1139
1136
  },
1140
1137
  async validatePendingReleasesLimit() {
1141
1138
  const featureCfg = strapi2.ee.features.get("cms-content-releases");
@@ -1224,10 +1221,33 @@ const createSchedulingService = ({ strapi: strapi2 }) => {
1224
1221
  }
1225
1222
  };
1226
1223
  };
1224
+ const DEFAULT_SETTINGS = {
1225
+ defaultTimezone: null
1226
+ };
1227
+ const createSettingsService = ({ strapi: strapi2 }) => {
1228
+ const getStore = async () => strapi2.store({ type: "core", name: "content-releases" });
1229
+ return {
1230
+ async update({ settings: settings2 }) {
1231
+ const store = await getStore();
1232
+ store.set({ key: "settings", value: settings2 });
1233
+ return settings2;
1234
+ },
1235
+ async find() {
1236
+ const store = await getStore();
1237
+ const settings2 = await store.get({ key: "settings" });
1238
+ return {
1239
+ ...DEFAULT_SETTINGS,
1240
+ ...settings2 || {}
1241
+ };
1242
+ }
1243
+ };
1244
+ };
1227
1245
  const services = {
1228
1246
  release: createReleaseService,
1247
+ "release-action": createReleaseActionService,
1229
1248
  "release-validation": createReleaseValidationService,
1230
- scheduling: createSchedulingService
1249
+ scheduling: createSchedulingService,
1250
+ settings: createSettingsService
1231
1251
  };
1232
1252
  const RELEASE_SCHEMA = yup.object().shape({
1233
1253
  name: yup.string().trim().required(),
@@ -1249,53 +1269,118 @@ const RELEASE_SCHEMA = yup.object().shape({
1249
1269
  otherwise: yup.string().nullable()
1250
1270
  })
1251
1271
  }).required().noUnknown();
1272
+ const SETTINGS_SCHEMA = yup.object().shape({
1273
+ defaultTimezone: yup.string().nullable().default(null)
1274
+ }).required().noUnknown();
1275
+ const FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA = yup$1.object().shape({
1276
+ contentType: yup$1.string().required(),
1277
+ entryDocumentId: yup$1.string().nullable(),
1278
+ hasEntryAttached: yup$1.string().nullable(),
1279
+ locale: yup$1.string().nullable()
1280
+ }).required().noUnknown();
1252
1281
  const validateRelease = validateYupSchema(RELEASE_SCHEMA);
1282
+ const validatefindByDocumentAttachedParams = validateYupSchema(
1283
+ FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA
1284
+ );
1253
1285
  const releaseController = {
1254
- async findMany(ctx) {
1286
+ /**
1287
+ * Find releases based on documents attached or not to the release.
1288
+ * If `hasEntryAttached` is true, it will return all releases that have the entry attached.
1289
+ * If `hasEntryAttached` is false, it will return all releases that don't have the entry attached.
1290
+ */
1291
+ async findByDocumentAttached(ctx) {
1255
1292
  const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
1256
1293
  ability: ctx.state.userAbility,
1257
1294
  model: RELEASE_MODEL_UID
1258
1295
  });
1259
1296
  await permissionsManager.validateQuery(ctx.query);
1260
1297
  const releaseService = getService("release", { strapi });
1261
- const isFindManyForContentTypeEntry = Boolean(ctx.query?.contentTypeUid && ctx.query?.entryId);
1262
- if (isFindManyForContentTypeEntry) {
1263
- const query = await permissionsManager.sanitizeQuery(ctx.query);
1264
- const contentTypeUid = query.contentTypeUid;
1265
- const entryId = query.entryId;
1266
- const hasEntryAttached = typeof query.hasEntryAttached === "string" ? JSON.parse(query.hasEntryAttached) : false;
1267
- const data = hasEntryAttached ? await releaseService.findManyWithContentTypeEntryAttached(contentTypeUid, entryId) : await releaseService.findManyWithoutContentTypeEntryAttached(contentTypeUid, entryId);
1268
- ctx.body = { data };
1298
+ const query = await permissionsManager.sanitizeQuery(ctx.query);
1299
+ await validatefindByDocumentAttachedParams(query);
1300
+ const { contentType, entryDocumentId, hasEntryAttached, locale } = query;
1301
+ const isEntryAttached = typeof hasEntryAttached === "string" ? Boolean(JSON.parse(hasEntryAttached)) : false;
1302
+ if (isEntryAttached) {
1303
+ const releases = await releaseService.findMany({
1304
+ where: {
1305
+ releasedAt: null,
1306
+ actions: {
1307
+ contentType,
1308
+ entryDocumentId: entryDocumentId ?? null,
1309
+ locale: locale ?? null
1310
+ }
1311
+ },
1312
+ populate: {
1313
+ actions: {
1314
+ fields: ["type"]
1315
+ }
1316
+ }
1317
+ });
1318
+ ctx.body = { data: releases };
1269
1319
  } else {
1270
- const query = await permissionsManager.sanitizeQuery(ctx.query);
1271
- const { results, pagination } = await releaseService.findPage(query);
1272
- const data = results.map((release2) => {
1273
- const { actions, ...releaseData } = release2;
1274
- return {
1275
- ...releaseData,
1320
+ const relatedReleases = await releaseService.findMany({
1321
+ where: {
1322
+ releasedAt: null,
1276
1323
  actions: {
1277
- meta: {
1278
- count: actions.count
1279
- }
1324
+ contentType,
1325
+ entryDocumentId: entryDocumentId ?? null,
1326
+ locale: locale ?? null
1280
1327
  }
1281
- };
1328
+ }
1282
1329
  });
1283
- const pendingReleasesCount = await strapi.db.query(RELEASE_MODEL_UID).count({
1330
+ const releases = await releaseService.findMany({
1284
1331
  where: {
1332
+ $or: [
1333
+ {
1334
+ id: {
1335
+ $notIn: relatedReleases.map((release2) => release2.id)
1336
+ }
1337
+ },
1338
+ {
1339
+ actions: null
1340
+ }
1341
+ ],
1285
1342
  releasedAt: null
1286
1343
  }
1287
1344
  });
1288
- ctx.body = { data, meta: { pagination, pendingReleasesCount } };
1345
+ ctx.body = { data: releases };
1289
1346
  }
1290
1347
  },
1348
+ async findPage(ctx) {
1349
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
1350
+ ability: ctx.state.userAbility,
1351
+ model: RELEASE_MODEL_UID
1352
+ });
1353
+ await permissionsManager.validateQuery(ctx.query);
1354
+ const releaseService = getService("release", { strapi });
1355
+ const query = await permissionsManager.sanitizeQuery(ctx.query);
1356
+ const { results, pagination } = await releaseService.findPage(query);
1357
+ const data = results.map((release2) => {
1358
+ const { actions, ...releaseData } = release2;
1359
+ return {
1360
+ ...releaseData,
1361
+ actions: {
1362
+ meta: {
1363
+ count: actions.count
1364
+ }
1365
+ }
1366
+ };
1367
+ });
1368
+ const pendingReleasesCount = await strapi.db.query(RELEASE_MODEL_UID).count({
1369
+ where: {
1370
+ releasedAt: null
1371
+ }
1372
+ });
1373
+ ctx.body = { data, meta: { pagination, pendingReleasesCount } };
1374
+ },
1291
1375
  async findOne(ctx) {
1292
1376
  const id = ctx.params.id;
1293
1377
  const releaseService = getService("release", { strapi });
1378
+ const releaseActionService = getService("release-action", { strapi });
1294
1379
  const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
1295
1380
  if (!release2) {
1296
1381
  throw new errors.NotFoundError(`Release not found for id: ${id}`);
1297
1382
  }
1298
- const count = await releaseService.countActions({
1383
+ const count = await releaseActionService.countActions({
1299
1384
  filters: {
1300
1385
  release: id
1301
1386
  }
@@ -1314,35 +1399,43 @@ const releaseController = {
1314
1399
  };
1315
1400
  ctx.body = { data };
1316
1401
  },
1317
- async mapEntriesToReleases(ctx) {
1318
- const { contentTypeUid, entriesIds } = ctx.query;
1319
- if (!contentTypeUid || !entriesIds) {
1320
- throw new errors.ValidationError("Missing required query parameters");
1321
- }
1322
- const releaseService = getService("release", { strapi });
1323
- const releasesWithActions = await releaseService.findManyWithContentTypeEntryAttached(
1324
- contentTypeUid,
1325
- entriesIds
1326
- );
1327
- const mappedEntriesInReleases = releasesWithActions.reduce(
1328
- // TODO: Fix for v5 removed mappedEntriedToRelease
1329
- (acc, release2) => {
1330
- release2.actions.forEach((action) => {
1331
- if (!acc[action.entry.id]) {
1332
- acc[action.entry.id] = [{ id: release2.id, name: release2.name }];
1333
- } else {
1334
- acc[action.entry.id].push({ id: release2.id, name: release2.name });
1335
- }
1336
- });
1337
- return acc;
1338
- },
1339
- // TODO: Fix for v5 removed mappedEntriedToRelease
1340
- {}
1341
- );
1342
- ctx.body = {
1343
- data: mappedEntriesInReleases
1344
- };
1345
- },
1402
+ /* @TODO: Migrate to new api
1403
+ async mapEntriesToReleases(ctx: Koa.Context) {
1404
+ const { contentTypeUid, entriesIds } = ctx.query;
1405
+
1406
+ if (!contentTypeUid || !entriesIds) {
1407
+ throw new errors.ValidationError('Missing required query parameters');
1408
+ }
1409
+
1410
+ const releaseService = getService('release', { strapi });
1411
+
1412
+ const releasesWithActions = await releaseService.findMany(
1413
+ contentTypeUid,
1414
+ entriesIds
1415
+ );
1416
+
1417
+ const mappedEntriesInReleases = releasesWithActions.reduce(
1418
+ // TODO: Fix for v5 removed mappedEntriedToRelease
1419
+ (acc: MapEntriesToReleases.Response['data'], release: Release) => {
1420
+ release.actions.forEach((action) => {
1421
+ if (!acc[action.entry.id]) {
1422
+ acc[action.entry.id] = [{ id: release.id, name: release.name }];
1423
+ } else {
1424
+ acc[action.entry.id].push({ id: release.id, name: release.name });
1425
+ }
1426
+ });
1427
+
1428
+ return acc;
1429
+ },
1430
+ // TODO: Fix for v5 removed mappedEntriedToRelease
1431
+ {} as MapEntriesToReleases.Response['data']
1432
+ );
1433
+
1434
+ ctx.body = {
1435
+ data: mappedEntriesInReleases,
1436
+ };
1437
+ },
1438
+ */
1346
1439
  async create(ctx) {
1347
1440
  const user = ctx.state.user;
1348
1441
  const releaseArgs = ctx.request.body;
@@ -1381,18 +1474,18 @@ const releaseController = {
1381
1474
  };
1382
1475
  },
1383
1476
  async publish(ctx) {
1384
- const user = ctx.state.user;
1385
1477
  const id = ctx.params.id;
1386
1478
  const releaseService = getService("release", { strapi });
1387
- const release2 = await releaseService.publish(id, { user });
1479
+ const releaseActionService = getService("release-action", { strapi });
1480
+ const release2 = await releaseService.publish(id);
1388
1481
  const [countPublishActions, countUnpublishActions] = await Promise.all([
1389
- releaseService.countActions({
1482
+ releaseActionService.countActions({
1390
1483
  filters: {
1391
1484
  release: id,
1392
1485
  type: "publish"
1393
1486
  }
1394
1487
  }),
1395
- releaseService.countActions({
1488
+ releaseActionService.countActions({
1396
1489
  filters: {
1397
1490
  release: id,
1398
1491
  type: "unpublish"
@@ -1410,42 +1503,47 @@ const releaseController = {
1410
1503
  }
1411
1504
  };
1412
1505
  const RELEASE_ACTION_SCHEMA = yup$1.object().shape({
1413
- entry: yup$1.object().shape({
1414
- id: yup$1.strapiID().required(),
1415
- contentType: yup$1.string().required()
1416
- }).required(),
1506
+ contentType: yup$1.string().required(),
1507
+ entryDocumentId: yup$1.strapiID(),
1508
+ locale: yup$1.string(),
1417
1509
  type: yup$1.string().oneOf(["publish", "unpublish"]).required()
1418
1510
  });
1419
1511
  const RELEASE_ACTION_UPDATE_SCHEMA = yup$1.object().shape({
1420
1512
  type: yup$1.string().oneOf(["publish", "unpublish"]).required()
1421
1513
  });
1514
+ const FIND_MANY_ACTIONS_PARAMS = yup$1.object().shape({
1515
+ groupBy: yup$1.string().oneOf(["action", "contentType", "locale"])
1516
+ });
1422
1517
  const validateReleaseAction = validateYupSchema(RELEASE_ACTION_SCHEMA);
1423
1518
  const validateReleaseActionUpdateSchema = validateYupSchema(RELEASE_ACTION_UPDATE_SCHEMA);
1519
+ const validateFindManyActionsParams = validateYupSchema(FIND_MANY_ACTIONS_PARAMS);
1424
1520
  const releaseActionController = {
1425
1521
  async create(ctx) {
1426
1522
  const releaseId = ctx.params.releaseId;
1427
1523
  const releaseActionArgs = ctx.request.body;
1428
1524
  await validateReleaseAction(releaseActionArgs);
1429
- const releaseService = getService("release", { strapi });
1430
- const releaseAction2 = await releaseService.createAction(releaseId, releaseActionArgs);
1525
+ const releaseActionService = getService("release-action", { strapi });
1526
+ const releaseAction2 = await releaseActionService.create(releaseId, releaseActionArgs);
1431
1527
  ctx.created({
1432
1528
  data: releaseAction2
1433
1529
  });
1434
1530
  },
1435
- async createMany(ctx) {
1436
- const releaseId = ctx.params.releaseId;
1437
- const releaseActionsArgs = ctx.request.body;
1531
+ /*
1532
+ async createMany(ctx: Koa.Context) {
1533
+ const releaseId: CreateManyReleaseActions.Request['params']['releaseId'] = ctx.params.releaseId;
1534
+ const releaseActionsArgs = ctx.request.body as CreateManyReleaseActions.Request['body'];
1438
1535
  await Promise.all(
1439
1536
  releaseActionsArgs.map((releaseActionArgs) => validateReleaseAction(releaseActionArgs))
1440
1537
  );
1441
- const releaseService = getService("release", { strapi });
1538
+ const releaseActionService = getService('release-action', { strapi });
1442
1539
  const releaseActions = await strapi.db.transaction(async () => {
1443
- const releaseActions2 = await Promise.all(
1540
+ const releaseActions = await Promise.all(
1444
1541
  releaseActionsArgs.map(async (releaseActionArgs) => {
1445
1542
  try {
1446
- const action = await releaseService.createAction(releaseId, releaseActionArgs);
1543
+ const action = await releaseActionService.create(releaseId, releaseActionArgs);
1447
1544
  return action;
1448
1545
  } catch (error) {
1546
+ // If the entry is already in the release, we don't want to throw an error, so we catch and ignore it
1449
1547
  if (error instanceof AlreadyOnReleaseError) {
1450
1548
  return null;
1451
1549
  }
@@ -1453,27 +1551,35 @@ const releaseActionController = {
1453
1551
  }
1454
1552
  })
1455
1553
  );
1456
- return releaseActions2;
1554
+ return releaseActions;
1457
1555
  });
1458
1556
  const newReleaseActions = releaseActions.filter((action) => action !== null);
1459
1557
  ctx.created({
1460
1558
  data: newReleaseActions,
1461
1559
  meta: {
1462
1560
  entriesAlreadyInRelease: releaseActions.length - newReleaseActions.length,
1463
- totalEntries: releaseActions.length
1464
- }
1561
+ totalEntries: releaseActions.length,
1562
+ },
1465
1563
  });
1466
1564
  },
1565
+ */
1467
1566
  async findMany(ctx) {
1468
1567
  const releaseId = ctx.params.releaseId;
1469
1568
  const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
1470
1569
  ability: ctx.state.userAbility,
1471
1570
  model: RELEASE_ACTION_MODEL_UID
1472
1571
  });
1572
+ await validateFindManyActionsParams(ctx.query);
1573
+ if (ctx.query.groupBy) {
1574
+ if (!["action", "contentType", "locale"].includes(ctx.query.groupBy)) {
1575
+ ctx.badRequest("Invalid groupBy parameter");
1576
+ }
1577
+ }
1578
+ ctx.query.sort = ctx.query.groupBy === "action" ? "type" : ctx.query.groupBy;
1579
+ delete ctx.query.groupBy;
1473
1580
  const query = await permissionsManager.sanitizeQuery(ctx.query);
1474
- const releaseService = getService("release", { strapi });
1475
- const { results, pagination } = await releaseService.findActions(releaseId, {
1476
- sort: query.groupBy === "action" ? "type" : query.groupBy,
1581
+ const releaseActionService = getService("release-action", { strapi });
1582
+ const { results, pagination } = await releaseActionService.findPage(releaseId, {
1477
1583
  ...query
1478
1584
  });
1479
1585
  const contentTypeOutputSanitizers = results.reduce((acc, action) => {
@@ -1489,10 +1595,11 @@ const releaseActionController = {
1489
1595
  }, {});
1490
1596
  const sanitizedResults = await async.map(results, async (action) => ({
1491
1597
  ...action,
1492
- entry: await contentTypeOutputSanitizers[action.contentType](action.entry)
1598
+ entry: action.entry ? await contentTypeOutputSanitizers[action.contentType](action.entry) : {}
1493
1599
  }));
1494
- const groupedData = await releaseService.groupActions(sanitizedResults, query.groupBy);
1495
- const contentTypes2 = releaseService.getContentTypeModelsFromActions(results);
1600
+ const groupedData = await releaseActionService.groupActions(sanitizedResults, query.sort);
1601
+ const contentTypes2 = releaseActionService.getContentTypeModelsFromActions(results);
1602
+ const releaseService = getService("release", { strapi });
1496
1603
  const components = await releaseService.getAllComponents();
1497
1604
  ctx.body = {
1498
1605
  data: groupedData,
@@ -1508,8 +1615,8 @@ const releaseActionController = {
1508
1615
  const releaseId = ctx.params.releaseId;
1509
1616
  const releaseActionUpdateArgs = ctx.request.body;
1510
1617
  await validateReleaseActionUpdateSchema(releaseActionUpdateArgs);
1511
- const releaseService = getService("release", { strapi });
1512
- const updatedAction = await releaseService.updateAction(
1618
+ const releaseActionService = getService("release-action", { strapi });
1619
+ const updatedAction = await releaseActionService.update(
1513
1620
  actionId,
1514
1621
  releaseId,
1515
1622
  releaseActionUpdateArgs
@@ -1521,21 +1628,58 @@ const releaseActionController = {
1521
1628
  async delete(ctx) {
1522
1629
  const actionId = ctx.params.actionId;
1523
1630
  const releaseId = ctx.params.releaseId;
1524
- const releaseService = getService("release", { strapi });
1525
- const deletedReleaseAction = await releaseService.deleteAction(actionId, releaseId);
1631
+ const releaseActionService = getService("release-action", { strapi });
1632
+ const deletedReleaseAction = await releaseActionService.delete(actionId, releaseId);
1526
1633
  ctx.body = {
1527
1634
  data: deletedReleaseAction
1528
1635
  };
1529
1636
  }
1530
1637
  };
1531
- const controllers = { release: releaseController, "release-action": releaseActionController };
1638
+ const validateSettings = validateYupSchema(SETTINGS_SCHEMA);
1639
+ const settingsController = {
1640
+ async find(ctx) {
1641
+ const settingsService = getService("settings", { strapi });
1642
+ const settings2 = await settingsService.find();
1643
+ ctx.body = { data: settings2 };
1644
+ },
1645
+ async update(ctx) {
1646
+ const settingsBody = ctx.request.body;
1647
+ const settings2 = await validateSettings(settingsBody);
1648
+ const settingsService = getService("settings", { strapi });
1649
+ const updatedSettings = await settingsService.update({ settings: settings2 });
1650
+ ctx.body = { data: updatedSettings };
1651
+ }
1652
+ };
1653
+ const controllers = {
1654
+ release: releaseController,
1655
+ "release-action": releaseActionController,
1656
+ settings: settingsController
1657
+ };
1532
1658
  const release = {
1533
1659
  type: "admin",
1534
1660
  routes: [
1661
+ /*
1662
+ {
1663
+ method: 'GET',
1664
+ path: '/mapEntriesToReleases',
1665
+ handler: 'release.mapEntriesToReleases',
1666
+ config: {
1667
+ policies: [
1668
+ 'admin::isAuthenticatedAdmin',
1669
+ {
1670
+ name: 'admin::hasPermissions',
1671
+ config: {
1672
+ actions: ['plugin::content-releases.read'],
1673
+ },
1674
+ },
1675
+ ],
1676
+ },
1677
+ },
1678
+ */
1535
1679
  {
1536
1680
  method: "GET",
1537
- path: "/mapEntriesToReleases",
1538
- handler: "release.mapEntriesToReleases",
1681
+ path: "/getByDocumentAttached",
1682
+ handler: "release.findByDocumentAttached",
1539
1683
  config: {
1540
1684
  policies: [
1541
1685
  "admin::isAuthenticatedAdmin",
@@ -1567,7 +1711,7 @@ const release = {
1567
1711
  {
1568
1712
  method: "GET",
1569
1713
  path: "/",
1570
- handler: "release.findMany",
1714
+ handler: "release.findPage",
1571
1715
  config: {
1572
1716
  policies: [
1573
1717
  "admin::isAuthenticatedAdmin",
@@ -1665,22 +1809,24 @@ const releaseAction = {
1665
1809
  ]
1666
1810
  }
1667
1811
  },
1812
+ /*
1668
1813
  {
1669
- method: "POST",
1670
- path: "/:releaseId/actions/bulk",
1671
- handler: "release-action.createMany",
1814
+ method: 'POST',
1815
+ path: '/:releaseId/actions/bulk',
1816
+ handler: 'release-action.createMany',
1672
1817
  config: {
1673
1818
  policies: [
1674
- "admin::isAuthenticatedAdmin",
1819
+ 'admin::isAuthenticatedAdmin',
1675
1820
  {
1676
- name: "admin::hasPermissions",
1821
+ name: 'admin::hasPermissions',
1677
1822
  config: {
1678
- actions: ["plugin::content-releases.create-action"]
1679
- }
1680
- }
1681
- ]
1682
- }
1823
+ actions: ['plugin::content-releases.create-action'],
1824
+ },
1825
+ },
1826
+ ],
1827
+ },
1683
1828
  },
1829
+ */
1684
1830
  {
1685
1831
  method: "GET",
1686
1832
  path: "/:releaseId/actions",
@@ -1731,7 +1877,45 @@ const releaseAction = {
1731
1877
  }
1732
1878
  ]
1733
1879
  };
1880
+ const settings = {
1881
+ type: "admin",
1882
+ routes: [
1883
+ {
1884
+ method: "GET",
1885
+ path: "/settings",
1886
+ handler: "settings.find",
1887
+ config: {
1888
+ policies: [
1889
+ "admin::isAuthenticatedAdmin",
1890
+ {
1891
+ name: "admin::hasPermissions",
1892
+ config: {
1893
+ actions: ["plugin::content-releases.settings.read"]
1894
+ }
1895
+ }
1896
+ ]
1897
+ }
1898
+ },
1899
+ {
1900
+ method: "PUT",
1901
+ path: "/settings",
1902
+ handler: "settings.update",
1903
+ config: {
1904
+ policies: [
1905
+ "admin::isAuthenticatedAdmin",
1906
+ {
1907
+ name: "admin::hasPermissions",
1908
+ config: {
1909
+ actions: ["plugin::content-releases.settings.update"]
1910
+ }
1911
+ }
1912
+ ]
1913
+ }
1914
+ }
1915
+ ]
1916
+ };
1734
1917
  const routes = {
1918
+ settings,
1735
1919
  release,
1736
1920
  "release-action": releaseAction
1737
1921
  };