@strapi/content-releases 0.0.0-next.fc231041206e6f3999b094160cfa05db2892ad54 → 0.0.0-next.fd9757603c653ca239c45d6e28ab536d2dae0b39

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 (32) hide show
  1. package/LICENSE +17 -1
  2. package/dist/_chunks/{App-l62gIUTX.js → App-dLXY5ei3.js} +48 -31
  3. package/dist/_chunks/App-dLXY5ei3.js.map +1 -0
  4. package/dist/_chunks/{App-HVXzE3i3.mjs → App-jrh58sXY.mjs} +51 -34
  5. package/dist/_chunks/App-jrh58sXY.mjs.map +1 -0
  6. package/dist/_chunks/{PurchaseContentReleases-Clm0iACO.mjs → PurchaseContentReleases-3tRbmbY3.mjs} +2 -2
  7. package/dist/_chunks/PurchaseContentReleases-3tRbmbY3.mjs.map +1 -0
  8. package/dist/_chunks/{PurchaseContentReleases-YhAPgpG9.js → PurchaseContentReleases-bpIYXOfu.js} +2 -2
  9. package/dist/_chunks/PurchaseContentReleases-bpIYXOfu.js.map +1 -0
  10. package/dist/_chunks/{en-faJDuv3q.js → en-HrREghh3.js} +11 -2
  11. package/dist/_chunks/en-HrREghh3.js.map +1 -0
  12. package/dist/_chunks/{en-RdapH-9X.mjs → en-ltT1TlKQ.mjs} +11 -2
  13. package/dist/_chunks/en-ltT1TlKQ.mjs.map +1 -0
  14. package/dist/_chunks/{index-ML_b3php.js → index-CVO0Rqdm.js} +315 -13
  15. package/dist/_chunks/index-CVO0Rqdm.js.map +1 -0
  16. package/dist/_chunks/{index-Ys87ROOe.mjs → index-PiOGBETy.mjs} +320 -18
  17. package/dist/_chunks/index-PiOGBETy.mjs.map +1 -0
  18. package/dist/admin/index.js +1 -1
  19. package/dist/admin/index.mjs +1 -1
  20. package/dist/server/index.js +79 -10
  21. package/dist/server/index.js.map +1 -1
  22. package/dist/server/index.mjs +79 -10
  23. package/dist/server/index.mjs.map +1 -1
  24. package/package.json +15 -14
  25. package/dist/_chunks/App-HVXzE3i3.mjs.map +0 -1
  26. package/dist/_chunks/App-l62gIUTX.js.map +0 -1
  27. package/dist/_chunks/PurchaseContentReleases-Clm0iACO.mjs.map +0 -1
  28. package/dist/_chunks/PurchaseContentReleases-YhAPgpG9.js.map +0 -1
  29. package/dist/_chunks/en-RdapH-9X.mjs.map +0 -1
  30. package/dist/_chunks/en-faJDuv3q.js.map +0 -1
  31. package/dist/_chunks/index-ML_b3php.js.map +0 -1
  32. package/dist/_chunks/index-Ys87ROOe.mjs.map +0 -1
@@ -211,13 +211,16 @@ async function disableContentTypeLocalized({ oldContentTypes, contentTypes: cont
211
211
  if (!oldContentTypes) {
212
212
  return;
213
213
  }
214
+ const i18nPlugin = strapi.plugin("i18n");
215
+ if (!i18nPlugin) {
216
+ return;
217
+ }
214
218
  for (const uid in contentTypes2) {
215
219
  if (!oldContentTypes[uid]) {
216
220
  continue;
217
221
  }
218
222
  const oldContentType = oldContentTypes[uid];
219
223
  const contentType = contentTypes2[uid];
220
- const i18nPlugin = strapi.plugin("i18n");
221
224
  const { isLocalizedContentType } = i18nPlugin.service("content-types");
222
225
  if (isLocalizedContentType(oldContentType) && !isLocalizedContentType(contentType)) {
223
226
  await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
@@ -230,13 +233,16 @@ async function enableContentTypeLocalized({ oldContentTypes, contentTypes: conte
230
233
  if (!oldContentTypes) {
231
234
  return;
232
235
  }
236
+ const i18nPlugin = strapi.plugin("i18n");
237
+ if (!i18nPlugin) {
238
+ return;
239
+ }
233
240
  for (const uid in contentTypes2) {
234
241
  if (!oldContentTypes[uid]) {
235
242
  continue;
236
243
  }
237
244
  const oldContentType = oldContentTypes[uid];
238
245
  const contentType = contentTypes2[uid];
239
- const i18nPlugin = strapi.plugin("i18n");
240
246
  const { isLocalizedContentType } = i18nPlugin.service("content-types");
241
247
  const { getDefaultLocale } = i18nPlugin.service("locales");
242
248
  if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {
@@ -655,12 +661,18 @@ const createReleaseService = ({ strapi: strapi2 }) => {
655
661
  }
656
662
  });
657
663
  },
658
- async findManyWithContentTypeEntryAttached(contentTypeUid, entryId) {
664
+ async findManyWithContentTypeEntryAttached(contentTypeUid, entriesIds) {
665
+ let entries = entriesIds;
666
+ if (!Array.isArray(entriesIds)) {
667
+ entries = [entriesIds];
668
+ }
659
669
  const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
660
670
  where: {
661
671
  actions: {
662
672
  target_type: contentTypeUid,
663
- target_id: entryId
673
+ target_id: {
674
+ $in: entries
675
+ }
664
676
  },
665
677
  releasedAt: {
666
678
  $null: true
@@ -671,18 +683,25 @@ const createReleaseService = ({ strapi: strapi2 }) => {
671
683
  actions: {
672
684
  where: {
673
685
  target_type: contentTypeUid,
674
- target_id: entryId
686
+ target_id: {
687
+ $in: entries
688
+ }
689
+ },
690
+ populate: {
691
+ entry: {
692
+ select: ["id"]
693
+ }
675
694
  }
676
695
  }
677
696
  }
678
697
  });
679
698
  return releases.map((release2) => {
680
699
  if (release2.actions?.length) {
681
- const [actionForEntry] = release2.actions;
700
+ const actionsForEntry = release2.actions;
682
701
  delete release2.actions;
683
702
  return {
684
703
  ...release2,
685
- action: actionForEntry
704
+ actions: actionsForEntry
686
705
  };
687
706
  }
688
707
  return release2;
@@ -766,7 +785,7 @@ const createReleaseService = ({ strapi: strapi2 }) => {
766
785
  strapi2.telemetry.send("didUpdateContentRelease");
767
786
  return updatedRelease;
768
787
  },
769
- async createAction(releaseId, action) {
788
+ async createAction(releaseId, action, { disableUpdateReleaseStatus = false } = {}) {
770
789
  const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
771
790
  strapi: strapi2
772
791
  });
@@ -799,7 +818,9 @@ const createReleaseService = ({ strapi: strapi2 }) => {
799
818
  },
800
819
  populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
801
820
  });
802
- this.updateReleaseStatus(releaseId);
821
+ if (!disableUpdateReleaseStatus) {
822
+ this.updateReleaseStatus(releaseId);
823
+ }
803
824
  return releaseAction2;
804
825
  },
805
826
  async findActions(releaseId, query) {
@@ -1298,6 +1319,33 @@ const releaseController = {
1298
1319
  };
1299
1320
  ctx.body = { data };
1300
1321
  },
1322
+ async mapEntriesToReleases(ctx) {
1323
+ const { contentTypeUid, entriesIds } = ctx.query;
1324
+ if (!contentTypeUid || !entriesIds) {
1325
+ throw new errors.ValidationError("Missing required query parameters");
1326
+ }
1327
+ const releaseService = getService("release", { strapi });
1328
+ const releasesWithActions = await releaseService.findManyWithContentTypeEntryAttached(
1329
+ contentTypeUid,
1330
+ entriesIds
1331
+ );
1332
+ const mappedEntriesInReleases = releasesWithActions.reduce(
1333
+ (acc, release2) => {
1334
+ release2.actions.forEach((action) => {
1335
+ if (!acc[action.entry.id]) {
1336
+ acc[action.entry.id] = [{ id: release2.id, name: release2.name }];
1337
+ } else {
1338
+ acc[action.entry.id].push({ id: release2.id, name: release2.name });
1339
+ }
1340
+ });
1341
+ return acc;
1342
+ },
1343
+ {}
1344
+ );
1345
+ ctx.body = {
1346
+ data: mappedEntriesInReleases
1347
+ };
1348
+ },
1301
1349
  async create(ctx) {
1302
1350
  const user = ctx.state.user;
1303
1351
  const releaseArgs = ctx.request.body;
@@ -1398,7 +1446,9 @@ const releaseActionController = {
1398
1446
  const releaseActions2 = await Promise.all(
1399
1447
  releaseActionsArgs.map(async (releaseActionArgs) => {
1400
1448
  try {
1401
- const action = await releaseService.createAction(releaseId, releaseActionArgs);
1449
+ const action = await releaseService.createAction(releaseId, releaseActionArgs, {
1450
+ disableUpdateReleaseStatus: true
1451
+ });
1402
1452
  return action;
1403
1453
  } catch (error) {
1404
1454
  if (error instanceof AlreadyOnReleaseError) {
@@ -1411,6 +1461,9 @@ const releaseActionController = {
1411
1461
  return releaseActions2;
1412
1462
  });
1413
1463
  const newReleaseActions = releaseActions.filter((action) => action !== null);
1464
+ if (newReleaseActions.length > 0) {
1465
+ releaseService.updateReleaseStatus(releaseId);
1466
+ }
1414
1467
  ctx.body = {
1415
1468
  data: newReleaseActions,
1416
1469
  meta: {
@@ -1487,6 +1540,22 @@ const controllers = { release: releaseController, "release-action": releaseActio
1487
1540
  const release = {
1488
1541
  type: "admin",
1489
1542
  routes: [
1543
+ {
1544
+ method: "GET",
1545
+ path: "/mapEntriesToReleases",
1546
+ handler: "release.mapEntriesToReleases",
1547
+ config: {
1548
+ policies: [
1549
+ "admin::isAuthenticatedAdmin",
1550
+ {
1551
+ name: "admin::hasPermissions",
1552
+ config: {
1553
+ actions: ["plugin::content-releases.read"]
1554
+ }
1555
+ }
1556
+ ]
1557
+ }
1558
+ },
1490
1559
  {
1491
1560
  method: "POST",
1492
1561
  path: "/",