@strapi/content-releases 0.0.0-experimental.ec073775440bb4757efb5a5d846535ae950fe4a6 → 0.0.0-experimental.edc24aaa3bb5a90fa5fd4fee208167dd4e2e38d4
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-D-lWdVb2.js +1372 -0
- package/dist/_chunks/App-D-lWdVb2.js.map +1 -0
- package/dist/_chunks/App-UQxgTJY5.mjs +1351 -0
- package/dist/_chunks/App-UQxgTJY5.mjs.map +1 -0
- package/dist/_chunks/PurchaseContentReleases-Be3acS2L.js +52 -0
- package/dist/_chunks/PurchaseContentReleases-Be3acS2L.js.map +1 -0
- package/dist/_chunks/PurchaseContentReleases-_MxP6-Dt.mjs +52 -0
- package/dist/_chunks/PurchaseContentReleases-_MxP6-Dt.mjs.map +1 -0
- package/dist/_chunks/ReleasesSettingsPage-CuUXvABk.mjs +178 -0
- package/dist/_chunks/ReleasesSettingsPage-CuUXvABk.mjs.map +1 -0
- package/dist/_chunks/ReleasesSettingsPage-xfAoY8N3.js +178 -0
- package/dist/_chunks/ReleasesSettingsPage-xfAoY8N3.js.map +1 -0
- package/dist/_chunks/{en-gYDqKYFd.js → en-BCDLTJn3.js} +36 -7
- package/dist/_chunks/en-BCDLTJn3.js.map +1 -0
- package/dist/_chunks/{en-MyLPoISH.mjs → en-CGXIF4vQ.mjs} +36 -7
- package/dist/_chunks/en-CGXIF4vQ.mjs.map +1 -0
- package/dist/_chunks/index-b3Ej95H7.mjs +1099 -0
- package/dist/_chunks/index-b3Ej95H7.mjs.map +1 -0
- package/dist/_chunks/index-jnv9zdcE.js +1118 -0
- package/dist/_chunks/index-jnv9zdcE.js.map +1 -0
- package/dist/_chunks/schemas-63pFihNF.mjs +44 -0
- package/dist/_chunks/schemas-63pFihNF.mjs.map +1 -0
- package/dist/_chunks/schemas-z5zp-_Gd.js +62 -0
- package/dist/_chunks/schemas-z5zp-_Gd.js.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 +0 -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 +110 -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 +1328 -497
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +1328 -497
- 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 +23 -0
- package/dist/server/src/controllers/index.d.ts.map +1 -0
- package/dist/server/src/controllers/release-action.d.ts +9 -0
- package/dist/server/src/controllers/release-action.d.ts.map +1 -0
- package/dist/server/src/controllers/release.d.ts +17 -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 +2111 -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 +1826 -0
- package/dist/server/src/services/index.d.ts.map +1 -0
- package/dist/server/src/services/release-action.d.ts +36 -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 +132 -0
- package/dist/shared/contracts/release-actions.d.ts.map +1 -0
- package/dist/shared/contracts/releases.d.ts +183 -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 -35
- package/dist/_chunks/App-L1jSxCiL.mjs +0 -1015
- package/dist/_chunks/App-L1jSxCiL.mjs.map +0 -1
- package/dist/_chunks/App-_20W9dYa.js +0 -1037
- package/dist/_chunks/App-_20W9dYa.js.map +0 -1
- package/dist/_chunks/en-MyLPoISH.mjs.map +0 -1
- package/dist/_chunks/en-gYDqKYFd.js.map +0 -1
- package/dist/_chunks/index-KJa1Rb5F.js +0 -908
- package/dist/_chunks/index-KJa1Rb5F.js.map +0 -1
- package/dist/_chunks/index-c4zRX_sg.mjs +0 -887
- package/dist/_chunks/index-c4zRX_sg.mjs.map +0 -1
package/dist/server/index.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { contentTypes as contentTypes$1,
|
|
1
|
+
import { contentTypes as contentTypes$1, async, setCreatorFields, errors, yup as yup$1, validateYupSchema } from "@strapi/utils";
|
|
2
|
+
import isEqual from "lodash/isEqual";
|
|
2
3
|
import { difference, keys } from "lodash";
|
|
3
4
|
import _ from "lodash/fp";
|
|
4
|
-
import
|
|
5
|
+
import { scheduleJob } from "node-schedule";
|
|
5
6
|
import * as yup from "yup";
|
|
6
7
|
const RELEASE_MODEL_UID = "plugin::content-releases.release";
|
|
7
8
|
const RELEASE_ACTION_MODEL_UID = "plugin::content-releases.release-action";
|
|
@@ -47,8 +48,83 @@ const ACTIONS = [
|
|
|
47
48
|
displayName: "Add an entry to a release",
|
|
48
49
|
uid: "create-action",
|
|
49
50
|
pluginName: "content-releases"
|
|
51
|
+
},
|
|
52
|
+
// Settings
|
|
53
|
+
{
|
|
54
|
+
uid: "settings.read",
|
|
55
|
+
section: "settings",
|
|
56
|
+
displayName: "Read",
|
|
57
|
+
category: "content releases",
|
|
58
|
+
subCategory: "options",
|
|
59
|
+
pluginName: "content-releases"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
uid: "settings.update",
|
|
63
|
+
section: "settings",
|
|
64
|
+
displayName: "Edit",
|
|
65
|
+
category: "content releases",
|
|
66
|
+
subCategory: "options",
|
|
67
|
+
pluginName: "content-releases"
|
|
50
68
|
}
|
|
51
69
|
];
|
|
70
|
+
const ALLOWED_WEBHOOK_EVENTS = {
|
|
71
|
+
RELEASES_PUBLISH: "releases.publish"
|
|
72
|
+
};
|
|
73
|
+
const getService = (name, { strapi: strapi2 }) => {
|
|
74
|
+
return strapi2.plugin("content-releases").service(name);
|
|
75
|
+
};
|
|
76
|
+
const getDraftEntryValidStatus = async ({ contentType, documentId, locale }, { strapi: strapi2 }) => {
|
|
77
|
+
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
78
|
+
const populate = await populateBuilderService(contentType).populateDeep(Infinity).build();
|
|
79
|
+
const entry = await getEntry({ contentType, documentId, locale, populate }, { strapi: strapi2 });
|
|
80
|
+
return isEntryValid(contentType, entry, { strapi: strapi2 });
|
|
81
|
+
};
|
|
82
|
+
const isEntryValid = async (contentTypeUid, entry, { strapi: strapi2 }) => {
|
|
83
|
+
try {
|
|
84
|
+
await strapi2.entityValidator.validateEntityCreation(
|
|
85
|
+
strapi2.getModel(contentTypeUid),
|
|
86
|
+
entry,
|
|
87
|
+
void 0,
|
|
88
|
+
// @ts-expect-error - FIXME: entity here is unnecessary
|
|
89
|
+
entry
|
|
90
|
+
);
|
|
91
|
+
return true;
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const getEntry = async ({
|
|
97
|
+
contentType,
|
|
98
|
+
documentId,
|
|
99
|
+
locale,
|
|
100
|
+
populate,
|
|
101
|
+
status = "draft"
|
|
102
|
+
}, { strapi: strapi2 }) => {
|
|
103
|
+
if (documentId) {
|
|
104
|
+
return strapi2.documents(contentType).findOne({ documentId, locale, populate, status });
|
|
105
|
+
}
|
|
106
|
+
return strapi2.documents(contentType).findFirst({ locale, populate, status });
|
|
107
|
+
};
|
|
108
|
+
const getEntryStatus = async (contentType, entry) => {
|
|
109
|
+
if (entry.publishedAt) {
|
|
110
|
+
return "published";
|
|
111
|
+
}
|
|
112
|
+
const publishedEntry = await strapi.documents(contentType).findOne({
|
|
113
|
+
documentId: entry.documentId,
|
|
114
|
+
locale: entry.locale,
|
|
115
|
+
status: "published",
|
|
116
|
+
fields: ["updatedAt"]
|
|
117
|
+
});
|
|
118
|
+
if (!publishedEntry) {
|
|
119
|
+
return "draft";
|
|
120
|
+
}
|
|
121
|
+
const entryUpdatedAt = new Date(entry.updatedAt).getTime();
|
|
122
|
+
const publishedEntryUpdatedAt = new Date(publishedEntry.updatedAt).getTime();
|
|
123
|
+
if (entryUpdatedAt > publishedEntryUpdatedAt) {
|
|
124
|
+
return "modified";
|
|
125
|
+
}
|
|
126
|
+
return "published";
|
|
127
|
+
};
|
|
52
128
|
async function deleteActionsOnDisableDraftAndPublish({
|
|
53
129
|
oldContentTypes,
|
|
54
130
|
contentTypes: contentTypes2
|
|
@@ -70,66 +146,349 @@ async function deleteActionsOnDisableDraftAndPublish({
|
|
|
70
146
|
async function deleteActionsOnDeleteContentType({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
71
147
|
const deletedContentTypes = difference(keys(oldContentTypes), keys(contentTypes2)) ?? [];
|
|
72
148
|
if (deletedContentTypes.length) {
|
|
73
|
-
await
|
|
149
|
+
await async.map(deletedContentTypes, async (deletedContentTypeUID) => {
|
|
74
150
|
return strapi.db?.queryBuilder(RELEASE_ACTION_MODEL_UID).delete().where({ contentType: deletedContentTypeUID }).execute();
|
|
75
151
|
});
|
|
76
152
|
}
|
|
77
153
|
}
|
|
78
|
-
|
|
154
|
+
async function migrateIsValidAndStatusReleases() {
|
|
155
|
+
const releasesWithoutStatus = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
156
|
+
where: {
|
|
157
|
+
status: null,
|
|
158
|
+
releasedAt: null
|
|
159
|
+
},
|
|
160
|
+
populate: {
|
|
161
|
+
actions: {
|
|
162
|
+
populate: {
|
|
163
|
+
entry: true
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
async.map(releasesWithoutStatus, async (release2) => {
|
|
169
|
+
const actions = release2.actions;
|
|
170
|
+
const notValidatedActions = actions.filter((action) => action.isEntryValid === null);
|
|
171
|
+
for (const action of notValidatedActions) {
|
|
172
|
+
if (action.entry) {
|
|
173
|
+
const isEntryValid2 = getDraftEntryValidStatus(
|
|
174
|
+
{
|
|
175
|
+
contentType: action.contentType,
|
|
176
|
+
documentId: action.entryDocumentId,
|
|
177
|
+
locale: action.locale
|
|
178
|
+
},
|
|
179
|
+
{ strapi }
|
|
180
|
+
);
|
|
181
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
182
|
+
where: {
|
|
183
|
+
id: action.id
|
|
184
|
+
},
|
|
185
|
+
data: {
|
|
186
|
+
isEntryValid: isEntryValid2
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
192
|
+
});
|
|
193
|
+
const publishedReleases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
194
|
+
where: {
|
|
195
|
+
status: null,
|
|
196
|
+
releasedAt: {
|
|
197
|
+
$notNull: true
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
async.map(publishedReleases, async (release2) => {
|
|
202
|
+
return strapi.db.query(RELEASE_MODEL_UID).update({
|
|
203
|
+
where: {
|
|
204
|
+
id: release2.id
|
|
205
|
+
},
|
|
206
|
+
data: {
|
|
207
|
+
status: "done"
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async function revalidateChangedContentTypes({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
213
|
+
if (oldContentTypes !== void 0 && contentTypes2 !== void 0) {
|
|
214
|
+
const contentTypesWithDraftAndPublish = Object.keys(oldContentTypes).filter(
|
|
215
|
+
(uid) => oldContentTypes[uid]?.options?.draftAndPublish
|
|
216
|
+
);
|
|
217
|
+
const releasesAffected = /* @__PURE__ */ new Set();
|
|
218
|
+
async.map(contentTypesWithDraftAndPublish, async (contentTypeUID) => {
|
|
219
|
+
const oldContentType = oldContentTypes[contentTypeUID];
|
|
220
|
+
const contentType = contentTypes2[contentTypeUID];
|
|
221
|
+
if (!isEqual(oldContentType?.attributes, contentType?.attributes)) {
|
|
222
|
+
const actions = await strapi.db.query(RELEASE_ACTION_MODEL_UID).findMany({
|
|
223
|
+
where: {
|
|
224
|
+
contentType: contentTypeUID
|
|
225
|
+
},
|
|
226
|
+
populate: {
|
|
227
|
+
entry: true,
|
|
228
|
+
release: true
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
await async.map(actions, async (action) => {
|
|
232
|
+
if (action.entry && action.release && action.type === "publish") {
|
|
233
|
+
const isEntryValid2 = await getDraftEntryValidStatus(
|
|
234
|
+
{
|
|
235
|
+
contentType: contentTypeUID,
|
|
236
|
+
documentId: action.entryDocumentId,
|
|
237
|
+
locale: action.locale
|
|
238
|
+
},
|
|
239
|
+
{ strapi }
|
|
240
|
+
);
|
|
241
|
+
releasesAffected.add(action.release.id);
|
|
242
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
243
|
+
where: {
|
|
244
|
+
id: action.id
|
|
245
|
+
},
|
|
246
|
+
data: {
|
|
247
|
+
isEntryValid: isEntryValid2
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}).then(() => {
|
|
254
|
+
async.map(releasesAffected, async (releaseId) => {
|
|
255
|
+
return getService("release", { strapi }).updateReleaseStatus(releaseId);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
async function disableContentTypeLocalized({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
261
|
+
if (!oldContentTypes) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const i18nPlugin = strapi.plugin("i18n");
|
|
265
|
+
if (!i18nPlugin) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
for (const uid in contentTypes2) {
|
|
269
|
+
if (!oldContentTypes[uid]) {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
const oldContentType = oldContentTypes[uid];
|
|
273
|
+
const contentType = contentTypes2[uid];
|
|
274
|
+
const { isLocalizedContentType } = i18nPlugin.service("content-types");
|
|
275
|
+
if (isLocalizedContentType(oldContentType) && !isLocalizedContentType(contentType)) {
|
|
276
|
+
await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
|
|
277
|
+
locale: null
|
|
278
|
+
}).where({ contentType: uid }).execute();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async function enableContentTypeLocalized({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
283
|
+
if (!oldContentTypes) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const i18nPlugin = strapi.plugin("i18n");
|
|
287
|
+
if (!i18nPlugin) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
for (const uid in contentTypes2) {
|
|
291
|
+
if (!oldContentTypes[uid]) {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
const oldContentType = oldContentTypes[uid];
|
|
295
|
+
const contentType = contentTypes2[uid];
|
|
296
|
+
const { isLocalizedContentType } = i18nPlugin.service("content-types");
|
|
297
|
+
const { getDefaultLocale } = i18nPlugin.service("locales");
|
|
298
|
+
if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {
|
|
299
|
+
const defaultLocale = await getDefaultLocale();
|
|
300
|
+
await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
|
|
301
|
+
locale: defaultLocale
|
|
302
|
+
}).where({ contentType: uid }).execute();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const addEntryDocumentToReleaseActions = {
|
|
307
|
+
name: "content-releases::5.0.0-add-entry-document-id-to-release-actions",
|
|
308
|
+
async up(trx, db) {
|
|
309
|
+
const hasPolymorphicColumn = await trx.schema.hasColumn("strapi_release_actions", "target_id");
|
|
310
|
+
if (hasPolymorphicColumn) {
|
|
311
|
+
const hasEntryDocumentIdColumn = await trx.schema.hasColumn(
|
|
312
|
+
"strapi_release_actions",
|
|
313
|
+
"entry_document_id"
|
|
314
|
+
);
|
|
315
|
+
if (!hasEntryDocumentIdColumn) {
|
|
316
|
+
await trx.schema.alterTable("strapi_release_actions", (table) => {
|
|
317
|
+
table.string("entry_document_id");
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
const releaseActions = await trx.select("*").from("strapi_release_actions");
|
|
321
|
+
async.map(releaseActions, async (action) => {
|
|
322
|
+
const { target_type, target_id } = action;
|
|
323
|
+
const entry = await db.query(target_type).findOne({ where: { id: target_id } });
|
|
324
|
+
if (entry) {
|
|
325
|
+
await trx("strapi_release_actions").update({ entry_document_id: entry.documentId }).where("id", action.id);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
async down() {
|
|
331
|
+
throw new Error("not implemented");
|
|
332
|
+
}
|
|
333
|
+
};
|
|
79
334
|
const register = async ({ strapi: strapi2 }) => {
|
|
80
|
-
if (features
|
|
81
|
-
await strapi2.admin
|
|
82
|
-
strapi2.
|
|
83
|
-
strapi2.hook("strapi::content-types.
|
|
335
|
+
if (strapi2.ee.features.isEnabled("cms-content-releases")) {
|
|
336
|
+
await strapi2.service("admin::permission").actionProvider.registerMany(ACTIONS);
|
|
337
|
+
strapi2.db.migrations.providers.internal.register(addEntryDocumentToReleaseActions);
|
|
338
|
+
strapi2.hook("strapi::content-types.beforeSync").register(disableContentTypeLocalized).register(deleteActionsOnDisableDraftAndPublish);
|
|
339
|
+
strapi2.hook("strapi::content-types.afterSync").register(deleteActionsOnDeleteContentType).register(enableContentTypeLocalized).register(revalidateChangedContentTypes).register(migrateIsValidAndStatusReleases);
|
|
340
|
+
}
|
|
341
|
+
if (strapi2.plugin("graphql")) {
|
|
342
|
+
const graphqlExtensionService = strapi2.plugin("graphql").service("extension");
|
|
343
|
+
graphqlExtensionService.shadowCRUD(RELEASE_MODEL_UID).disable();
|
|
344
|
+
graphqlExtensionService.shadowCRUD(RELEASE_ACTION_MODEL_UID).disable();
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
const updateActionsStatusAndUpdateReleaseStatus = async (contentType, entry) => {
|
|
348
|
+
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
349
|
+
where: {
|
|
350
|
+
actions: {
|
|
351
|
+
contentType,
|
|
352
|
+
entryDocumentId: entry.documentId,
|
|
353
|
+
locale: entry.locale
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
const entryStatus = await isEntryValid(contentType, entry, { strapi });
|
|
358
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
359
|
+
where: {
|
|
360
|
+
contentType,
|
|
361
|
+
entryDocumentId: entry.documentId,
|
|
362
|
+
locale: entry.locale
|
|
363
|
+
},
|
|
364
|
+
data: {
|
|
365
|
+
isEntryValid: entryStatus
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
for (const release2 of releases) {
|
|
369
|
+
getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
const deleteActionsAndUpdateReleaseStatus = async (params) => {
|
|
373
|
+
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
374
|
+
where: {
|
|
375
|
+
actions: params
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
379
|
+
where: params
|
|
380
|
+
});
|
|
381
|
+
for (const release2 of releases) {
|
|
382
|
+
getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const deleteActionsOnDelete = async (ctx, next) => {
|
|
386
|
+
if (ctx.action !== "delete") {
|
|
387
|
+
return next();
|
|
388
|
+
}
|
|
389
|
+
if (!contentTypes$1.hasDraftAndPublish(ctx.contentType)) {
|
|
390
|
+
return next();
|
|
391
|
+
}
|
|
392
|
+
const contentType = ctx.contentType.uid;
|
|
393
|
+
const { documentId, locale } = ctx.params;
|
|
394
|
+
const result = await next();
|
|
395
|
+
if (!result) {
|
|
396
|
+
return result;
|
|
397
|
+
}
|
|
398
|
+
try {
|
|
399
|
+
deleteActionsAndUpdateReleaseStatus({
|
|
400
|
+
contentType,
|
|
401
|
+
entryDocumentId: documentId,
|
|
402
|
+
...locale !== "*" && { locale }
|
|
403
|
+
});
|
|
404
|
+
} catch (error) {
|
|
405
|
+
strapi.log.error("Error while deleting release actions after delete", {
|
|
406
|
+
error
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
return result;
|
|
410
|
+
};
|
|
411
|
+
const updateActionsOnUpdate = async (ctx, next) => {
|
|
412
|
+
if (ctx.action !== "update") {
|
|
413
|
+
return next();
|
|
414
|
+
}
|
|
415
|
+
if (!contentTypes$1.hasDraftAndPublish(ctx.contentType)) {
|
|
416
|
+
return next();
|
|
417
|
+
}
|
|
418
|
+
const contentType = ctx.contentType.uid;
|
|
419
|
+
const result = await next();
|
|
420
|
+
if (!result) {
|
|
421
|
+
return result;
|
|
422
|
+
}
|
|
423
|
+
try {
|
|
424
|
+
updateActionsStatusAndUpdateReleaseStatus(contentType, result);
|
|
425
|
+
} catch (error) {
|
|
426
|
+
strapi.log.error("Error while updating release actions after update", {
|
|
427
|
+
error
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
return result;
|
|
431
|
+
};
|
|
432
|
+
const deleteReleasesActionsAndUpdateReleaseStatus = async (params) => {
|
|
433
|
+
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
434
|
+
where: {
|
|
435
|
+
actions: params
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
439
|
+
where: params
|
|
440
|
+
});
|
|
441
|
+
for (const release2 of releases) {
|
|
442
|
+
getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
84
443
|
}
|
|
85
444
|
};
|
|
86
|
-
const { features: features$1 } = require("@strapi/strapi/dist/utils/ee");
|
|
87
445
|
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
88
|
-
if (features
|
|
446
|
+
if (strapi2.ee.features.isEnabled("cms-content-releases")) {
|
|
447
|
+
const contentTypesWithDraftAndPublish = Object.keys(strapi2.contentTypes).filter(
|
|
448
|
+
(uid) => strapi2.contentTypes[uid]?.options?.draftAndPublish
|
|
449
|
+
);
|
|
89
450
|
strapi2.db.lifecycles.subscribe({
|
|
90
|
-
|
|
91
|
-
const { model, result } = event;
|
|
92
|
-
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
93
|
-
const { id } = result;
|
|
94
|
-
strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
95
|
-
where: {
|
|
96
|
-
target_type: model.uid,
|
|
97
|
-
target_id: id
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
/**
|
|
103
|
-
* deleteMany hook doesn't return the deleted entries ids
|
|
104
|
-
* so we need to fetch them before deleting the entries to save the ids on our state
|
|
105
|
-
*/
|
|
106
|
-
async beforeDeleteMany(event) {
|
|
107
|
-
const { model, params } = event;
|
|
108
|
-
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
109
|
-
const { where } = params;
|
|
110
|
-
const entriesToDelete = await strapi2.db.query(model.uid).findMany({ select: ["id"], where });
|
|
111
|
-
event.state.entriesToDelete = entriesToDelete;
|
|
112
|
-
}
|
|
113
|
-
},
|
|
451
|
+
models: contentTypesWithDraftAndPublish,
|
|
114
452
|
/**
|
|
115
|
-
*
|
|
116
|
-
* We make this only after deleteMany is succesfully executed to avoid errors
|
|
453
|
+
* deleteMany is still used outside documents service, for example when deleting a locale
|
|
117
454
|
*/
|
|
118
455
|
async afterDeleteMany(event) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
456
|
+
try {
|
|
457
|
+
const model = strapi2.getModel(event.model.uid);
|
|
458
|
+
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
459
|
+
const { where } = event.params;
|
|
460
|
+
deleteReleasesActionsAndUpdateReleaseStatus({
|
|
461
|
+
contentType: model.uid,
|
|
462
|
+
locale: where.locale ?? null,
|
|
463
|
+
...where.documentId && { entryDocumentId: where.documentId }
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
} catch (error) {
|
|
467
|
+
strapi2.log.error("Error while deleting release actions after entry deleteMany", {
|
|
468
|
+
error
|
|
129
469
|
});
|
|
130
470
|
}
|
|
131
471
|
}
|
|
132
472
|
});
|
|
473
|
+
strapi2.documents.use(deleteActionsOnDelete);
|
|
474
|
+
strapi2.documents.use(updateActionsOnUpdate);
|
|
475
|
+
getService("scheduling", { strapi: strapi2 }).syncFromDatabase().catch((err) => {
|
|
476
|
+
strapi2.log.error(
|
|
477
|
+
"Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling."
|
|
478
|
+
);
|
|
479
|
+
throw err;
|
|
480
|
+
});
|
|
481
|
+
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
|
482
|
+
strapi2.get("webhookStore").addAllowedEvent(key, value);
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
const destroy = async ({ strapi: strapi2 }) => {
|
|
487
|
+
const scheduledJobs = getService("scheduling", {
|
|
488
|
+
strapi: strapi2
|
|
489
|
+
}).getAll();
|
|
490
|
+
for (const [, job] of scheduledJobs) {
|
|
491
|
+
job.cancel();
|
|
133
492
|
}
|
|
134
493
|
};
|
|
135
494
|
const schema$1 = {
|
|
@@ -158,6 +517,17 @@ const schema$1 = {
|
|
|
158
517
|
releasedAt: {
|
|
159
518
|
type: "datetime"
|
|
160
519
|
},
|
|
520
|
+
scheduledAt: {
|
|
521
|
+
type: "datetime"
|
|
522
|
+
},
|
|
523
|
+
timezone: {
|
|
524
|
+
type: "string"
|
|
525
|
+
},
|
|
526
|
+
status: {
|
|
527
|
+
type: "enumeration",
|
|
528
|
+
enum: ["ready", "blocked", "failed", "done", "empty"],
|
|
529
|
+
required: true
|
|
530
|
+
},
|
|
161
531
|
actions: {
|
|
162
532
|
type: "relation",
|
|
163
533
|
relation: "oneToMany",
|
|
@@ -193,15 +563,13 @@ const schema = {
|
|
|
193
563
|
enum: ["publish", "unpublish"],
|
|
194
564
|
required: true
|
|
195
565
|
},
|
|
196
|
-
entry: {
|
|
197
|
-
type: "relation",
|
|
198
|
-
relation: "morphToOne",
|
|
199
|
-
configurable: false
|
|
200
|
-
},
|
|
201
566
|
contentType: {
|
|
202
567
|
type: "string",
|
|
203
568
|
required: true
|
|
204
569
|
},
|
|
570
|
+
entryDocumentId: {
|
|
571
|
+
type: "string"
|
|
572
|
+
},
|
|
205
573
|
locale: {
|
|
206
574
|
type: "string"
|
|
207
575
|
},
|
|
@@ -210,6 +578,9 @@ const schema = {
|
|
|
210
578
|
relation: "manyToOne",
|
|
211
579
|
target: RELEASE_MODEL_UID,
|
|
212
580
|
inversedBy: "actions"
|
|
581
|
+
},
|
|
582
|
+
isEntryValid: {
|
|
583
|
+
type: "boolean"
|
|
213
584
|
}
|
|
214
585
|
}
|
|
215
586
|
};
|
|
@@ -220,226 +591,297 @@ const contentTypes = {
|
|
|
220
591
|
release: release$1,
|
|
221
592
|
"release-action": releaseAction$1
|
|
222
593
|
};
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return "contentType.displayName";
|
|
230
|
-
case "action":
|
|
231
|
-
return "type";
|
|
232
|
-
case "locale":
|
|
233
|
-
return _.getOr("No locale", "locale.name");
|
|
234
|
-
default:
|
|
235
|
-
return "contentType.displayName";
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
const createReleaseService = ({ strapi: strapi2 }) => ({
|
|
239
|
-
async create(releaseData, { user }) {
|
|
240
|
-
const releaseWithCreatorFields = await setCreatorFields({ user })(releaseData);
|
|
241
|
-
const { validatePendingReleasesLimit, validateUniqueNameForPendingRelease } = getService(
|
|
242
|
-
"release-validation",
|
|
243
|
-
{ strapi: strapi2 }
|
|
244
|
-
);
|
|
245
|
-
await Promise.all([
|
|
246
|
-
validatePendingReleasesLimit(),
|
|
247
|
-
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name)
|
|
248
|
-
]);
|
|
249
|
-
return strapi2.entityService.create(RELEASE_MODEL_UID, {
|
|
250
|
-
data: releaseWithCreatorFields
|
|
251
|
-
});
|
|
252
|
-
},
|
|
253
|
-
async findOne(id, query = {}) {
|
|
254
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id, {
|
|
255
|
-
...query
|
|
594
|
+
const createReleaseService = ({ strapi: strapi2 }) => {
|
|
595
|
+
const dispatchWebhook = (event, { isPublished, release: release2, error }) => {
|
|
596
|
+
strapi2.eventHub.emit(event, {
|
|
597
|
+
isPublished,
|
|
598
|
+
error,
|
|
599
|
+
release: release2
|
|
256
600
|
});
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
actions: {
|
|
264
|
-
// @ts-expect-error Ignore missing properties
|
|
265
|
-
count: true
|
|
601
|
+
};
|
|
602
|
+
const getFormattedActions = async (releaseId) => {
|
|
603
|
+
const actions = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findMany({
|
|
604
|
+
where: {
|
|
605
|
+
release: {
|
|
606
|
+
id: releaseId
|
|
266
607
|
}
|
|
267
608
|
}
|
|
268
609
|
});
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
610
|
+
if (actions.length === 0) {
|
|
611
|
+
throw new errors.ValidationError("No entries to publish");
|
|
612
|
+
}
|
|
613
|
+
const formattedActions = {};
|
|
614
|
+
for (const action of actions) {
|
|
615
|
+
const contentTypeUid = action.contentType;
|
|
616
|
+
if (!formattedActions[contentTypeUid]) {
|
|
617
|
+
formattedActions[contentTypeUid] = {
|
|
618
|
+
publish: [],
|
|
619
|
+
unpublish: []
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
formattedActions[contentTypeUid][action.type].push({
|
|
623
|
+
documentId: action.entryDocumentId,
|
|
624
|
+
locale: action.locale
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
return formattedActions;
|
|
628
|
+
};
|
|
629
|
+
return {
|
|
630
|
+
async create(releaseData, { user }) {
|
|
631
|
+
const releaseWithCreatorFields = await setCreatorFields({ user })(releaseData);
|
|
632
|
+
const {
|
|
633
|
+
validatePendingReleasesLimit,
|
|
634
|
+
validateUniqueNameForPendingRelease,
|
|
635
|
+
validateScheduledAtIsLaterThanNow
|
|
636
|
+
} = getService("release-validation", { strapi: strapi2 });
|
|
637
|
+
await Promise.all([
|
|
638
|
+
validatePendingReleasesLimit(),
|
|
639
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
|
|
640
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
641
|
+
]);
|
|
642
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).create({
|
|
643
|
+
data: {
|
|
644
|
+
...releaseWithCreatorFields,
|
|
645
|
+
status: "empty"
|
|
279
646
|
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
647
|
+
});
|
|
648
|
+
if (releaseWithCreatorFields.scheduledAt) {
|
|
649
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
650
|
+
await schedulingService.set(release2.id, release2.scheduledAt);
|
|
651
|
+
}
|
|
652
|
+
strapi2.telemetry.send("didCreateContentRelease");
|
|
653
|
+
return release2;
|
|
654
|
+
},
|
|
655
|
+
async findOne(id, query = {}) {
|
|
656
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query);
|
|
657
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
658
|
+
...dbQuery,
|
|
659
|
+
where: { id }
|
|
660
|
+
});
|
|
661
|
+
return release2;
|
|
662
|
+
},
|
|
663
|
+
findPage(query) {
|
|
664
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
|
|
665
|
+
return strapi2.db.query(RELEASE_MODEL_UID).findPage({
|
|
666
|
+
...dbQuery,
|
|
667
|
+
populate: {
|
|
668
|
+
actions: {
|
|
669
|
+
count: true
|
|
287
670
|
}
|
|
288
671
|
}
|
|
672
|
+
});
|
|
673
|
+
},
|
|
674
|
+
findMany(query) {
|
|
675
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
|
|
676
|
+
return strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
677
|
+
...dbQuery
|
|
678
|
+
});
|
|
679
|
+
},
|
|
680
|
+
async update(id, releaseData, { user }) {
|
|
681
|
+
const releaseWithCreatorFields = await setCreatorFields({ user, isEdition: true })(
|
|
682
|
+
releaseData
|
|
683
|
+
);
|
|
684
|
+
const { validateUniqueNameForPendingRelease, validateScheduledAtIsLaterThanNow } = getService(
|
|
685
|
+
"release-validation",
|
|
686
|
+
{ strapi: strapi2 }
|
|
687
|
+
);
|
|
688
|
+
await Promise.all([
|
|
689
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name, id),
|
|
690
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
691
|
+
]);
|
|
692
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id } });
|
|
693
|
+
if (!release2) {
|
|
694
|
+
throw new errors.NotFoundError(`No release found for id ${id}`);
|
|
289
695
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if (release2.actions?.length) {
|
|
293
|
-
const [actionForEntry] = release2.actions;
|
|
294
|
-
delete release2.actions;
|
|
295
|
-
return {
|
|
296
|
-
...release2,
|
|
297
|
-
action: actionForEntry
|
|
298
|
-
};
|
|
696
|
+
if (release2.releasedAt) {
|
|
697
|
+
throw new errors.ValidationError("Release already published");
|
|
299
698
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
699
|
+
const updatedRelease = await strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
700
|
+
where: { id },
|
|
701
|
+
data: releaseWithCreatorFields
|
|
702
|
+
});
|
|
703
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
704
|
+
if (releaseData.scheduledAt) {
|
|
705
|
+
await schedulingService.set(id, releaseData.scheduledAt);
|
|
706
|
+
} else if (release2.scheduledAt) {
|
|
707
|
+
schedulingService.cancel(id);
|
|
708
|
+
}
|
|
709
|
+
this.updateReleaseStatus(id);
|
|
710
|
+
strapi2.telemetry.send("didUpdateContentRelease");
|
|
711
|
+
return updatedRelease;
|
|
712
|
+
},
|
|
713
|
+
async getAllComponents() {
|
|
714
|
+
const contentManagerComponentsService = strapi2.plugin("content-manager").service("components");
|
|
715
|
+
const components = await contentManagerComponentsService.findAllComponents();
|
|
716
|
+
const componentsMap = components.reduce(
|
|
717
|
+
(acc, component) => {
|
|
718
|
+
acc[component.uid] = component;
|
|
719
|
+
return acc;
|
|
308
720
|
},
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
721
|
+
{}
|
|
722
|
+
);
|
|
723
|
+
return componentsMap;
|
|
724
|
+
},
|
|
725
|
+
async delete(releaseId) {
|
|
726
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
727
|
+
where: { id: releaseId },
|
|
728
|
+
populate: {
|
|
729
|
+
actions: {
|
|
730
|
+
select: ["id"]
|
|
731
|
+
}
|
|
312
732
|
}
|
|
733
|
+
});
|
|
734
|
+
if (!release2) {
|
|
735
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
313
736
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
737
|
+
if (release2.releasedAt) {
|
|
738
|
+
throw new errors.ValidationError("Release already published");
|
|
739
|
+
}
|
|
740
|
+
await strapi2.db.transaction(async () => {
|
|
741
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
742
|
+
where: {
|
|
319
743
|
id: {
|
|
320
|
-
$
|
|
744
|
+
$in: release2.actions.map((action) => action.id)
|
|
321
745
|
}
|
|
322
|
-
},
|
|
323
|
-
{
|
|
324
|
-
actions: null
|
|
325
746
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
if (release2.
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
return {
|
|
337
|
-
...release2,
|
|
338
|
-
action: actionForEntry
|
|
339
|
-
};
|
|
747
|
+
});
|
|
748
|
+
await strapi2.db.query(RELEASE_MODEL_UID).delete({
|
|
749
|
+
where: {
|
|
750
|
+
id: releaseId
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
if (release2.scheduledAt) {
|
|
755
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
756
|
+
await schedulingService.cancel(release2.id);
|
|
340
757
|
}
|
|
758
|
+
strapi2.telemetry.send("didDeleteContentRelease");
|
|
341
759
|
return release2;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
throw new errors.ValidationError("Release already published");
|
|
352
|
-
}
|
|
353
|
-
const updatedRelease = await strapi2.entityService.update(RELEASE_MODEL_UID, id, {
|
|
354
|
-
/*
|
|
355
|
-
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">>
|
|
356
|
-
* is not compatible with the type we are passing here: UpdateRelease.Request['body']
|
|
357
|
-
*/
|
|
358
|
-
// @ts-expect-error see above
|
|
359
|
-
data: releaseWithCreatorFields
|
|
360
|
-
});
|
|
361
|
-
return updatedRelease;
|
|
362
|
-
},
|
|
363
|
-
async createAction(releaseId, action) {
|
|
364
|
-
const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
|
|
365
|
-
strapi: strapi2
|
|
366
|
-
});
|
|
367
|
-
await Promise.all([
|
|
368
|
-
validateEntryContentType(action.entry.contentType),
|
|
369
|
-
validateUniqueEntry(releaseId, action)
|
|
370
|
-
]);
|
|
371
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
|
|
372
|
-
if (!release2) {
|
|
373
|
-
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
374
|
-
}
|
|
375
|
-
if (release2.releasedAt) {
|
|
376
|
-
throw new errors.ValidationError("Release already published");
|
|
377
|
-
}
|
|
378
|
-
const { entry, type } = action;
|
|
379
|
-
return strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
|
|
380
|
-
data: {
|
|
381
|
-
type,
|
|
382
|
-
contentType: entry.contentType,
|
|
383
|
-
locale: entry.locale,
|
|
384
|
-
entry: {
|
|
385
|
-
id: entry.id,
|
|
386
|
-
__type: entry.contentType,
|
|
387
|
-
__pivot: { field: "entry" }
|
|
388
|
-
},
|
|
389
|
-
release: releaseId
|
|
390
|
-
},
|
|
391
|
-
populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
|
|
392
|
-
});
|
|
393
|
-
},
|
|
394
|
-
async findActions(releaseId, query) {
|
|
395
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
396
|
-
fields: ["id"]
|
|
397
|
-
});
|
|
398
|
-
if (!release2) {
|
|
399
|
-
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
400
|
-
}
|
|
401
|
-
return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
|
|
402
|
-
...query,
|
|
403
|
-
populate: {
|
|
404
|
-
entry: {
|
|
405
|
-
populate: "*"
|
|
760
|
+
},
|
|
761
|
+
async publish(releaseId) {
|
|
762
|
+
const {
|
|
763
|
+
release: release2,
|
|
764
|
+
error
|
|
765
|
+
} = await strapi2.db.transaction(async ({ trx }) => {
|
|
766
|
+
const lockedRelease = await strapi2.db?.queryBuilder(RELEASE_MODEL_UID).where({ id: releaseId }).select(["id", "name", "releasedAt", "status"]).first().transacting(trx).forUpdate().execute();
|
|
767
|
+
if (!lockedRelease) {
|
|
768
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
406
769
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
770
|
+
if (lockedRelease.releasedAt) {
|
|
771
|
+
throw new errors.ValidationError("Release already published");
|
|
772
|
+
}
|
|
773
|
+
if (lockedRelease.status === "failed") {
|
|
774
|
+
throw new errors.ValidationError("Release failed to publish");
|
|
775
|
+
}
|
|
776
|
+
try {
|
|
777
|
+
strapi2.log.info(`[Content Releases] Starting to publish release ${lockedRelease.name}`);
|
|
778
|
+
const formattedActions = await getFormattedActions(releaseId);
|
|
779
|
+
await strapi2.db.transaction(
|
|
780
|
+
async () => Promise.all(
|
|
781
|
+
Object.keys(formattedActions).map(async (contentTypeUid) => {
|
|
782
|
+
const contentType = contentTypeUid;
|
|
783
|
+
const { publish, unpublish } = formattedActions[contentType];
|
|
784
|
+
return Promise.all([
|
|
785
|
+
...publish.map((params) => strapi2.documents(contentType).publish(params)),
|
|
786
|
+
...unpublish.map((params) => strapi2.documents(contentType).unpublish(params))
|
|
787
|
+
]);
|
|
788
|
+
})
|
|
789
|
+
)
|
|
790
|
+
);
|
|
791
|
+
const release22 = await strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
792
|
+
where: {
|
|
793
|
+
id: releaseId
|
|
794
|
+
},
|
|
795
|
+
data: {
|
|
796
|
+
status: "done",
|
|
797
|
+
releasedAt: /* @__PURE__ */ new Date()
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
801
|
+
isPublished: true,
|
|
802
|
+
release: release22
|
|
803
|
+
});
|
|
804
|
+
strapi2.telemetry.send("didPublishContentRelease");
|
|
805
|
+
return { release: release22, error: null };
|
|
806
|
+
} catch (error2) {
|
|
807
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
808
|
+
isPublished: false,
|
|
809
|
+
error: error2
|
|
810
|
+
});
|
|
811
|
+
await strapi2.db?.queryBuilder(RELEASE_MODEL_UID).where({ id: releaseId }).update({
|
|
812
|
+
status: "failed"
|
|
813
|
+
}).transacting(trx).execute();
|
|
814
|
+
return {
|
|
815
|
+
release: null,
|
|
816
|
+
error: error2
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
if (error instanceof Error) {
|
|
821
|
+
throw error;
|
|
410
822
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
823
|
+
return release2;
|
|
824
|
+
},
|
|
825
|
+
async updateReleaseStatus(releaseId) {
|
|
826
|
+
const releaseActionService = getService("release-action", { strapi: strapi2 });
|
|
827
|
+
const [totalActions, invalidActions] = await Promise.all([
|
|
828
|
+
releaseActionService.countActions({
|
|
829
|
+
filters: {
|
|
830
|
+
release: releaseId
|
|
831
|
+
}
|
|
832
|
+
}),
|
|
833
|
+
releaseActionService.countActions({
|
|
834
|
+
filters: {
|
|
835
|
+
release: releaseId,
|
|
836
|
+
isEntryValid: false
|
|
837
|
+
}
|
|
838
|
+
})
|
|
839
|
+
]);
|
|
840
|
+
if (totalActions > 0) {
|
|
841
|
+
if (invalidActions > 0) {
|
|
842
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
843
|
+
where: {
|
|
844
|
+
id: releaseId
|
|
845
|
+
},
|
|
846
|
+
data: {
|
|
847
|
+
status: "blocked"
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
852
|
+
where: {
|
|
853
|
+
id: releaseId
|
|
854
|
+
},
|
|
855
|
+
data: {
|
|
856
|
+
status: "ready"
|
|
857
|
+
}
|
|
858
|
+
});
|
|
420
859
|
}
|
|
421
|
-
return
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
const formattedData = actions.map((action) => {
|
|
428
|
-
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
429
|
-
return {
|
|
430
|
-
...action,
|
|
431
|
-
locale: action.locale ? allLocalesDictionary[action.locale] : null,
|
|
432
|
-
contentType: {
|
|
433
|
-
displayName,
|
|
434
|
-
mainFieldValue: action.entry[mainField],
|
|
435
|
-
uid: action.contentType
|
|
860
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
861
|
+
where: {
|
|
862
|
+
id: releaseId
|
|
863
|
+
},
|
|
864
|
+
data: {
|
|
865
|
+
status: "empty"
|
|
436
866
|
}
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
};
|
|
871
|
+
const getGroupName = (queryValue) => {
|
|
872
|
+
switch (queryValue) {
|
|
873
|
+
case "contentType":
|
|
874
|
+
return "contentType.displayName";
|
|
875
|
+
case "type":
|
|
876
|
+
return "type";
|
|
877
|
+
case "locale":
|
|
878
|
+
return _.getOr("No locale", "locale.name");
|
|
879
|
+
default:
|
|
880
|
+
return "contentType.displayName";
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
const createReleaseActionService = ({ strapi: strapi2 }) => {
|
|
884
|
+
const getLocalesDataForActions = async () => {
|
|
443
885
|
if (!strapi2.plugin("i18n")) {
|
|
444
886
|
return {};
|
|
445
887
|
}
|
|
@@ -448,8 +890,8 @@ const createReleaseService = ({ strapi: strapi2 }) => ({
|
|
|
448
890
|
acc[locale.code] = { name: locale.name, code: locale.code };
|
|
449
891
|
return acc;
|
|
450
892
|
}, {});
|
|
451
|
-
}
|
|
452
|
-
async
|
|
893
|
+
};
|
|
894
|
+
const getContentTypesDataForActions = async (contentTypesUids) => {
|
|
453
895
|
const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
|
|
454
896
|
const contentTypesData = {};
|
|
455
897
|
for (const contentTypeUid of contentTypesUids) {
|
|
@@ -462,221 +904,239 @@ const createReleaseService = ({ strapi: strapi2 }) => ({
|
|
|
462
904
|
};
|
|
463
905
|
}
|
|
464
906
|
return contentTypesData;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
907
|
+
};
|
|
908
|
+
return {
|
|
909
|
+
async create(releaseId, action) {
|
|
910
|
+
const { validateEntryData, validateUniqueEntry } = getService("release-validation", {
|
|
911
|
+
strapi: strapi2
|
|
912
|
+
});
|
|
913
|
+
await Promise.all([
|
|
914
|
+
validateEntryData(action.contentType, action.entryDocumentId),
|
|
915
|
+
validateUniqueEntry(releaseId, action)
|
|
916
|
+
]);
|
|
917
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id: releaseId } });
|
|
918
|
+
if (!release2) {
|
|
919
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
470
920
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
const contentTypeModelsMap = contentTypeUids.reduce(
|
|
474
|
-
(acc, contentTypeUid) => {
|
|
475
|
-
acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
|
|
476
|
-
return acc;
|
|
477
|
-
},
|
|
478
|
-
{}
|
|
479
|
-
);
|
|
480
|
-
return contentTypeModelsMap;
|
|
481
|
-
},
|
|
482
|
-
async getAllComponents() {
|
|
483
|
-
const contentManagerComponentsService = strapi2.plugin("content-manager").service("components");
|
|
484
|
-
const components = await contentManagerComponentsService.findAllComponents();
|
|
485
|
-
const componentsMap = components.reduce(
|
|
486
|
-
(acc, component) => {
|
|
487
|
-
acc[component.uid] = component;
|
|
488
|
-
return acc;
|
|
489
|
-
},
|
|
490
|
-
{}
|
|
491
|
-
);
|
|
492
|
-
return componentsMap;
|
|
493
|
-
},
|
|
494
|
-
async delete(releaseId) {
|
|
495
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
496
|
-
populate: {
|
|
497
|
-
actions: {
|
|
498
|
-
fields: ["id"]
|
|
499
|
-
}
|
|
921
|
+
if (release2.releasedAt) {
|
|
922
|
+
throw new errors.ValidationError("Release already published");
|
|
500
923
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
510
|
-
where: {
|
|
511
|
-
id: {
|
|
512
|
-
$in: release2.actions.map((action) => action.id)
|
|
513
|
-
}
|
|
924
|
+
const actionStatus = action.type === "publish" ? await getDraftEntryValidStatus(
|
|
925
|
+
{
|
|
926
|
+
contentType: action.contentType,
|
|
927
|
+
documentId: action.entryDocumentId,
|
|
928
|
+
locale: action.locale
|
|
929
|
+
},
|
|
930
|
+
{
|
|
931
|
+
strapi: strapi2
|
|
514
932
|
}
|
|
933
|
+
) : true;
|
|
934
|
+
const releaseAction2 = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).create({
|
|
935
|
+
data: {
|
|
936
|
+
...action,
|
|
937
|
+
release: release2.id,
|
|
938
|
+
isEntryValid: actionStatus
|
|
939
|
+
},
|
|
940
|
+
populate: { release: { select: ["id"] } }
|
|
515
941
|
});
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
{
|
|
525
|
-
|
|
526
|
-
actions: {
|
|
527
|
-
populate: {
|
|
528
|
-
entry: {
|
|
529
|
-
fields: ["id"]
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
);
|
|
536
|
-
if (!releaseWithPopulatedActionEntries) {
|
|
537
|
-
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
538
|
-
}
|
|
539
|
-
if (releaseWithPopulatedActionEntries.releasedAt) {
|
|
540
|
-
throw new errors.ValidationError("Release already published");
|
|
541
|
-
}
|
|
542
|
-
if (releaseWithPopulatedActionEntries.actions.length === 0) {
|
|
543
|
-
throw new errors.ValidationError("No entries to publish");
|
|
544
|
-
}
|
|
545
|
-
const actions = {};
|
|
546
|
-
for (const action of releaseWithPopulatedActionEntries.actions) {
|
|
547
|
-
const contentTypeUid = action.contentType;
|
|
548
|
-
if (!actions[contentTypeUid]) {
|
|
549
|
-
actions[contentTypeUid] = {
|
|
550
|
-
entriestoPublishIds: [],
|
|
551
|
-
entriesToUnpublishIds: []
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
if (action.type === "publish") {
|
|
555
|
-
actions[contentTypeUid].entriestoPublishIds.push(action.entry.id);
|
|
556
|
-
} else {
|
|
557
|
-
actions[contentTypeUid].entriesToUnpublishIds.push(action.entry.id);
|
|
942
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
|
|
943
|
+
return releaseAction2;
|
|
944
|
+
},
|
|
945
|
+
async findPage(releaseId, query) {
|
|
946
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
947
|
+
where: { id: releaseId },
|
|
948
|
+
select: ["id"]
|
|
949
|
+
});
|
|
950
|
+
if (!release2) {
|
|
951
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
558
952
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
id: {
|
|
571
|
-
$in: entriestoPublishIds
|
|
572
|
-
}
|
|
573
|
-
},
|
|
574
|
-
populate
|
|
575
|
-
}
|
|
576
|
-
);
|
|
577
|
-
const entriesToUnpublish = await strapi2.entityService.findMany(
|
|
578
|
-
contentTypeUid,
|
|
953
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
|
|
954
|
+
const { results: actions, pagination } = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findPage({
|
|
955
|
+
...dbQuery,
|
|
956
|
+
where: {
|
|
957
|
+
release: releaseId
|
|
958
|
+
}
|
|
959
|
+
});
|
|
960
|
+
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
961
|
+
const actionsWithEntry = await async.map(actions, async (action) => {
|
|
962
|
+
const populate = await populateBuilderService(action.contentType).populateDeep(Infinity).build();
|
|
963
|
+
const entry = await getEntry(
|
|
579
964
|
{
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
}
|
|
965
|
+
contentType: action.contentType,
|
|
966
|
+
documentId: action.entryDocumentId,
|
|
967
|
+
locale: action.locale,
|
|
968
|
+
populate,
|
|
969
|
+
status: action.type === "publish" ? "draft" : "published"
|
|
970
|
+
},
|
|
971
|
+
{ strapi: strapi2 }
|
|
587
972
|
);
|
|
588
|
-
|
|
589
|
-
|
|
973
|
+
return {
|
|
974
|
+
...action,
|
|
975
|
+
entry,
|
|
976
|
+
status: entry ? await getEntryStatus(action.contentType, entry) : null
|
|
977
|
+
};
|
|
978
|
+
});
|
|
979
|
+
return {
|
|
980
|
+
results: actionsWithEntry,
|
|
981
|
+
pagination
|
|
982
|
+
};
|
|
983
|
+
},
|
|
984
|
+
async groupActions(actions, groupBy) {
|
|
985
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
986
|
+
if (!acc.includes(action.contentType)) {
|
|
987
|
+
acc.push(action.contentType);
|
|
988
|
+
}
|
|
989
|
+
return acc;
|
|
990
|
+
}, []);
|
|
991
|
+
const allReleaseContentTypesDictionary = await getContentTypesDataForActions(contentTypeUids);
|
|
992
|
+
const allLocalesDictionary = await getLocalesDataForActions();
|
|
993
|
+
const formattedData = actions.map((action) => {
|
|
994
|
+
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
995
|
+
return {
|
|
996
|
+
...action,
|
|
997
|
+
locale: action.locale ? allLocalesDictionary[action.locale] : null,
|
|
998
|
+
contentType: {
|
|
999
|
+
displayName,
|
|
1000
|
+
mainFieldValue: action.entry[mainField],
|
|
1001
|
+
uid: action.contentType
|
|
1002
|
+
}
|
|
1003
|
+
};
|
|
1004
|
+
});
|
|
1005
|
+
const groupName = getGroupName(groupBy);
|
|
1006
|
+
return _.groupBy(groupName)(formattedData);
|
|
1007
|
+
},
|
|
1008
|
+
getContentTypeModelsFromActions(actions) {
|
|
1009
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
1010
|
+
if (!acc.includes(action.contentType)) {
|
|
1011
|
+
acc.push(action.contentType);
|
|
590
1012
|
}
|
|
591
|
-
|
|
592
|
-
|
|
1013
|
+
return acc;
|
|
1014
|
+
}, []);
|
|
1015
|
+
const contentTypeModelsMap = contentTypeUids.reduce(
|
|
1016
|
+
(acc, contentTypeUid) => {
|
|
1017
|
+
acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
|
|
1018
|
+
return acc;
|
|
1019
|
+
},
|
|
1020
|
+
{}
|
|
1021
|
+
);
|
|
1022
|
+
return contentTypeModelsMap;
|
|
1023
|
+
},
|
|
1024
|
+
async countActions(query) {
|
|
1025
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
|
|
1026
|
+
return strapi2.db.query(RELEASE_ACTION_MODEL_UID).count(dbQuery);
|
|
1027
|
+
},
|
|
1028
|
+
async update(actionId, releaseId, update) {
|
|
1029
|
+
const action = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findOne({
|
|
1030
|
+
where: {
|
|
1031
|
+
id: actionId,
|
|
1032
|
+
release: {
|
|
1033
|
+
id: releaseId,
|
|
1034
|
+
releasedAt: {
|
|
1035
|
+
$null: true
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
593
1038
|
}
|
|
1039
|
+
});
|
|
1040
|
+
if (!action) {
|
|
1041
|
+
throw new errors.NotFoundError(
|
|
1042
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
1043
|
+
);
|
|
594
1044
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
releasedAt: {
|
|
614
|
-
$null: true
|
|
1045
|
+
const actionStatus = update.type === "publish" ? getDraftEntryValidStatus(
|
|
1046
|
+
{
|
|
1047
|
+
contentType: action.contentType,
|
|
1048
|
+
documentId: action.entryDocumentId,
|
|
1049
|
+
locale: action.locale
|
|
1050
|
+
},
|
|
1051
|
+
{
|
|
1052
|
+
strapi: strapi2
|
|
1053
|
+
}
|
|
1054
|
+
) : true;
|
|
1055
|
+
const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
1056
|
+
where: {
|
|
1057
|
+
id: actionId,
|
|
1058
|
+
release: {
|
|
1059
|
+
id: releaseId,
|
|
1060
|
+
releasedAt: {
|
|
1061
|
+
$null: true
|
|
1062
|
+
}
|
|
615
1063
|
}
|
|
1064
|
+
},
|
|
1065
|
+
data: {
|
|
1066
|
+
...update,
|
|
1067
|
+
isEntryValid: actionStatus
|
|
616
1068
|
}
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
id: actionId,
|
|
631
|
-
release: {
|
|
632
|
-
id: releaseId,
|
|
633
|
-
releasedAt: {
|
|
634
|
-
$null: true
|
|
1069
|
+
});
|
|
1070
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
|
|
1071
|
+
return updatedAction;
|
|
1072
|
+
},
|
|
1073
|
+
async delete(actionId, releaseId) {
|
|
1074
|
+
const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
|
|
1075
|
+
where: {
|
|
1076
|
+
id: actionId,
|
|
1077
|
+
release: {
|
|
1078
|
+
id: releaseId,
|
|
1079
|
+
releasedAt: {
|
|
1080
|
+
$null: true
|
|
1081
|
+
}
|
|
635
1082
|
}
|
|
636
1083
|
}
|
|
1084
|
+
});
|
|
1085
|
+
if (!deletedAction) {
|
|
1086
|
+
throw new errors.NotFoundError(
|
|
1087
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
1088
|
+
);
|
|
637
1089
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
throw new errors.NotFoundError(
|
|
641
|
-
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
642
|
-
);
|
|
1090
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
|
|
1091
|
+
return deletedAction;
|
|
643
1092
|
}
|
|
644
|
-
|
|
1093
|
+
};
|
|
1094
|
+
};
|
|
1095
|
+
class AlreadyOnReleaseError extends errors.ApplicationError {
|
|
1096
|
+
constructor(message) {
|
|
1097
|
+
super(message);
|
|
1098
|
+
this.name = "AlreadyOnReleaseError";
|
|
645
1099
|
}
|
|
646
|
-
}
|
|
1100
|
+
}
|
|
647
1101
|
const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
648
1102
|
async validateUniqueEntry(releaseId, releaseActionArgs) {
|
|
649
|
-
const release2 = await strapi2.
|
|
650
|
-
|
|
1103
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
1104
|
+
where: {
|
|
1105
|
+
id: releaseId
|
|
1106
|
+
},
|
|
1107
|
+
populate: {
|
|
1108
|
+
actions: true
|
|
1109
|
+
}
|
|
651
1110
|
});
|
|
652
1111
|
if (!release2) {
|
|
653
1112
|
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
654
1113
|
}
|
|
655
1114
|
const isEntryInRelease = release2.actions.some(
|
|
656
|
-
(action) => Number(action.
|
|
1115
|
+
(action) => Number(action.entryDocumentId) === Number(releaseActionArgs.entryDocumentId) && action.contentType === releaseActionArgs.contentType && action.locale === releaseActionArgs.locale
|
|
657
1116
|
);
|
|
658
1117
|
if (isEntryInRelease) {
|
|
659
|
-
throw new
|
|
660
|
-
`Entry with
|
|
1118
|
+
throw new AlreadyOnReleaseError(
|
|
1119
|
+
`Entry with documentId ${releaseActionArgs.entryDocumentId} ${releaseActionArgs.locale ? `(${releaseActionArgs.locale})` : ""} and contentType ${releaseActionArgs.contentType} already exists in release with id ${releaseId}`
|
|
661
1120
|
);
|
|
662
1121
|
}
|
|
663
1122
|
},
|
|
664
|
-
|
|
1123
|
+
validateEntryData(contentTypeUid, entryDocumentId) {
|
|
665
1124
|
const contentType = strapi2.contentType(contentTypeUid);
|
|
666
1125
|
if (!contentType) {
|
|
667
1126
|
throw new errors.NotFoundError(`No content type found for uid ${contentTypeUid}`);
|
|
668
1127
|
}
|
|
669
|
-
if (!contentType
|
|
1128
|
+
if (!contentTypes$1.hasDraftAndPublish(contentType)) {
|
|
670
1129
|
throw new errors.ValidationError(
|
|
671
1130
|
`Content type with uid ${contentTypeUid} does not have draftAndPublish enabled`
|
|
672
1131
|
);
|
|
673
1132
|
}
|
|
1133
|
+
if (contentType.kind === "collectionType" && !entryDocumentId) {
|
|
1134
|
+
throw new errors.ValidationError("Document id is required for collection type");
|
|
1135
|
+
}
|
|
674
1136
|
},
|
|
675
1137
|
async validatePendingReleasesLimit() {
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
EE.features.get("cms-content-releases")?.options?.maximumReleases || 3
|
|
679
|
-
);
|
|
1138
|
+
const featureCfg = strapi2.ee.features.get("cms-content-releases");
|
|
1139
|
+
const maximumPendingReleases = typeof featureCfg === "object" && featureCfg?.options?.maximumReleases || 3;
|
|
680
1140
|
const [, pendingReleasesCount] = await strapi2.db.query(RELEASE_MODEL_UID).findWithCount({
|
|
681
1141
|
filters: {
|
|
682
1142
|
releasedAt: {
|
|
@@ -688,79 +1148,233 @@ const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
|
688
1148
|
throw new errors.ValidationError("You have reached the maximum number of pending releases");
|
|
689
1149
|
}
|
|
690
1150
|
},
|
|
691
|
-
async validateUniqueNameForPendingRelease(name) {
|
|
692
|
-
const pendingReleases = await strapi2.
|
|
693
|
-
|
|
1151
|
+
async validateUniqueNameForPendingRelease(name, id) {
|
|
1152
|
+
const pendingReleases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
1153
|
+
where: {
|
|
694
1154
|
releasedAt: {
|
|
695
1155
|
$null: true
|
|
696
1156
|
},
|
|
697
|
-
name
|
|
1157
|
+
name,
|
|
1158
|
+
...id && { id: { $ne: id } }
|
|
698
1159
|
}
|
|
699
1160
|
});
|
|
700
1161
|
const isNameUnique = pendingReleases.length === 0;
|
|
701
1162
|
if (!isNameUnique) {
|
|
702
1163
|
throw new errors.ValidationError(`Release with name ${name} already exists`);
|
|
703
1164
|
}
|
|
1165
|
+
},
|
|
1166
|
+
async validateScheduledAtIsLaterThanNow(scheduledAt) {
|
|
1167
|
+
if (scheduledAt && new Date(scheduledAt) <= /* @__PURE__ */ new Date()) {
|
|
1168
|
+
throw new errors.ValidationError("Scheduled at must be later than now");
|
|
1169
|
+
}
|
|
704
1170
|
}
|
|
705
1171
|
});
|
|
1172
|
+
const createSchedulingService = ({ strapi: strapi2 }) => {
|
|
1173
|
+
const scheduledJobs = /* @__PURE__ */ new Map();
|
|
1174
|
+
return {
|
|
1175
|
+
async set(releaseId, scheduleDate) {
|
|
1176
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id: releaseId, releasedAt: null } });
|
|
1177
|
+
if (!release2) {
|
|
1178
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
1179
|
+
}
|
|
1180
|
+
const job = scheduleJob(scheduleDate, async () => {
|
|
1181
|
+
try {
|
|
1182
|
+
await getService("release", { strapi: strapi2 }).publish(releaseId);
|
|
1183
|
+
} catch (error) {
|
|
1184
|
+
}
|
|
1185
|
+
this.cancel(releaseId);
|
|
1186
|
+
});
|
|
1187
|
+
if (scheduledJobs.has(releaseId)) {
|
|
1188
|
+
this.cancel(releaseId);
|
|
1189
|
+
}
|
|
1190
|
+
scheduledJobs.set(releaseId, job);
|
|
1191
|
+
return scheduledJobs;
|
|
1192
|
+
},
|
|
1193
|
+
cancel(releaseId) {
|
|
1194
|
+
if (scheduledJobs.has(releaseId)) {
|
|
1195
|
+
scheduledJobs.get(releaseId).cancel();
|
|
1196
|
+
scheduledJobs.delete(releaseId);
|
|
1197
|
+
}
|
|
1198
|
+
return scheduledJobs;
|
|
1199
|
+
},
|
|
1200
|
+
getAll() {
|
|
1201
|
+
return scheduledJobs;
|
|
1202
|
+
},
|
|
1203
|
+
/**
|
|
1204
|
+
* On bootstrap, we can use this function to make sure to sync the scheduled jobs from the database that are not yet released
|
|
1205
|
+
* This is useful in case the server was restarted and the scheduled jobs were lost
|
|
1206
|
+
* This also could be used to sync different Strapi instances in case of a cluster
|
|
1207
|
+
*/
|
|
1208
|
+
async syncFromDatabase() {
|
|
1209
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
1210
|
+
where: {
|
|
1211
|
+
scheduledAt: {
|
|
1212
|
+
$gte: /* @__PURE__ */ new Date()
|
|
1213
|
+
},
|
|
1214
|
+
releasedAt: null
|
|
1215
|
+
}
|
|
1216
|
+
});
|
|
1217
|
+
for (const release2 of releases) {
|
|
1218
|
+
this.set(release2.id, release2.scheduledAt);
|
|
1219
|
+
}
|
|
1220
|
+
return scheduledJobs;
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
};
|
|
1224
|
+
const DEFAULT_SETTINGS = {
|
|
1225
|
+
defaultTimezone: null
|
|
1226
|
+
};
|
|
1227
|
+
const createSettingsService = ({ strapi: strapi2 }) => {
|
|
1228
|
+
const getStore = async () => strapi2.store({ type: "core", name: "content-releases" });
|
|
1229
|
+
return {
|
|
1230
|
+
async update({ settings: settings2 }) {
|
|
1231
|
+
const store = await getStore();
|
|
1232
|
+
store.set({ key: "settings", value: settings2 });
|
|
1233
|
+
return settings2;
|
|
1234
|
+
},
|
|
1235
|
+
async find() {
|
|
1236
|
+
const store = await getStore();
|
|
1237
|
+
const settings2 = await store.get({ key: "settings" });
|
|
1238
|
+
return {
|
|
1239
|
+
...DEFAULT_SETTINGS,
|
|
1240
|
+
...settings2 || {}
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
};
|
|
1244
|
+
};
|
|
706
1245
|
const services = {
|
|
707
1246
|
release: createReleaseService,
|
|
708
|
-
"release-
|
|
1247
|
+
"release-action": createReleaseActionService,
|
|
1248
|
+
"release-validation": createReleaseValidationService,
|
|
1249
|
+
scheduling: createSchedulingService,
|
|
1250
|
+
settings: createSettingsService
|
|
709
1251
|
};
|
|
710
|
-
const RELEASE_SCHEMA = yup.object().shape({
|
|
711
|
-
name: yup.string().trim().required()
|
|
1252
|
+
const RELEASE_SCHEMA = yup$1.object().shape({
|
|
1253
|
+
name: yup$1.string().trim().required(),
|
|
1254
|
+
scheduledAt: yup$1.string().nullable(),
|
|
1255
|
+
timezone: yup$1.string().when("scheduledAt", {
|
|
1256
|
+
is: (value) => value !== null && value !== void 0,
|
|
1257
|
+
then: yup$1.string().required(),
|
|
1258
|
+
otherwise: yup$1.string().nullable()
|
|
1259
|
+
})
|
|
1260
|
+
}).required().noUnknown();
|
|
1261
|
+
const FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA = yup$1.object().shape({
|
|
1262
|
+
contentType: yup$1.string().required(),
|
|
1263
|
+
entryDocumentId: yup$1.string().nullable(),
|
|
1264
|
+
hasEntryAttached: yup$1.string().nullable(),
|
|
1265
|
+
locale: yup$1.string().nullable()
|
|
712
1266
|
}).required().noUnknown();
|
|
713
1267
|
const validateRelease = validateYupSchema(RELEASE_SCHEMA);
|
|
1268
|
+
const validatefindByDocumentAttachedParams = validateYupSchema(
|
|
1269
|
+
FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA
|
|
1270
|
+
);
|
|
714
1271
|
const releaseController = {
|
|
715
|
-
|
|
716
|
-
|
|
1272
|
+
/**
|
|
1273
|
+
* Find releases based on documents attached or not to the release.
|
|
1274
|
+
* If `hasEntryAttached` is true, it will return all releases that have the entry attached.
|
|
1275
|
+
* If `hasEntryAttached` is false, it will return all releases that don't have the entry attached.
|
|
1276
|
+
*/
|
|
1277
|
+
async findByDocumentAttached(ctx) {
|
|
1278
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
717
1279
|
ability: ctx.state.userAbility,
|
|
718
1280
|
model: RELEASE_MODEL_UID
|
|
719
1281
|
});
|
|
720
1282
|
await permissionsManager.validateQuery(ctx.query);
|
|
721
1283
|
const releaseService = getService("release", { strapi });
|
|
722
|
-
const
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
const
|
|
728
|
-
|
|
729
|
-
|
|
1284
|
+
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
1285
|
+
await validatefindByDocumentAttachedParams(query);
|
|
1286
|
+
const { contentType, entryDocumentId, hasEntryAttached, locale } = query;
|
|
1287
|
+
const isEntryAttached = typeof hasEntryAttached === "string" ? Boolean(JSON.parse(hasEntryAttached)) : false;
|
|
1288
|
+
if (isEntryAttached) {
|
|
1289
|
+
const releases = await releaseService.findMany({
|
|
1290
|
+
where: {
|
|
1291
|
+
releasedAt: null,
|
|
1292
|
+
actions: {
|
|
1293
|
+
contentType,
|
|
1294
|
+
entryDocumentId: entryDocumentId ?? null,
|
|
1295
|
+
locale: locale ?? null
|
|
1296
|
+
}
|
|
1297
|
+
},
|
|
1298
|
+
populate: {
|
|
1299
|
+
actions: {
|
|
1300
|
+
fields: ["type"]
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
ctx.body = { data: releases };
|
|
730
1305
|
} else {
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
const { actions, ...releaseData } = release2;
|
|
735
|
-
return {
|
|
736
|
-
...releaseData,
|
|
1306
|
+
const relatedReleases = await releaseService.findMany({
|
|
1307
|
+
where: {
|
|
1308
|
+
releasedAt: null,
|
|
737
1309
|
actions: {
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
1310
|
+
contentType,
|
|
1311
|
+
entryDocumentId: entryDocumentId ?? null,
|
|
1312
|
+
locale: locale ?? null
|
|
741
1313
|
}
|
|
742
|
-
}
|
|
1314
|
+
}
|
|
1315
|
+
});
|
|
1316
|
+
const releases = await releaseService.findMany({
|
|
1317
|
+
where: {
|
|
1318
|
+
$or: [
|
|
1319
|
+
{
|
|
1320
|
+
id: {
|
|
1321
|
+
$notIn: relatedReleases.map((release2) => release2.id)
|
|
1322
|
+
}
|
|
1323
|
+
},
|
|
1324
|
+
{
|
|
1325
|
+
actions: null
|
|
1326
|
+
}
|
|
1327
|
+
],
|
|
1328
|
+
releasedAt: null
|
|
1329
|
+
}
|
|
743
1330
|
});
|
|
744
|
-
ctx.body = { data
|
|
1331
|
+
ctx.body = { data: releases };
|
|
745
1332
|
}
|
|
746
1333
|
},
|
|
747
|
-
async
|
|
748
|
-
const
|
|
749
|
-
const releaseService = getService("release", { strapi });
|
|
750
|
-
const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
|
|
751
|
-
const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
|
|
1334
|
+
async findPage(ctx) {
|
|
1335
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
752
1336
|
ability: ctx.state.userAbility,
|
|
753
1337
|
model: RELEASE_MODEL_UID
|
|
754
1338
|
});
|
|
755
|
-
|
|
756
|
-
const
|
|
757
|
-
|
|
758
|
-
|
|
1339
|
+
await permissionsManager.validateQuery(ctx.query);
|
|
1340
|
+
const releaseService = getService("release", { strapi });
|
|
1341
|
+
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
1342
|
+
const { results, pagination } = await releaseService.findPage(query);
|
|
1343
|
+
const data = results.map((release2) => {
|
|
1344
|
+
const { actions, ...releaseData } = release2;
|
|
1345
|
+
return {
|
|
1346
|
+
...releaseData,
|
|
1347
|
+
actions: {
|
|
1348
|
+
meta: {
|
|
1349
|
+
count: actions.count
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
};
|
|
1353
|
+
});
|
|
1354
|
+
const pendingReleasesCount = await strapi.db.query(RELEASE_MODEL_UID).count({
|
|
1355
|
+
where: {
|
|
1356
|
+
releasedAt: null
|
|
759
1357
|
}
|
|
760
1358
|
});
|
|
1359
|
+
ctx.body = { data, meta: { pagination, pendingReleasesCount } };
|
|
1360
|
+
},
|
|
1361
|
+
async findOne(ctx) {
|
|
1362
|
+
const id = ctx.params.id;
|
|
1363
|
+
const releaseService = getService("release", { strapi });
|
|
1364
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1365
|
+
const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
|
|
761
1366
|
if (!release2) {
|
|
762
1367
|
throw new errors.NotFoundError(`Release not found for id: ${id}`);
|
|
763
1368
|
}
|
|
1369
|
+
const count = await releaseActionService.countActions({
|
|
1370
|
+
filters: {
|
|
1371
|
+
release: id
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
const sanitizedRelease = {
|
|
1375
|
+
...release2,
|
|
1376
|
+
createdBy: release2.createdBy ? strapi.service("admin::user").sanitizeUser(release2.createdBy) : null
|
|
1377
|
+
};
|
|
764
1378
|
const data = {
|
|
765
1379
|
...sanitizedRelease,
|
|
766
1380
|
actions: {
|
|
@@ -771,19 +1385,56 @@ const releaseController = {
|
|
|
771
1385
|
};
|
|
772
1386
|
ctx.body = { data };
|
|
773
1387
|
},
|
|
1388
|
+
/* @TODO: Migrate to new api
|
|
1389
|
+
async mapEntriesToReleases(ctx: Koa.Context) {
|
|
1390
|
+
const { contentTypeUid, entriesIds } = ctx.query;
|
|
1391
|
+
|
|
1392
|
+
if (!contentTypeUid || !entriesIds) {
|
|
1393
|
+
throw new errors.ValidationError('Missing required query parameters');
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
const releaseService = getService('release', { strapi });
|
|
1397
|
+
|
|
1398
|
+
const releasesWithActions = await releaseService.findMany(
|
|
1399
|
+
contentTypeUid,
|
|
1400
|
+
entriesIds
|
|
1401
|
+
);
|
|
1402
|
+
|
|
1403
|
+
const mappedEntriesInReleases = releasesWithActions.reduce(
|
|
1404
|
+
// TODO: Fix for v5 removed mappedEntriedToRelease
|
|
1405
|
+
(acc: MapEntriesToReleases.Response['data'], release: Release) => {
|
|
1406
|
+
release.actions.forEach((action) => {
|
|
1407
|
+
if (!acc[action.entry.id]) {
|
|
1408
|
+
acc[action.entry.id] = [{ id: release.id, name: release.name }];
|
|
1409
|
+
} else {
|
|
1410
|
+
acc[action.entry.id].push({ id: release.id, name: release.name });
|
|
1411
|
+
}
|
|
1412
|
+
});
|
|
1413
|
+
|
|
1414
|
+
return acc;
|
|
1415
|
+
},
|
|
1416
|
+
// TODO: Fix for v5 removed mappedEntriedToRelease
|
|
1417
|
+
{} as MapEntriesToReleases.Response['data']
|
|
1418
|
+
);
|
|
1419
|
+
|
|
1420
|
+
ctx.body = {
|
|
1421
|
+
data: mappedEntriesInReleases,
|
|
1422
|
+
};
|
|
1423
|
+
},
|
|
1424
|
+
*/
|
|
774
1425
|
async create(ctx) {
|
|
775
1426
|
const user = ctx.state.user;
|
|
776
1427
|
const releaseArgs = ctx.request.body;
|
|
777
1428
|
await validateRelease(releaseArgs);
|
|
778
1429
|
const releaseService = getService("release", { strapi });
|
|
779
1430
|
const release2 = await releaseService.create(releaseArgs, { user });
|
|
780
|
-
const permissionsManager = strapi.admin
|
|
1431
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
781
1432
|
ability: ctx.state.userAbility,
|
|
782
1433
|
model: RELEASE_MODEL_UID
|
|
783
1434
|
});
|
|
784
|
-
ctx.
|
|
1435
|
+
ctx.created({
|
|
785
1436
|
data: await permissionsManager.sanitizeOutput(release2)
|
|
786
|
-
};
|
|
1437
|
+
});
|
|
787
1438
|
},
|
|
788
1439
|
async update(ctx) {
|
|
789
1440
|
const user = ctx.state.user;
|
|
@@ -792,7 +1443,7 @@ const releaseController = {
|
|
|
792
1443
|
await validateRelease(releaseArgs);
|
|
793
1444
|
const releaseService = getService("release", { strapi });
|
|
794
1445
|
const release2 = await releaseService.update(id, releaseArgs, { user });
|
|
795
|
-
const permissionsManager = strapi.admin
|
|
1446
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
796
1447
|
ability: ctx.state.userAbility,
|
|
797
1448
|
model: RELEASE_MODEL_UID
|
|
798
1449
|
});
|
|
@@ -809,67 +1460,132 @@ const releaseController = {
|
|
|
809
1460
|
};
|
|
810
1461
|
},
|
|
811
1462
|
async publish(ctx) {
|
|
812
|
-
const user = ctx.state.user;
|
|
813
1463
|
const id = ctx.params.id;
|
|
814
1464
|
const releaseService = getService("release", { strapi });
|
|
815
|
-
const
|
|
1465
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1466
|
+
const release2 = await releaseService.publish(id);
|
|
1467
|
+
const [countPublishActions, countUnpublishActions] = await Promise.all([
|
|
1468
|
+
releaseActionService.countActions({
|
|
1469
|
+
filters: {
|
|
1470
|
+
release: id,
|
|
1471
|
+
type: "publish"
|
|
1472
|
+
}
|
|
1473
|
+
}),
|
|
1474
|
+
releaseActionService.countActions({
|
|
1475
|
+
filters: {
|
|
1476
|
+
release: id,
|
|
1477
|
+
type: "unpublish"
|
|
1478
|
+
}
|
|
1479
|
+
})
|
|
1480
|
+
]);
|
|
816
1481
|
ctx.body = {
|
|
817
|
-
data: release2
|
|
1482
|
+
data: release2,
|
|
1483
|
+
meta: {
|
|
1484
|
+
totalEntries: countPublishActions + countUnpublishActions,
|
|
1485
|
+
totalPublishedEntries: countPublishActions,
|
|
1486
|
+
totalUnpublishedEntries: countUnpublishActions
|
|
1487
|
+
}
|
|
818
1488
|
};
|
|
819
1489
|
}
|
|
820
1490
|
};
|
|
821
1491
|
const RELEASE_ACTION_SCHEMA = yup$1.object().shape({
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
}).required(),
|
|
1492
|
+
contentType: yup$1.string().required(),
|
|
1493
|
+
entryDocumentId: yup$1.strapiID(),
|
|
1494
|
+
locale: yup$1.string(),
|
|
826
1495
|
type: yup$1.string().oneOf(["publish", "unpublish"]).required()
|
|
827
1496
|
});
|
|
828
1497
|
const RELEASE_ACTION_UPDATE_SCHEMA = yup$1.object().shape({
|
|
829
1498
|
type: yup$1.string().oneOf(["publish", "unpublish"]).required()
|
|
830
1499
|
});
|
|
1500
|
+
const FIND_MANY_ACTIONS_PARAMS = yup$1.object().shape({
|
|
1501
|
+
groupBy: yup$1.string().oneOf(["action", "contentType", "locale"])
|
|
1502
|
+
});
|
|
831
1503
|
const validateReleaseAction = validateYupSchema(RELEASE_ACTION_SCHEMA);
|
|
832
1504
|
const validateReleaseActionUpdateSchema = validateYupSchema(RELEASE_ACTION_UPDATE_SCHEMA);
|
|
1505
|
+
const validateFindManyActionsParams = validateYupSchema(FIND_MANY_ACTIONS_PARAMS);
|
|
833
1506
|
const releaseActionController = {
|
|
834
1507
|
async create(ctx) {
|
|
835
1508
|
const releaseId = ctx.params.releaseId;
|
|
836
1509
|
const releaseActionArgs = ctx.request.body;
|
|
837
1510
|
await validateReleaseAction(releaseActionArgs);
|
|
838
|
-
const
|
|
839
|
-
const releaseAction2 = await
|
|
840
|
-
ctx.
|
|
1511
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1512
|
+
const releaseAction2 = await releaseActionService.create(releaseId, releaseActionArgs);
|
|
1513
|
+
ctx.created({
|
|
841
1514
|
data: releaseAction2
|
|
842
|
-
};
|
|
1515
|
+
});
|
|
1516
|
+
},
|
|
1517
|
+
/*
|
|
1518
|
+
async createMany(ctx: Koa.Context) {
|
|
1519
|
+
const releaseId: CreateManyReleaseActions.Request['params']['releaseId'] = ctx.params.releaseId;
|
|
1520
|
+
const releaseActionsArgs = ctx.request.body as CreateManyReleaseActions.Request['body'];
|
|
1521
|
+
await Promise.all(
|
|
1522
|
+
releaseActionsArgs.map((releaseActionArgs) => validateReleaseAction(releaseActionArgs))
|
|
1523
|
+
);
|
|
1524
|
+
const releaseActionService = getService('release-action', { strapi });
|
|
1525
|
+
const releaseActions = await strapi.db.transaction(async () => {
|
|
1526
|
+
const releaseActions = await Promise.all(
|
|
1527
|
+
releaseActionsArgs.map(async (releaseActionArgs) => {
|
|
1528
|
+
try {
|
|
1529
|
+
const action = await releaseActionService.create(releaseId, releaseActionArgs);
|
|
1530
|
+
return action;
|
|
1531
|
+
} catch (error) {
|
|
1532
|
+
// If the entry is already in the release, we don't want to throw an error, so we catch and ignore it
|
|
1533
|
+
if (error instanceof AlreadyOnReleaseError) {
|
|
1534
|
+
return null;
|
|
1535
|
+
}
|
|
1536
|
+
throw error;
|
|
1537
|
+
}
|
|
1538
|
+
})
|
|
1539
|
+
);
|
|
1540
|
+
return releaseActions;
|
|
1541
|
+
});
|
|
1542
|
+
const newReleaseActions = releaseActions.filter((action) => action !== null);
|
|
1543
|
+
ctx.created({
|
|
1544
|
+
data: newReleaseActions,
|
|
1545
|
+
meta: {
|
|
1546
|
+
entriesAlreadyInRelease: releaseActions.length - newReleaseActions.length,
|
|
1547
|
+
totalEntries: releaseActions.length,
|
|
1548
|
+
},
|
|
1549
|
+
});
|
|
843
1550
|
},
|
|
1551
|
+
*/
|
|
844
1552
|
async findMany(ctx) {
|
|
845
1553
|
const releaseId = ctx.params.releaseId;
|
|
846
|
-
const permissionsManager = strapi.admin
|
|
1554
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
847
1555
|
ability: ctx.state.userAbility,
|
|
848
1556
|
model: RELEASE_ACTION_MODEL_UID
|
|
849
1557
|
});
|
|
1558
|
+
await validateFindManyActionsParams(ctx.query);
|
|
1559
|
+
if (ctx.query.groupBy) {
|
|
1560
|
+
if (!["action", "contentType", "locale"].includes(ctx.query.groupBy)) {
|
|
1561
|
+
ctx.badRequest("Invalid groupBy parameter");
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
ctx.query.sort = ctx.query.groupBy === "action" ? "type" : ctx.query.groupBy;
|
|
1565
|
+
delete ctx.query.groupBy;
|
|
850
1566
|
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
851
|
-
const
|
|
852
|
-
const { results, pagination } = await
|
|
853
|
-
sort: query.groupBy === "action" ? "type" : query.groupBy,
|
|
1567
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1568
|
+
const { results, pagination } = await releaseActionService.findPage(releaseId, {
|
|
854
1569
|
...query
|
|
855
1570
|
});
|
|
856
1571
|
const contentTypeOutputSanitizers = results.reduce((acc, action) => {
|
|
857
1572
|
if (acc[action.contentType]) {
|
|
858
1573
|
return acc;
|
|
859
1574
|
}
|
|
860
|
-
const contentTypePermissionsManager = strapi.admin
|
|
1575
|
+
const contentTypePermissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
861
1576
|
ability: ctx.state.userAbility,
|
|
862
1577
|
model: action.contentType
|
|
863
1578
|
});
|
|
864
1579
|
acc[action.contentType] = contentTypePermissionsManager.sanitizeOutput;
|
|
865
1580
|
return acc;
|
|
866
1581
|
}, {});
|
|
867
|
-
const sanitizedResults = await
|
|
1582
|
+
const sanitizedResults = await async.map(results, async (action) => ({
|
|
868
1583
|
...action,
|
|
869
|
-
entry: await contentTypeOutputSanitizers[action.contentType](action.entry)
|
|
1584
|
+
entry: action.entry ? await contentTypeOutputSanitizers[action.contentType](action.entry) : {}
|
|
870
1585
|
}));
|
|
871
|
-
const groupedData = await
|
|
872
|
-
const contentTypes2 =
|
|
1586
|
+
const groupedData = await releaseActionService.groupActions(sanitizedResults, query.sort);
|
|
1587
|
+
const contentTypes2 = releaseActionService.getContentTypeModelsFromActions(results);
|
|
1588
|
+
const releaseService = getService("release", { strapi });
|
|
873
1589
|
const components = await releaseService.getAllComponents();
|
|
874
1590
|
ctx.body = {
|
|
875
1591
|
data: groupedData,
|
|
@@ -885,8 +1601,8 @@ const releaseActionController = {
|
|
|
885
1601
|
const releaseId = ctx.params.releaseId;
|
|
886
1602
|
const releaseActionUpdateArgs = ctx.request.body;
|
|
887
1603
|
await validateReleaseActionUpdateSchema(releaseActionUpdateArgs);
|
|
888
|
-
const
|
|
889
|
-
const updatedAction = await
|
|
1604
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1605
|
+
const updatedAction = await releaseActionService.update(
|
|
890
1606
|
actionId,
|
|
891
1607
|
releaseId,
|
|
892
1608
|
releaseActionUpdateArgs
|
|
@@ -898,17 +1614,73 @@ const releaseActionController = {
|
|
|
898
1614
|
async delete(ctx) {
|
|
899
1615
|
const actionId = ctx.params.actionId;
|
|
900
1616
|
const releaseId = ctx.params.releaseId;
|
|
901
|
-
const
|
|
902
|
-
const deletedReleaseAction = await
|
|
1617
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1618
|
+
const deletedReleaseAction = await releaseActionService.delete(actionId, releaseId);
|
|
903
1619
|
ctx.body = {
|
|
904
1620
|
data: deletedReleaseAction
|
|
905
1621
|
};
|
|
906
1622
|
}
|
|
907
1623
|
};
|
|
908
|
-
const
|
|
1624
|
+
const SETTINGS_SCHEMA = yup.object().shape({
|
|
1625
|
+
defaultTimezone: yup.string().nullable().default(null)
|
|
1626
|
+
}).required().noUnknown();
|
|
1627
|
+
const validateSettings = validateYupSchema(SETTINGS_SCHEMA);
|
|
1628
|
+
const settingsController = {
|
|
1629
|
+
async find(ctx) {
|
|
1630
|
+
const settingsService = getService("settings", { strapi });
|
|
1631
|
+
const settings2 = await settingsService.find();
|
|
1632
|
+
ctx.body = { data: settings2 };
|
|
1633
|
+
},
|
|
1634
|
+
async update(ctx) {
|
|
1635
|
+
const settingsBody = ctx.request.body;
|
|
1636
|
+
const settings2 = await validateSettings(settingsBody);
|
|
1637
|
+
const settingsService = getService("settings", { strapi });
|
|
1638
|
+
const updatedSettings = await settingsService.update({ settings: settings2 });
|
|
1639
|
+
ctx.body = { data: updatedSettings };
|
|
1640
|
+
}
|
|
1641
|
+
};
|
|
1642
|
+
const controllers = {
|
|
1643
|
+
release: releaseController,
|
|
1644
|
+
"release-action": releaseActionController,
|
|
1645
|
+
settings: settingsController
|
|
1646
|
+
};
|
|
909
1647
|
const release = {
|
|
910
1648
|
type: "admin",
|
|
911
1649
|
routes: [
|
|
1650
|
+
/*
|
|
1651
|
+
{
|
|
1652
|
+
method: 'GET',
|
|
1653
|
+
path: '/mapEntriesToReleases',
|
|
1654
|
+
handler: 'release.mapEntriesToReleases',
|
|
1655
|
+
config: {
|
|
1656
|
+
policies: [
|
|
1657
|
+
'admin::isAuthenticatedAdmin',
|
|
1658
|
+
{
|
|
1659
|
+
name: 'admin::hasPermissions',
|
|
1660
|
+
config: {
|
|
1661
|
+
actions: ['plugin::content-releases.read'],
|
|
1662
|
+
},
|
|
1663
|
+
},
|
|
1664
|
+
],
|
|
1665
|
+
},
|
|
1666
|
+
},
|
|
1667
|
+
*/
|
|
1668
|
+
{
|
|
1669
|
+
method: "GET",
|
|
1670
|
+
path: "/getByDocumentAttached",
|
|
1671
|
+
handler: "release.findByDocumentAttached",
|
|
1672
|
+
config: {
|
|
1673
|
+
policies: [
|
|
1674
|
+
"admin::isAuthenticatedAdmin",
|
|
1675
|
+
{
|
|
1676
|
+
name: "admin::hasPermissions",
|
|
1677
|
+
config: {
|
|
1678
|
+
actions: ["plugin::content-releases.read"]
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
]
|
|
1682
|
+
}
|
|
1683
|
+
},
|
|
912
1684
|
{
|
|
913
1685
|
method: "POST",
|
|
914
1686
|
path: "/",
|
|
@@ -928,7 +1700,7 @@ const release = {
|
|
|
928
1700
|
{
|
|
929
1701
|
method: "GET",
|
|
930
1702
|
path: "/",
|
|
931
|
-
handler: "release.
|
|
1703
|
+
handler: "release.findPage",
|
|
932
1704
|
config: {
|
|
933
1705
|
policies: [
|
|
934
1706
|
"admin::isAuthenticatedAdmin",
|
|
@@ -1026,6 +1798,24 @@ const releaseAction = {
|
|
|
1026
1798
|
]
|
|
1027
1799
|
}
|
|
1028
1800
|
},
|
|
1801
|
+
/*
|
|
1802
|
+
{
|
|
1803
|
+
method: 'POST',
|
|
1804
|
+
path: '/:releaseId/actions/bulk',
|
|
1805
|
+
handler: 'release-action.createMany',
|
|
1806
|
+
config: {
|
|
1807
|
+
policies: [
|
|
1808
|
+
'admin::isAuthenticatedAdmin',
|
|
1809
|
+
{
|
|
1810
|
+
name: 'admin::hasPermissions',
|
|
1811
|
+
config: {
|
|
1812
|
+
actions: ['plugin::content-releases.create-action'],
|
|
1813
|
+
},
|
|
1814
|
+
},
|
|
1815
|
+
],
|
|
1816
|
+
},
|
|
1817
|
+
},
|
|
1818
|
+
*/
|
|
1029
1819
|
{
|
|
1030
1820
|
method: "GET",
|
|
1031
1821
|
path: "/:releaseId/actions",
|
|
@@ -1076,16 +1866,54 @@ const releaseAction = {
|
|
|
1076
1866
|
}
|
|
1077
1867
|
]
|
|
1078
1868
|
};
|
|
1869
|
+
const settings = {
|
|
1870
|
+
type: "admin",
|
|
1871
|
+
routes: [
|
|
1872
|
+
{
|
|
1873
|
+
method: "GET",
|
|
1874
|
+
path: "/settings",
|
|
1875
|
+
handler: "settings.find",
|
|
1876
|
+
config: {
|
|
1877
|
+
policies: [
|
|
1878
|
+
"admin::isAuthenticatedAdmin",
|
|
1879
|
+
{
|
|
1880
|
+
name: "admin::hasPermissions",
|
|
1881
|
+
config: {
|
|
1882
|
+
actions: ["plugin::content-releases.settings.read"]
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
]
|
|
1886
|
+
}
|
|
1887
|
+
},
|
|
1888
|
+
{
|
|
1889
|
+
method: "PUT",
|
|
1890
|
+
path: "/settings",
|
|
1891
|
+
handler: "settings.update",
|
|
1892
|
+
config: {
|
|
1893
|
+
policies: [
|
|
1894
|
+
"admin::isAuthenticatedAdmin",
|
|
1895
|
+
{
|
|
1896
|
+
name: "admin::hasPermissions",
|
|
1897
|
+
config: {
|
|
1898
|
+
actions: ["plugin::content-releases.settings.update"]
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
]
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
]
|
|
1905
|
+
};
|
|
1079
1906
|
const routes = {
|
|
1907
|
+
settings,
|
|
1080
1908
|
release,
|
|
1081
1909
|
"release-action": releaseAction
|
|
1082
1910
|
};
|
|
1083
|
-
const { features } = require("@strapi/strapi/dist/utils/ee");
|
|
1084
1911
|
const getPlugin = () => {
|
|
1085
|
-
if (features.isEnabled("cms-content-releases")) {
|
|
1912
|
+
if (strapi.ee.features.isEnabled("cms-content-releases")) {
|
|
1086
1913
|
return {
|
|
1087
1914
|
register,
|
|
1088
1915
|
bootstrap,
|
|
1916
|
+
destroy,
|
|
1089
1917
|
contentTypes,
|
|
1090
1918
|
services,
|
|
1091
1919
|
controllers,
|
|
@@ -1093,6 +1921,9 @@ const getPlugin = () => {
|
|
|
1093
1921
|
};
|
|
1094
1922
|
}
|
|
1095
1923
|
return {
|
|
1924
|
+
// Always return register, it handles its own feature check
|
|
1925
|
+
register,
|
|
1926
|
+
// Always return contentTypes to avoid losing data when the feature is disabled
|
|
1096
1927
|
contentTypes
|
|
1097
1928
|
};
|
|
1098
1929
|
};
|