@strapi/content-releases 0.0.0-next.78ea7925e0dad75936ae2e937a041a0666e3d65a → 0.0.0-next.7f1333f1967e625c57ab16648c057aea08c9dddb

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 (140) hide show
  1. package/LICENSE +17 -1
  2. package/dist/_chunks/{App-p8aKBitd.js → App-BKB1esYS.js} +600 -551
  3. package/dist/_chunks/App-BKB1esYS.js.map +1 -0
  4. package/dist/_chunks/{App-bpzO2Ljh.mjs → App-Cne--1Z8.mjs} +582 -531
  5. package/dist/_chunks/App-Cne--1Z8.mjs.map +1 -0
  6. package/dist/_chunks/{PurchaseContentReleases-YhAPgpG9.js → PurchaseContentReleases-Be3acS2L.js} +8 -7
  7. package/dist/_chunks/PurchaseContentReleases-Be3acS2L.js.map +1 -0
  8. package/dist/_chunks/{PurchaseContentReleases-Clm0iACO.mjs → PurchaseContentReleases-_MxP6-Dt.mjs} +9 -8
  9. package/dist/_chunks/PurchaseContentReleases-_MxP6-Dt.mjs.map +1 -0
  10. package/dist/_chunks/ReleasesSettingsPage-C1WwGWIH.mjs +178 -0
  11. package/dist/_chunks/ReleasesSettingsPage-C1WwGWIH.mjs.map +1 -0
  12. package/dist/_chunks/ReleasesSettingsPage-kuXIwpWp.js +178 -0
  13. package/dist/_chunks/ReleasesSettingsPage-kuXIwpWp.js.map +1 -0
  14. package/dist/_chunks/{en-gcJJ5htG.js → en-CmYoEnA7.js} +19 -4
  15. package/dist/_chunks/en-CmYoEnA7.js.map +1 -0
  16. package/dist/_chunks/{en-WuuhP6Bn.mjs → en-D0yVZFqf.mjs} +19 -4
  17. package/dist/_chunks/en-D0yVZFqf.mjs.map +1 -0
  18. package/dist/_chunks/index-5Odi61vw.js +1381 -0
  19. package/dist/_chunks/index-5Odi61vw.js.map +1 -0
  20. package/dist/_chunks/index-Cy7qwpaU.mjs +1362 -0
  21. package/dist/_chunks/index-Cy7qwpaU.mjs.map +1 -0
  22. package/dist/_chunks/schemas-BE1LxE9J.js +62 -0
  23. package/dist/_chunks/schemas-BE1LxE9J.js.map +1 -0
  24. package/dist/_chunks/schemas-DdA2ic2U.mjs +44 -0
  25. package/dist/_chunks/schemas-DdA2ic2U.mjs.map +1 -0
  26. package/dist/admin/index.js +1 -15
  27. package/dist/admin/index.js.map +1 -1
  28. package/dist/admin/index.mjs +2 -16
  29. package/dist/admin/index.mjs.map +1 -1
  30. package/dist/admin/src/components/RelativeTime.d.ts +28 -0
  31. package/dist/admin/src/components/ReleaseAction.d.ts +3 -0
  32. package/dist/admin/src/components/ReleaseActionMenu.d.ts +26 -0
  33. package/dist/admin/src/components/ReleaseActionModal.d.ts +24 -0
  34. package/dist/admin/src/components/ReleaseActionOptions.d.ts +9 -0
  35. package/dist/admin/src/components/ReleaseListCell.d.ts +28 -0
  36. package/dist/admin/src/components/ReleaseModal.d.ts +17 -0
  37. package/dist/admin/src/components/ReleasesPanel.d.ts +3 -0
  38. package/dist/admin/src/constants.d.ts +76 -0
  39. package/dist/admin/src/index.d.ts +3 -0
  40. package/dist/admin/src/modules/hooks.d.ts +7 -0
  41. package/dist/admin/src/pages/App.d.ts +1 -0
  42. package/dist/admin/src/pages/PurchaseContentReleases.d.ts +2 -0
  43. package/dist/admin/src/pages/ReleaseDetailsPage.d.ts +2 -0
  44. package/dist/admin/src/pages/ReleasesPage.d.ts +8 -0
  45. package/dist/admin/src/pages/ReleasesSettingsPage.d.ts +1 -0
  46. package/dist/admin/src/pages/tests/mockReleaseDetailsPageData.d.ts +181 -0
  47. package/dist/admin/src/pages/tests/mockReleasesPageData.d.ts +39 -0
  48. package/dist/admin/src/pluginId.d.ts +1 -0
  49. package/dist/admin/src/services/release.d.ts +112 -0
  50. package/dist/admin/src/store/hooks.d.ts +7 -0
  51. package/dist/admin/src/utils/api.d.ts +6 -0
  52. package/dist/admin/src/utils/prefixPluginTranslations.d.ts +3 -0
  53. package/dist/admin/src/utils/time.d.ts +10 -0
  54. package/dist/admin/src/validation/schemas.d.ts +6 -0
  55. package/dist/server/index.js +974 -665
  56. package/dist/server/index.js.map +1 -1
  57. package/dist/server/index.mjs +975 -665
  58. package/dist/server/index.mjs.map +1 -1
  59. package/dist/server/src/bootstrap.d.ts +5 -0
  60. package/dist/server/src/bootstrap.d.ts.map +1 -0
  61. package/dist/server/src/constants.d.ts +21 -0
  62. package/dist/server/src/constants.d.ts.map +1 -0
  63. package/dist/server/src/content-types/index.d.ts +97 -0
  64. package/dist/server/src/content-types/index.d.ts.map +1 -0
  65. package/dist/server/src/content-types/release/index.d.ts +48 -0
  66. package/dist/server/src/content-types/release/index.d.ts.map +1 -0
  67. package/dist/server/src/content-types/release/schema.d.ts +47 -0
  68. package/dist/server/src/content-types/release/schema.d.ts.map +1 -0
  69. package/dist/server/src/content-types/release-action/index.d.ts +48 -0
  70. package/dist/server/src/content-types/release-action/index.d.ts.map +1 -0
  71. package/dist/server/src/content-types/release-action/schema.d.ts +47 -0
  72. package/dist/server/src/content-types/release-action/schema.d.ts.map +1 -0
  73. package/dist/server/src/controllers/index.d.ts +25 -0
  74. package/dist/server/src/controllers/index.d.ts.map +1 -0
  75. package/dist/server/src/controllers/release-action.d.ts +10 -0
  76. package/dist/server/src/controllers/release-action.d.ts.map +1 -0
  77. package/dist/server/src/controllers/release.d.ts +18 -0
  78. package/dist/server/src/controllers/release.d.ts.map +1 -0
  79. package/dist/server/src/controllers/settings.d.ts +11 -0
  80. package/dist/server/src/controllers/settings.d.ts.map +1 -0
  81. package/dist/server/src/controllers/validation/release-action.d.ts +14 -0
  82. package/dist/server/src/controllers/validation/release-action.d.ts.map +1 -0
  83. package/dist/server/src/controllers/validation/release.d.ts +4 -0
  84. package/dist/server/src/controllers/validation/release.d.ts.map +1 -0
  85. package/dist/server/src/controllers/validation/settings.d.ts +3 -0
  86. package/dist/server/src/controllers/validation/settings.d.ts.map +1 -0
  87. package/dist/server/src/destroy.d.ts +5 -0
  88. package/dist/server/src/destroy.d.ts.map +1 -0
  89. package/dist/server/src/index.d.ts +2115 -0
  90. package/dist/server/src/index.d.ts.map +1 -0
  91. package/dist/server/src/middlewares/documents.d.ts +6 -0
  92. package/dist/server/src/middlewares/documents.d.ts.map +1 -0
  93. package/dist/server/src/migrations/database/5.0.0-document-id-in-actions.d.ts +9 -0
  94. package/dist/server/src/migrations/database/5.0.0-document-id-in-actions.d.ts.map +1 -0
  95. package/dist/server/src/migrations/index.d.ts +13 -0
  96. package/dist/server/src/migrations/index.d.ts.map +1 -0
  97. package/dist/server/src/register.d.ts +5 -0
  98. package/dist/server/src/register.d.ts.map +1 -0
  99. package/dist/server/src/routes/index.d.ts +51 -0
  100. package/dist/server/src/routes/index.d.ts.map +1 -0
  101. package/dist/server/src/routes/release-action.d.ts +18 -0
  102. package/dist/server/src/routes/release-action.d.ts.map +1 -0
  103. package/dist/server/src/routes/release.d.ts +18 -0
  104. package/dist/server/src/routes/release.d.ts.map +1 -0
  105. package/dist/server/src/routes/settings.d.ts +18 -0
  106. package/dist/server/src/routes/settings.d.ts.map +1 -0
  107. package/dist/server/src/services/index.d.ts +1828 -0
  108. package/dist/server/src/services/index.d.ts.map +1 -0
  109. package/dist/server/src/services/release-action.d.ts +38 -0
  110. package/dist/server/src/services/release-action.d.ts.map +1 -0
  111. package/dist/server/src/services/release.d.ts +31 -0
  112. package/dist/server/src/services/release.d.ts.map +1 -0
  113. package/dist/server/src/services/scheduling.d.ts +18 -0
  114. package/dist/server/src/services/scheduling.d.ts.map +1 -0
  115. package/dist/server/src/services/settings.d.ts +13 -0
  116. package/dist/server/src/services/settings.d.ts.map +1 -0
  117. package/dist/server/src/services/validation.d.ts +18 -0
  118. package/dist/server/src/services/validation.d.ts.map +1 -0
  119. package/dist/server/src/utils/index.d.ts +35 -0
  120. package/dist/server/src/utils/index.d.ts.map +1 -0
  121. package/dist/shared/contracts/release-actions.d.ts +130 -0
  122. package/dist/shared/contracts/release-actions.d.ts.map +1 -0
  123. package/dist/shared/contracts/releases.d.ts +184 -0
  124. package/dist/shared/contracts/releases.d.ts.map +1 -0
  125. package/dist/shared/contracts/settings.d.ts +39 -0
  126. package/dist/shared/contracts/settings.d.ts.map +1 -0
  127. package/dist/shared/types.d.ts +24 -0
  128. package/dist/shared/types.d.ts.map +1 -0
  129. package/package.json +33 -38
  130. package/dist/_chunks/App-bpzO2Ljh.mjs.map +0 -1
  131. package/dist/_chunks/App-p8aKBitd.js.map +0 -1
  132. package/dist/_chunks/PurchaseContentReleases-Clm0iACO.mjs.map +0 -1
  133. package/dist/_chunks/PurchaseContentReleases-YhAPgpG9.js.map +0 -1
  134. package/dist/_chunks/en-WuuhP6Bn.mjs.map +0 -1
  135. package/dist/_chunks/en-gcJJ5htG.js.map +0 -1
  136. package/dist/_chunks/index-AECgcaDa.mjs +0 -1013
  137. package/dist/_chunks/index-AECgcaDa.mjs.map +0 -1
  138. package/dist/_chunks/index-fP3qoWZ4.js +0 -1034
  139. package/dist/_chunks/index-fP3qoWZ4.js.map +0 -1
  140. package/strapi-server.js +0 -3
@@ -3,7 +3,6 @@ const utils = require("@strapi/utils");
3
3
  const isEqual = require("lodash/isEqual");
4
4
  const lodash = require("lodash");
5
5
  const _ = require("lodash/fp");
6
- const EE = require("@strapi/strapi/dist/utils/ee");
7
6
  const nodeSchedule = require("node-schedule");
8
7
  const yup = require("yup");
9
8
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
@@ -27,7 +26,6 @@ function _interopNamespace(e) {
27
26
  }
28
27
  const isEqual__default = /* @__PURE__ */ _interopDefault(isEqual);
29
28
  const ___default = /* @__PURE__ */ _interopDefault(_);
30
- const EE__default = /* @__PURE__ */ _interopDefault(EE);
31
29
  const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
32
30
  const RELEASE_MODEL_UID = "plugin::content-releases.release";
33
31
  const RELEASE_ACTION_MODEL_UID = "plugin::content-releases.release-action";
@@ -73,21 +71,38 @@ const ACTIONS = [
73
71
  displayName: "Add an entry to a release",
74
72
  uid: "create-action",
75
73
  pluginName: "content-releases"
74
+ },
75
+ // Settings
76
+ {
77
+ uid: "settings.read",
78
+ section: "settings",
79
+ displayName: "Read",
80
+ category: "content releases",
81
+ subCategory: "options",
82
+ pluginName: "content-releases"
83
+ },
84
+ {
85
+ uid: "settings.update",
86
+ section: "settings",
87
+ displayName: "Edit",
88
+ category: "content releases",
89
+ subCategory: "options",
90
+ pluginName: "content-releases"
76
91
  }
77
92
  ];
78
93
  const ALLOWED_WEBHOOK_EVENTS = {
79
94
  RELEASES_PUBLISH: "releases.publish"
80
95
  };
81
- const getService = (name, { strapi: strapi2 } = { strapi: global.strapi }) => {
96
+ const getService = (name, { strapi: strapi2 }) => {
82
97
  return strapi2.plugin("content-releases").service(name);
83
98
  };
84
- const getPopulatedEntry = async (contentTypeUid, entryId, { strapi: strapi2 } = { strapi: global.strapi }) => {
99
+ const getDraftEntryValidStatus = async ({ contentType, documentId, locale }, { strapi: strapi2 }) => {
85
100
  const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
86
- const populate = await populateBuilderService(contentTypeUid).populateDeep(Infinity).build();
87
- const entry = await strapi2.entityService.findOne(contentTypeUid, entryId, { populate });
88
- return entry;
101
+ const populate = await populateBuilderService(contentType).populateDeep(Infinity).build();
102
+ const entry = await getEntry({ contentType, documentId, locale, populate }, { strapi: strapi2 });
103
+ return isEntryValid(contentType, entry, { strapi: strapi2 });
89
104
  };
90
- const getEntryValidStatus = async (contentTypeUid, entry, { strapi: strapi2 } = { strapi: global.strapi }) => {
105
+ const isEntryValid = async (contentTypeUid, entry, { strapi: strapi2 }) => {
91
106
  try {
92
107
  await strapi2.entityValidator.validateEntityCreation(
93
108
  strapi2.getModel(contentTypeUid),
@@ -101,6 +116,38 @@ const getEntryValidStatus = async (contentTypeUid, entry, { strapi: strapi2 } =
101
116
  return false;
102
117
  }
103
118
  };
119
+ const getEntry = async ({
120
+ contentType,
121
+ documentId,
122
+ locale,
123
+ populate,
124
+ status = "draft"
125
+ }, { strapi: strapi2 }) => {
126
+ if (documentId) {
127
+ return strapi2.documents(contentType).findOne({ documentId, locale, populate, status });
128
+ }
129
+ return strapi2.documents(contentType).findFirst({ locale, populate, status });
130
+ };
131
+ const getEntryStatus = async (contentType, entry) => {
132
+ if (entry.publishedAt) {
133
+ return "published";
134
+ }
135
+ const publishedEntry = await strapi.documents(contentType).findOne({
136
+ documentId: entry.documentId,
137
+ locale: entry.locale,
138
+ status: "published",
139
+ fields: ["updatedAt"]
140
+ });
141
+ if (!publishedEntry) {
142
+ return "draft";
143
+ }
144
+ const entryUpdatedAt = new Date(entry.updatedAt).getTime();
145
+ const publishedEntryUpdatedAt = new Date(publishedEntry.updatedAt).getTime();
146
+ if (entryUpdatedAt > publishedEntryUpdatedAt) {
147
+ return "modified";
148
+ }
149
+ return "published";
150
+ };
104
151
  async function deleteActionsOnDisableDraftAndPublish({
105
152
  oldContentTypes,
106
153
  contentTypes: contentTypes2
@@ -122,7 +169,7 @@ async function deleteActionsOnDisableDraftAndPublish({
122
169
  async function deleteActionsOnDeleteContentType({ oldContentTypes, contentTypes: contentTypes2 }) {
123
170
  const deletedContentTypes = lodash.difference(lodash.keys(oldContentTypes), lodash.keys(contentTypes2)) ?? [];
124
171
  if (deletedContentTypes.length) {
125
- await utils.mapAsync(deletedContentTypes, async (deletedContentTypeUID) => {
172
+ await utils.async.map(deletedContentTypes, async (deletedContentTypeUID) => {
126
173
  return strapi.db?.queryBuilder(RELEASE_ACTION_MODEL_UID).delete().where({ contentType: deletedContentTypeUID }).execute();
127
174
  });
128
175
  }
@@ -141,25 +188,27 @@ async function migrateIsValidAndStatusReleases() {
141
188
  }
142
189
  }
143
190
  });
144
- utils.mapAsync(releasesWithoutStatus, async (release2) => {
191
+ utils.async.map(releasesWithoutStatus, async (release2) => {
145
192
  const actions = release2.actions;
146
193
  const notValidatedActions = actions.filter((action) => action.isEntryValid === null);
147
194
  for (const action of notValidatedActions) {
148
195
  if (action.entry) {
149
- const populatedEntry = await getPopulatedEntry(action.contentType, action.entry.id, {
150
- strapi
196
+ const isEntryValid2 = getDraftEntryValidStatus(
197
+ {
198
+ contentType: action.contentType,
199
+ documentId: action.entryDocumentId,
200
+ locale: action.locale
201
+ },
202
+ { strapi }
203
+ );
204
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
205
+ where: {
206
+ id: action.id
207
+ },
208
+ data: {
209
+ isEntryValid: isEntryValid2
210
+ }
151
211
  });
152
- if (populatedEntry) {
153
- const isEntryValid = getEntryValidStatus(action.contentType, populatedEntry, { strapi });
154
- await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
155
- where: {
156
- id: action.id
157
- },
158
- data: {
159
- isEntryValid
160
- }
161
- });
162
- }
163
212
  }
164
213
  }
165
214
  return getService("release", { strapi }).updateReleaseStatus(release2.id);
@@ -172,7 +221,7 @@ async function migrateIsValidAndStatusReleases() {
172
221
  }
173
222
  }
174
223
  });
175
- utils.mapAsync(publishedReleases, async (release2) => {
224
+ utils.async.map(publishedReleases, async (release2) => {
176
225
  return strapi.db.query(RELEASE_MODEL_UID).update({
177
226
  where: {
178
227
  id: release2.id
@@ -189,7 +238,7 @@ async function revalidateChangedContentTypes({ oldContentTypes, contentTypes: co
189
238
  (uid) => oldContentTypes[uid]?.options?.draftAndPublish
190
239
  );
191
240
  const releasesAffected = /* @__PURE__ */ new Set();
192
- utils.mapAsync(contentTypesWithDraftAndPublish, async (contentTypeUID) => {
241
+ utils.async.map(contentTypesWithDraftAndPublish, async (contentTypeUID) => {
193
242
  const oldContentType = oldContentTypes[contentTypeUID];
194
243
  const contentType = contentTypes2[contentTypeUID];
195
244
  if (!isEqual__default.default(oldContentType?.attributes, contentType?.attributes)) {
@@ -202,30 +251,30 @@ async function revalidateChangedContentTypes({ oldContentTypes, contentTypes: co
202
251
  release: true
203
252
  }
204
253
  });
205
- await utils.mapAsync(actions, async (action) => {
206
- if (action.entry && action.release) {
207
- const populatedEntry = await getPopulatedEntry(contentTypeUID, action.entry.id, {
208
- strapi
254
+ await utils.async.map(actions, async (action) => {
255
+ if (action.entry && action.release && action.type === "publish") {
256
+ const isEntryValid2 = await getDraftEntryValidStatus(
257
+ {
258
+ contentType: contentTypeUID,
259
+ documentId: action.entryDocumentId,
260
+ locale: action.locale
261
+ },
262
+ { strapi }
263
+ );
264
+ releasesAffected.add(action.release.id);
265
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
266
+ where: {
267
+ id: action.id
268
+ },
269
+ data: {
270
+ isEntryValid: isEntryValid2
271
+ }
209
272
  });
210
- if (populatedEntry) {
211
- const isEntryValid = await getEntryValidStatus(contentTypeUID, populatedEntry, {
212
- strapi
213
- });
214
- releasesAffected.add(action.release.id);
215
- await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
216
- where: {
217
- id: action.id
218
- },
219
- data: {
220
- isEntryValid
221
- }
222
- });
223
- }
224
273
  }
225
274
  });
226
275
  }
227
276
  }).then(() => {
228
- utils.mapAsync(releasesAffected, async (releaseId) => {
277
+ utils.async.map(releasesAffected, async (releaseId) => {
229
278
  return getService("release", { strapi }).updateReleaseStatus(releaseId);
230
279
  });
231
280
  });
@@ -235,13 +284,16 @@ async function disableContentTypeLocalized({ oldContentTypes, contentTypes: cont
235
284
  if (!oldContentTypes) {
236
285
  return;
237
286
  }
287
+ const i18nPlugin = strapi.plugin("i18n");
288
+ if (!i18nPlugin) {
289
+ return;
290
+ }
238
291
  for (const uid in contentTypes2) {
239
292
  if (!oldContentTypes[uid]) {
240
293
  continue;
241
294
  }
242
295
  const oldContentType = oldContentTypes[uid];
243
296
  const contentType = contentTypes2[uid];
244
- const i18nPlugin = strapi.plugin("i18n");
245
297
  const { isLocalizedContentType } = i18nPlugin.service("content-types");
246
298
  if (isLocalizedContentType(oldContentType) && !isLocalizedContentType(contentType)) {
247
299
  await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
@@ -254,13 +306,16 @@ async function enableContentTypeLocalized({ oldContentTypes, contentTypes: conte
254
306
  if (!oldContentTypes) {
255
307
  return;
256
308
  }
309
+ const i18nPlugin = strapi.plugin("i18n");
310
+ if (!i18nPlugin) {
311
+ return;
312
+ }
257
313
  for (const uid in contentTypes2) {
258
314
  if (!oldContentTypes[uid]) {
259
315
  continue;
260
316
  }
261
317
  const oldContentType = oldContentTypes[uid];
262
318
  const contentType = contentTypes2[uid];
263
- const i18nPlugin = strapi.plugin("i18n");
264
319
  const { isLocalizedContentType } = i18nPlugin.service("content-types");
265
320
  const { getDefaultLocale } = i18nPlugin.service("locales");
266
321
  if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {
@@ -271,11 +326,43 @@ async function enableContentTypeLocalized({ oldContentTypes, contentTypes: conte
271
326
  }
272
327
  }
273
328
  }
274
- const { features: features$2 } = require("@strapi/strapi/dist/utils/ee");
329
+ const addEntryDocumentToReleaseActions = {
330
+ name: "content-releases::5.0.0-add-entry-document-id-to-release-actions",
331
+ async up(trx, db) {
332
+ const hasTable = await trx.schema.hasTable("strapi_release_actions");
333
+ if (!hasTable) {
334
+ return;
335
+ }
336
+ const hasPolymorphicColumn = await trx.schema.hasColumn("strapi_release_actions", "target_id");
337
+ if (hasPolymorphicColumn) {
338
+ const hasEntryDocumentIdColumn = await trx.schema.hasColumn(
339
+ "strapi_release_actions",
340
+ "entry_document_id"
341
+ );
342
+ if (!hasEntryDocumentIdColumn) {
343
+ await trx.schema.alterTable("strapi_release_actions", (table) => {
344
+ table.string("entry_document_id");
345
+ });
346
+ }
347
+ const releaseActions = await trx.select("*").from("strapi_release_actions");
348
+ utils.async.map(releaseActions, async (action) => {
349
+ const { target_type, target_id } = action;
350
+ const entry = await db.query(target_type).findOne({ where: { id: target_id } });
351
+ if (entry) {
352
+ await trx("strapi_release_actions").update({ entry_document_id: entry.documentId }).where("id", action.id);
353
+ }
354
+ });
355
+ }
356
+ },
357
+ async down() {
358
+ throw new Error("not implemented");
359
+ }
360
+ };
275
361
  const register = async ({ strapi: strapi2 }) => {
276
- if (features$2.isEnabled("cms-content-releases")) {
277
- await strapi2.admin.services.permission.actionProvider.registerMany(ACTIONS);
278
- strapi2.hook("strapi::content-types.beforeSync").register(deleteActionsOnDisableDraftAndPublish).register(disableContentTypeLocalized);
362
+ if (strapi2.ee.features.isEnabled("cms-content-releases")) {
363
+ await strapi2.service("admin::permission").actionProvider.registerMany(ACTIONS);
364
+ strapi2.db.migrations.providers.internal.register(addEntryDocumentToReleaseActions);
365
+ strapi2.hook("strapi::content-types.beforeSync").register(disableContentTypeLocalized).register(deleteActionsOnDisableDraftAndPublish);
279
366
  strapi2.hook("strapi::content-types.afterSync").register(deleteActionsOnDeleteContentType).register(enableContentTypeLocalized).register(revalidateChangedContentTypes).register(migrateIsValidAndStatusReleases);
280
367
  }
281
368
  if (strapi2.plugin("graphql")) {
@@ -284,150 +371,151 @@ const register = async ({ strapi: strapi2 }) => {
284
371
  graphqlExtensionService.shadowCRUD(RELEASE_ACTION_MODEL_UID).disable();
285
372
  }
286
373
  };
287
- const { features: features$1 } = require("@strapi/strapi/dist/utils/ee");
374
+ const updateActionsStatusAndUpdateReleaseStatus = async (contentType, entry) => {
375
+ const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
376
+ where: {
377
+ actions: {
378
+ contentType,
379
+ entryDocumentId: entry.documentId,
380
+ locale: entry.locale
381
+ }
382
+ }
383
+ });
384
+ const entryStatus = await isEntryValid(contentType, entry, { strapi });
385
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
386
+ where: {
387
+ contentType,
388
+ entryDocumentId: entry.documentId,
389
+ locale: entry.locale
390
+ },
391
+ data: {
392
+ isEntryValid: entryStatus
393
+ }
394
+ });
395
+ for (const release2 of releases) {
396
+ getService("release", { strapi }).updateReleaseStatus(release2.id);
397
+ }
398
+ };
399
+ const deleteActionsAndUpdateReleaseStatus = async (params) => {
400
+ const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
401
+ where: {
402
+ actions: params
403
+ }
404
+ });
405
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
406
+ where: params
407
+ });
408
+ for (const release2 of releases) {
409
+ getService("release", { strapi }).updateReleaseStatus(release2.id);
410
+ }
411
+ };
412
+ const deleteActionsOnDelete = async (ctx, next) => {
413
+ if (ctx.action !== "delete") {
414
+ return next();
415
+ }
416
+ if (!utils.contentTypes.hasDraftAndPublish(ctx.contentType)) {
417
+ return next();
418
+ }
419
+ const contentType = ctx.contentType.uid;
420
+ const { documentId, locale } = ctx.params;
421
+ const result = await next();
422
+ if (!result) {
423
+ return result;
424
+ }
425
+ try {
426
+ deleteActionsAndUpdateReleaseStatus({
427
+ contentType,
428
+ entryDocumentId: documentId,
429
+ ...locale !== "*" && { locale }
430
+ });
431
+ } catch (error) {
432
+ strapi.log.error("Error while deleting release actions after delete", {
433
+ error
434
+ });
435
+ }
436
+ return result;
437
+ };
438
+ const updateActionsOnUpdate = async (ctx, next) => {
439
+ if (ctx.action !== "update") {
440
+ return next();
441
+ }
442
+ if (!utils.contentTypes.hasDraftAndPublish(ctx.contentType)) {
443
+ return next();
444
+ }
445
+ const contentType = ctx.contentType.uid;
446
+ const result = await next();
447
+ if (!result) {
448
+ return result;
449
+ }
450
+ try {
451
+ updateActionsStatusAndUpdateReleaseStatus(contentType, result);
452
+ } catch (error) {
453
+ strapi.log.error("Error while updating release actions after update", {
454
+ error
455
+ });
456
+ }
457
+ return result;
458
+ };
459
+ const deleteReleasesActionsAndUpdateReleaseStatus = async (params) => {
460
+ const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
461
+ where: {
462
+ actions: params
463
+ }
464
+ });
465
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
466
+ where: params
467
+ });
468
+ for (const release2 of releases) {
469
+ getService("release", { strapi }).updateReleaseStatus(release2.id);
470
+ }
471
+ };
288
472
  const bootstrap = async ({ strapi: strapi2 }) => {
289
- if (features$1.isEnabled("cms-content-releases")) {
473
+ if (strapi2.ee.features.isEnabled("cms-content-releases")) {
290
474
  const contentTypesWithDraftAndPublish = Object.keys(strapi2.contentTypes).filter(
291
475
  (uid) => strapi2.contentTypes[uid]?.options?.draftAndPublish
292
476
  );
293
477
  strapi2.db.lifecycles.subscribe({
294
478
  models: contentTypesWithDraftAndPublish,
295
- async afterDelete(event) {
296
- try {
297
- const { model, result } = event;
298
- if (model.kind === "collectionType" && model.options?.draftAndPublish) {
299
- const { id } = result;
300
- const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
301
- where: {
302
- actions: {
303
- target_type: model.uid,
304
- target_id: id
305
- }
306
- }
307
- });
308
- await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
309
- where: {
310
- target_type: model.uid,
311
- target_id: id
312
- }
313
- });
314
- for (const release2 of releases) {
315
- getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
316
- }
317
- }
318
- } catch (error) {
319
- strapi2.log.error("Error while deleting release actions after entry delete", { error });
320
- }
321
- },
322
479
  /**
323
- * deleteMany hook doesn't return the deleted entries ids
324
- * so we need to fetch them before deleting the entries to save the ids on our state
325
- */
326
- async beforeDeleteMany(event) {
327
- const { model, params } = event;
328
- if (model.kind === "collectionType" && model.options?.draftAndPublish) {
329
- const { where } = params;
330
- const entriesToDelete = await strapi2.db.query(model.uid).findMany({ select: ["id"], where });
331
- event.state.entriesToDelete = entriesToDelete;
332
- }
333
- },
334
- /**
335
- * We delete the release actions related to deleted entries
336
- * We make this only after deleteMany is succesfully executed to avoid errors
480
+ * deleteMany is still used outside documents service, for example when deleting a locale
337
481
  */
338
482
  async afterDeleteMany(event) {
339
483
  try {
340
- const { model, state } = event;
341
- const entriesToDelete = state.entriesToDelete;
342
- if (entriesToDelete) {
343
- const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
344
- where: {
345
- actions: {
346
- target_type: model.uid,
347
- target_id: {
348
- $in: entriesToDelete.map(
349
- (entry) => entry.id
350
- )
351
- }
352
- }
353
- }
354
- });
355
- await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
356
- where: {
357
- target_type: model.uid,
358
- target_id: {
359
- $in: entriesToDelete.map((entry) => entry.id)
360
- }
361
- }
484
+ const model = strapi2.getModel(event.model.uid);
485
+ if (model.kind === "collectionType" && model.options?.draftAndPublish) {
486
+ const { where } = event.params;
487
+ deleteReleasesActionsAndUpdateReleaseStatus({
488
+ contentType: model.uid,
489
+ locale: where.locale ?? null,
490
+ ...where.documentId && { entryDocumentId: where.documentId }
362
491
  });
363
- for (const release2 of releases) {
364
- getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
365
- }
366
492
  }
367
493
  } catch (error) {
368
494
  strapi2.log.error("Error while deleting release actions after entry deleteMany", {
369
495
  error
370
496
  });
371
497
  }
372
- },
373
- async afterUpdate(event) {
374
- try {
375
- const { model, result } = event;
376
- if (model.kind === "collectionType" && model.options?.draftAndPublish) {
377
- const isEntryValid = await getEntryValidStatus(
378
- model.uid,
379
- result,
380
- {
381
- strapi: strapi2
382
- }
383
- );
384
- await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
385
- where: {
386
- target_type: model.uid,
387
- target_id: result.id
388
- },
389
- data: {
390
- isEntryValid
391
- }
392
- });
393
- const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
394
- where: {
395
- actions: {
396
- target_type: model.uid,
397
- target_id: result.id
398
- }
399
- }
400
- });
401
- for (const release2 of releases) {
402
- getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
403
- }
404
- }
405
- } catch (error) {
406
- strapi2.log.error("Error while updating release actions after entry update", { error });
407
- }
408
498
  }
409
499
  });
410
- if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
411
- getService("scheduling", { strapi: strapi2 }).syncFromDatabase().catch((err) => {
412
- strapi2.log.error(
413
- "Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling."
414
- );
415
- throw err;
416
- });
417
- Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
418
- strapi2.webhookStore.addAllowedEvent(key, value);
419
- });
420
- }
500
+ strapi2.documents.use(deleteActionsOnDelete);
501
+ strapi2.documents.use(updateActionsOnUpdate);
502
+ getService("scheduling", { strapi: strapi2 }).syncFromDatabase().catch((err) => {
503
+ strapi2.log.error(
504
+ "Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling."
505
+ );
506
+ throw err;
507
+ });
508
+ Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
509
+ strapi2.get("webhookStore").addAllowedEvent(key, value);
510
+ });
421
511
  }
422
512
  };
423
513
  const destroy = async ({ strapi: strapi2 }) => {
424
- if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
425
- const scheduledJobs = getService("scheduling", {
426
- strapi: strapi2
427
- }).getAll();
428
- for (const [, job] of scheduledJobs) {
429
- job.cancel();
430
- }
514
+ const scheduledJobs = getService("scheduling", {
515
+ strapi: strapi2
516
+ }).getAll();
517
+ for (const [, job] of scheduledJobs) {
518
+ job.cancel();
431
519
  }
432
520
  };
433
521
  const schema$1 = {
@@ -502,15 +590,13 @@ const schema = {
502
590
  enum: ["publish", "unpublish"],
503
591
  required: true
504
592
  },
505
- entry: {
506
- type: "relation",
507
- relation: "morphToOne",
508
- configurable: false
509
- },
510
593
  contentType: {
511
594
  type: "string",
512
595
  required: true
513
596
  },
597
+ entryDocumentId: {
598
+ type: "string"
599
+ },
514
600
  locale: {
515
601
  type: "string"
516
602
  },
@@ -532,18 +618,6 @@ const contentTypes = {
532
618
  release: release$1,
533
619
  "release-action": releaseAction$1
534
620
  };
535
- const getGroupName = (queryValue) => {
536
- switch (queryValue) {
537
- case "contentType":
538
- return "contentType.displayName";
539
- case "action":
540
- return "type";
541
- case "locale":
542
- return ___default.default.getOr("No locale", "locale.name");
543
- default:
544
- return "contentType.displayName";
545
- }
546
- };
547
621
  const createReleaseService = ({ strapi: strapi2 }) => {
548
622
  const dispatchWebhook = (event, { isPublished, release: release2, error }) => {
549
623
  strapi2.eventHub.emit(event, {
@@ -552,93 +626,32 @@ const createReleaseService = ({ strapi: strapi2 }) => {
552
626
  release: release2
553
627
  });
554
628
  };
555
- const publishSingleTypeAction = async (uid, actionType, entryId) => {
556
- const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
557
- const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
558
- const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
559
- const entry = await strapi2.entityService.findOne(uid, entryId, { populate });
560
- try {
561
- if (actionType === "publish") {
562
- await entityManagerService.publish(entry, uid);
563
- } else {
564
- await entityManagerService.unpublish(entry, uid);
565
- }
566
- } catch (error) {
567
- if (error instanceof utils.errors.ApplicationError && (error.message === "already.published" || error.message === "already.draft"))
568
- ;
569
- else {
570
- throw error;
571
- }
572
- }
573
- };
574
- const publishCollectionTypeAction = async (uid, entriesToPublishIds, entriestoUnpublishIds) => {
575
- const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
576
- const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
577
- const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
578
- const entriesToPublish = await strapi2.entityService.findMany(uid, {
579
- filters: {
580
- id: {
581
- $in: entriesToPublishIds
582
- }
583
- },
584
- populate
585
- });
586
- const entriesToUnpublish = await strapi2.entityService.findMany(uid, {
587
- filters: {
588
- id: {
589
- $in: entriestoUnpublishIds
590
- }
591
- },
592
- populate
593
- });
594
- if (entriesToPublish.length > 0) {
595
- await entityManagerService.publishMany(entriesToPublish, uid);
596
- }
597
- if (entriesToUnpublish.length > 0) {
598
- await entityManagerService.unpublishMany(entriesToUnpublish, uid);
599
- }
600
- };
601
629
  const getFormattedActions = async (releaseId) => {
602
630
  const actions = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findMany({
603
631
  where: {
604
632
  release: {
605
633
  id: releaseId
606
634
  }
607
- },
608
- populate: {
609
- entry: {
610
- fields: ["id"]
611
- }
612
635
  }
613
636
  });
614
637
  if (actions.length === 0) {
615
638
  throw new utils.errors.ValidationError("No entries to publish");
616
639
  }
617
- const collectionTypeActions = {};
618
- const singleTypeActions = [];
640
+ const formattedActions = {};
619
641
  for (const action of actions) {
620
642
  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
- }
633
- } else {
634
- singleTypeActions.push({
635
- uid: contentTypeUid,
636
- action: action.type,
637
- id: action.entry.id
638
- });
643
+ if (!formattedActions[contentTypeUid]) {
644
+ formattedActions[contentTypeUid] = {
645
+ publish: [],
646
+ unpublish: []
647
+ };
639
648
  }
649
+ formattedActions[contentTypeUid][action.type].push({
650
+ documentId: action.entryDocumentId,
651
+ locale: action.locale
652
+ });
640
653
  }
641
- return { collectionTypeActions, singleTypeActions };
654
+ return formattedActions;
642
655
  };
643
656
  return {
644
657
  async create(releaseData, { user }) {
@@ -653,13 +666,13 @@ const createReleaseService = ({ strapi: strapi2 }) => {
653
666
  validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
654
667
  validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
655
668
  ]);
656
- const release2 = await strapi2.entityService.create(RELEASE_MODEL_UID, {
669
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).create({
657
670
  data: {
658
671
  ...releaseWithCreatorFields,
659
672
  status: "empty"
660
673
  }
661
674
  });
662
- if (strapi2.features.future.isEnabled("contentReleasesScheduling") && releaseWithCreatorFields.scheduledAt) {
675
+ if (releaseWithCreatorFields.scheduledAt) {
663
676
  const schedulingService = getService("scheduling", { strapi: strapi2 });
664
677
  await schedulingService.set(release2.id, release2.scheduledAt);
665
678
  }
@@ -667,94 +680,28 @@ const createReleaseService = ({ strapi: strapi2 }) => {
667
680
  return release2;
668
681
  },
669
682
  async findOne(id, query = {}) {
670
- const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id, {
671
- ...query
683
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query);
684
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
685
+ ...dbQuery,
686
+ where: { id }
672
687
  });
673
688
  return release2;
674
689
  },
675
690
  findPage(query) {
676
- return strapi2.entityService.findPage(RELEASE_MODEL_UID, {
677
- ...query,
691
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
692
+ return strapi2.db.query(RELEASE_MODEL_UID).findPage({
693
+ ...dbQuery,
678
694
  populate: {
679
695
  actions: {
680
- // @ts-expect-error Ignore missing properties
681
696
  count: true
682
697
  }
683
698
  }
684
699
  });
685
700
  },
686
- async findManyWithContentTypeEntryAttached(contentTypeUid, entryId) {
687
- const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
688
- where: {
689
- actions: {
690
- target_type: contentTypeUid,
691
- target_id: entryId
692
- },
693
- releasedAt: {
694
- $null: true
695
- }
696
- },
697
- populate: {
698
- // Filter the action to get only the content type entry
699
- actions: {
700
- where: {
701
- target_type: contentTypeUid,
702
- target_id: entryId
703
- }
704
- }
705
- }
706
- });
707
- return releases.map((release2) => {
708
- if (release2.actions?.length) {
709
- const [actionForEntry] = release2.actions;
710
- delete release2.actions;
711
- return {
712
- ...release2,
713
- action: actionForEntry
714
- };
715
- }
716
- return release2;
717
- });
718
- },
719
- async findManyWithoutContentTypeEntryAttached(contentTypeUid, entryId) {
720
- const releasesRelated = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
721
- where: {
722
- releasedAt: {
723
- $null: true
724
- },
725
- actions: {
726
- target_type: contentTypeUid,
727
- target_id: entryId
728
- }
729
- }
730
- });
731
- const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
732
- where: {
733
- $or: [
734
- {
735
- id: {
736
- $notIn: releasesRelated.map((release2) => release2.id)
737
- }
738
- },
739
- {
740
- actions: null
741
- }
742
- ],
743
- releasedAt: {
744
- $null: true
745
- }
746
- }
747
- });
748
- return releases.map((release2) => {
749
- if (release2.actions?.length) {
750
- const [actionForEntry] = release2.actions;
751
- delete release2.actions;
752
- return {
753
- ...release2,
754
- action: actionForEntry
755
- };
756
- }
757
- return release2;
701
+ findMany(query) {
702
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
703
+ return strapi2.db.query(RELEASE_MODEL_UID).findMany({
704
+ ...dbQuery
758
705
  });
759
706
  },
760
707
  async update(id, releaseData, { user }) {
@@ -769,157 +716,27 @@ const createReleaseService = ({ strapi: strapi2 }) => {
769
716
  validateUniqueNameForPendingRelease(releaseWithCreatorFields.name, id),
770
717
  validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
771
718
  ]);
772
- const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id);
719
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id } });
773
720
  if (!release2) {
774
721
  throw new utils.errors.NotFoundError(`No release found for id ${id}`);
775
722
  }
776
723
  if (release2.releasedAt) {
777
724
  throw new utils.errors.ValidationError("Release already published");
778
725
  }
779
- const updatedRelease = await strapi2.entityService.update(RELEASE_MODEL_UID, id, {
780
- /*
781
- * The type returned from the entity service: Partial<Input<"plugin::content-releases.release">>
782
- * is not compatible with the type we are passing here: UpdateRelease.Request['body']
783
- */
784
- // @ts-expect-error see above
726
+ const updatedRelease = await strapi2.db.query(RELEASE_MODEL_UID).update({
727
+ where: { id },
785
728
  data: releaseWithCreatorFields
786
729
  });
787
- if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
788
- const schedulingService = getService("scheduling", { strapi: strapi2 });
789
- if (releaseData.scheduledAt) {
790
- await schedulingService.set(id, releaseData.scheduledAt);
791
- } else if (release2.scheduledAt) {
792
- schedulingService.cancel(id);
793
- }
730
+ const schedulingService = getService("scheduling", { strapi: strapi2 });
731
+ if (releaseData.scheduledAt) {
732
+ await schedulingService.set(id, releaseData.scheduledAt);
733
+ } else if (release2.scheduledAt) {
734
+ schedulingService.cancel(id);
794
735
  }
795
736
  this.updateReleaseStatus(id);
796
737
  strapi2.telemetry.send("didUpdateContentRelease");
797
738
  return updatedRelease;
798
739
  },
799
- async createAction(releaseId, action) {
800
- const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
801
- strapi: strapi2
802
- });
803
- await Promise.all([
804
- validateEntryContentType(action.entry.contentType),
805
- validateUniqueEntry(releaseId, action)
806
- ]);
807
- const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
808
- if (!release2) {
809
- throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
810
- }
811
- if (release2.releasedAt) {
812
- throw new utils.errors.ValidationError("Release already published");
813
- }
814
- const { entry, type } = action;
815
- const populatedEntry = await getPopulatedEntry(entry.contentType, entry.id, { strapi: strapi2 });
816
- const isEntryValid = await getEntryValidStatus(entry.contentType, populatedEntry, { strapi: strapi2 });
817
- const releaseAction2 = await strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
818
- data: {
819
- type,
820
- contentType: entry.contentType,
821
- locale: entry.locale,
822
- isEntryValid,
823
- entry: {
824
- id: entry.id,
825
- __type: entry.contentType,
826
- __pivot: { field: "entry" }
827
- },
828
- release: releaseId
829
- },
830
- populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
831
- });
832
- this.updateReleaseStatus(releaseId);
833
- return releaseAction2;
834
- },
835
- async findActions(releaseId, query) {
836
- const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
837
- fields: ["id"]
838
- });
839
- if (!release2) {
840
- throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
841
- }
842
- return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
843
- ...query,
844
- populate: {
845
- entry: {
846
- populate: "*"
847
- }
848
- },
849
- filters: {
850
- release: releaseId
851
- }
852
- });
853
- },
854
- async countActions(query) {
855
- return strapi2.entityService.count(RELEASE_ACTION_MODEL_UID, query);
856
- },
857
- async groupActions(actions, groupBy) {
858
- const contentTypeUids = actions.reduce((acc, action) => {
859
- if (!acc.includes(action.contentType)) {
860
- acc.push(action.contentType);
861
- }
862
- return acc;
863
- }, []);
864
- const allReleaseContentTypesDictionary = await this.getContentTypesDataForActions(
865
- contentTypeUids
866
- );
867
- const allLocalesDictionary = await this.getLocalesDataForActions();
868
- const formattedData = actions.map((action) => {
869
- const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
870
- return {
871
- ...action,
872
- locale: action.locale ? allLocalesDictionary[action.locale] : null,
873
- contentType: {
874
- displayName,
875
- mainFieldValue: action.entry[mainField],
876
- uid: action.contentType
877
- }
878
- };
879
- });
880
- const groupName = getGroupName(groupBy);
881
- return ___default.default.groupBy(groupName)(formattedData);
882
- },
883
- async getLocalesDataForActions() {
884
- if (!strapi2.plugin("i18n")) {
885
- return {};
886
- }
887
- const allLocales = await strapi2.plugin("i18n").service("locales").find() || [];
888
- return allLocales.reduce((acc, locale) => {
889
- acc[locale.code] = { name: locale.name, code: locale.code };
890
- return acc;
891
- }, {});
892
- },
893
- async getContentTypesDataForActions(contentTypesUids) {
894
- const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
895
- const contentTypesData = {};
896
- for (const contentTypeUid of contentTypesUids) {
897
- const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
898
- uid: contentTypeUid
899
- });
900
- contentTypesData[contentTypeUid] = {
901
- mainField: contentTypeConfig.settings.mainField,
902
- displayName: strapi2.getModel(contentTypeUid).info.displayName
903
- };
904
- }
905
- return contentTypesData;
906
- },
907
- getContentTypeModelsFromActions(actions) {
908
- const contentTypeUids = actions.reduce((acc, action) => {
909
- if (!acc.includes(action.contentType)) {
910
- acc.push(action.contentType);
911
- }
912
- return acc;
913
- }, []);
914
- const contentTypeModelsMap = contentTypeUids.reduce(
915
- (acc, contentTypeUid) => {
916
- acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
917
- return acc;
918
- },
919
- {}
920
- );
921
- return contentTypeModelsMap;
922
- },
923
740
  async getAllComponents() {
924
741
  const contentManagerComponentsService = strapi2.plugin("content-manager").service("components");
925
742
  const components = await contentManagerComponentsService.findAllComponents();
@@ -933,10 +750,11 @@ const createReleaseService = ({ strapi: strapi2 }) => {
933
750
  return componentsMap;
934
751
  },
935
752
  async delete(releaseId) {
936
- const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
753
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
754
+ where: { id: releaseId },
937
755
  populate: {
938
756
  actions: {
939
- fields: ["id"]
757
+ select: ["id"]
940
758
  }
941
759
  }
942
760
  });
@@ -954,9 +772,13 @@ const createReleaseService = ({ strapi: strapi2 }) => {
954
772
  }
955
773
  }
956
774
  });
957
- await strapi2.entityService.delete(RELEASE_MODEL_UID, releaseId);
775
+ await strapi2.db.query(RELEASE_MODEL_UID).delete({
776
+ where: {
777
+ id: releaseId
778
+ }
779
+ });
958
780
  });
959
- if (strapi2.features.future.isEnabled("contentReleasesScheduling") && release2.scheduledAt) {
781
+ if (release2.scheduledAt) {
960
782
  const schedulingService = getService("scheduling", { strapi: strapi2 });
961
783
  await schedulingService.cancel(release2.id);
962
784
  }
@@ -980,22 +802,19 @@ const createReleaseService = ({ strapi: strapi2 }) => {
980
802
  }
981
803
  try {
982
804
  strapi2.log.info(`[Content Releases] Starting to publish release ${lockedRelease.name}`);
983
- const { collectionTypeActions, singleTypeActions } = await getFormattedActions(
984
- releaseId
805
+ const formattedActions = await getFormattedActions(releaseId);
806
+ await strapi2.db.transaction(
807
+ async () => Promise.all(
808
+ Object.keys(formattedActions).map(async (contentTypeUid) => {
809
+ const contentType = contentTypeUid;
810
+ const { publish, unpublish } = formattedActions[contentType];
811
+ return Promise.all([
812
+ ...publish.map((params) => strapi2.documents(contentType).publish(params)),
813
+ ...unpublish.map((params) => strapi2.documents(contentType).unpublish(params))
814
+ ]);
815
+ })
816
+ )
985
817
  );
986
- await strapi2.db.transaction(async () => {
987
- for (const { uid, action, id } of singleTypeActions) {
988
- await publishSingleTypeAction(uid, action, id);
989
- }
990
- for (const contentTypeUid of Object.keys(collectionTypeActions)) {
991
- const uid = contentTypeUid;
992
- await publishCollectionTypeAction(
993
- uid,
994
- collectionTypeActions[uid].entriesToPublishIds,
995
- collectionTypeActions[uid].entriesToUnpublishIds
996
- );
997
- }
998
- });
999
818
  const release22 = await strapi2.db.query(RELEASE_MODEL_UID).update({
1000
819
  where: {
1001
820
  id: releaseId
@@ -1004,37 +823,272 @@ const createReleaseService = ({ strapi: strapi2 }) => {
1004
823
  status: "done",
1005
824
  releasedAt: /* @__PURE__ */ new Date()
1006
825
  }
1007
- });
1008
- if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
1009
- dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
1010
- isPublished: true,
1011
- release: release22
1012
- });
1013
- }
1014
- strapi2.telemetry.send("didPublishContentRelease");
1015
- return { release: release22, error: null };
1016
- } catch (error2) {
1017
- if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
1018
- dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
1019
- isPublished: false,
1020
- error: error2
1021
- });
826
+ });
827
+ dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
828
+ isPublished: true,
829
+ release: release22
830
+ });
831
+ strapi2.telemetry.send("didPublishContentRelease");
832
+ return { release: release22, error: null };
833
+ } catch (error2) {
834
+ dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
835
+ isPublished: false,
836
+ error: error2
837
+ });
838
+ await strapi2.db?.queryBuilder(RELEASE_MODEL_UID).where({ id: releaseId }).update({
839
+ status: "failed"
840
+ }).transacting(trx).execute();
841
+ return {
842
+ release: null,
843
+ error: error2
844
+ };
845
+ }
846
+ });
847
+ if (error instanceof Error) {
848
+ throw error;
849
+ }
850
+ return release2;
851
+ },
852
+ async updateReleaseStatus(releaseId) {
853
+ const releaseActionService = getService("release-action", { strapi: strapi2 });
854
+ const [totalActions, invalidActions] = await Promise.all([
855
+ releaseActionService.countActions({
856
+ filters: {
857
+ release: releaseId
858
+ }
859
+ }),
860
+ releaseActionService.countActions({
861
+ filters: {
862
+ release: releaseId,
863
+ isEntryValid: false
864
+ }
865
+ })
866
+ ]);
867
+ if (totalActions > 0) {
868
+ if (invalidActions > 0) {
869
+ return strapi2.db.query(RELEASE_MODEL_UID).update({
870
+ where: {
871
+ id: releaseId
872
+ },
873
+ data: {
874
+ status: "blocked"
875
+ }
876
+ });
877
+ }
878
+ return strapi2.db.query(RELEASE_MODEL_UID).update({
879
+ where: {
880
+ id: releaseId
881
+ },
882
+ data: {
883
+ status: "ready"
884
+ }
885
+ });
886
+ }
887
+ return strapi2.db.query(RELEASE_MODEL_UID).update({
888
+ where: {
889
+ id: releaseId
890
+ },
891
+ data: {
892
+ status: "empty"
893
+ }
894
+ });
895
+ }
896
+ };
897
+ };
898
+ const getGroupName = (queryValue) => {
899
+ switch (queryValue) {
900
+ case "contentType":
901
+ return "contentType.displayName";
902
+ case "type":
903
+ return "type";
904
+ case "locale":
905
+ return ___default.default.getOr("No locale", "locale.name");
906
+ default:
907
+ return "contentType.displayName";
908
+ }
909
+ };
910
+ const createReleaseActionService = ({ strapi: strapi2 }) => {
911
+ const getLocalesDataForActions = async () => {
912
+ if (!strapi2.plugin("i18n")) {
913
+ return {};
914
+ }
915
+ const allLocales = await strapi2.plugin("i18n").service("locales").find() || [];
916
+ return allLocales.reduce((acc, locale) => {
917
+ acc[locale.code] = { name: locale.name, code: locale.code };
918
+ return acc;
919
+ }, {});
920
+ };
921
+ const getContentTypesDataForActions = async (contentTypesUids) => {
922
+ const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
923
+ const contentTypesData = {};
924
+ for (const contentTypeUid of contentTypesUids) {
925
+ const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
926
+ uid: contentTypeUid
927
+ });
928
+ contentTypesData[contentTypeUid] = {
929
+ mainField: contentTypeConfig.settings.mainField,
930
+ displayName: strapi2.getModel(contentTypeUid).info.displayName
931
+ };
932
+ }
933
+ return contentTypesData;
934
+ };
935
+ return {
936
+ async create(releaseId, action, { disableUpdateReleaseStatus = false } = {}) {
937
+ const { validateEntryData, validateUniqueEntry } = getService("release-validation", {
938
+ strapi: strapi2
939
+ });
940
+ await Promise.all([
941
+ validateEntryData(action.contentType, action.entryDocumentId),
942
+ validateUniqueEntry(releaseId, action)
943
+ ]);
944
+ const model = strapi2.contentType(action.contentType);
945
+ if (model.kind === "singleType") {
946
+ const document = await strapi2.db.query(model.uid).findOne({ select: ["documentId"] });
947
+ if (!document) {
948
+ throw new utils.errors.NotFoundError(`No entry found for contentType ${action.contentType}`);
949
+ }
950
+ action.entryDocumentId = document.documentId;
951
+ }
952
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id: releaseId } });
953
+ if (!release2) {
954
+ throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
955
+ }
956
+ if (release2.releasedAt) {
957
+ throw new utils.errors.ValidationError("Release already published");
958
+ }
959
+ const actionStatus = action.type === "publish" ? await getDraftEntryValidStatus(
960
+ {
961
+ contentType: action.contentType,
962
+ documentId: action.entryDocumentId,
963
+ locale: action.locale
964
+ },
965
+ {
966
+ strapi: strapi2
967
+ }
968
+ ) : true;
969
+ const releaseAction2 = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).create({
970
+ data: {
971
+ ...action,
972
+ release: release2.id,
973
+ isEntryValid: actionStatus
974
+ },
975
+ populate: { release: { select: ["id"] } }
976
+ });
977
+ if (!disableUpdateReleaseStatus) {
978
+ getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
979
+ }
980
+ return releaseAction2;
981
+ },
982
+ async findPage(releaseId, query) {
983
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
984
+ where: { id: releaseId },
985
+ select: ["id"]
986
+ });
987
+ if (!release2) {
988
+ throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
989
+ }
990
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
991
+ const { results: actions, pagination } = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findPage({
992
+ ...dbQuery,
993
+ where: {
994
+ release: releaseId
995
+ }
996
+ });
997
+ const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
998
+ const actionsWithEntry = await utils.async.map(actions, async (action) => {
999
+ const populate = await populateBuilderService(action.contentType).populateDeep(Infinity).build();
1000
+ const entry = await getEntry(
1001
+ {
1002
+ contentType: action.contentType,
1003
+ documentId: action.entryDocumentId,
1004
+ locale: action.locale,
1005
+ populate,
1006
+ status: action.type === "publish" ? "draft" : "published"
1007
+ },
1008
+ { strapi: strapi2 }
1009
+ );
1010
+ return {
1011
+ ...action,
1012
+ entry,
1013
+ status: entry ? await getEntryStatus(action.contentType, entry) : null
1014
+ };
1015
+ });
1016
+ return {
1017
+ results: actionsWithEntry,
1018
+ pagination
1019
+ };
1020
+ },
1021
+ async groupActions(actions, groupBy) {
1022
+ const contentTypeUids = actions.reduce((acc, action) => {
1023
+ if (!acc.includes(action.contentType)) {
1024
+ acc.push(action.contentType);
1025
+ }
1026
+ return acc;
1027
+ }, []);
1028
+ const allReleaseContentTypesDictionary = await getContentTypesDataForActions(contentTypeUids);
1029
+ const allLocalesDictionary = await getLocalesDataForActions();
1030
+ const formattedData = actions.map((action) => {
1031
+ const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
1032
+ return {
1033
+ ...action,
1034
+ locale: action.locale ? allLocalesDictionary[action.locale] : null,
1035
+ contentType: {
1036
+ displayName,
1037
+ mainFieldValue: action.entry[mainField],
1038
+ uid: action.contentType
1039
+ }
1040
+ };
1041
+ });
1042
+ const groupName = getGroupName(groupBy);
1043
+ return ___default.default.groupBy(groupName)(formattedData);
1044
+ },
1045
+ getContentTypeModelsFromActions(actions) {
1046
+ const contentTypeUids = actions.reduce((acc, action) => {
1047
+ if (!acc.includes(action.contentType)) {
1048
+ acc.push(action.contentType);
1049
+ }
1050
+ return acc;
1051
+ }, []);
1052
+ const contentTypeModelsMap = contentTypeUids.reduce(
1053
+ (acc, contentTypeUid) => {
1054
+ acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
1055
+ return acc;
1056
+ },
1057
+ {}
1058
+ );
1059
+ return contentTypeModelsMap;
1060
+ },
1061
+ async countActions(query) {
1062
+ const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
1063
+ return strapi2.db.query(RELEASE_ACTION_MODEL_UID).count(dbQuery);
1064
+ },
1065
+ async update(actionId, releaseId, update) {
1066
+ const action = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findOne({
1067
+ where: {
1068
+ id: actionId,
1069
+ release: {
1070
+ id: releaseId,
1071
+ releasedAt: {
1072
+ $null: true
1073
+ }
1022
1074
  }
1023
- await strapi2.db?.queryBuilder(RELEASE_MODEL_UID).where({ id: releaseId }).update({
1024
- status: "failed"
1025
- }).transacting(trx).execute();
1026
- return {
1027
- release: null,
1028
- error: error2
1029
- };
1030
1075
  }
1031
1076
  });
1032
- if (error) {
1033
- throw error;
1077
+ if (!action) {
1078
+ throw new utils.errors.NotFoundError(
1079
+ `Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
1080
+ );
1034
1081
  }
1035
- return release2;
1036
- },
1037
- async updateAction(actionId, releaseId, update) {
1082
+ const actionStatus = update.type === "publish" ? await getDraftEntryValidStatus(
1083
+ {
1084
+ contentType: action.contentType,
1085
+ documentId: action.entryDocumentId,
1086
+ locale: action.locale
1087
+ },
1088
+ {
1089
+ strapi: strapi2
1090
+ }
1091
+ ) : true;
1038
1092
  const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
1039
1093
  where: {
1040
1094
  id: actionId,
@@ -1045,16 +1099,15 @@ const createReleaseService = ({ strapi: strapi2 }) => {
1045
1099
  }
1046
1100
  }
1047
1101
  },
1048
- data: update
1102
+ data: {
1103
+ ...update,
1104
+ isEntryValid: actionStatus
1105
+ }
1049
1106
  });
1050
- if (!updatedAction) {
1051
- throw new utils.errors.NotFoundError(
1052
- `Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
1053
- );
1054
- }
1107
+ getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
1055
1108
  return updatedAction;
1056
1109
  },
1057
- async deleteAction(actionId, releaseId) {
1110
+ async delete(actionId, releaseId) {
1058
1111
  const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
1059
1112
  where: {
1060
1113
  id: actionId,
@@ -1071,87 +1124,56 @@ const createReleaseService = ({ strapi: strapi2 }) => {
1071
1124
  `Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
1072
1125
  );
1073
1126
  }
1074
- this.updateReleaseStatus(releaseId);
1127
+ getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
1075
1128
  return deletedAction;
1076
- },
1077
- async updateReleaseStatus(releaseId) {
1078
- const [totalActions, invalidActions] = await Promise.all([
1079
- this.countActions({
1080
- filters: {
1081
- release: releaseId
1082
- }
1083
- }),
1084
- this.countActions({
1085
- filters: {
1086
- release: releaseId,
1087
- isEntryValid: false
1088
- }
1089
- })
1090
- ]);
1091
- if (totalActions > 0) {
1092
- if (invalidActions > 0) {
1093
- return strapi2.db.query(RELEASE_MODEL_UID).update({
1094
- where: {
1095
- id: releaseId
1096
- },
1097
- data: {
1098
- status: "blocked"
1099
- }
1100
- });
1101
- }
1102
- return strapi2.db.query(RELEASE_MODEL_UID).update({
1103
- where: {
1104
- id: releaseId
1105
- },
1106
- data: {
1107
- status: "ready"
1108
- }
1109
- });
1110
- }
1111
- return strapi2.db.query(RELEASE_MODEL_UID).update({
1112
- where: {
1113
- id: releaseId
1114
- },
1115
- data: {
1116
- status: "empty"
1117
- }
1118
- });
1119
1129
  }
1120
1130
  };
1121
1131
  };
1132
+ class AlreadyOnReleaseError extends utils.errors.ApplicationError {
1133
+ constructor(message) {
1134
+ super(message);
1135
+ this.name = "AlreadyOnReleaseError";
1136
+ }
1137
+ }
1122
1138
  const createReleaseValidationService = ({ strapi: strapi2 }) => ({
1123
1139
  async validateUniqueEntry(releaseId, releaseActionArgs) {
1124
- const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
1125
- populate: { actions: { populate: { entry: { fields: ["id"] } } } }
1140
+ const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
1141
+ where: {
1142
+ id: releaseId
1143
+ },
1144
+ populate: {
1145
+ actions: true
1146
+ }
1126
1147
  });
1127
1148
  if (!release2) {
1128
1149
  throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
1129
1150
  }
1130
1151
  const isEntryInRelease = release2.actions.some(
1131
- (action) => Number(action.entry.id) === Number(releaseActionArgs.entry.id) && action.contentType === releaseActionArgs.entry.contentType
1152
+ (action) => action.entryDocumentId === releaseActionArgs.entryDocumentId && action.contentType === releaseActionArgs.contentType && (releaseActionArgs.locale ? action.locale === releaseActionArgs.locale : true)
1132
1153
  );
1133
1154
  if (isEntryInRelease) {
1134
- throw new utils.errors.ValidationError(
1135
- `Entry with id ${releaseActionArgs.entry.id} and contentType ${releaseActionArgs.entry.contentType} already exists in release with id ${releaseId}`
1155
+ throw new AlreadyOnReleaseError(
1156
+ `Entry with documentId ${releaseActionArgs.entryDocumentId}${releaseActionArgs.locale ? `( ${releaseActionArgs.locale})` : ""} and contentType ${releaseActionArgs.contentType} already exists in release with id ${releaseId}`
1136
1157
  );
1137
1158
  }
1138
1159
  },
1139
- validateEntryContentType(contentTypeUid) {
1160
+ validateEntryData(contentTypeUid, entryDocumentId) {
1140
1161
  const contentType = strapi2.contentType(contentTypeUid);
1141
1162
  if (!contentType) {
1142
1163
  throw new utils.errors.NotFoundError(`No content type found for uid ${contentTypeUid}`);
1143
1164
  }
1144
- if (!contentType.options?.draftAndPublish) {
1165
+ if (!utils.contentTypes.hasDraftAndPublish(contentType)) {
1145
1166
  throw new utils.errors.ValidationError(
1146
1167
  `Content type with uid ${contentTypeUid} does not have draftAndPublish enabled`
1147
1168
  );
1148
1169
  }
1170
+ if (contentType.kind === "collectionType" && !entryDocumentId) {
1171
+ throw new utils.errors.ValidationError("Document id is required for collection type");
1172
+ }
1149
1173
  },
1150
1174
  async validatePendingReleasesLimit() {
1151
- const maximumPendingReleases = (
1152
- // @ts-expect-error - options is not typed into features
1153
- EE__default.default.features.get("cms-content-releases")?.options?.maximumReleases || 3
1154
- );
1175
+ const featureCfg = strapi2.ee.features.get("cms-content-releases");
1176
+ const maximumPendingReleases = typeof featureCfg === "object" && featureCfg?.options?.maximumReleases || 3;
1155
1177
  const [, pendingReleasesCount] = await strapi2.db.query(RELEASE_MODEL_UID).findWithCount({
1156
1178
  filters: {
1157
1179
  releasedAt: {
@@ -1164,8 +1186,8 @@ const createReleaseValidationService = ({ strapi: strapi2 }) => ({
1164
1186
  }
1165
1187
  },
1166
1188
  async validateUniqueNameForPendingRelease(name, id) {
1167
- const pendingReleases = await strapi2.entityService.findMany(RELEASE_MODEL_UID, {
1168
- filters: {
1189
+ const pendingReleases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
1190
+ where: {
1169
1191
  releasedAt: {
1170
1192
  $null: true
1171
1193
  },
@@ -1194,7 +1216,7 @@ const createSchedulingService = ({ strapi: strapi2 }) => {
1194
1216
  }
1195
1217
  const job = nodeSchedule.scheduleJob(scheduleDate, async () => {
1196
1218
  try {
1197
- await getService("release").publish(releaseId);
1219
+ await getService("release", { strapi: strapi2 }).publish(releaseId);
1198
1220
  } catch (error) {
1199
1221
  }
1200
1222
  this.cancel(releaseId);
@@ -1236,85 +1258,172 @@ const createSchedulingService = ({ strapi: strapi2 }) => {
1236
1258
  }
1237
1259
  };
1238
1260
  };
1261
+ const DEFAULT_SETTINGS = {
1262
+ defaultTimezone: null
1263
+ };
1264
+ const createSettingsService = ({ strapi: strapi2 }) => {
1265
+ const getStore = async () => strapi2.store({ type: "core", name: "content-releases" });
1266
+ return {
1267
+ async update({ settings: settings2 }) {
1268
+ const store = await getStore();
1269
+ store.set({ key: "settings", value: settings2 });
1270
+ return settings2;
1271
+ },
1272
+ async find() {
1273
+ const store = await getStore();
1274
+ const settings2 = await store.get({ key: "settings" });
1275
+ return {
1276
+ ...DEFAULT_SETTINGS,
1277
+ ...settings2 || {}
1278
+ };
1279
+ }
1280
+ };
1281
+ };
1239
1282
  const services = {
1240
1283
  release: createReleaseService,
1284
+ "release-action": createReleaseActionService,
1241
1285
  "release-validation": createReleaseValidationService,
1242
- ...strapi.features.future.isEnabled("contentReleasesScheduling") ? { scheduling: createSchedulingService } : {}
1286
+ scheduling: createSchedulingService,
1287
+ settings: createSettingsService
1243
1288
  };
1244
- const RELEASE_SCHEMA = yup__namespace.object().shape({
1245
- name: yup__namespace.string().trim().required(),
1246
- scheduledAt: yup__namespace.string().nullable(),
1247
- isScheduled: yup__namespace.boolean().optional(),
1248
- time: yup__namespace.string().when("isScheduled", {
1249
- is: true,
1250
- then: yup__namespace.string().trim().required(),
1251
- otherwise: yup__namespace.string().nullable()
1252
- }),
1253
- timezone: yup__namespace.string().when("isScheduled", {
1254
- is: true,
1255
- then: yup__namespace.string().required().nullable(),
1256
- otherwise: yup__namespace.string().nullable()
1257
- }),
1258
- date: yup__namespace.string().when("isScheduled", {
1259
- is: true,
1260
- then: yup__namespace.string().required().nullable(),
1261
- otherwise: yup__namespace.string().nullable()
1289
+ const RELEASE_SCHEMA = utils.yup.object().shape({
1290
+ name: utils.yup.string().trim().required(),
1291
+ scheduledAt: utils.yup.string().nullable(),
1292
+ timezone: utils.yup.string().when("scheduledAt", {
1293
+ is: (value) => value !== null && value !== void 0,
1294
+ then: utils.yup.string().required(),
1295
+ otherwise: utils.yup.string().nullable()
1262
1296
  })
1263
1297
  }).required().noUnknown();
1298
+ const FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA = utils.yup.object().shape({
1299
+ contentType: utils.yup.string().required(),
1300
+ entryDocumentId: utils.yup.string().nullable(),
1301
+ hasEntryAttached: utils.yup.string().nullable(),
1302
+ locale: utils.yup.string().nullable()
1303
+ }).required().noUnknown();
1264
1304
  const validateRelease = utils.validateYupSchema(RELEASE_SCHEMA);
1305
+ const validatefindByDocumentAttachedParams = utils.validateYupSchema(
1306
+ FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA
1307
+ );
1265
1308
  const releaseController = {
1266
- async findMany(ctx) {
1267
- const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
1309
+ /**
1310
+ * Find releases based on documents attached or not to the release.
1311
+ * If `hasEntryAttached` is true, it will return all releases that have the entry attached.
1312
+ * If `hasEntryAttached` is false, it will return all releases that don't have the entry attached.
1313
+ */
1314
+ async findByDocumentAttached(ctx) {
1315
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
1268
1316
  ability: ctx.state.userAbility,
1269
1317
  model: RELEASE_MODEL_UID
1270
1318
  });
1271
1319
  await permissionsManager.validateQuery(ctx.query);
1272
1320
  const releaseService = getService("release", { strapi });
1273
- const isFindManyForContentTypeEntry = Boolean(ctx.query?.contentTypeUid && ctx.query?.entryId);
1274
- if (isFindManyForContentTypeEntry) {
1275
- const query = await permissionsManager.sanitizeQuery(ctx.query);
1276
- const contentTypeUid = query.contentTypeUid;
1277
- const entryId = query.entryId;
1278
- const hasEntryAttached = typeof query.hasEntryAttached === "string" ? JSON.parse(query.hasEntryAttached) : false;
1279
- const data = hasEntryAttached ? await releaseService.findManyWithContentTypeEntryAttached(contentTypeUid, entryId) : await releaseService.findManyWithoutContentTypeEntryAttached(contentTypeUid, entryId);
1280
- ctx.body = { data };
1281
- } else {
1282
- const query = await permissionsManager.sanitizeQuery(ctx.query);
1283
- const { results, pagination } = await releaseService.findPage(query);
1284
- const data = results.map((release2) => {
1285
- const { actions, ...releaseData } = release2;
1286
- return {
1287
- ...releaseData,
1321
+ const query = await permissionsManager.sanitizeQuery(ctx.query);
1322
+ await validatefindByDocumentAttachedParams(query);
1323
+ const model = strapi.getModel(query.contentType);
1324
+ if (model.kind && model.kind === "singleType") {
1325
+ const document = await strapi.db.query(model.uid).findOne({ select: ["documentId"] });
1326
+ if (!document) {
1327
+ throw new utils.errors.NotFoundError(`No entry found for contentType ${query.contentType}`);
1328
+ }
1329
+ query.entryDocumentId = document.documentId;
1330
+ }
1331
+ const { contentType, hasEntryAttached, entryDocumentId, locale } = query;
1332
+ const isEntryAttached = typeof hasEntryAttached === "string" ? Boolean(JSON.parse(hasEntryAttached)) : false;
1333
+ if (isEntryAttached) {
1334
+ const releases = await releaseService.findMany({
1335
+ where: {
1336
+ releasedAt: null,
1288
1337
  actions: {
1289
- meta: {
1290
- count: actions.count
1338
+ contentType,
1339
+ entryDocumentId: entryDocumentId ?? null,
1340
+ locale: locale ?? null
1341
+ }
1342
+ },
1343
+ populate: {
1344
+ actions: {
1345
+ fields: ["type"],
1346
+ filters: {
1347
+ contentType,
1348
+ entryDocumentId: entryDocumentId ?? null,
1349
+ locale: locale ?? null
1291
1350
  }
1292
1351
  }
1293
- };
1352
+ }
1353
+ });
1354
+ ctx.body = { data: releases };
1355
+ } else {
1356
+ const relatedReleases = await releaseService.findMany({
1357
+ where: {
1358
+ releasedAt: null,
1359
+ actions: {
1360
+ contentType,
1361
+ entryDocumentId: entryDocumentId ?? null,
1362
+ locale: locale ?? null
1363
+ }
1364
+ }
1294
1365
  });
1295
- const pendingReleasesCount = await strapi.query(RELEASE_MODEL_UID).count({
1366
+ const releases = await releaseService.findMany({
1296
1367
  where: {
1368
+ $or: [
1369
+ {
1370
+ id: {
1371
+ $notIn: relatedReleases.map((release2) => release2.id)
1372
+ }
1373
+ },
1374
+ {
1375
+ actions: null
1376
+ }
1377
+ ],
1297
1378
  releasedAt: null
1298
1379
  }
1299
1380
  });
1300
- ctx.body = { data, meta: { pagination, pendingReleasesCount } };
1381
+ ctx.body = { data: releases };
1301
1382
  }
1302
1383
  },
1384
+ async findPage(ctx) {
1385
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
1386
+ ability: ctx.state.userAbility,
1387
+ model: RELEASE_MODEL_UID
1388
+ });
1389
+ await permissionsManager.validateQuery(ctx.query);
1390
+ const releaseService = getService("release", { strapi });
1391
+ const query = await permissionsManager.sanitizeQuery(ctx.query);
1392
+ const { results, pagination } = await releaseService.findPage(query);
1393
+ const data = results.map((release2) => {
1394
+ const { actions, ...releaseData } = release2;
1395
+ return {
1396
+ ...releaseData,
1397
+ actions: {
1398
+ meta: {
1399
+ count: actions.count
1400
+ }
1401
+ }
1402
+ };
1403
+ });
1404
+ const pendingReleasesCount = await strapi.db.query(RELEASE_MODEL_UID).count({
1405
+ where: {
1406
+ releasedAt: null
1407
+ }
1408
+ });
1409
+ ctx.body = { data, meta: { pagination, pendingReleasesCount } };
1410
+ },
1303
1411
  async findOne(ctx) {
1304
1412
  const id = ctx.params.id;
1305
1413
  const releaseService = getService("release", { strapi });
1414
+ const releaseActionService = getService("release-action", { strapi });
1306
1415
  const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
1307
1416
  if (!release2) {
1308
1417
  throw new utils.errors.NotFoundError(`Release not found for id: ${id}`);
1309
1418
  }
1310
- const count = await releaseService.countActions({
1419
+ const count = await releaseActionService.countActions({
1311
1420
  filters: {
1312
1421
  release: id
1313
1422
  }
1314
1423
  });
1315
1424
  const sanitizedRelease = {
1316
1425
  ...release2,
1317
- createdBy: release2.createdBy ? strapi.admin.services.user.sanitizeUser(release2.createdBy) : null
1426
+ createdBy: release2.createdBy ? strapi.service("admin::user").sanitizeUser(release2.createdBy) : null
1318
1427
  };
1319
1428
  const data = {
1320
1429
  ...sanitizedRelease,
@@ -1326,19 +1435,63 @@ const releaseController = {
1326
1435
  };
1327
1436
  ctx.body = { data };
1328
1437
  },
1438
+ async mapEntriesToReleases(ctx) {
1439
+ const { contentTypeUid, documentIds, locale } = ctx.query;
1440
+ if (!contentTypeUid || !documentIds) {
1441
+ throw new utils.errors.ValidationError("Missing required query parameters");
1442
+ }
1443
+ const releaseService = getService("release", { strapi });
1444
+ const releasesWithActions = await releaseService.findMany({
1445
+ where: {
1446
+ releasedAt: null,
1447
+ actions: {
1448
+ contentType: contentTypeUid,
1449
+ entryDocumentId: {
1450
+ $in: documentIds
1451
+ },
1452
+ locale
1453
+ }
1454
+ },
1455
+ populate: {
1456
+ actions: true
1457
+ }
1458
+ });
1459
+ const mappedEntriesInReleases = releasesWithActions.reduce(
1460
+ (acc, release2) => {
1461
+ release2.actions.forEach((action) => {
1462
+ if (action.contentType !== contentTypeUid) {
1463
+ return;
1464
+ }
1465
+ if (locale && action.locale !== locale) {
1466
+ return;
1467
+ }
1468
+ if (!acc[action.entryDocumentId]) {
1469
+ acc[action.entryDocumentId] = [{ id: release2.id, name: release2.name }];
1470
+ } else {
1471
+ acc[action.entryDocumentId].push({ id: release2.id, name: release2.name });
1472
+ }
1473
+ });
1474
+ return acc;
1475
+ },
1476
+ {}
1477
+ );
1478
+ ctx.body = {
1479
+ data: mappedEntriesInReleases
1480
+ };
1481
+ },
1329
1482
  async create(ctx) {
1330
1483
  const user = ctx.state.user;
1331
1484
  const releaseArgs = ctx.request.body;
1332
1485
  await validateRelease(releaseArgs);
1333
1486
  const releaseService = getService("release", { strapi });
1334
1487
  const release2 = await releaseService.create(releaseArgs, { user });
1335
- const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
1488
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
1336
1489
  ability: ctx.state.userAbility,
1337
1490
  model: RELEASE_MODEL_UID
1338
1491
  });
1339
- ctx.body = {
1492
+ ctx.created({
1340
1493
  data: await permissionsManager.sanitizeOutput(release2)
1341
- };
1494
+ });
1342
1495
  },
1343
1496
  async update(ctx) {
1344
1497
  const user = ctx.state.user;
@@ -1347,7 +1500,7 @@ const releaseController = {
1347
1500
  await validateRelease(releaseArgs);
1348
1501
  const releaseService = getService("release", { strapi });
1349
1502
  const release2 = await releaseService.update(id, releaseArgs, { user });
1350
- const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
1503
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
1351
1504
  ability: ctx.state.userAbility,
1352
1505
  model: RELEASE_MODEL_UID
1353
1506
  });
@@ -1364,18 +1517,18 @@ const releaseController = {
1364
1517
  };
1365
1518
  },
1366
1519
  async publish(ctx) {
1367
- const user = ctx.state.user;
1368
1520
  const id = ctx.params.id;
1369
1521
  const releaseService = getService("release", { strapi });
1370
- const release2 = await releaseService.publish(id, { user });
1522
+ const releaseActionService = getService("release-action", { strapi });
1523
+ const release2 = await releaseService.publish(id);
1371
1524
  const [countPublishActions, countUnpublishActions] = await Promise.all([
1372
- releaseService.countActions({
1525
+ releaseActionService.countActions({
1373
1526
  filters: {
1374
1527
  release: id,
1375
1528
  type: "publish"
1376
1529
  }
1377
1530
  }),
1378
- releaseService.countActions({
1531
+ releaseActionService.countActions({
1379
1532
  filters: {
1380
1533
  release: id,
1381
1534
  type: "unpublish"
@@ -1393,57 +1546,106 @@ const releaseController = {
1393
1546
  }
1394
1547
  };
1395
1548
  const RELEASE_ACTION_SCHEMA = utils.yup.object().shape({
1396
- entry: utils.yup.object().shape({
1397
- id: utils.yup.strapiID().required(),
1398
- contentType: utils.yup.string().required()
1399
- }).required(),
1549
+ contentType: utils.yup.string().required(),
1550
+ entryDocumentId: utils.yup.strapiID(),
1551
+ locale: utils.yup.string(),
1400
1552
  type: utils.yup.string().oneOf(["publish", "unpublish"]).required()
1401
1553
  });
1402
1554
  const RELEASE_ACTION_UPDATE_SCHEMA = utils.yup.object().shape({
1403
1555
  type: utils.yup.string().oneOf(["publish", "unpublish"]).required()
1404
1556
  });
1557
+ const FIND_MANY_ACTIONS_PARAMS = utils.yup.object().shape({
1558
+ groupBy: utils.yup.string().oneOf(["action", "contentType", "locale"])
1559
+ });
1405
1560
  const validateReleaseAction = utils.validateYupSchema(RELEASE_ACTION_SCHEMA);
1406
1561
  const validateReleaseActionUpdateSchema = utils.validateYupSchema(RELEASE_ACTION_UPDATE_SCHEMA);
1562
+ const validateFindManyActionsParams = utils.validateYupSchema(FIND_MANY_ACTIONS_PARAMS);
1407
1563
  const releaseActionController = {
1408
1564
  async create(ctx) {
1409
1565
  const releaseId = ctx.params.releaseId;
1410
1566
  const releaseActionArgs = ctx.request.body;
1411
1567
  await validateReleaseAction(releaseActionArgs);
1412
- const releaseService = getService("release", { strapi });
1413
- const releaseAction2 = await releaseService.createAction(releaseId, releaseActionArgs);
1414
- ctx.body = {
1568
+ const releaseActionService = getService("release-action", { strapi });
1569
+ const releaseAction2 = await releaseActionService.create(releaseId, releaseActionArgs);
1570
+ ctx.created({
1415
1571
  data: releaseAction2
1416
- };
1572
+ });
1573
+ },
1574
+ async createMany(ctx) {
1575
+ const releaseId = ctx.params.releaseId;
1576
+ const releaseActionsArgs = ctx.request.body;
1577
+ await Promise.all(
1578
+ releaseActionsArgs.map((releaseActionArgs) => validateReleaseAction(releaseActionArgs))
1579
+ );
1580
+ const releaseActionService = getService("release-action", { strapi });
1581
+ const releaseService = getService("release", { strapi });
1582
+ const releaseActions = await strapi.db.transaction(async () => {
1583
+ const releaseActions2 = await Promise.all(
1584
+ releaseActionsArgs.map(async (releaseActionArgs) => {
1585
+ try {
1586
+ const action = await releaseActionService.create(releaseId, releaseActionArgs, {
1587
+ disableUpdateReleaseStatus: true
1588
+ });
1589
+ return action;
1590
+ } catch (error) {
1591
+ if (error instanceof AlreadyOnReleaseError) {
1592
+ return null;
1593
+ }
1594
+ throw error;
1595
+ }
1596
+ })
1597
+ );
1598
+ return releaseActions2;
1599
+ });
1600
+ const newReleaseActions = releaseActions.filter((action) => action !== null);
1601
+ if (newReleaseActions.length > 0) {
1602
+ releaseService.updateReleaseStatus(releaseId);
1603
+ }
1604
+ ctx.created({
1605
+ data: newReleaseActions,
1606
+ meta: {
1607
+ entriesAlreadyInRelease: releaseActions.length - newReleaseActions.length,
1608
+ totalEntries: releaseActions.length
1609
+ }
1610
+ });
1417
1611
  },
1418
1612
  async findMany(ctx) {
1419
1613
  const releaseId = ctx.params.releaseId;
1420
- const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
1614
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
1421
1615
  ability: ctx.state.userAbility,
1422
1616
  model: RELEASE_ACTION_MODEL_UID
1423
1617
  });
1618
+ await validateFindManyActionsParams(ctx.query);
1619
+ if (ctx.query.groupBy) {
1620
+ if (!["action", "contentType", "locale"].includes(ctx.query.groupBy)) {
1621
+ ctx.badRequest("Invalid groupBy parameter");
1622
+ }
1623
+ }
1624
+ ctx.query.sort = ctx.query.groupBy === "action" ? "type" : ctx.query.groupBy;
1625
+ delete ctx.query.groupBy;
1424
1626
  const query = await permissionsManager.sanitizeQuery(ctx.query);
1425
- const releaseService = getService("release", { strapi });
1426
- const { results, pagination } = await releaseService.findActions(releaseId, {
1427
- sort: query.groupBy === "action" ? "type" : query.groupBy,
1627
+ const releaseActionService = getService("release-action", { strapi });
1628
+ const { results, pagination } = await releaseActionService.findPage(releaseId, {
1428
1629
  ...query
1429
1630
  });
1430
1631
  const contentTypeOutputSanitizers = results.reduce((acc, action) => {
1431
1632
  if (acc[action.contentType]) {
1432
1633
  return acc;
1433
1634
  }
1434
- const contentTypePermissionsManager = strapi.admin.services.permission.createPermissionsManager({
1635
+ const contentTypePermissionsManager = strapi.service("admin::permission").createPermissionsManager({
1435
1636
  ability: ctx.state.userAbility,
1436
1637
  model: action.contentType
1437
1638
  });
1438
1639
  acc[action.contentType] = contentTypePermissionsManager.sanitizeOutput;
1439
1640
  return acc;
1440
1641
  }, {});
1441
- const sanitizedResults = await utils.mapAsync(results, async (action) => ({
1642
+ const sanitizedResults = await utils.async.map(results, async (action) => ({
1442
1643
  ...action,
1443
- entry: await contentTypeOutputSanitizers[action.contentType](action.entry)
1644
+ entry: action.entry ? await contentTypeOutputSanitizers[action.contentType](action.entry) : {}
1444
1645
  }));
1445
- const groupedData = await releaseService.groupActions(sanitizedResults, query.groupBy);
1446
- const contentTypes2 = releaseService.getContentTypeModelsFromActions(results);
1646
+ const groupedData = await releaseActionService.groupActions(sanitizedResults, query.sort);
1647
+ const contentTypes2 = releaseActionService.getContentTypeModelsFromActions(results);
1648
+ const releaseService = getService("release", { strapi });
1447
1649
  const components = await releaseService.getAllComponents();
1448
1650
  ctx.body = {
1449
1651
  data: groupedData,
@@ -1459,8 +1661,8 @@ const releaseActionController = {
1459
1661
  const releaseId = ctx.params.releaseId;
1460
1662
  const releaseActionUpdateArgs = ctx.request.body;
1461
1663
  await validateReleaseActionUpdateSchema(releaseActionUpdateArgs);
1462
- const releaseService = getService("release", { strapi });
1463
- const updatedAction = await releaseService.updateAction(
1664
+ const releaseActionService = getService("release-action", { strapi });
1665
+ const updatedAction = await releaseActionService.update(
1464
1666
  actionId,
1465
1667
  releaseId,
1466
1668
  releaseActionUpdateArgs
@@ -1472,17 +1674,71 @@ const releaseActionController = {
1472
1674
  async delete(ctx) {
1473
1675
  const actionId = ctx.params.actionId;
1474
1676
  const releaseId = ctx.params.releaseId;
1475
- const releaseService = getService("release", { strapi });
1476
- const deletedReleaseAction = await releaseService.deleteAction(actionId, releaseId);
1677
+ const releaseActionService = getService("release-action", { strapi });
1678
+ const deletedReleaseAction = await releaseActionService.delete(actionId, releaseId);
1477
1679
  ctx.body = {
1478
1680
  data: deletedReleaseAction
1479
1681
  };
1480
1682
  }
1481
1683
  };
1482
- const controllers = { release: releaseController, "release-action": releaseActionController };
1684
+ const SETTINGS_SCHEMA = yup__namespace.object().shape({
1685
+ defaultTimezone: yup__namespace.string().nullable().default(null)
1686
+ }).required().noUnknown();
1687
+ const validateSettings = utils.validateYupSchema(SETTINGS_SCHEMA);
1688
+ const settingsController = {
1689
+ async find(ctx) {
1690
+ const settingsService = getService("settings", { strapi });
1691
+ const settings2 = await settingsService.find();
1692
+ ctx.body = { data: settings2 };
1693
+ },
1694
+ async update(ctx) {
1695
+ const settingsBody = ctx.request.body;
1696
+ const settings2 = await validateSettings(settingsBody);
1697
+ const settingsService = getService("settings", { strapi });
1698
+ const updatedSettings = await settingsService.update({ settings: settings2 });
1699
+ ctx.body = { data: updatedSettings };
1700
+ }
1701
+ };
1702
+ const controllers = {
1703
+ release: releaseController,
1704
+ "release-action": releaseActionController,
1705
+ settings: settingsController
1706
+ };
1483
1707
  const release = {
1484
1708
  type: "admin",
1485
1709
  routes: [
1710
+ {
1711
+ method: "GET",
1712
+ path: "/mapEntriesToReleases",
1713
+ handler: "release.mapEntriesToReleases",
1714
+ config: {
1715
+ policies: [
1716
+ "admin::isAuthenticatedAdmin",
1717
+ {
1718
+ name: "admin::hasPermissions",
1719
+ config: {
1720
+ actions: ["plugin::content-releases.read"]
1721
+ }
1722
+ }
1723
+ ]
1724
+ }
1725
+ },
1726
+ {
1727
+ method: "GET",
1728
+ path: "/getByDocumentAttached",
1729
+ handler: "release.findByDocumentAttached",
1730
+ config: {
1731
+ policies: [
1732
+ "admin::isAuthenticatedAdmin",
1733
+ {
1734
+ name: "admin::hasPermissions",
1735
+ config: {
1736
+ actions: ["plugin::content-releases.read"]
1737
+ }
1738
+ }
1739
+ ]
1740
+ }
1741
+ },
1486
1742
  {
1487
1743
  method: "POST",
1488
1744
  path: "/",
@@ -1502,7 +1758,7 @@ const release = {
1502
1758
  {
1503
1759
  method: "GET",
1504
1760
  path: "/",
1505
- handler: "release.findMany",
1761
+ handler: "release.findPage",
1506
1762
  config: {
1507
1763
  policies: [
1508
1764
  "admin::isAuthenticatedAdmin",
@@ -1600,6 +1856,22 @@ const releaseAction = {
1600
1856
  ]
1601
1857
  }
1602
1858
  },
1859
+ {
1860
+ method: "POST",
1861
+ path: "/:releaseId/actions/bulk",
1862
+ handler: "release-action.createMany",
1863
+ config: {
1864
+ policies: [
1865
+ "admin::isAuthenticatedAdmin",
1866
+ {
1867
+ name: "admin::hasPermissions",
1868
+ config: {
1869
+ actions: ["plugin::content-releases.create-action"]
1870
+ }
1871
+ }
1872
+ ]
1873
+ }
1874
+ },
1603
1875
  {
1604
1876
  method: "GET",
1605
1877
  path: "/:releaseId/actions",
@@ -1650,13 +1922,50 @@ const releaseAction = {
1650
1922
  }
1651
1923
  ]
1652
1924
  };
1925
+ const settings = {
1926
+ type: "admin",
1927
+ routes: [
1928
+ {
1929
+ method: "GET",
1930
+ path: "/settings",
1931
+ handler: "settings.find",
1932
+ config: {
1933
+ policies: [
1934
+ "admin::isAuthenticatedAdmin",
1935
+ {
1936
+ name: "admin::hasPermissions",
1937
+ config: {
1938
+ actions: ["plugin::content-releases.settings.read"]
1939
+ }
1940
+ }
1941
+ ]
1942
+ }
1943
+ },
1944
+ {
1945
+ method: "PUT",
1946
+ path: "/settings",
1947
+ handler: "settings.update",
1948
+ config: {
1949
+ policies: [
1950
+ "admin::isAuthenticatedAdmin",
1951
+ {
1952
+ name: "admin::hasPermissions",
1953
+ config: {
1954
+ actions: ["plugin::content-releases.settings.update"]
1955
+ }
1956
+ }
1957
+ ]
1958
+ }
1959
+ }
1960
+ ]
1961
+ };
1653
1962
  const routes = {
1963
+ settings,
1654
1964
  release,
1655
1965
  "release-action": releaseAction
1656
1966
  };
1657
- const { features } = require("@strapi/strapi/dist/utils/ee");
1658
1967
  const getPlugin = () => {
1659
- if (features.isEnabled("cms-content-releases")) {
1968
+ if (strapi.ee.features.isEnabled("cms-content-releases")) {
1660
1969
  return {
1661
1970
  register,
1662
1971
  bootstrap,