@strapi/content-releases 0.0.0-next.4052765aa209dd4f3d92b81baee295fc0213c04c → 0.0.0-next.4119cc523a8fec549bb2f1869c6e789650f7f4de

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 (41) hide show
  1. package/dist/_chunks/{App-BA2xDdy0.mjs → App-FQyYFBJT.mjs} +298 -113
  2. package/dist/_chunks/App-FQyYFBJT.mjs.map +1 -0
  3. package/dist/_chunks/{App-D4Wira1X.js → App-lx4Ucy9W.js} +337 -152
  4. package/dist/_chunks/App-lx4Ucy9W.js.map +1 -0
  5. package/dist/_chunks/{ReleasesSettingsPage-BAlbMWpw.mjs → ReleasesSettingsPage-DqBxvJ9i.mjs} +2 -2
  6. package/dist/_chunks/{ReleasesSettingsPage-BAlbMWpw.mjs.map → ReleasesSettingsPage-DqBxvJ9i.mjs.map} +1 -1
  7. package/dist/_chunks/{ReleasesSettingsPage-xhFyRXCM.js → ReleasesSettingsPage-T5VEAV03.js} +2 -2
  8. package/dist/_chunks/{ReleasesSettingsPage-xhFyRXCM.js.map → ReleasesSettingsPage-T5VEAV03.js.map} +1 -1
  9. package/dist/_chunks/{en-CmYoEnA7.js → en-BWPPsSH-.js} +11 -2
  10. package/dist/_chunks/en-BWPPsSH-.js.map +1 -0
  11. package/dist/_chunks/{en-D0yVZFqf.mjs → en-D9Q4YW03.mjs} +11 -2
  12. package/dist/_chunks/en-D9Q4YW03.mjs.map +1 -0
  13. package/dist/_chunks/{index-CCFFG3Zs.mjs → index-CK9G80CL.mjs} +22 -7
  14. package/dist/_chunks/index-CK9G80CL.mjs.map +1 -0
  15. package/dist/_chunks/{index-DxkQGp4N.js → index-Cl3tM1YW.js} +22 -7
  16. package/dist/_chunks/index-Cl3tM1YW.js.map +1 -0
  17. package/dist/admin/index.js +1 -1
  18. package/dist/admin/index.mjs +1 -1
  19. package/dist/admin/src/components/EntryValidationPopover.d.ts +13 -0
  20. package/dist/server/index.js +83 -9
  21. package/dist/server/index.js.map +1 -1
  22. package/dist/server/index.mjs +83 -9
  23. package/dist/server/index.mjs.map +1 -1
  24. package/dist/server/src/index.d.ts +2 -6
  25. package/dist/server/src/index.d.ts.map +1 -1
  26. package/dist/server/src/middlewares/documents.d.ts.map +1 -1
  27. package/dist/server/src/migrations/database/5.0.0-document-id-in-actions.d.ts.map +1 -1
  28. package/dist/server/src/services/index.d.ts +2 -6
  29. package/dist/server/src/services/index.d.ts.map +1 -1
  30. package/dist/server/src/services/release-action.d.ts +3 -7
  31. package/dist/server/src/services/release-action.d.ts.map +1 -1
  32. package/dist/server/src/utils/index.d.ts.map +1 -1
  33. package/dist/shared/contracts/release-actions.d.ts +8 -1
  34. package/dist/shared/contracts/release-actions.d.ts.map +1 -1
  35. package/package.json +15 -14
  36. package/dist/_chunks/App-BA2xDdy0.mjs.map +0 -1
  37. package/dist/_chunks/App-D4Wira1X.js.map +0 -1
  38. package/dist/_chunks/en-CmYoEnA7.js.map +0 -1
  39. package/dist/_chunks/en-D0yVZFqf.mjs.map +0 -1
  40. package/dist/_chunks/index-CCFFG3Zs.mjs.map +0 -1
  41. package/dist/_chunks/index-DxkQGp4N.js.map +0 -1
@@ -111,6 +111,13 @@ const isEntryValid = async (contentTypeUid, entry, { strapi: strapi2 }) => {
111
111
  // @ts-expect-error - FIXME: entity here is unnecessary
112
112
  entry
113
113
  );
114
+ const workflowsService = strapi2.plugin("review-workflows").service("workflows");
115
+ const workflow = await workflowsService.getAssignedWorkflow(contentTypeUid, {
116
+ populate: "stageRequiredToPublish"
117
+ });
118
+ if (workflow?.stageRequiredToPublish) {
119
+ return entry.strapi_stage.id === workflow.stageRequiredToPublish.id;
120
+ }
114
121
  return true;
115
122
  } catch {
116
123
  return false;
@@ -124,7 +131,11 @@ const getEntry = async ({
124
131
  status = "draft"
125
132
  }, { strapi: strapi2 }) => {
126
133
  if (documentId) {
127
- return strapi2.documents(contentType).findOne({ documentId, locale, populate, status });
134
+ const entry = await strapi2.documents(contentType).findOne({ documentId, locale, populate, status });
135
+ if (status === "published" && !entry) {
136
+ return strapi2.documents(contentType).findOne({ documentId, locale, populate, status: "draft" });
137
+ }
138
+ return entry;
128
139
  }
129
140
  return strapi2.documents(contentType).findFirst({ locale, populate, status });
130
141
  };
@@ -329,6 +340,10 @@ async function enableContentTypeLocalized({ oldContentTypes, contentTypes: conte
329
340
  const addEntryDocumentToReleaseActions = {
330
341
  name: "content-releases::5.0.0-add-entry-document-id-to-release-actions",
331
342
  async up(trx, db) {
343
+ const hasTable = await trx.schema.hasTable("strapi_release_actions");
344
+ if (!hasTable) {
345
+ return;
346
+ }
332
347
  const hasPolymorphicColumn = await trx.schema.hasColumn("strapi_release_actions", "target_id");
333
348
  if (hasPolymorphicColumn) {
334
349
  const hasEntryDocumentIdColumn = await trx.schema.hasColumn(
@@ -370,6 +385,7 @@ const register = async ({ strapi: strapi2 }) => {
370
385
  const updateActionsStatusAndUpdateReleaseStatus = async (contentType, entry) => {
371
386
  const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
372
387
  where: {
388
+ releasedAt: null,
373
389
  actions: {
374
390
  contentType,
375
391
  entryDocumentId: entry.documentId,
@@ -378,7 +394,7 @@ const updateActionsStatusAndUpdateReleaseStatus = async (contentType, entry) =>
378
394
  }
379
395
  });
380
396
  const entryStatus = await isEntryValid(contentType, entry, { strapi });
381
- await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
397
+ await strapi.db.query(RELEASE_ACTION_MODEL_UID).updateMany({
382
398
  where: {
383
399
  contentType,
384
400
  entryDocumentId: entry.documentId,
@@ -482,8 +498,8 @@ const bootstrap = async ({ strapi: strapi2 }) => {
482
498
  const { where } = event.params;
483
499
  deleteReleasesActionsAndUpdateReleaseStatus({
484
500
  contentType: model.uid,
485
- locale: where.locale ?? null,
486
- ...where.documentId && { entryDocumentId: where.documentId }
501
+ locale: where?.locale ?? null,
502
+ ...where?.documentId && { entryDocumentId: where.documentId }
487
503
  });
488
504
  }
489
505
  } catch (error) {
@@ -1038,16 +1054,26 @@ const createReleaseActionService = ({ strapi: strapi2 }) => {
1038
1054
  const groupName = getGroupName(groupBy);
1039
1055
  return ___default.default.groupBy(groupName)(formattedData);
1040
1056
  },
1041
- getContentTypeModelsFromActions(actions) {
1057
+ async getContentTypeModelsFromActions(actions) {
1042
1058
  const contentTypeUids = actions.reduce((acc, action) => {
1043
1059
  if (!acc.includes(action.contentType)) {
1044
1060
  acc.push(action.contentType);
1045
1061
  }
1046
1062
  return acc;
1047
1063
  }, []);
1048
- const contentTypeModelsMap = contentTypeUids.reduce(
1049
- (acc, contentTypeUid) => {
1050
- acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
1064
+ const workflowsService = strapi2.plugin("review-workflows").service("workflows");
1065
+ const contentTypeModelsMap = await utils.async.reduce(contentTypeUids)(
1066
+ async (accPromise, contentTypeUid) => {
1067
+ const acc = await accPromise;
1068
+ const contentTypeModel = strapi2.getModel(contentTypeUid);
1069
+ const workflow = await workflowsService.getAssignedWorkflow(contentTypeUid, {
1070
+ populate: "stageRequiredToPublish"
1071
+ });
1072
+ acc[contentTypeUid] = {
1073
+ ...contentTypeModel,
1074
+ hasReviewWorkflow: !!workflow,
1075
+ stageRequiredToPublish: workflow?.stageRequiredToPublish
1076
+ };
1051
1077
  return acc;
1052
1078
  },
1053
1079
  {}
@@ -1122,6 +1148,54 @@ const createReleaseActionService = ({ strapi: strapi2 }) => {
1122
1148
  }
1123
1149
  getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
1124
1150
  return deletedAction;
1151
+ },
1152
+ async validateActionsByContentTypes(contentTypeUids) {
1153
+ const actions = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findMany({
1154
+ where: {
1155
+ contentType: {
1156
+ $in: contentTypeUids
1157
+ },
1158
+ // We only want to validate actions that are going to be published
1159
+ type: "publish",
1160
+ release: {
1161
+ releasedAt: {
1162
+ $null: true
1163
+ }
1164
+ }
1165
+ },
1166
+ populate: { release: true }
1167
+ });
1168
+ const releasesUpdated = [];
1169
+ await utils.async.map(actions, async (action) => {
1170
+ const isValid = await getDraftEntryValidStatus(
1171
+ {
1172
+ contentType: action.contentType,
1173
+ documentId: action.entryDocumentId,
1174
+ locale: action.locale
1175
+ },
1176
+ { strapi: strapi2 }
1177
+ );
1178
+ await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
1179
+ where: {
1180
+ id: action.id
1181
+ },
1182
+ data: {
1183
+ isEntryValid: isValid
1184
+ }
1185
+ });
1186
+ if (!releasesUpdated.includes(action.release.id)) {
1187
+ releasesUpdated.push(action.release.id);
1188
+ }
1189
+ return {
1190
+ id: action.id,
1191
+ isEntryValid: isValid
1192
+ };
1193
+ });
1194
+ if (releasesUpdated.length > 0) {
1195
+ await utils.async.map(releasesUpdated, async (releaseId) => {
1196
+ await getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
1197
+ });
1198
+ }
1125
1199
  }
1126
1200
  };
1127
1201
  };
@@ -1640,7 +1714,7 @@ const releaseActionController = {
1640
1714
  entry: action.entry ? await contentTypeOutputSanitizers[action.contentType](action.entry) : {}
1641
1715
  }));
1642
1716
  const groupedData = await releaseActionService.groupActions(sanitizedResults, query.sort);
1643
- const contentTypes2 = releaseActionService.getContentTypeModelsFromActions(results);
1717
+ const contentTypes2 = await releaseActionService.getContentTypeModelsFromActions(results);
1644
1718
  const releaseService = getService("release", { strapi });
1645
1719
  const components = await releaseService.getAllComponents();
1646
1720
  ctx.body = {