@strapi/content-releases 0.0.0-next.d0bd7aa4c25bfb448b93a62f3d47db9b6fdd8ee3 → 0.0.0-next.d2d15ef227d67cce89c2673764c0555c841cd29c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -1
- package/dist/_chunks/App-BA2xDdy0.mjs +1374 -0
- package/dist/_chunks/App-BA2xDdy0.mjs.map +1 -0
- package/dist/_chunks/App-D4Wira1X.js +1395 -0
- package/dist/_chunks/App-D4Wira1X.js.map +1 -0
- package/dist/_chunks/{PurchaseContentReleases-YhAPgpG9.js → PurchaseContentReleases-Be3acS2L.js} +8 -7
- package/dist/_chunks/PurchaseContentReleases-Be3acS2L.js.map +1 -0
- package/dist/_chunks/{PurchaseContentReleases-Clm0iACO.mjs → PurchaseContentReleases-_MxP6-Dt.mjs} +9 -8
- package/dist/_chunks/PurchaseContentReleases-_MxP6-Dt.mjs.map +1 -0
- package/dist/_chunks/ReleasesSettingsPage-BAlbMWpw.mjs +178 -0
- package/dist/_chunks/ReleasesSettingsPage-BAlbMWpw.mjs.map +1 -0
- package/dist/_chunks/ReleasesSettingsPage-xhFyRXCM.js +178 -0
- package/dist/_chunks/ReleasesSettingsPage-xhFyRXCM.js.map +1 -0
- package/dist/_chunks/{en-faJDuv3q.js → en-CmYoEnA7.js} +19 -3
- package/dist/_chunks/en-CmYoEnA7.js.map +1 -0
- package/dist/_chunks/{en-RdapH-9X.mjs → en-D0yVZFqf.mjs} +19 -3
- package/dist/_chunks/en-D0yVZFqf.mjs.map +1 -0
- package/dist/_chunks/index-CCFFG3Zs.mjs +1365 -0
- package/dist/_chunks/index-CCFFG3Zs.mjs.map +1 -0
- package/dist/_chunks/index-DxkQGp4N.js +1384 -0
- package/dist/_chunks/index-DxkQGp4N.js.map +1 -0
- package/dist/_chunks/schemas-BE1LxE9J.js +62 -0
- package/dist/_chunks/schemas-BE1LxE9J.js.map +1 -0
- package/dist/_chunks/schemas-DdA2ic2U.mjs +44 -0
- package/dist/_chunks/schemas-DdA2ic2U.mjs.map +1 -0
- package/dist/admin/index.js +1 -15
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +2 -16
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/src/components/RelativeTime.d.ts +28 -0
- package/dist/admin/src/components/ReleaseAction.d.ts +3 -0
- package/dist/admin/src/components/ReleaseActionMenu.d.ts +26 -0
- package/dist/admin/src/components/ReleaseActionModal.d.ts +24 -0
- package/dist/admin/src/components/ReleaseActionOptions.d.ts +9 -0
- package/dist/admin/src/components/ReleaseListCell.d.ts +28 -0
- package/dist/admin/src/components/ReleaseModal.d.ts +17 -0
- package/dist/admin/src/components/ReleasesPanel.d.ts +3 -0
- package/dist/admin/src/constants.d.ts +76 -0
- package/dist/admin/src/index.d.ts +3 -0
- package/dist/admin/src/modules/hooks.d.ts +7 -0
- package/dist/admin/src/pages/App.d.ts +1 -0
- package/dist/admin/src/pages/PurchaseContentReleases.d.ts +2 -0
- package/dist/admin/src/pages/ReleaseDetailsPage.d.ts +2 -0
- package/dist/admin/src/pages/ReleasesPage.d.ts +8 -0
- package/dist/admin/src/pages/ReleasesSettingsPage.d.ts +1 -0
- package/dist/admin/src/pages/tests/mockReleaseDetailsPageData.d.ts +181 -0
- package/dist/admin/src/pages/tests/mockReleasesPageData.d.ts +39 -0
- package/dist/admin/src/pluginId.d.ts +1 -0
- package/dist/admin/src/services/release.d.ts +112 -0
- package/dist/admin/src/store/hooks.d.ts +7 -0
- package/dist/admin/src/utils/api.d.ts +6 -0
- package/dist/admin/src/utils/prefixPluginTranslations.d.ts +3 -0
- package/dist/admin/src/utils/time.d.ts +10 -0
- package/dist/admin/src/validation/schemas.d.ts +6 -0
- package/dist/server/index.js +878 -617
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +879 -617
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/bootstrap.d.ts +5 -0
- package/dist/server/src/bootstrap.d.ts.map +1 -0
- package/dist/server/src/constants.d.ts +21 -0
- package/dist/server/src/constants.d.ts.map +1 -0
- package/dist/server/src/content-types/index.d.ts +97 -0
- package/dist/server/src/content-types/index.d.ts.map +1 -0
- package/dist/server/src/content-types/release/index.d.ts +48 -0
- package/dist/server/src/content-types/release/index.d.ts.map +1 -0
- package/dist/server/src/content-types/release/schema.d.ts +47 -0
- package/dist/server/src/content-types/release/schema.d.ts.map +1 -0
- package/dist/server/src/content-types/release-action/index.d.ts +48 -0
- package/dist/server/src/content-types/release-action/index.d.ts.map +1 -0
- package/dist/server/src/content-types/release-action/schema.d.ts +47 -0
- package/dist/server/src/content-types/release-action/schema.d.ts.map +1 -0
- package/dist/server/src/controllers/index.d.ts +25 -0
- package/dist/server/src/controllers/index.d.ts.map +1 -0
- package/dist/server/src/controllers/release-action.d.ts +10 -0
- package/dist/server/src/controllers/release-action.d.ts.map +1 -0
- package/dist/server/src/controllers/release.d.ts +18 -0
- package/dist/server/src/controllers/release.d.ts.map +1 -0
- package/dist/server/src/controllers/settings.d.ts +11 -0
- package/dist/server/src/controllers/settings.d.ts.map +1 -0
- package/dist/server/src/controllers/validation/release-action.d.ts +14 -0
- package/dist/server/src/controllers/validation/release-action.d.ts.map +1 -0
- package/dist/server/src/controllers/validation/release.d.ts +4 -0
- package/dist/server/src/controllers/validation/release.d.ts.map +1 -0
- package/dist/server/src/controllers/validation/settings.d.ts +3 -0
- package/dist/server/src/controllers/validation/settings.d.ts.map +1 -0
- package/dist/server/src/destroy.d.ts +5 -0
- package/dist/server/src/destroy.d.ts.map +1 -0
- package/dist/server/src/index.d.ts +2115 -0
- package/dist/server/src/index.d.ts.map +1 -0
- package/dist/server/src/middlewares/documents.d.ts +6 -0
- package/dist/server/src/middlewares/documents.d.ts.map +1 -0
- package/dist/server/src/migrations/database/5.0.0-document-id-in-actions.d.ts +9 -0
- package/dist/server/src/migrations/database/5.0.0-document-id-in-actions.d.ts.map +1 -0
- package/dist/server/src/migrations/index.d.ts +13 -0
- package/dist/server/src/migrations/index.d.ts.map +1 -0
- package/dist/server/src/register.d.ts +5 -0
- package/dist/server/src/register.d.ts.map +1 -0
- package/dist/server/src/routes/index.d.ts +51 -0
- package/dist/server/src/routes/index.d.ts.map +1 -0
- package/dist/server/src/routes/release-action.d.ts +18 -0
- package/dist/server/src/routes/release-action.d.ts.map +1 -0
- package/dist/server/src/routes/release.d.ts +18 -0
- package/dist/server/src/routes/release.d.ts.map +1 -0
- package/dist/server/src/routes/settings.d.ts +18 -0
- package/dist/server/src/routes/settings.d.ts.map +1 -0
- package/dist/server/src/services/index.d.ts +1828 -0
- package/dist/server/src/services/index.d.ts.map +1 -0
- package/dist/server/src/services/release-action.d.ts +38 -0
- package/dist/server/src/services/release-action.d.ts.map +1 -0
- package/dist/server/src/services/release.d.ts +31 -0
- package/dist/server/src/services/release.d.ts.map +1 -0
- package/dist/server/src/services/scheduling.d.ts +18 -0
- package/dist/server/src/services/scheduling.d.ts.map +1 -0
- package/dist/server/src/services/settings.d.ts +13 -0
- package/dist/server/src/services/settings.d.ts.map +1 -0
- package/dist/server/src/services/validation.d.ts +18 -0
- package/dist/server/src/services/validation.d.ts.map +1 -0
- package/dist/server/src/utils/index.d.ts +35 -0
- package/dist/server/src/utils/index.d.ts.map +1 -0
- package/dist/shared/contracts/release-actions.d.ts +130 -0
- package/dist/shared/contracts/release-actions.d.ts.map +1 -0
- package/dist/shared/contracts/releases.d.ts +184 -0
- package/dist/shared/contracts/releases.d.ts.map +1 -0
- package/dist/shared/contracts/settings.d.ts +39 -0
- package/dist/shared/contracts/settings.d.ts.map +1 -0
- package/dist/shared/types.d.ts +24 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/package.json +32 -37
- package/dist/_chunks/App-HVXzE3i3.mjs +0 -1313
- package/dist/_chunks/App-HVXzE3i3.mjs.map +0 -1
- package/dist/_chunks/App-l62gIUTX.js +0 -1336
- package/dist/_chunks/App-l62gIUTX.js.map +0 -1
- package/dist/_chunks/PurchaseContentReleases-Clm0iACO.mjs.map +0 -1
- package/dist/_chunks/PurchaseContentReleases-YhAPgpG9.js.map +0 -1
- package/dist/_chunks/en-RdapH-9X.mjs.map +0 -1
- package/dist/_chunks/en-faJDuv3q.js.map +0 -1
- package/dist/_chunks/index-ML_b3php.js +0 -1034
- package/dist/_chunks/index-ML_b3php.js.map +0 -1
- package/dist/_chunks/index-Ys87ROOe.mjs +0 -1013
- package/dist/_chunks/index-Ys87ROOe.mjs.map +0 -1
- package/strapi-server.js +0 -3
package/dist/server/index.js
CHANGED
|
@@ -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 }
|
|
96
|
+
const getService = (name, { strapi: strapi2 }) => {
|
|
82
97
|
return strapi2.plugin("content-releases").service(name);
|
|
83
98
|
};
|
|
84
|
-
const
|
|
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(
|
|
87
|
-
const entry = await
|
|
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
|
|
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.
|
|
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.
|
|
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
|
|
150
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
206
|
-
if (action.entry && action.release) {
|
|
207
|
-
const
|
|
208
|
-
|
|
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.
|
|
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,39 @@ async function enableContentTypeLocalized({ oldContentTypes, contentTypes: conte
|
|
|
271
326
|
}
|
|
272
327
|
}
|
|
273
328
|
}
|
|
274
|
-
const
|
|
329
|
+
const addEntryDocumentToReleaseActions = {
|
|
330
|
+
name: "content-releases::5.0.0-add-entry-document-id-to-release-actions",
|
|
331
|
+
async up(trx, db) {
|
|
332
|
+
const hasPolymorphicColumn = await trx.schema.hasColumn("strapi_release_actions", "target_id");
|
|
333
|
+
if (hasPolymorphicColumn) {
|
|
334
|
+
const hasEntryDocumentIdColumn = await trx.schema.hasColumn(
|
|
335
|
+
"strapi_release_actions",
|
|
336
|
+
"entry_document_id"
|
|
337
|
+
);
|
|
338
|
+
if (!hasEntryDocumentIdColumn) {
|
|
339
|
+
await trx.schema.alterTable("strapi_release_actions", (table) => {
|
|
340
|
+
table.string("entry_document_id");
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
const releaseActions = await trx.select("*").from("strapi_release_actions");
|
|
344
|
+
utils.async.map(releaseActions, async (action) => {
|
|
345
|
+
const { target_type, target_id } = action;
|
|
346
|
+
const entry = await db.query(target_type).findOne({ where: { id: target_id } });
|
|
347
|
+
if (entry) {
|
|
348
|
+
await trx("strapi_release_actions").update({ entry_document_id: entry.documentId }).where("id", action.id);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
async down() {
|
|
354
|
+
throw new Error("not implemented");
|
|
355
|
+
}
|
|
356
|
+
};
|
|
275
357
|
const register = async ({ strapi: strapi2 }) => {
|
|
276
|
-
if (features
|
|
277
|
-
await strapi2.admin
|
|
278
|
-
strapi2.
|
|
358
|
+
if (strapi2.ee.features.isEnabled("cms-content-releases")) {
|
|
359
|
+
await strapi2.service("admin::permission").actionProvider.registerMany(ACTIONS);
|
|
360
|
+
strapi2.db.migrations.providers.internal.register(addEntryDocumentToReleaseActions);
|
|
361
|
+
strapi2.hook("strapi::content-types.beforeSync").register(disableContentTypeLocalized).register(deleteActionsOnDisableDraftAndPublish);
|
|
279
362
|
strapi2.hook("strapi::content-types.afterSync").register(deleteActionsOnDeleteContentType).register(enableContentTypeLocalized).register(revalidateChangedContentTypes).register(migrateIsValidAndStatusReleases);
|
|
280
363
|
}
|
|
281
364
|
if (strapi2.plugin("graphql")) {
|
|
@@ -284,129 +367,134 @@ const register = async ({ strapi: strapi2 }) => {
|
|
|
284
367
|
graphqlExtensionService.shadowCRUD(RELEASE_ACTION_MODEL_UID).disable();
|
|
285
368
|
}
|
|
286
369
|
};
|
|
287
|
-
const
|
|
370
|
+
const updateActionsStatusAndUpdateReleaseStatus = async (contentType, entry) => {
|
|
371
|
+
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
372
|
+
where: {
|
|
373
|
+
actions: {
|
|
374
|
+
contentType,
|
|
375
|
+
entryDocumentId: entry.documentId,
|
|
376
|
+
locale: entry.locale
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
const entryStatus = await isEntryValid(contentType, entry, { strapi });
|
|
381
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
382
|
+
where: {
|
|
383
|
+
contentType,
|
|
384
|
+
entryDocumentId: entry.documentId,
|
|
385
|
+
locale: entry.locale
|
|
386
|
+
},
|
|
387
|
+
data: {
|
|
388
|
+
isEntryValid: entryStatus
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
for (const release2 of releases) {
|
|
392
|
+
getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
const deleteActionsAndUpdateReleaseStatus = async (params) => {
|
|
396
|
+
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
397
|
+
where: {
|
|
398
|
+
actions: params
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
402
|
+
where: params
|
|
403
|
+
});
|
|
404
|
+
for (const release2 of releases) {
|
|
405
|
+
getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
const deleteActionsOnDelete = async (ctx, next) => {
|
|
409
|
+
if (ctx.action !== "delete") {
|
|
410
|
+
return next();
|
|
411
|
+
}
|
|
412
|
+
if (!utils.contentTypes.hasDraftAndPublish(ctx.contentType)) {
|
|
413
|
+
return next();
|
|
414
|
+
}
|
|
415
|
+
const contentType = ctx.contentType.uid;
|
|
416
|
+
const { documentId, locale } = ctx.params;
|
|
417
|
+
const result = await next();
|
|
418
|
+
if (!result) {
|
|
419
|
+
return result;
|
|
420
|
+
}
|
|
421
|
+
try {
|
|
422
|
+
deleteActionsAndUpdateReleaseStatus({
|
|
423
|
+
contentType,
|
|
424
|
+
entryDocumentId: documentId,
|
|
425
|
+
...locale !== "*" && { locale }
|
|
426
|
+
});
|
|
427
|
+
} catch (error) {
|
|
428
|
+
strapi.log.error("Error while deleting release actions after delete", {
|
|
429
|
+
error
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
return result;
|
|
433
|
+
};
|
|
434
|
+
const updateActionsOnUpdate = async (ctx, next) => {
|
|
435
|
+
if (ctx.action !== "update") {
|
|
436
|
+
return next();
|
|
437
|
+
}
|
|
438
|
+
if (!utils.contentTypes.hasDraftAndPublish(ctx.contentType)) {
|
|
439
|
+
return next();
|
|
440
|
+
}
|
|
441
|
+
const contentType = ctx.contentType.uid;
|
|
442
|
+
const result = await next();
|
|
443
|
+
if (!result) {
|
|
444
|
+
return result;
|
|
445
|
+
}
|
|
446
|
+
try {
|
|
447
|
+
updateActionsStatusAndUpdateReleaseStatus(contentType, result);
|
|
448
|
+
} catch (error) {
|
|
449
|
+
strapi.log.error("Error while updating release actions after update", {
|
|
450
|
+
error
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
return result;
|
|
454
|
+
};
|
|
455
|
+
const deleteReleasesActionsAndUpdateReleaseStatus = async (params) => {
|
|
456
|
+
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
457
|
+
where: {
|
|
458
|
+
actions: params
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
462
|
+
where: params
|
|
463
|
+
});
|
|
464
|
+
for (const release2 of releases) {
|
|
465
|
+
getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
466
|
+
}
|
|
467
|
+
};
|
|
288
468
|
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
289
|
-
if (features
|
|
469
|
+
if (strapi2.ee.features.isEnabled("cms-content-releases")) {
|
|
290
470
|
const contentTypesWithDraftAndPublish = Object.keys(strapi2.contentTypes).filter(
|
|
291
471
|
(uid) => strapi2.contentTypes[uid]?.options?.draftAndPublish
|
|
292
472
|
);
|
|
293
473
|
strapi2.db.lifecycles.subscribe({
|
|
294
474
|
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
|
-
/**
|
|
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
475
|
/**
|
|
335
|
-
*
|
|
336
|
-
* We make this only after deleteMany is succesfully executed to avoid errors
|
|
476
|
+
* deleteMany is still used outside documents service, for example when deleting a locale
|
|
337
477
|
*/
|
|
338
478
|
async afterDeleteMany(event) {
|
|
339
479
|
try {
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
-
}
|
|
480
|
+
const model = strapi2.getModel(event.model.uid);
|
|
481
|
+
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
482
|
+
const { where } = event.params;
|
|
483
|
+
deleteReleasesActionsAndUpdateReleaseStatus({
|
|
484
|
+
contentType: model.uid,
|
|
485
|
+
locale: where.locale ?? null,
|
|
486
|
+
...where.documentId && { entryDocumentId: where.documentId }
|
|
362
487
|
});
|
|
363
|
-
for (const release2 of releases) {
|
|
364
|
-
getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
|
|
365
|
-
}
|
|
366
488
|
}
|
|
367
489
|
} catch (error) {
|
|
368
490
|
strapi2.log.error("Error while deleting release actions after entry deleteMany", {
|
|
369
491
|
error
|
|
370
492
|
});
|
|
371
493
|
}
|
|
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
494
|
}
|
|
409
495
|
});
|
|
496
|
+
strapi2.documents.use(deleteActionsOnDelete);
|
|
497
|
+
strapi2.documents.use(updateActionsOnUpdate);
|
|
410
498
|
getService("scheduling", { strapi: strapi2 }).syncFromDatabase().catch((err) => {
|
|
411
499
|
strapi2.log.error(
|
|
412
500
|
"Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling."
|
|
@@ -414,7 +502,7 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
414
502
|
throw err;
|
|
415
503
|
});
|
|
416
504
|
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
|
417
|
-
strapi2.webhookStore.addAllowedEvent(key, value);
|
|
505
|
+
strapi2.get("webhookStore").addAllowedEvent(key, value);
|
|
418
506
|
});
|
|
419
507
|
}
|
|
420
508
|
};
|
|
@@ -498,15 +586,13 @@ const schema = {
|
|
|
498
586
|
enum: ["publish", "unpublish"],
|
|
499
587
|
required: true
|
|
500
588
|
},
|
|
501
|
-
entry: {
|
|
502
|
-
type: "relation",
|
|
503
|
-
relation: "morphToOne",
|
|
504
|
-
configurable: false
|
|
505
|
-
},
|
|
506
589
|
contentType: {
|
|
507
590
|
type: "string",
|
|
508
591
|
required: true
|
|
509
592
|
},
|
|
593
|
+
entryDocumentId: {
|
|
594
|
+
type: "string"
|
|
595
|
+
},
|
|
510
596
|
locale: {
|
|
511
597
|
type: "string"
|
|
512
598
|
},
|
|
@@ -528,18 +614,6 @@ const contentTypes = {
|
|
|
528
614
|
release: release$1,
|
|
529
615
|
"release-action": releaseAction$1
|
|
530
616
|
};
|
|
531
|
-
const getGroupName = (queryValue) => {
|
|
532
|
-
switch (queryValue) {
|
|
533
|
-
case "contentType":
|
|
534
|
-
return "contentType.displayName";
|
|
535
|
-
case "action":
|
|
536
|
-
return "type";
|
|
537
|
-
case "locale":
|
|
538
|
-
return ___default.default.getOr("No locale", "locale.name");
|
|
539
|
-
default:
|
|
540
|
-
return "contentType.displayName";
|
|
541
|
-
}
|
|
542
|
-
};
|
|
543
617
|
const createReleaseService = ({ strapi: strapi2 }) => {
|
|
544
618
|
const dispatchWebhook = (event, { isPublished, release: release2, error }) => {
|
|
545
619
|
strapi2.eventHub.emit(event, {
|
|
@@ -548,93 +622,32 @@ const createReleaseService = ({ strapi: strapi2 }) => {
|
|
|
548
622
|
release: release2
|
|
549
623
|
});
|
|
550
624
|
};
|
|
551
|
-
const publishSingleTypeAction = async (uid, actionType, entryId) => {
|
|
552
|
-
const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
|
|
553
|
-
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
554
|
-
const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
|
|
555
|
-
const entry = await strapi2.entityService.findOne(uid, entryId, { populate });
|
|
556
|
-
try {
|
|
557
|
-
if (actionType === "publish") {
|
|
558
|
-
await entityManagerService.publish(entry, uid);
|
|
559
|
-
} else {
|
|
560
|
-
await entityManagerService.unpublish(entry, uid);
|
|
561
|
-
}
|
|
562
|
-
} catch (error) {
|
|
563
|
-
if (error instanceof utils.errors.ApplicationError && (error.message === "already.published" || error.message === "already.draft"))
|
|
564
|
-
;
|
|
565
|
-
else {
|
|
566
|
-
throw error;
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
const publishCollectionTypeAction = async (uid, entriesToPublishIds, entriestoUnpublishIds) => {
|
|
571
|
-
const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
|
|
572
|
-
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
573
|
-
const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
|
|
574
|
-
const entriesToPublish = await strapi2.entityService.findMany(uid, {
|
|
575
|
-
filters: {
|
|
576
|
-
id: {
|
|
577
|
-
$in: entriesToPublishIds
|
|
578
|
-
}
|
|
579
|
-
},
|
|
580
|
-
populate
|
|
581
|
-
});
|
|
582
|
-
const entriesToUnpublish = await strapi2.entityService.findMany(uid, {
|
|
583
|
-
filters: {
|
|
584
|
-
id: {
|
|
585
|
-
$in: entriestoUnpublishIds
|
|
586
|
-
}
|
|
587
|
-
},
|
|
588
|
-
populate
|
|
589
|
-
});
|
|
590
|
-
if (entriesToPublish.length > 0) {
|
|
591
|
-
await entityManagerService.publishMany(entriesToPublish, uid);
|
|
592
|
-
}
|
|
593
|
-
if (entriesToUnpublish.length > 0) {
|
|
594
|
-
await entityManagerService.unpublishMany(entriesToUnpublish, uid);
|
|
595
|
-
}
|
|
596
|
-
};
|
|
597
625
|
const getFormattedActions = async (releaseId) => {
|
|
598
626
|
const actions = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findMany({
|
|
599
627
|
where: {
|
|
600
628
|
release: {
|
|
601
629
|
id: releaseId
|
|
602
630
|
}
|
|
603
|
-
},
|
|
604
|
-
populate: {
|
|
605
|
-
entry: {
|
|
606
|
-
fields: ["id"]
|
|
607
|
-
}
|
|
608
631
|
}
|
|
609
632
|
});
|
|
610
633
|
if (actions.length === 0) {
|
|
611
634
|
throw new utils.errors.ValidationError("No entries to publish");
|
|
612
635
|
}
|
|
613
|
-
const
|
|
614
|
-
const singleTypeActions = [];
|
|
636
|
+
const formattedActions = {};
|
|
615
637
|
for (const action of actions) {
|
|
616
638
|
const contentTypeUid = action.contentType;
|
|
617
|
-
if (
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
if (action.type === "publish") {
|
|
625
|
-
collectionTypeActions[contentTypeUid].entriesToPublishIds.push(action.entry.id);
|
|
626
|
-
} else {
|
|
627
|
-
collectionTypeActions[contentTypeUid].entriesToUnpublishIds.push(action.entry.id);
|
|
628
|
-
}
|
|
629
|
-
} else {
|
|
630
|
-
singleTypeActions.push({
|
|
631
|
-
uid: contentTypeUid,
|
|
632
|
-
action: action.type,
|
|
633
|
-
id: action.entry.id
|
|
634
|
-
});
|
|
639
|
+
if (!formattedActions[contentTypeUid]) {
|
|
640
|
+
formattedActions[contentTypeUid] = {
|
|
641
|
+
publish: [],
|
|
642
|
+
unpublish: []
|
|
643
|
+
};
|
|
635
644
|
}
|
|
645
|
+
formattedActions[contentTypeUid][action.type].push({
|
|
646
|
+
documentId: action.entryDocumentId,
|
|
647
|
+
locale: action.locale
|
|
648
|
+
});
|
|
636
649
|
}
|
|
637
|
-
return
|
|
650
|
+
return formattedActions;
|
|
638
651
|
};
|
|
639
652
|
return {
|
|
640
653
|
async create(releaseData, { user }) {
|
|
@@ -649,7 +662,7 @@ const createReleaseService = ({ strapi: strapi2 }) => {
|
|
|
649
662
|
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
|
|
650
663
|
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
651
664
|
]);
|
|
652
|
-
const release2 = await strapi2.
|
|
665
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).create({
|
|
653
666
|
data: {
|
|
654
667
|
...releaseWithCreatorFields,
|
|
655
668
|
status: "empty"
|
|
@@ -663,94 +676,28 @@ const createReleaseService = ({ strapi: strapi2 }) => {
|
|
|
663
676
|
return release2;
|
|
664
677
|
},
|
|
665
678
|
async findOne(id, query = {}) {
|
|
666
|
-
const
|
|
667
|
-
|
|
679
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query);
|
|
680
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
681
|
+
...dbQuery,
|
|
682
|
+
where: { id }
|
|
668
683
|
});
|
|
669
684
|
return release2;
|
|
670
685
|
},
|
|
671
686
|
findPage(query) {
|
|
672
|
-
|
|
673
|
-
|
|
687
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
|
|
688
|
+
return strapi2.db.query(RELEASE_MODEL_UID).findPage({
|
|
689
|
+
...dbQuery,
|
|
674
690
|
populate: {
|
|
675
691
|
actions: {
|
|
676
|
-
// @ts-expect-error Ignore missing properties
|
|
677
692
|
count: true
|
|
678
693
|
}
|
|
679
694
|
}
|
|
680
695
|
});
|
|
681
696
|
},
|
|
682
|
-
|
|
683
|
-
const
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
target_type: contentTypeUid,
|
|
687
|
-
target_id: entryId
|
|
688
|
-
},
|
|
689
|
-
releasedAt: {
|
|
690
|
-
$null: true
|
|
691
|
-
}
|
|
692
|
-
},
|
|
693
|
-
populate: {
|
|
694
|
-
// Filter the action to get only the content type entry
|
|
695
|
-
actions: {
|
|
696
|
-
where: {
|
|
697
|
-
target_type: contentTypeUid,
|
|
698
|
-
target_id: entryId
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
});
|
|
703
|
-
return releases.map((release2) => {
|
|
704
|
-
if (release2.actions?.length) {
|
|
705
|
-
const [actionForEntry] = release2.actions;
|
|
706
|
-
delete release2.actions;
|
|
707
|
-
return {
|
|
708
|
-
...release2,
|
|
709
|
-
action: actionForEntry
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
return release2;
|
|
713
|
-
});
|
|
714
|
-
},
|
|
715
|
-
async findManyWithoutContentTypeEntryAttached(contentTypeUid, entryId) {
|
|
716
|
-
const releasesRelated = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
717
|
-
where: {
|
|
718
|
-
releasedAt: {
|
|
719
|
-
$null: true
|
|
720
|
-
},
|
|
721
|
-
actions: {
|
|
722
|
-
target_type: contentTypeUid,
|
|
723
|
-
target_id: entryId
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
});
|
|
727
|
-
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
728
|
-
where: {
|
|
729
|
-
$or: [
|
|
730
|
-
{
|
|
731
|
-
id: {
|
|
732
|
-
$notIn: releasesRelated.map((release2) => release2.id)
|
|
733
|
-
}
|
|
734
|
-
},
|
|
735
|
-
{
|
|
736
|
-
actions: null
|
|
737
|
-
}
|
|
738
|
-
],
|
|
739
|
-
releasedAt: {
|
|
740
|
-
$null: true
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
});
|
|
744
|
-
return releases.map((release2) => {
|
|
745
|
-
if (release2.actions?.length) {
|
|
746
|
-
const [actionForEntry] = release2.actions;
|
|
747
|
-
delete release2.actions;
|
|
748
|
-
return {
|
|
749
|
-
...release2,
|
|
750
|
-
action: actionForEntry
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
return release2;
|
|
697
|
+
findMany(query) {
|
|
698
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
|
|
699
|
+
return strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
700
|
+
...dbQuery
|
|
754
701
|
});
|
|
755
702
|
},
|
|
756
703
|
async update(id, releaseData, { user }) {
|
|
@@ -765,19 +712,15 @@ const createReleaseService = ({ strapi: strapi2 }) => {
|
|
|
765
712
|
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name, id),
|
|
766
713
|
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
767
714
|
]);
|
|
768
|
-
const release2 = await strapi2.
|
|
715
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id } });
|
|
769
716
|
if (!release2) {
|
|
770
717
|
throw new utils.errors.NotFoundError(`No release found for id ${id}`);
|
|
771
718
|
}
|
|
772
719
|
if (release2.releasedAt) {
|
|
773
720
|
throw new utils.errors.ValidationError("Release already published");
|
|
774
721
|
}
|
|
775
|
-
const updatedRelease = await strapi2.
|
|
776
|
-
|
|
777
|
-
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">>
|
|
778
|
-
* is not compatible with the type we are passing here: UpdateRelease.Request['body']
|
|
779
|
-
*/
|
|
780
|
-
// @ts-expect-error see above
|
|
722
|
+
const updatedRelease = await strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
723
|
+
where: { id },
|
|
781
724
|
data: releaseWithCreatorFields
|
|
782
725
|
});
|
|
783
726
|
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
@@ -790,130 +733,6 @@ const createReleaseService = ({ strapi: strapi2 }) => {
|
|
|
790
733
|
strapi2.telemetry.send("didUpdateContentRelease");
|
|
791
734
|
return updatedRelease;
|
|
792
735
|
},
|
|
793
|
-
async createAction(releaseId, action) {
|
|
794
|
-
const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
|
|
795
|
-
strapi: strapi2
|
|
796
|
-
});
|
|
797
|
-
await Promise.all([
|
|
798
|
-
validateEntryContentType(action.entry.contentType),
|
|
799
|
-
validateUniqueEntry(releaseId, action)
|
|
800
|
-
]);
|
|
801
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
|
|
802
|
-
if (!release2) {
|
|
803
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
804
|
-
}
|
|
805
|
-
if (release2.releasedAt) {
|
|
806
|
-
throw new utils.errors.ValidationError("Release already published");
|
|
807
|
-
}
|
|
808
|
-
const { entry, type } = action;
|
|
809
|
-
const populatedEntry = await getPopulatedEntry(entry.contentType, entry.id, { strapi: strapi2 });
|
|
810
|
-
const isEntryValid = await getEntryValidStatus(entry.contentType, populatedEntry, { strapi: strapi2 });
|
|
811
|
-
const releaseAction2 = await strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
|
|
812
|
-
data: {
|
|
813
|
-
type,
|
|
814
|
-
contentType: entry.contentType,
|
|
815
|
-
locale: entry.locale,
|
|
816
|
-
isEntryValid,
|
|
817
|
-
entry: {
|
|
818
|
-
id: entry.id,
|
|
819
|
-
__type: entry.contentType,
|
|
820
|
-
__pivot: { field: "entry" }
|
|
821
|
-
},
|
|
822
|
-
release: releaseId
|
|
823
|
-
},
|
|
824
|
-
populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
|
|
825
|
-
});
|
|
826
|
-
this.updateReleaseStatus(releaseId);
|
|
827
|
-
return releaseAction2;
|
|
828
|
-
},
|
|
829
|
-
async findActions(releaseId, query) {
|
|
830
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
831
|
-
fields: ["id"]
|
|
832
|
-
});
|
|
833
|
-
if (!release2) {
|
|
834
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
835
|
-
}
|
|
836
|
-
return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
|
|
837
|
-
...query,
|
|
838
|
-
populate: {
|
|
839
|
-
entry: {
|
|
840
|
-
populate: "*"
|
|
841
|
-
}
|
|
842
|
-
},
|
|
843
|
-
filters: {
|
|
844
|
-
release: releaseId
|
|
845
|
-
}
|
|
846
|
-
});
|
|
847
|
-
},
|
|
848
|
-
async countActions(query) {
|
|
849
|
-
return strapi2.entityService.count(RELEASE_ACTION_MODEL_UID, query);
|
|
850
|
-
},
|
|
851
|
-
async groupActions(actions, groupBy) {
|
|
852
|
-
const contentTypeUids = actions.reduce((acc, action) => {
|
|
853
|
-
if (!acc.includes(action.contentType)) {
|
|
854
|
-
acc.push(action.contentType);
|
|
855
|
-
}
|
|
856
|
-
return acc;
|
|
857
|
-
}, []);
|
|
858
|
-
const allReleaseContentTypesDictionary = await this.getContentTypesDataForActions(
|
|
859
|
-
contentTypeUids
|
|
860
|
-
);
|
|
861
|
-
const allLocalesDictionary = await this.getLocalesDataForActions();
|
|
862
|
-
const formattedData = actions.map((action) => {
|
|
863
|
-
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
864
|
-
return {
|
|
865
|
-
...action,
|
|
866
|
-
locale: action.locale ? allLocalesDictionary[action.locale] : null,
|
|
867
|
-
contentType: {
|
|
868
|
-
displayName,
|
|
869
|
-
mainFieldValue: action.entry[mainField],
|
|
870
|
-
uid: action.contentType
|
|
871
|
-
}
|
|
872
|
-
};
|
|
873
|
-
});
|
|
874
|
-
const groupName = getGroupName(groupBy);
|
|
875
|
-
return ___default.default.groupBy(groupName)(formattedData);
|
|
876
|
-
},
|
|
877
|
-
async getLocalesDataForActions() {
|
|
878
|
-
if (!strapi2.plugin("i18n")) {
|
|
879
|
-
return {};
|
|
880
|
-
}
|
|
881
|
-
const allLocales = await strapi2.plugin("i18n").service("locales").find() || [];
|
|
882
|
-
return allLocales.reduce((acc, locale) => {
|
|
883
|
-
acc[locale.code] = { name: locale.name, code: locale.code };
|
|
884
|
-
return acc;
|
|
885
|
-
}, {});
|
|
886
|
-
},
|
|
887
|
-
async getContentTypesDataForActions(contentTypesUids) {
|
|
888
|
-
const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
|
|
889
|
-
const contentTypesData = {};
|
|
890
|
-
for (const contentTypeUid of contentTypesUids) {
|
|
891
|
-
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
892
|
-
uid: contentTypeUid
|
|
893
|
-
});
|
|
894
|
-
contentTypesData[contentTypeUid] = {
|
|
895
|
-
mainField: contentTypeConfig.settings.mainField,
|
|
896
|
-
displayName: strapi2.getModel(contentTypeUid).info.displayName
|
|
897
|
-
};
|
|
898
|
-
}
|
|
899
|
-
return contentTypesData;
|
|
900
|
-
},
|
|
901
|
-
getContentTypeModelsFromActions(actions) {
|
|
902
|
-
const contentTypeUids = actions.reduce((acc, action) => {
|
|
903
|
-
if (!acc.includes(action.contentType)) {
|
|
904
|
-
acc.push(action.contentType);
|
|
905
|
-
}
|
|
906
|
-
return acc;
|
|
907
|
-
}, []);
|
|
908
|
-
const contentTypeModelsMap = contentTypeUids.reduce(
|
|
909
|
-
(acc, contentTypeUid) => {
|
|
910
|
-
acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
|
|
911
|
-
return acc;
|
|
912
|
-
},
|
|
913
|
-
{}
|
|
914
|
-
);
|
|
915
|
-
return contentTypeModelsMap;
|
|
916
|
-
},
|
|
917
736
|
async getAllComponents() {
|
|
918
737
|
const contentManagerComponentsService = strapi2.plugin("content-manager").service("components");
|
|
919
738
|
const components = await contentManagerComponentsService.findAllComponents();
|
|
@@ -927,10 +746,11 @@ const createReleaseService = ({ strapi: strapi2 }) => {
|
|
|
927
746
|
return componentsMap;
|
|
928
747
|
},
|
|
929
748
|
async delete(releaseId) {
|
|
930
|
-
const release2 = await strapi2.
|
|
749
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
750
|
+
where: { id: releaseId },
|
|
931
751
|
populate: {
|
|
932
752
|
actions: {
|
|
933
|
-
|
|
753
|
+
select: ["id"]
|
|
934
754
|
}
|
|
935
755
|
}
|
|
936
756
|
});
|
|
@@ -948,7 +768,11 @@ const createReleaseService = ({ strapi: strapi2 }) => {
|
|
|
948
768
|
}
|
|
949
769
|
}
|
|
950
770
|
});
|
|
951
|
-
await strapi2.
|
|
771
|
+
await strapi2.db.query(RELEASE_MODEL_UID).delete({
|
|
772
|
+
where: {
|
|
773
|
+
id: releaseId
|
|
774
|
+
}
|
|
775
|
+
});
|
|
952
776
|
});
|
|
953
777
|
if (release2.scheduledAt) {
|
|
954
778
|
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
@@ -974,22 +798,19 @@ const createReleaseService = ({ strapi: strapi2 }) => {
|
|
|
974
798
|
}
|
|
975
799
|
try {
|
|
976
800
|
strapi2.log.info(`[Content Releases] Starting to publish release ${lockedRelease.name}`);
|
|
977
|
-
const
|
|
978
|
-
|
|
801
|
+
const formattedActions = await getFormattedActions(releaseId);
|
|
802
|
+
await strapi2.db.transaction(
|
|
803
|
+
async () => Promise.all(
|
|
804
|
+
Object.keys(formattedActions).map(async (contentTypeUid) => {
|
|
805
|
+
const contentType = contentTypeUid;
|
|
806
|
+
const { publish, unpublish } = formattedActions[contentType];
|
|
807
|
+
return Promise.all([
|
|
808
|
+
...publish.map((params) => strapi2.documents(contentType).publish(params)),
|
|
809
|
+
...unpublish.map((params) => strapi2.documents(contentType).unpublish(params))
|
|
810
|
+
]);
|
|
811
|
+
})
|
|
812
|
+
)
|
|
979
813
|
);
|
|
980
|
-
await strapi2.db.transaction(async () => {
|
|
981
|
-
for (const { uid, action, id } of singleTypeActions) {
|
|
982
|
-
await publishSingleTypeAction(uid, action, id);
|
|
983
|
-
}
|
|
984
|
-
for (const contentTypeUid of Object.keys(collectionTypeActions)) {
|
|
985
|
-
const uid = contentTypeUid;
|
|
986
|
-
await publishCollectionTypeAction(
|
|
987
|
-
uid,
|
|
988
|
-
collectionTypeActions[uid].entriesToPublishIds,
|
|
989
|
-
collectionTypeActions[uid].entriesToUnpublishIds
|
|
990
|
-
);
|
|
991
|
-
}
|
|
992
|
-
});
|
|
993
814
|
const release22 = await strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
994
815
|
where: {
|
|
995
816
|
id: releaseId
|
|
@@ -1019,13 +840,226 @@ const createReleaseService = ({ strapi: strapi2 }) => {
|
|
|
1019
840
|
};
|
|
1020
841
|
}
|
|
1021
842
|
});
|
|
1022
|
-
if (error) {
|
|
1023
|
-
throw error;
|
|
1024
|
-
}
|
|
1025
|
-
return release2;
|
|
843
|
+
if (error instanceof Error) {
|
|
844
|
+
throw error;
|
|
845
|
+
}
|
|
846
|
+
return release2;
|
|
847
|
+
},
|
|
848
|
+
async updateReleaseStatus(releaseId) {
|
|
849
|
+
const releaseActionService = getService("release-action", { strapi: strapi2 });
|
|
850
|
+
const [totalActions, invalidActions] = await Promise.all([
|
|
851
|
+
releaseActionService.countActions({
|
|
852
|
+
filters: {
|
|
853
|
+
release: releaseId
|
|
854
|
+
}
|
|
855
|
+
}),
|
|
856
|
+
releaseActionService.countActions({
|
|
857
|
+
filters: {
|
|
858
|
+
release: releaseId,
|
|
859
|
+
isEntryValid: false
|
|
860
|
+
}
|
|
861
|
+
})
|
|
862
|
+
]);
|
|
863
|
+
if (totalActions > 0) {
|
|
864
|
+
if (invalidActions > 0) {
|
|
865
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
866
|
+
where: {
|
|
867
|
+
id: releaseId
|
|
868
|
+
},
|
|
869
|
+
data: {
|
|
870
|
+
status: "blocked"
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
875
|
+
where: {
|
|
876
|
+
id: releaseId
|
|
877
|
+
},
|
|
878
|
+
data: {
|
|
879
|
+
status: "ready"
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
884
|
+
where: {
|
|
885
|
+
id: releaseId
|
|
886
|
+
},
|
|
887
|
+
data: {
|
|
888
|
+
status: "empty"
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
};
|
|
894
|
+
const getGroupName = (queryValue) => {
|
|
895
|
+
switch (queryValue) {
|
|
896
|
+
case "contentType":
|
|
897
|
+
return "contentType.displayName";
|
|
898
|
+
case "type":
|
|
899
|
+
return "type";
|
|
900
|
+
case "locale":
|
|
901
|
+
return ___default.default.getOr("No locale", "locale.name");
|
|
902
|
+
default:
|
|
903
|
+
return "contentType.displayName";
|
|
904
|
+
}
|
|
905
|
+
};
|
|
906
|
+
const createReleaseActionService = ({ strapi: strapi2 }) => {
|
|
907
|
+
const getLocalesDataForActions = async () => {
|
|
908
|
+
if (!strapi2.plugin("i18n")) {
|
|
909
|
+
return {};
|
|
910
|
+
}
|
|
911
|
+
const allLocales = await strapi2.plugin("i18n").service("locales").find() || [];
|
|
912
|
+
return allLocales.reduce((acc, locale) => {
|
|
913
|
+
acc[locale.code] = { name: locale.name, code: locale.code };
|
|
914
|
+
return acc;
|
|
915
|
+
}, {});
|
|
916
|
+
};
|
|
917
|
+
const getContentTypesDataForActions = async (contentTypesUids) => {
|
|
918
|
+
const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
|
|
919
|
+
const contentTypesData = {};
|
|
920
|
+
for (const contentTypeUid of contentTypesUids) {
|
|
921
|
+
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
922
|
+
uid: contentTypeUid
|
|
923
|
+
});
|
|
924
|
+
contentTypesData[contentTypeUid] = {
|
|
925
|
+
mainField: contentTypeConfig.settings.mainField,
|
|
926
|
+
displayName: strapi2.getModel(contentTypeUid).info.displayName
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
return contentTypesData;
|
|
930
|
+
};
|
|
931
|
+
return {
|
|
932
|
+
async create(releaseId, action, { disableUpdateReleaseStatus = false } = {}) {
|
|
933
|
+
const { validateEntryData, validateUniqueEntry } = getService("release-validation", {
|
|
934
|
+
strapi: strapi2
|
|
935
|
+
});
|
|
936
|
+
await Promise.all([
|
|
937
|
+
validateEntryData(action.contentType, action.entryDocumentId),
|
|
938
|
+
validateUniqueEntry(releaseId, action)
|
|
939
|
+
]);
|
|
940
|
+
const model = strapi2.contentType(action.contentType);
|
|
941
|
+
if (model.kind === "singleType") {
|
|
942
|
+
const document = await strapi2.db.query(model.uid).findOne({ select: ["documentId"] });
|
|
943
|
+
if (!document) {
|
|
944
|
+
throw new utils.errors.NotFoundError(`No entry found for contentType ${action.contentType}`);
|
|
945
|
+
}
|
|
946
|
+
action.entryDocumentId = document.documentId;
|
|
947
|
+
}
|
|
948
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id: releaseId } });
|
|
949
|
+
if (!release2) {
|
|
950
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
951
|
+
}
|
|
952
|
+
if (release2.releasedAt) {
|
|
953
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
954
|
+
}
|
|
955
|
+
const actionStatus = action.type === "publish" ? await getDraftEntryValidStatus(
|
|
956
|
+
{
|
|
957
|
+
contentType: action.contentType,
|
|
958
|
+
documentId: action.entryDocumentId,
|
|
959
|
+
locale: action.locale
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
strapi: strapi2
|
|
963
|
+
}
|
|
964
|
+
) : true;
|
|
965
|
+
const releaseAction2 = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).create({
|
|
966
|
+
data: {
|
|
967
|
+
...action,
|
|
968
|
+
release: release2.id,
|
|
969
|
+
isEntryValid: actionStatus
|
|
970
|
+
},
|
|
971
|
+
populate: { release: { select: ["id"] } }
|
|
972
|
+
});
|
|
973
|
+
if (!disableUpdateReleaseStatus) {
|
|
974
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
|
|
975
|
+
}
|
|
976
|
+
return releaseAction2;
|
|
977
|
+
},
|
|
978
|
+
async findPage(releaseId, query) {
|
|
979
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
980
|
+
where: { id: releaseId },
|
|
981
|
+
select: ["id"]
|
|
982
|
+
});
|
|
983
|
+
if (!release2) {
|
|
984
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
985
|
+
}
|
|
986
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
|
|
987
|
+
const { results: actions, pagination } = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findPage({
|
|
988
|
+
...dbQuery,
|
|
989
|
+
where: {
|
|
990
|
+
release: releaseId
|
|
991
|
+
}
|
|
992
|
+
});
|
|
993
|
+
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
994
|
+
const actionsWithEntry = await utils.async.map(actions, async (action) => {
|
|
995
|
+
const populate = await populateBuilderService(action.contentType).populateDeep(Infinity).build();
|
|
996
|
+
const entry = await getEntry(
|
|
997
|
+
{
|
|
998
|
+
contentType: action.contentType,
|
|
999
|
+
documentId: action.entryDocumentId,
|
|
1000
|
+
locale: action.locale,
|
|
1001
|
+
populate,
|
|
1002
|
+
status: action.type === "publish" ? "draft" : "published"
|
|
1003
|
+
},
|
|
1004
|
+
{ strapi: strapi2 }
|
|
1005
|
+
);
|
|
1006
|
+
return {
|
|
1007
|
+
...action,
|
|
1008
|
+
entry,
|
|
1009
|
+
status: entry ? await getEntryStatus(action.contentType, entry) : null
|
|
1010
|
+
};
|
|
1011
|
+
});
|
|
1012
|
+
return {
|
|
1013
|
+
results: actionsWithEntry,
|
|
1014
|
+
pagination
|
|
1015
|
+
};
|
|
1016
|
+
},
|
|
1017
|
+
async groupActions(actions, groupBy) {
|
|
1018
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
1019
|
+
if (!acc.includes(action.contentType)) {
|
|
1020
|
+
acc.push(action.contentType);
|
|
1021
|
+
}
|
|
1022
|
+
return acc;
|
|
1023
|
+
}, []);
|
|
1024
|
+
const allReleaseContentTypesDictionary = await getContentTypesDataForActions(contentTypeUids);
|
|
1025
|
+
const allLocalesDictionary = await getLocalesDataForActions();
|
|
1026
|
+
const formattedData = actions.map((action) => {
|
|
1027
|
+
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
1028
|
+
return {
|
|
1029
|
+
...action,
|
|
1030
|
+
locale: action.locale ? allLocalesDictionary[action.locale] : null,
|
|
1031
|
+
contentType: {
|
|
1032
|
+
displayName,
|
|
1033
|
+
mainFieldValue: action.entry[mainField],
|
|
1034
|
+
uid: action.contentType
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
});
|
|
1038
|
+
const groupName = getGroupName(groupBy);
|
|
1039
|
+
return ___default.default.groupBy(groupName)(formattedData);
|
|
1026
1040
|
},
|
|
1027
|
-
|
|
1028
|
-
const
|
|
1041
|
+
getContentTypeModelsFromActions(actions) {
|
|
1042
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
1043
|
+
if (!acc.includes(action.contentType)) {
|
|
1044
|
+
acc.push(action.contentType);
|
|
1045
|
+
}
|
|
1046
|
+
return acc;
|
|
1047
|
+
}, []);
|
|
1048
|
+
const contentTypeModelsMap = contentTypeUids.reduce(
|
|
1049
|
+
(acc, contentTypeUid) => {
|
|
1050
|
+
acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
|
|
1051
|
+
return acc;
|
|
1052
|
+
},
|
|
1053
|
+
{}
|
|
1054
|
+
);
|
|
1055
|
+
return contentTypeModelsMap;
|
|
1056
|
+
},
|
|
1057
|
+
async countActions(query) {
|
|
1058
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
|
|
1059
|
+
return strapi2.db.query(RELEASE_ACTION_MODEL_UID).count(dbQuery);
|
|
1060
|
+
},
|
|
1061
|
+
async update(actionId, releaseId, update) {
|
|
1062
|
+
const action = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findOne({
|
|
1029
1063
|
where: {
|
|
1030
1064
|
id: actionId,
|
|
1031
1065
|
release: {
|
|
@@ -1034,17 +1068,42 @@ const createReleaseService = ({ strapi: strapi2 }) => {
|
|
|
1034
1068
|
$null: true
|
|
1035
1069
|
}
|
|
1036
1070
|
}
|
|
1037
|
-
}
|
|
1038
|
-
data: update
|
|
1071
|
+
}
|
|
1039
1072
|
});
|
|
1040
|
-
if (!
|
|
1073
|
+
if (!action) {
|
|
1041
1074
|
throw new utils.errors.NotFoundError(
|
|
1042
1075
|
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
1043
1076
|
);
|
|
1044
1077
|
}
|
|
1078
|
+
const actionStatus = update.type === "publish" ? await getDraftEntryValidStatus(
|
|
1079
|
+
{
|
|
1080
|
+
contentType: action.contentType,
|
|
1081
|
+
documentId: action.entryDocumentId,
|
|
1082
|
+
locale: action.locale
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
strapi: strapi2
|
|
1086
|
+
}
|
|
1087
|
+
) : true;
|
|
1088
|
+
const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
1089
|
+
where: {
|
|
1090
|
+
id: actionId,
|
|
1091
|
+
release: {
|
|
1092
|
+
id: releaseId,
|
|
1093
|
+
releasedAt: {
|
|
1094
|
+
$null: true
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
},
|
|
1098
|
+
data: {
|
|
1099
|
+
...update,
|
|
1100
|
+
isEntryValid: actionStatus
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
|
|
1045
1104
|
return updatedAction;
|
|
1046
1105
|
},
|
|
1047
|
-
async
|
|
1106
|
+
async delete(actionId, releaseId) {
|
|
1048
1107
|
const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
|
|
1049
1108
|
where: {
|
|
1050
1109
|
id: actionId,
|
|
@@ -1061,51 +1120,8 @@ const createReleaseService = ({ strapi: strapi2 }) => {
|
|
|
1061
1120
|
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
1062
1121
|
);
|
|
1063
1122
|
}
|
|
1064
|
-
|
|
1123
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
|
|
1065
1124
|
return deletedAction;
|
|
1066
|
-
},
|
|
1067
|
-
async updateReleaseStatus(releaseId) {
|
|
1068
|
-
const [totalActions, invalidActions] = await Promise.all([
|
|
1069
|
-
this.countActions({
|
|
1070
|
-
filters: {
|
|
1071
|
-
release: releaseId
|
|
1072
|
-
}
|
|
1073
|
-
}),
|
|
1074
|
-
this.countActions({
|
|
1075
|
-
filters: {
|
|
1076
|
-
release: releaseId,
|
|
1077
|
-
isEntryValid: false
|
|
1078
|
-
}
|
|
1079
|
-
})
|
|
1080
|
-
]);
|
|
1081
|
-
if (totalActions > 0) {
|
|
1082
|
-
if (invalidActions > 0) {
|
|
1083
|
-
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1084
|
-
where: {
|
|
1085
|
-
id: releaseId
|
|
1086
|
-
},
|
|
1087
|
-
data: {
|
|
1088
|
-
status: "blocked"
|
|
1089
|
-
}
|
|
1090
|
-
});
|
|
1091
|
-
}
|
|
1092
|
-
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1093
|
-
where: {
|
|
1094
|
-
id: releaseId
|
|
1095
|
-
},
|
|
1096
|
-
data: {
|
|
1097
|
-
status: "ready"
|
|
1098
|
-
}
|
|
1099
|
-
});
|
|
1100
|
-
}
|
|
1101
|
-
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1102
|
-
where: {
|
|
1103
|
-
id: releaseId
|
|
1104
|
-
},
|
|
1105
|
-
data: {
|
|
1106
|
-
status: "empty"
|
|
1107
|
-
}
|
|
1108
|
-
});
|
|
1109
1125
|
}
|
|
1110
1126
|
};
|
|
1111
1127
|
};
|
|
@@ -1117,37 +1133,43 @@ class AlreadyOnReleaseError extends utils.errors.ApplicationError {
|
|
|
1117
1133
|
}
|
|
1118
1134
|
const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
1119
1135
|
async validateUniqueEntry(releaseId, releaseActionArgs) {
|
|
1120
|
-
const release2 = await strapi2.
|
|
1121
|
-
|
|
1136
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
1137
|
+
where: {
|
|
1138
|
+
id: releaseId
|
|
1139
|
+
},
|
|
1140
|
+
populate: {
|
|
1141
|
+
actions: true
|
|
1142
|
+
}
|
|
1122
1143
|
});
|
|
1123
1144
|
if (!release2) {
|
|
1124
1145
|
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
1125
1146
|
}
|
|
1126
1147
|
const isEntryInRelease = release2.actions.some(
|
|
1127
|
-
(action) =>
|
|
1148
|
+
(action) => action.entryDocumentId === releaseActionArgs.entryDocumentId && action.contentType === releaseActionArgs.contentType && (releaseActionArgs.locale ? action.locale === releaseActionArgs.locale : true)
|
|
1128
1149
|
);
|
|
1129
1150
|
if (isEntryInRelease) {
|
|
1130
1151
|
throw new AlreadyOnReleaseError(
|
|
1131
|
-
`Entry with
|
|
1152
|
+
`Entry with documentId ${releaseActionArgs.entryDocumentId}${releaseActionArgs.locale ? `( ${releaseActionArgs.locale})` : ""} and contentType ${releaseActionArgs.contentType} already exists in release with id ${releaseId}`
|
|
1132
1153
|
);
|
|
1133
1154
|
}
|
|
1134
1155
|
},
|
|
1135
|
-
|
|
1156
|
+
validateEntryData(contentTypeUid, entryDocumentId) {
|
|
1136
1157
|
const contentType = strapi2.contentType(contentTypeUid);
|
|
1137
1158
|
if (!contentType) {
|
|
1138
1159
|
throw new utils.errors.NotFoundError(`No content type found for uid ${contentTypeUid}`);
|
|
1139
1160
|
}
|
|
1140
|
-
if (!contentType
|
|
1161
|
+
if (!utils.contentTypes.hasDraftAndPublish(contentType)) {
|
|
1141
1162
|
throw new utils.errors.ValidationError(
|
|
1142
1163
|
`Content type with uid ${contentTypeUid} does not have draftAndPublish enabled`
|
|
1143
1164
|
);
|
|
1144
1165
|
}
|
|
1166
|
+
if (contentType.kind === "collectionType" && !entryDocumentId) {
|
|
1167
|
+
throw new utils.errors.ValidationError("Document id is required for collection type");
|
|
1168
|
+
}
|
|
1145
1169
|
},
|
|
1146
1170
|
async validatePendingReleasesLimit() {
|
|
1147
|
-
const
|
|
1148
|
-
|
|
1149
|
-
EE__default.default.features.get("cms-content-releases")?.options?.maximumReleases || 3
|
|
1150
|
-
);
|
|
1171
|
+
const featureCfg = strapi2.ee.features.get("cms-content-releases");
|
|
1172
|
+
const maximumPendingReleases = typeof featureCfg === "object" && featureCfg?.options?.maximumReleases || 3;
|
|
1151
1173
|
const [, pendingReleasesCount] = await strapi2.db.query(RELEASE_MODEL_UID).findWithCount({
|
|
1152
1174
|
filters: {
|
|
1153
1175
|
releasedAt: {
|
|
@@ -1160,8 +1182,8 @@ const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
|
1160
1182
|
}
|
|
1161
1183
|
},
|
|
1162
1184
|
async validateUniqueNameForPendingRelease(name, id) {
|
|
1163
|
-
const pendingReleases = await strapi2.
|
|
1164
|
-
|
|
1185
|
+
const pendingReleases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
1186
|
+
where: {
|
|
1165
1187
|
releasedAt: {
|
|
1166
1188
|
$null: true
|
|
1167
1189
|
},
|
|
@@ -1190,7 +1212,7 @@ const createSchedulingService = ({ strapi: strapi2 }) => {
|
|
|
1190
1212
|
}
|
|
1191
1213
|
const job = nodeSchedule.scheduleJob(scheduleDate, async () => {
|
|
1192
1214
|
try {
|
|
1193
|
-
await getService("release").publish(releaseId);
|
|
1215
|
+
await getService("release", { strapi: strapi2 }).publish(releaseId);
|
|
1194
1216
|
} catch (error) {
|
|
1195
1217
|
}
|
|
1196
1218
|
this.cancel(releaseId);
|
|
@@ -1232,85 +1254,172 @@ const createSchedulingService = ({ strapi: strapi2 }) => {
|
|
|
1232
1254
|
}
|
|
1233
1255
|
};
|
|
1234
1256
|
};
|
|
1257
|
+
const DEFAULT_SETTINGS = {
|
|
1258
|
+
defaultTimezone: null
|
|
1259
|
+
};
|
|
1260
|
+
const createSettingsService = ({ strapi: strapi2 }) => {
|
|
1261
|
+
const getStore = async () => strapi2.store({ type: "core", name: "content-releases" });
|
|
1262
|
+
return {
|
|
1263
|
+
async update({ settings: settings2 }) {
|
|
1264
|
+
const store = await getStore();
|
|
1265
|
+
store.set({ key: "settings", value: settings2 });
|
|
1266
|
+
return settings2;
|
|
1267
|
+
},
|
|
1268
|
+
async find() {
|
|
1269
|
+
const store = await getStore();
|
|
1270
|
+
const settings2 = await store.get({ key: "settings" });
|
|
1271
|
+
return {
|
|
1272
|
+
...DEFAULT_SETTINGS,
|
|
1273
|
+
...settings2 || {}
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
};
|
|
1235
1278
|
const services = {
|
|
1236
1279
|
release: createReleaseService,
|
|
1280
|
+
"release-action": createReleaseActionService,
|
|
1237
1281
|
"release-validation": createReleaseValidationService,
|
|
1238
|
-
scheduling: createSchedulingService
|
|
1282
|
+
scheduling: createSchedulingService,
|
|
1283
|
+
settings: createSettingsService
|
|
1239
1284
|
};
|
|
1240
|
-
const RELEASE_SCHEMA =
|
|
1241
|
-
name:
|
|
1242
|
-
scheduledAt:
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
otherwise: yup__namespace.string().nullable()
|
|
1248
|
-
}),
|
|
1249
|
-
timezone: yup__namespace.string().when("isScheduled", {
|
|
1250
|
-
is: true,
|
|
1251
|
-
then: yup__namespace.string().required().nullable(),
|
|
1252
|
-
otherwise: yup__namespace.string().nullable()
|
|
1253
|
-
}),
|
|
1254
|
-
date: yup__namespace.string().when("isScheduled", {
|
|
1255
|
-
is: true,
|
|
1256
|
-
then: yup__namespace.string().required().nullable(),
|
|
1257
|
-
otherwise: yup__namespace.string().nullable()
|
|
1285
|
+
const RELEASE_SCHEMA = utils.yup.object().shape({
|
|
1286
|
+
name: utils.yup.string().trim().required(),
|
|
1287
|
+
scheduledAt: utils.yup.string().nullable(),
|
|
1288
|
+
timezone: utils.yup.string().when("scheduledAt", {
|
|
1289
|
+
is: (value) => value !== null && value !== void 0,
|
|
1290
|
+
then: utils.yup.string().required(),
|
|
1291
|
+
otherwise: utils.yup.string().nullable()
|
|
1258
1292
|
})
|
|
1259
1293
|
}).required().noUnknown();
|
|
1294
|
+
const FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA = utils.yup.object().shape({
|
|
1295
|
+
contentType: utils.yup.string().required(),
|
|
1296
|
+
entryDocumentId: utils.yup.string().nullable(),
|
|
1297
|
+
hasEntryAttached: utils.yup.string().nullable(),
|
|
1298
|
+
locale: utils.yup.string().nullable()
|
|
1299
|
+
}).required().noUnknown();
|
|
1260
1300
|
const validateRelease = utils.validateYupSchema(RELEASE_SCHEMA);
|
|
1301
|
+
const validatefindByDocumentAttachedParams = utils.validateYupSchema(
|
|
1302
|
+
FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA
|
|
1303
|
+
);
|
|
1261
1304
|
const releaseController = {
|
|
1262
|
-
|
|
1263
|
-
|
|
1305
|
+
/**
|
|
1306
|
+
* Find releases based on documents attached or not to the release.
|
|
1307
|
+
* If `hasEntryAttached` is true, it will return all releases that have the entry attached.
|
|
1308
|
+
* If `hasEntryAttached` is false, it will return all releases that don't have the entry attached.
|
|
1309
|
+
*/
|
|
1310
|
+
async findByDocumentAttached(ctx) {
|
|
1311
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
1264
1312
|
ability: ctx.state.userAbility,
|
|
1265
1313
|
model: RELEASE_MODEL_UID
|
|
1266
1314
|
});
|
|
1267
1315
|
await permissionsManager.validateQuery(ctx.query);
|
|
1268
1316
|
const releaseService = getService("release", { strapi });
|
|
1269
|
-
const
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
const
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1317
|
+
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
1318
|
+
await validatefindByDocumentAttachedParams(query);
|
|
1319
|
+
const model = strapi.getModel(query.contentType);
|
|
1320
|
+
if (model.kind && model.kind === "singleType") {
|
|
1321
|
+
const document = await strapi.db.query(model.uid).findOne({ select: ["documentId"] });
|
|
1322
|
+
if (!document) {
|
|
1323
|
+
throw new utils.errors.NotFoundError(`No entry found for contentType ${query.contentType}`);
|
|
1324
|
+
}
|
|
1325
|
+
query.entryDocumentId = document.documentId;
|
|
1326
|
+
}
|
|
1327
|
+
const { contentType, hasEntryAttached, entryDocumentId, locale } = query;
|
|
1328
|
+
const isEntryAttached = typeof hasEntryAttached === "string" ? Boolean(JSON.parse(hasEntryAttached)) : false;
|
|
1329
|
+
if (isEntryAttached) {
|
|
1330
|
+
const releases = await releaseService.findMany({
|
|
1331
|
+
where: {
|
|
1332
|
+
releasedAt: null,
|
|
1333
|
+
actions: {
|
|
1334
|
+
contentType,
|
|
1335
|
+
entryDocumentId: entryDocumentId ?? null,
|
|
1336
|
+
locale: locale ?? null
|
|
1337
|
+
}
|
|
1338
|
+
},
|
|
1339
|
+
populate: {
|
|
1284
1340
|
actions: {
|
|
1285
|
-
|
|
1286
|
-
|
|
1341
|
+
fields: ["type"],
|
|
1342
|
+
filters: {
|
|
1343
|
+
contentType,
|
|
1344
|
+
entryDocumentId: entryDocumentId ?? null,
|
|
1345
|
+
locale: locale ?? null
|
|
1287
1346
|
}
|
|
1288
1347
|
}
|
|
1289
|
-
}
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
ctx.body = { data: releases };
|
|
1351
|
+
} else {
|
|
1352
|
+
const relatedReleases = await releaseService.findMany({
|
|
1353
|
+
where: {
|
|
1354
|
+
releasedAt: null,
|
|
1355
|
+
actions: {
|
|
1356
|
+
contentType,
|
|
1357
|
+
entryDocumentId: entryDocumentId ?? null,
|
|
1358
|
+
locale: locale ?? null
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1290
1361
|
});
|
|
1291
|
-
const
|
|
1362
|
+
const releases = await releaseService.findMany({
|
|
1292
1363
|
where: {
|
|
1364
|
+
$or: [
|
|
1365
|
+
{
|
|
1366
|
+
id: {
|
|
1367
|
+
$notIn: relatedReleases.map((release2) => release2.id)
|
|
1368
|
+
}
|
|
1369
|
+
},
|
|
1370
|
+
{
|
|
1371
|
+
actions: null
|
|
1372
|
+
}
|
|
1373
|
+
],
|
|
1293
1374
|
releasedAt: null
|
|
1294
1375
|
}
|
|
1295
1376
|
});
|
|
1296
|
-
ctx.body = { data
|
|
1377
|
+
ctx.body = { data: releases };
|
|
1297
1378
|
}
|
|
1298
1379
|
},
|
|
1380
|
+
async findPage(ctx) {
|
|
1381
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
1382
|
+
ability: ctx.state.userAbility,
|
|
1383
|
+
model: RELEASE_MODEL_UID
|
|
1384
|
+
});
|
|
1385
|
+
await permissionsManager.validateQuery(ctx.query);
|
|
1386
|
+
const releaseService = getService("release", { strapi });
|
|
1387
|
+
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
1388
|
+
const { results, pagination } = await releaseService.findPage(query);
|
|
1389
|
+
const data = results.map((release2) => {
|
|
1390
|
+
const { actions, ...releaseData } = release2;
|
|
1391
|
+
return {
|
|
1392
|
+
...releaseData,
|
|
1393
|
+
actions: {
|
|
1394
|
+
meta: {
|
|
1395
|
+
count: actions.count
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1399
|
+
});
|
|
1400
|
+
const pendingReleasesCount = await strapi.db.query(RELEASE_MODEL_UID).count({
|
|
1401
|
+
where: {
|
|
1402
|
+
releasedAt: null
|
|
1403
|
+
}
|
|
1404
|
+
});
|
|
1405
|
+
ctx.body = { data, meta: { pagination, pendingReleasesCount } };
|
|
1406
|
+
},
|
|
1299
1407
|
async findOne(ctx) {
|
|
1300
1408
|
const id = ctx.params.id;
|
|
1301
1409
|
const releaseService = getService("release", { strapi });
|
|
1410
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1302
1411
|
const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
|
|
1303
1412
|
if (!release2) {
|
|
1304
1413
|
throw new utils.errors.NotFoundError(`Release not found for id: ${id}`);
|
|
1305
1414
|
}
|
|
1306
|
-
const count = await
|
|
1415
|
+
const count = await releaseActionService.countActions({
|
|
1307
1416
|
filters: {
|
|
1308
1417
|
release: id
|
|
1309
1418
|
}
|
|
1310
1419
|
});
|
|
1311
1420
|
const sanitizedRelease = {
|
|
1312
1421
|
...release2,
|
|
1313
|
-
createdBy: release2.createdBy ? strapi.admin
|
|
1422
|
+
createdBy: release2.createdBy ? strapi.service("admin::user").sanitizeUser(release2.createdBy) : null
|
|
1314
1423
|
};
|
|
1315
1424
|
const data = {
|
|
1316
1425
|
...sanitizedRelease,
|
|
@@ -1322,19 +1431,63 @@ const releaseController = {
|
|
|
1322
1431
|
};
|
|
1323
1432
|
ctx.body = { data };
|
|
1324
1433
|
},
|
|
1434
|
+
async mapEntriesToReleases(ctx) {
|
|
1435
|
+
const { contentTypeUid, documentIds, locale } = ctx.query;
|
|
1436
|
+
if (!contentTypeUid || !documentIds) {
|
|
1437
|
+
throw new utils.errors.ValidationError("Missing required query parameters");
|
|
1438
|
+
}
|
|
1439
|
+
const releaseService = getService("release", { strapi });
|
|
1440
|
+
const releasesWithActions = await releaseService.findMany({
|
|
1441
|
+
where: {
|
|
1442
|
+
releasedAt: null,
|
|
1443
|
+
actions: {
|
|
1444
|
+
contentType: contentTypeUid,
|
|
1445
|
+
entryDocumentId: {
|
|
1446
|
+
$in: documentIds
|
|
1447
|
+
},
|
|
1448
|
+
locale
|
|
1449
|
+
}
|
|
1450
|
+
},
|
|
1451
|
+
populate: {
|
|
1452
|
+
actions: true
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1455
|
+
const mappedEntriesInReleases = releasesWithActions.reduce(
|
|
1456
|
+
(acc, release2) => {
|
|
1457
|
+
release2.actions.forEach((action) => {
|
|
1458
|
+
if (action.contentType !== contentTypeUid) {
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1461
|
+
if (locale && action.locale !== locale) {
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
if (!acc[action.entryDocumentId]) {
|
|
1465
|
+
acc[action.entryDocumentId] = [{ id: release2.id, name: release2.name }];
|
|
1466
|
+
} else {
|
|
1467
|
+
acc[action.entryDocumentId].push({ id: release2.id, name: release2.name });
|
|
1468
|
+
}
|
|
1469
|
+
});
|
|
1470
|
+
return acc;
|
|
1471
|
+
},
|
|
1472
|
+
{}
|
|
1473
|
+
);
|
|
1474
|
+
ctx.body = {
|
|
1475
|
+
data: mappedEntriesInReleases
|
|
1476
|
+
};
|
|
1477
|
+
},
|
|
1325
1478
|
async create(ctx) {
|
|
1326
1479
|
const user = ctx.state.user;
|
|
1327
1480
|
const releaseArgs = ctx.request.body;
|
|
1328
1481
|
await validateRelease(releaseArgs);
|
|
1329
1482
|
const releaseService = getService("release", { strapi });
|
|
1330
1483
|
const release2 = await releaseService.create(releaseArgs, { user });
|
|
1331
|
-
const permissionsManager = strapi.admin
|
|
1484
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
1332
1485
|
ability: ctx.state.userAbility,
|
|
1333
1486
|
model: RELEASE_MODEL_UID
|
|
1334
1487
|
});
|
|
1335
|
-
ctx.
|
|
1488
|
+
ctx.created({
|
|
1336
1489
|
data: await permissionsManager.sanitizeOutput(release2)
|
|
1337
|
-
};
|
|
1490
|
+
});
|
|
1338
1491
|
},
|
|
1339
1492
|
async update(ctx) {
|
|
1340
1493
|
const user = ctx.state.user;
|
|
@@ -1343,7 +1496,7 @@ const releaseController = {
|
|
|
1343
1496
|
await validateRelease(releaseArgs);
|
|
1344
1497
|
const releaseService = getService("release", { strapi });
|
|
1345
1498
|
const release2 = await releaseService.update(id, releaseArgs, { user });
|
|
1346
|
-
const permissionsManager = strapi.admin
|
|
1499
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
1347
1500
|
ability: ctx.state.userAbility,
|
|
1348
1501
|
model: RELEASE_MODEL_UID
|
|
1349
1502
|
});
|
|
@@ -1360,18 +1513,18 @@ const releaseController = {
|
|
|
1360
1513
|
};
|
|
1361
1514
|
},
|
|
1362
1515
|
async publish(ctx) {
|
|
1363
|
-
const user = ctx.state.user;
|
|
1364
1516
|
const id = ctx.params.id;
|
|
1365
1517
|
const releaseService = getService("release", { strapi });
|
|
1366
|
-
const
|
|
1518
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1519
|
+
const release2 = await releaseService.publish(id);
|
|
1367
1520
|
const [countPublishActions, countUnpublishActions] = await Promise.all([
|
|
1368
|
-
|
|
1521
|
+
releaseActionService.countActions({
|
|
1369
1522
|
filters: {
|
|
1370
1523
|
release: id,
|
|
1371
1524
|
type: "publish"
|
|
1372
1525
|
}
|
|
1373
1526
|
}),
|
|
1374
|
-
|
|
1527
|
+
releaseActionService.countActions({
|
|
1375
1528
|
filters: {
|
|
1376
1529
|
release: id,
|
|
1377
1530
|
type: "unpublish"
|
|
@@ -1389,27 +1542,30 @@ const releaseController = {
|
|
|
1389
1542
|
}
|
|
1390
1543
|
};
|
|
1391
1544
|
const RELEASE_ACTION_SCHEMA = utils.yup.object().shape({
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
}).required(),
|
|
1545
|
+
contentType: utils.yup.string().required(),
|
|
1546
|
+
entryDocumentId: utils.yup.strapiID(),
|
|
1547
|
+
locale: utils.yup.string(),
|
|
1396
1548
|
type: utils.yup.string().oneOf(["publish", "unpublish"]).required()
|
|
1397
1549
|
});
|
|
1398
1550
|
const RELEASE_ACTION_UPDATE_SCHEMA = utils.yup.object().shape({
|
|
1399
1551
|
type: utils.yup.string().oneOf(["publish", "unpublish"]).required()
|
|
1400
1552
|
});
|
|
1553
|
+
const FIND_MANY_ACTIONS_PARAMS = utils.yup.object().shape({
|
|
1554
|
+
groupBy: utils.yup.string().oneOf(["action", "contentType", "locale"])
|
|
1555
|
+
});
|
|
1401
1556
|
const validateReleaseAction = utils.validateYupSchema(RELEASE_ACTION_SCHEMA);
|
|
1402
1557
|
const validateReleaseActionUpdateSchema = utils.validateYupSchema(RELEASE_ACTION_UPDATE_SCHEMA);
|
|
1558
|
+
const validateFindManyActionsParams = utils.validateYupSchema(FIND_MANY_ACTIONS_PARAMS);
|
|
1403
1559
|
const releaseActionController = {
|
|
1404
1560
|
async create(ctx) {
|
|
1405
1561
|
const releaseId = ctx.params.releaseId;
|
|
1406
1562
|
const releaseActionArgs = ctx.request.body;
|
|
1407
1563
|
await validateReleaseAction(releaseActionArgs);
|
|
1408
|
-
const
|
|
1409
|
-
const releaseAction2 = await
|
|
1410
|
-
ctx.
|
|
1564
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1565
|
+
const releaseAction2 = await releaseActionService.create(releaseId, releaseActionArgs);
|
|
1566
|
+
ctx.created({
|
|
1411
1567
|
data: releaseAction2
|
|
1412
|
-
};
|
|
1568
|
+
});
|
|
1413
1569
|
},
|
|
1414
1570
|
async createMany(ctx) {
|
|
1415
1571
|
const releaseId = ctx.params.releaseId;
|
|
@@ -1417,12 +1573,15 @@ const releaseActionController = {
|
|
|
1417
1573
|
await Promise.all(
|
|
1418
1574
|
releaseActionsArgs.map((releaseActionArgs) => validateReleaseAction(releaseActionArgs))
|
|
1419
1575
|
);
|
|
1576
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1420
1577
|
const releaseService = getService("release", { strapi });
|
|
1421
1578
|
const releaseActions = await strapi.db.transaction(async () => {
|
|
1422
1579
|
const releaseActions2 = await Promise.all(
|
|
1423
1580
|
releaseActionsArgs.map(async (releaseActionArgs) => {
|
|
1424
1581
|
try {
|
|
1425
|
-
const action = await
|
|
1582
|
+
const action = await releaseActionService.create(releaseId, releaseActionArgs, {
|
|
1583
|
+
disableUpdateReleaseStatus: true
|
|
1584
|
+
});
|
|
1426
1585
|
return action;
|
|
1427
1586
|
} catch (error) {
|
|
1428
1587
|
if (error instanceof AlreadyOnReleaseError) {
|
|
@@ -1435,43 +1594,54 @@ const releaseActionController = {
|
|
|
1435
1594
|
return releaseActions2;
|
|
1436
1595
|
});
|
|
1437
1596
|
const newReleaseActions = releaseActions.filter((action) => action !== null);
|
|
1438
|
-
|
|
1597
|
+
if (newReleaseActions.length > 0) {
|
|
1598
|
+
releaseService.updateReleaseStatus(releaseId);
|
|
1599
|
+
}
|
|
1600
|
+
ctx.created({
|
|
1439
1601
|
data: newReleaseActions,
|
|
1440
1602
|
meta: {
|
|
1441
1603
|
entriesAlreadyInRelease: releaseActions.length - newReleaseActions.length,
|
|
1442
1604
|
totalEntries: releaseActions.length
|
|
1443
1605
|
}
|
|
1444
|
-
};
|
|
1606
|
+
});
|
|
1445
1607
|
},
|
|
1446
1608
|
async findMany(ctx) {
|
|
1447
1609
|
const releaseId = ctx.params.releaseId;
|
|
1448
|
-
const permissionsManager = strapi.admin
|
|
1610
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
1449
1611
|
ability: ctx.state.userAbility,
|
|
1450
1612
|
model: RELEASE_ACTION_MODEL_UID
|
|
1451
1613
|
});
|
|
1614
|
+
await validateFindManyActionsParams(ctx.query);
|
|
1615
|
+
if (ctx.query.groupBy) {
|
|
1616
|
+
if (!["action", "contentType", "locale"].includes(ctx.query.groupBy)) {
|
|
1617
|
+
ctx.badRequest("Invalid groupBy parameter");
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
ctx.query.sort = ctx.query.groupBy === "action" ? "type" : ctx.query.groupBy;
|
|
1621
|
+
delete ctx.query.groupBy;
|
|
1452
1622
|
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
1453
|
-
const
|
|
1454
|
-
const { results, pagination } = await
|
|
1455
|
-
sort: query.groupBy === "action" ? "type" : query.groupBy,
|
|
1623
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1624
|
+
const { results, pagination } = await releaseActionService.findPage(releaseId, {
|
|
1456
1625
|
...query
|
|
1457
1626
|
});
|
|
1458
1627
|
const contentTypeOutputSanitizers = results.reduce((acc, action) => {
|
|
1459
1628
|
if (acc[action.contentType]) {
|
|
1460
1629
|
return acc;
|
|
1461
1630
|
}
|
|
1462
|
-
const contentTypePermissionsManager = strapi.admin
|
|
1631
|
+
const contentTypePermissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
1463
1632
|
ability: ctx.state.userAbility,
|
|
1464
1633
|
model: action.contentType
|
|
1465
1634
|
});
|
|
1466
1635
|
acc[action.contentType] = contentTypePermissionsManager.sanitizeOutput;
|
|
1467
1636
|
return acc;
|
|
1468
1637
|
}, {});
|
|
1469
|
-
const sanitizedResults = await utils.
|
|
1638
|
+
const sanitizedResults = await utils.async.map(results, async (action) => ({
|
|
1470
1639
|
...action,
|
|
1471
|
-
entry: await contentTypeOutputSanitizers[action.contentType](action.entry)
|
|
1640
|
+
entry: action.entry ? await contentTypeOutputSanitizers[action.contentType](action.entry) : {}
|
|
1472
1641
|
}));
|
|
1473
|
-
const groupedData = await
|
|
1474
|
-
const contentTypes2 =
|
|
1642
|
+
const groupedData = await releaseActionService.groupActions(sanitizedResults, query.sort);
|
|
1643
|
+
const contentTypes2 = releaseActionService.getContentTypeModelsFromActions(results);
|
|
1644
|
+
const releaseService = getService("release", { strapi });
|
|
1475
1645
|
const components = await releaseService.getAllComponents();
|
|
1476
1646
|
ctx.body = {
|
|
1477
1647
|
data: groupedData,
|
|
@@ -1487,8 +1657,8 @@ const releaseActionController = {
|
|
|
1487
1657
|
const releaseId = ctx.params.releaseId;
|
|
1488
1658
|
const releaseActionUpdateArgs = ctx.request.body;
|
|
1489
1659
|
await validateReleaseActionUpdateSchema(releaseActionUpdateArgs);
|
|
1490
|
-
const
|
|
1491
|
-
const updatedAction = await
|
|
1660
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1661
|
+
const updatedAction = await releaseActionService.update(
|
|
1492
1662
|
actionId,
|
|
1493
1663
|
releaseId,
|
|
1494
1664
|
releaseActionUpdateArgs
|
|
@@ -1500,17 +1670,71 @@ const releaseActionController = {
|
|
|
1500
1670
|
async delete(ctx) {
|
|
1501
1671
|
const actionId = ctx.params.actionId;
|
|
1502
1672
|
const releaseId = ctx.params.releaseId;
|
|
1503
|
-
const
|
|
1504
|
-
const deletedReleaseAction = await
|
|
1673
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1674
|
+
const deletedReleaseAction = await releaseActionService.delete(actionId, releaseId);
|
|
1505
1675
|
ctx.body = {
|
|
1506
1676
|
data: deletedReleaseAction
|
|
1507
1677
|
};
|
|
1508
1678
|
}
|
|
1509
1679
|
};
|
|
1510
|
-
const
|
|
1680
|
+
const SETTINGS_SCHEMA = yup__namespace.object().shape({
|
|
1681
|
+
defaultTimezone: yup__namespace.string().nullable().default(null)
|
|
1682
|
+
}).required().noUnknown();
|
|
1683
|
+
const validateSettings = utils.validateYupSchema(SETTINGS_SCHEMA);
|
|
1684
|
+
const settingsController = {
|
|
1685
|
+
async find(ctx) {
|
|
1686
|
+
const settingsService = getService("settings", { strapi });
|
|
1687
|
+
const settings2 = await settingsService.find();
|
|
1688
|
+
ctx.body = { data: settings2 };
|
|
1689
|
+
},
|
|
1690
|
+
async update(ctx) {
|
|
1691
|
+
const settingsBody = ctx.request.body;
|
|
1692
|
+
const settings2 = await validateSettings(settingsBody);
|
|
1693
|
+
const settingsService = getService("settings", { strapi });
|
|
1694
|
+
const updatedSettings = await settingsService.update({ settings: settings2 });
|
|
1695
|
+
ctx.body = { data: updatedSettings };
|
|
1696
|
+
}
|
|
1697
|
+
};
|
|
1698
|
+
const controllers = {
|
|
1699
|
+
release: releaseController,
|
|
1700
|
+
"release-action": releaseActionController,
|
|
1701
|
+
settings: settingsController
|
|
1702
|
+
};
|
|
1511
1703
|
const release = {
|
|
1512
1704
|
type: "admin",
|
|
1513
1705
|
routes: [
|
|
1706
|
+
{
|
|
1707
|
+
method: "GET",
|
|
1708
|
+
path: "/mapEntriesToReleases",
|
|
1709
|
+
handler: "release.mapEntriesToReleases",
|
|
1710
|
+
config: {
|
|
1711
|
+
policies: [
|
|
1712
|
+
"admin::isAuthenticatedAdmin",
|
|
1713
|
+
{
|
|
1714
|
+
name: "admin::hasPermissions",
|
|
1715
|
+
config: {
|
|
1716
|
+
actions: ["plugin::content-releases.read"]
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
]
|
|
1720
|
+
}
|
|
1721
|
+
},
|
|
1722
|
+
{
|
|
1723
|
+
method: "GET",
|
|
1724
|
+
path: "/getByDocumentAttached",
|
|
1725
|
+
handler: "release.findByDocumentAttached",
|
|
1726
|
+
config: {
|
|
1727
|
+
policies: [
|
|
1728
|
+
"admin::isAuthenticatedAdmin",
|
|
1729
|
+
{
|
|
1730
|
+
name: "admin::hasPermissions",
|
|
1731
|
+
config: {
|
|
1732
|
+
actions: ["plugin::content-releases.read"]
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
]
|
|
1736
|
+
}
|
|
1737
|
+
},
|
|
1514
1738
|
{
|
|
1515
1739
|
method: "POST",
|
|
1516
1740
|
path: "/",
|
|
@@ -1530,7 +1754,7 @@ const release = {
|
|
|
1530
1754
|
{
|
|
1531
1755
|
method: "GET",
|
|
1532
1756
|
path: "/",
|
|
1533
|
-
handler: "release.
|
|
1757
|
+
handler: "release.findPage",
|
|
1534
1758
|
config: {
|
|
1535
1759
|
policies: [
|
|
1536
1760
|
"admin::isAuthenticatedAdmin",
|
|
@@ -1694,13 +1918,50 @@ const releaseAction = {
|
|
|
1694
1918
|
}
|
|
1695
1919
|
]
|
|
1696
1920
|
};
|
|
1921
|
+
const settings = {
|
|
1922
|
+
type: "admin",
|
|
1923
|
+
routes: [
|
|
1924
|
+
{
|
|
1925
|
+
method: "GET",
|
|
1926
|
+
path: "/settings",
|
|
1927
|
+
handler: "settings.find",
|
|
1928
|
+
config: {
|
|
1929
|
+
policies: [
|
|
1930
|
+
"admin::isAuthenticatedAdmin",
|
|
1931
|
+
{
|
|
1932
|
+
name: "admin::hasPermissions",
|
|
1933
|
+
config: {
|
|
1934
|
+
actions: ["plugin::content-releases.settings.read"]
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
]
|
|
1938
|
+
}
|
|
1939
|
+
},
|
|
1940
|
+
{
|
|
1941
|
+
method: "PUT",
|
|
1942
|
+
path: "/settings",
|
|
1943
|
+
handler: "settings.update",
|
|
1944
|
+
config: {
|
|
1945
|
+
policies: [
|
|
1946
|
+
"admin::isAuthenticatedAdmin",
|
|
1947
|
+
{
|
|
1948
|
+
name: "admin::hasPermissions",
|
|
1949
|
+
config: {
|
|
1950
|
+
actions: ["plugin::content-releases.settings.update"]
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
]
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
]
|
|
1957
|
+
};
|
|
1697
1958
|
const routes = {
|
|
1959
|
+
settings,
|
|
1698
1960
|
release,
|
|
1699
1961
|
"release-action": releaseAction
|
|
1700
1962
|
};
|
|
1701
|
-
const { features } = require("@strapi/strapi/dist/utils/ee");
|
|
1702
1963
|
const getPlugin = () => {
|
|
1703
|
-
if (features.isEnabled("cms-content-releases")) {
|
|
1964
|
+
if (strapi.ee.features.isEnabled("cms-content-releases")) {
|
|
1704
1965
|
return {
|
|
1705
1966
|
register,
|
|
1706
1967
|
bootstrap,
|