@strapi/content-releases 0.0.0-next.7abe81e395faf152048bfba0b088b9062e8ac602 → 0.0.0-next.836f74517f9a428a4798ed889c3f05057ec6beb1
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/dist/_chunks/{App-U6GbyLIE.mjs → App-fcvNs2Qb.mjs} +612 -367
- package/dist/_chunks/App-fcvNs2Qb.mjs.map +1 -0
- package/dist/_chunks/{App-1hHIqUoZ.js → App-pNsURCL_.js} +602 -356
- package/dist/_chunks/App-pNsURCL_.js.map +1 -0
- package/dist/_chunks/{en-GqXgfmzl.mjs → en-WuuhP6Bn.mjs} +13 -4
- package/dist/_chunks/en-WuuhP6Bn.mjs.map +1 -0
- package/dist/_chunks/{en-bDhIlw-B.js → en-gcJJ5htG.js} +13 -4
- package/dist/_chunks/en-gcJJ5htG.js.map +1 -0
- package/dist/_chunks/{index-l-FvkQlQ.js → index-gzTuOXiK.js} +74 -11
- package/dist/_chunks/index-gzTuOXiK.js.map +1 -0
- package/dist/_chunks/{index-gkExFBa0.mjs → index-pxhi8wsT.mjs} +85 -22
- package/dist/_chunks/index-pxhi8wsT.mjs.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/server/index.js +804 -438
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +803 -438
- package/dist/server/index.mjs.map +1 -1
- package/package.json +13 -11
- package/dist/_chunks/App-1hHIqUoZ.js.map +0 -1
- package/dist/_chunks/App-U6GbyLIE.mjs.map +0 -1
- package/dist/_chunks/en-GqXgfmzl.mjs.map +0 -1
- package/dist/_chunks/en-bDhIlw-B.js.map +0 -1
- package/dist/_chunks/index-gkExFBa0.mjs.map +0 -1
- package/dist/_chunks/index-l-FvkQlQ.js.map +0 -1
package/dist/server/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const utils = require("@strapi/utils");
|
|
3
|
+
const isEqual = require("lodash/isEqual");
|
|
3
4
|
const lodash = require("lodash");
|
|
4
5
|
const _ = require("lodash/fp");
|
|
5
6
|
const EE = require("@strapi/strapi/dist/utils/ee");
|
|
@@ -24,6 +25,7 @@ function _interopNamespace(e) {
|
|
|
24
25
|
n.default = e;
|
|
25
26
|
return Object.freeze(n);
|
|
26
27
|
}
|
|
28
|
+
const isEqual__default = /* @__PURE__ */ _interopDefault(isEqual);
|
|
27
29
|
const ___default = /* @__PURE__ */ _interopDefault(_);
|
|
28
30
|
const EE__default = /* @__PURE__ */ _interopDefault(EE);
|
|
29
31
|
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
@@ -73,6 +75,32 @@ const ACTIONS = [
|
|
|
73
75
|
pluginName: "content-releases"
|
|
74
76
|
}
|
|
75
77
|
];
|
|
78
|
+
const ALLOWED_WEBHOOK_EVENTS = {
|
|
79
|
+
RELEASES_PUBLISH: "releases.publish"
|
|
80
|
+
};
|
|
81
|
+
const getService = (name, { strapi: strapi2 } = { strapi: global.strapi }) => {
|
|
82
|
+
return strapi2.plugin("content-releases").service(name);
|
|
83
|
+
};
|
|
84
|
+
const getPopulatedEntry = async (contentTypeUid, entryId, { strapi: strapi2 } = { strapi: global.strapi }) => {
|
|
85
|
+
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
86
|
+
const populate = await populateBuilderService(contentTypeUid).populateDeep(Infinity).build();
|
|
87
|
+
const entry = await strapi2.entityService.findOne(contentTypeUid, entryId, { populate });
|
|
88
|
+
return entry;
|
|
89
|
+
};
|
|
90
|
+
const getEntryValidStatus = async (contentTypeUid, entry, { strapi: strapi2 } = { strapi: global.strapi }) => {
|
|
91
|
+
try {
|
|
92
|
+
await strapi2.entityValidator.validateEntityCreation(
|
|
93
|
+
strapi2.getModel(contentTypeUid),
|
|
94
|
+
entry,
|
|
95
|
+
void 0,
|
|
96
|
+
// @ts-expect-error - FIXME: entity here is unnecessary
|
|
97
|
+
entry
|
|
98
|
+
);
|
|
99
|
+
return true;
|
|
100
|
+
} catch {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
76
104
|
async function deleteActionsOnDisableDraftAndPublish({
|
|
77
105
|
oldContentTypes,
|
|
78
106
|
contentTypes: contentTypes2
|
|
@@ -99,31 +127,191 @@ async function deleteActionsOnDeleteContentType({ oldContentTypes, contentTypes:
|
|
|
99
127
|
});
|
|
100
128
|
}
|
|
101
129
|
}
|
|
130
|
+
async function migrateIsValidAndStatusReleases() {
|
|
131
|
+
const releasesWithoutStatus = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
132
|
+
where: {
|
|
133
|
+
status: null,
|
|
134
|
+
releasedAt: null
|
|
135
|
+
},
|
|
136
|
+
populate: {
|
|
137
|
+
actions: {
|
|
138
|
+
populate: {
|
|
139
|
+
entry: true
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
utils.mapAsync(releasesWithoutStatus, async (release2) => {
|
|
145
|
+
const actions = release2.actions;
|
|
146
|
+
const notValidatedActions = actions.filter((action) => action.isEntryValid === null);
|
|
147
|
+
for (const action of notValidatedActions) {
|
|
148
|
+
if (action.entry) {
|
|
149
|
+
const populatedEntry = await getPopulatedEntry(action.contentType, action.entry.id, {
|
|
150
|
+
strapi
|
|
151
|
+
});
|
|
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
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
166
|
+
});
|
|
167
|
+
const publishedReleases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
168
|
+
where: {
|
|
169
|
+
status: null,
|
|
170
|
+
releasedAt: {
|
|
171
|
+
$notNull: true
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
utils.mapAsync(publishedReleases, async (release2) => {
|
|
176
|
+
return strapi.db.query(RELEASE_MODEL_UID).update({
|
|
177
|
+
where: {
|
|
178
|
+
id: release2.id
|
|
179
|
+
},
|
|
180
|
+
data: {
|
|
181
|
+
status: "done"
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
async function revalidateChangedContentTypes({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
187
|
+
if (oldContentTypes !== void 0 && contentTypes2 !== void 0) {
|
|
188
|
+
const contentTypesWithDraftAndPublish = Object.keys(oldContentTypes).filter(
|
|
189
|
+
(uid) => oldContentTypes[uid]?.options?.draftAndPublish
|
|
190
|
+
);
|
|
191
|
+
const releasesAffected = /* @__PURE__ */ new Set();
|
|
192
|
+
utils.mapAsync(contentTypesWithDraftAndPublish, async (contentTypeUID) => {
|
|
193
|
+
const oldContentType = oldContentTypes[contentTypeUID];
|
|
194
|
+
const contentType = contentTypes2[contentTypeUID];
|
|
195
|
+
if (!isEqual__default.default(oldContentType?.attributes, contentType?.attributes)) {
|
|
196
|
+
const actions = await strapi.db.query(RELEASE_ACTION_MODEL_UID).findMany({
|
|
197
|
+
where: {
|
|
198
|
+
contentType: contentTypeUID
|
|
199
|
+
},
|
|
200
|
+
populate: {
|
|
201
|
+
entry: true,
|
|
202
|
+
release: true
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
await utils.mapAsync(actions, async (action) => {
|
|
206
|
+
if (action.entry && action.release) {
|
|
207
|
+
const populatedEntry = await getPopulatedEntry(contentTypeUID, action.entry.id, {
|
|
208
|
+
strapi
|
|
209
|
+
});
|
|
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
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}).then(() => {
|
|
228
|
+
utils.mapAsync(releasesAffected, async (releaseId) => {
|
|
229
|
+
return getService("release", { strapi }).updateReleaseStatus(releaseId);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
async function disableContentTypeLocalized({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
235
|
+
if (!oldContentTypes) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
for (const uid in contentTypes2) {
|
|
239
|
+
if (!oldContentTypes[uid]) {
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
const oldContentType = oldContentTypes[uid];
|
|
243
|
+
const contentType = contentTypes2[uid];
|
|
244
|
+
const i18nPlugin = strapi.plugin("i18n");
|
|
245
|
+
const { isLocalizedContentType } = i18nPlugin.service("content-types");
|
|
246
|
+
if (isLocalizedContentType(oldContentType) && !isLocalizedContentType(contentType)) {
|
|
247
|
+
await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
|
|
248
|
+
locale: null
|
|
249
|
+
}).where({ contentType: uid }).execute();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
async function enableContentTypeLocalized({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
254
|
+
if (!oldContentTypes) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
for (const uid in contentTypes2) {
|
|
258
|
+
if (!oldContentTypes[uid]) {
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
const oldContentType = oldContentTypes[uid];
|
|
262
|
+
const contentType = contentTypes2[uid];
|
|
263
|
+
const i18nPlugin = strapi.plugin("i18n");
|
|
264
|
+
const { isLocalizedContentType } = i18nPlugin.service("content-types");
|
|
265
|
+
const { getDefaultLocale } = i18nPlugin.service("locales");
|
|
266
|
+
if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {
|
|
267
|
+
const defaultLocale = await getDefaultLocale();
|
|
268
|
+
await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
|
|
269
|
+
locale: defaultLocale
|
|
270
|
+
}).where({ contentType: uid }).execute();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
102
274
|
const { features: features$2 } = require("@strapi/strapi/dist/utils/ee");
|
|
103
275
|
const register = async ({ strapi: strapi2 }) => {
|
|
104
276
|
if (features$2.isEnabled("cms-content-releases")) {
|
|
105
277
|
await strapi2.admin.services.permission.actionProvider.registerMany(ACTIONS);
|
|
106
|
-
strapi2.hook("strapi::content-types.beforeSync").register(deleteActionsOnDisableDraftAndPublish);
|
|
107
|
-
strapi2.hook("strapi::content-types.afterSync").register(deleteActionsOnDeleteContentType);
|
|
278
|
+
strapi2.hook("strapi::content-types.beforeSync").register(deleteActionsOnDisableDraftAndPublish).register(disableContentTypeLocalized);
|
|
279
|
+
strapi2.hook("strapi::content-types.afterSync").register(deleteActionsOnDeleteContentType).register(enableContentTypeLocalized).register(revalidateChangedContentTypes).register(migrateIsValidAndStatusReleases);
|
|
108
280
|
}
|
|
109
281
|
};
|
|
110
|
-
const getService = (name, { strapi: strapi2 } = { strapi: global.strapi }) => {
|
|
111
|
-
return strapi2.plugin("content-releases").service(name);
|
|
112
|
-
};
|
|
113
282
|
const { features: features$1 } = require("@strapi/strapi/dist/utils/ee");
|
|
114
283
|
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
115
284
|
if (features$1.isEnabled("cms-content-releases")) {
|
|
285
|
+
const contentTypesWithDraftAndPublish = Object.keys(strapi2.contentTypes).filter(
|
|
286
|
+
(uid) => strapi2.contentTypes[uid]?.options?.draftAndPublish
|
|
287
|
+
);
|
|
116
288
|
strapi2.db.lifecycles.subscribe({
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
289
|
+
models: contentTypesWithDraftAndPublish,
|
|
290
|
+
async afterDelete(event) {
|
|
291
|
+
try {
|
|
292
|
+
const { model, result } = event;
|
|
293
|
+
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
294
|
+
const { id } = result;
|
|
295
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
296
|
+
where: {
|
|
297
|
+
actions: {
|
|
298
|
+
target_type: model.uid,
|
|
299
|
+
target_id: id
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
304
|
+
where: {
|
|
305
|
+
target_type: model.uid,
|
|
306
|
+
target_id: id
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
for (const release2 of releases) {
|
|
310
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
|
|
125
311
|
}
|
|
126
|
-
}
|
|
312
|
+
}
|
|
313
|
+
} catch (error) {
|
|
314
|
+
strapi2.log.error("Error while deleting release actions after entry delete", { error });
|
|
127
315
|
}
|
|
128
316
|
},
|
|
129
317
|
/**
|
|
@@ -143,18 +331,75 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
143
331
|
* We make this only after deleteMany is succesfully executed to avoid errors
|
|
144
332
|
*/
|
|
145
333
|
async afterDeleteMany(event) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
334
|
+
try {
|
|
335
|
+
const { model, state } = event;
|
|
336
|
+
const entriesToDelete = state.entriesToDelete;
|
|
337
|
+
if (entriesToDelete) {
|
|
338
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
339
|
+
where: {
|
|
340
|
+
actions: {
|
|
341
|
+
target_type: model.uid,
|
|
342
|
+
target_id: {
|
|
343
|
+
$in: entriesToDelete.map(
|
|
344
|
+
(entry) => entry.id
|
|
345
|
+
)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
351
|
+
where: {
|
|
352
|
+
target_type: model.uid,
|
|
353
|
+
target_id: {
|
|
354
|
+
$in: entriesToDelete.map((entry) => entry.id)
|
|
355
|
+
}
|
|
154
356
|
}
|
|
357
|
+
});
|
|
358
|
+
for (const release2 of releases) {
|
|
359
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
|
|
155
360
|
}
|
|
361
|
+
}
|
|
362
|
+
} catch (error) {
|
|
363
|
+
strapi2.log.error("Error while deleting release actions after entry deleteMany", {
|
|
364
|
+
error
|
|
156
365
|
});
|
|
157
366
|
}
|
|
367
|
+
},
|
|
368
|
+
async afterUpdate(event) {
|
|
369
|
+
try {
|
|
370
|
+
const { model, result } = event;
|
|
371
|
+
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
372
|
+
const isEntryValid = await getEntryValidStatus(
|
|
373
|
+
model.uid,
|
|
374
|
+
result,
|
|
375
|
+
{
|
|
376
|
+
strapi: strapi2
|
|
377
|
+
}
|
|
378
|
+
);
|
|
379
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
380
|
+
where: {
|
|
381
|
+
target_type: model.uid,
|
|
382
|
+
target_id: result.id
|
|
383
|
+
},
|
|
384
|
+
data: {
|
|
385
|
+
isEntryValid
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
389
|
+
where: {
|
|
390
|
+
actions: {
|
|
391
|
+
target_type: model.uid,
|
|
392
|
+
target_id: result.id
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
for (const release2 of releases) {
|
|
397
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
} catch (error) {
|
|
401
|
+
strapi2.log.error("Error while updating release actions after entry update", { error });
|
|
402
|
+
}
|
|
158
403
|
}
|
|
159
404
|
});
|
|
160
405
|
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
@@ -164,6 +409,9 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
164
409
|
);
|
|
165
410
|
throw err;
|
|
166
411
|
});
|
|
412
|
+
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
|
413
|
+
strapi2.webhookStore.addAllowedEvent(key, value);
|
|
414
|
+
});
|
|
167
415
|
}
|
|
168
416
|
}
|
|
169
417
|
};
|
|
@@ -209,6 +457,11 @@ const schema$1 = {
|
|
|
209
457
|
timezone: {
|
|
210
458
|
type: "string"
|
|
211
459
|
},
|
|
460
|
+
status: {
|
|
461
|
+
type: "enumeration",
|
|
462
|
+
enum: ["ready", "blocked", "failed", "done", "empty"],
|
|
463
|
+
required: true
|
|
464
|
+
},
|
|
212
465
|
actions: {
|
|
213
466
|
type: "relation",
|
|
214
467
|
relation: "oneToMany",
|
|
@@ -261,6 +514,9 @@ const schema = {
|
|
|
261
514
|
relation: "manyToOne",
|
|
262
515
|
target: RELEASE_MODEL_UID,
|
|
263
516
|
inversedBy: "actions"
|
|
517
|
+
},
|
|
518
|
+
isEntryValid: {
|
|
519
|
+
type: "boolean"
|
|
264
520
|
}
|
|
265
521
|
}
|
|
266
522
|
};
|
|
@@ -283,468 +539,563 @@ const getGroupName = (queryValue) => {
|
|
|
283
539
|
return "contentType.displayName";
|
|
284
540
|
}
|
|
285
541
|
};
|
|
286
|
-
const createReleaseService = ({ strapi: strapi2 }) =>
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
validateScheduledAtIsLaterThanNow
|
|
293
|
-
} = getService("release-validation", { strapi: strapi2 });
|
|
294
|
-
await Promise.all([
|
|
295
|
-
validatePendingReleasesLimit(),
|
|
296
|
-
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
|
|
297
|
-
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
298
|
-
]);
|
|
299
|
-
const release2 = await strapi2.entityService.create(RELEASE_MODEL_UID, {
|
|
300
|
-
data: releaseWithCreatorFields
|
|
301
|
-
});
|
|
302
|
-
if (strapi2.features.future.isEnabled("contentReleasesScheduling") && releaseWithCreatorFields.scheduledAt) {
|
|
303
|
-
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
304
|
-
await schedulingService.set(release2.id, release2.scheduledAt);
|
|
305
|
-
}
|
|
306
|
-
return release2;
|
|
307
|
-
},
|
|
308
|
-
async findOne(id, query = {}) {
|
|
309
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id, {
|
|
310
|
-
...query
|
|
542
|
+
const createReleaseService = ({ strapi: strapi2 }) => {
|
|
543
|
+
const dispatchWebhook = (event, { isPublished, release: release2, error }) => {
|
|
544
|
+
strapi2.eventHub.emit(event, {
|
|
545
|
+
isPublished,
|
|
546
|
+
error,
|
|
547
|
+
release: release2
|
|
311
548
|
});
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
549
|
+
};
|
|
550
|
+
return {
|
|
551
|
+
async create(releaseData, { user }) {
|
|
552
|
+
const releaseWithCreatorFields = await utils.setCreatorFields({ user })(releaseData);
|
|
553
|
+
const {
|
|
554
|
+
validatePendingReleasesLimit,
|
|
555
|
+
validateUniqueNameForPendingRelease,
|
|
556
|
+
validateScheduledAtIsLaterThanNow
|
|
557
|
+
} = getService("release-validation", { strapi: strapi2 });
|
|
558
|
+
await Promise.all([
|
|
559
|
+
validatePendingReleasesLimit(),
|
|
560
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
|
|
561
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
562
|
+
]);
|
|
563
|
+
const release2 = await strapi2.entityService.create(RELEASE_MODEL_UID, {
|
|
564
|
+
data: {
|
|
565
|
+
...releaseWithCreatorFields,
|
|
566
|
+
status: "empty"
|
|
321
567
|
}
|
|
568
|
+
});
|
|
569
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling") && releaseWithCreatorFields.scheduledAt) {
|
|
570
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
571
|
+
await schedulingService.set(release2.id, release2.scheduledAt);
|
|
322
572
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
573
|
+
strapi2.telemetry.send("didCreateContentRelease");
|
|
574
|
+
return release2;
|
|
575
|
+
},
|
|
576
|
+
async findOne(id, query = {}) {
|
|
577
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id, {
|
|
578
|
+
...query
|
|
579
|
+
});
|
|
580
|
+
return release2;
|
|
581
|
+
},
|
|
582
|
+
findPage(query) {
|
|
583
|
+
return strapi2.entityService.findPage(RELEASE_MODEL_UID, {
|
|
584
|
+
...query,
|
|
585
|
+
populate: {
|
|
586
|
+
actions: {
|
|
587
|
+
// @ts-expect-error Ignore missing properties
|
|
588
|
+
count: true
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
},
|
|
593
|
+
async findManyWithContentTypeEntryAttached(contentTypeUid, entryId) {
|
|
594
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
595
|
+
where: {
|
|
596
|
+
actions: {
|
|
597
|
+
target_type: contentTypeUid,
|
|
598
|
+
target_id: entryId
|
|
599
|
+
},
|
|
600
|
+
releasedAt: {
|
|
601
|
+
$null: true
|
|
602
|
+
}
|
|
331
603
|
},
|
|
332
|
-
|
|
333
|
-
|
|
604
|
+
populate: {
|
|
605
|
+
// Filter the action to get only the content type entry
|
|
606
|
+
actions: {
|
|
607
|
+
where: {
|
|
608
|
+
target_type: contentTypeUid,
|
|
609
|
+
target_id: entryId
|
|
610
|
+
}
|
|
611
|
+
}
|
|
334
612
|
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
613
|
+
});
|
|
614
|
+
return releases.map((release2) => {
|
|
615
|
+
if (release2.actions?.length) {
|
|
616
|
+
const [actionForEntry] = release2.actions;
|
|
617
|
+
delete release2.actions;
|
|
618
|
+
return {
|
|
619
|
+
...release2,
|
|
620
|
+
action: actionForEntry
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
return release2;
|
|
624
|
+
});
|
|
625
|
+
},
|
|
626
|
+
async findManyWithoutContentTypeEntryAttached(contentTypeUid, entryId) {
|
|
627
|
+
const releasesRelated = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
628
|
+
where: {
|
|
629
|
+
releasedAt: {
|
|
630
|
+
$null: true
|
|
631
|
+
},
|
|
632
|
+
actions: {
|
|
340
633
|
target_type: contentTypeUid,
|
|
341
634
|
target_id: entryId
|
|
342
635
|
}
|
|
343
636
|
}
|
|
637
|
+
});
|
|
638
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
639
|
+
where: {
|
|
640
|
+
$or: [
|
|
641
|
+
{
|
|
642
|
+
id: {
|
|
643
|
+
$notIn: releasesRelated.map((release2) => release2.id)
|
|
644
|
+
}
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
actions: null
|
|
648
|
+
}
|
|
649
|
+
],
|
|
650
|
+
releasedAt: {
|
|
651
|
+
$null: true
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
return releases.map((release2) => {
|
|
656
|
+
if (release2.actions?.length) {
|
|
657
|
+
const [actionForEntry] = release2.actions;
|
|
658
|
+
delete release2.actions;
|
|
659
|
+
return {
|
|
660
|
+
...release2,
|
|
661
|
+
action: actionForEntry
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
return release2;
|
|
665
|
+
});
|
|
666
|
+
},
|
|
667
|
+
async update(id, releaseData, { user }) {
|
|
668
|
+
const releaseWithCreatorFields = await utils.setCreatorFields({ user, isEdition: true })(
|
|
669
|
+
releaseData
|
|
670
|
+
);
|
|
671
|
+
const { validateUniqueNameForPendingRelease, validateScheduledAtIsLaterThanNow } = getService(
|
|
672
|
+
"release-validation",
|
|
673
|
+
{ strapi: strapi2 }
|
|
674
|
+
);
|
|
675
|
+
await Promise.all([
|
|
676
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name, id),
|
|
677
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
678
|
+
]);
|
|
679
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id);
|
|
680
|
+
if (!release2) {
|
|
681
|
+
throw new utils.errors.NotFoundError(`No release found for id ${id}`);
|
|
344
682
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if (release2.actions?.length) {
|
|
348
|
-
const [actionForEntry] = release2.actions;
|
|
349
|
-
delete release2.actions;
|
|
350
|
-
return {
|
|
351
|
-
...release2,
|
|
352
|
-
action: actionForEntry
|
|
353
|
-
};
|
|
683
|
+
if (release2.releasedAt) {
|
|
684
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
354
685
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
686
|
+
const updatedRelease = await strapi2.entityService.update(RELEASE_MODEL_UID, id, {
|
|
687
|
+
/*
|
|
688
|
+
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">>
|
|
689
|
+
* is not compatible with the type we are passing here: UpdateRelease.Request['body']
|
|
690
|
+
*/
|
|
691
|
+
// @ts-expect-error see above
|
|
692
|
+
data: releaseWithCreatorFields
|
|
693
|
+
});
|
|
694
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
695
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
696
|
+
if (releaseData.scheduledAt) {
|
|
697
|
+
await schedulingService.set(id, releaseData.scheduledAt);
|
|
698
|
+
} else if (release2.scheduledAt) {
|
|
699
|
+
schedulingService.cancel(id);
|
|
367
700
|
}
|
|
368
701
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
702
|
+
this.updateReleaseStatus(id);
|
|
703
|
+
strapi2.telemetry.send("didUpdateContentRelease");
|
|
704
|
+
return updatedRelease;
|
|
705
|
+
},
|
|
706
|
+
async createAction(releaseId, action) {
|
|
707
|
+
const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
|
|
708
|
+
strapi: strapi2
|
|
709
|
+
});
|
|
710
|
+
await Promise.all([
|
|
711
|
+
validateEntryContentType(action.entry.contentType),
|
|
712
|
+
validateUniqueEntry(releaseId, action)
|
|
713
|
+
]);
|
|
714
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
|
|
715
|
+
if (!release2) {
|
|
716
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
385
717
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
if (release2.actions?.length) {
|
|
389
|
-
const [actionForEntry] = release2.actions;
|
|
390
|
-
delete release2.actions;
|
|
391
|
-
return {
|
|
392
|
-
...release2,
|
|
393
|
-
action: actionForEntry
|
|
394
|
-
};
|
|
718
|
+
if (release2.releasedAt) {
|
|
719
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
395
720
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
});
|
|
424
|
-
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
425
|
-
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
426
|
-
if (releaseData.scheduledAt) {
|
|
427
|
-
await schedulingService.set(id, releaseData.scheduledAt);
|
|
428
|
-
} else if (release2.scheduledAt) {
|
|
429
|
-
schedulingService.cancel(id);
|
|
721
|
+
const { entry, type } = action;
|
|
722
|
+
const populatedEntry = await getPopulatedEntry(entry.contentType, entry.id, { strapi: strapi2 });
|
|
723
|
+
const isEntryValid = await getEntryValidStatus(entry.contentType, populatedEntry, { strapi: strapi2 });
|
|
724
|
+
const releaseAction2 = await strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
|
|
725
|
+
data: {
|
|
726
|
+
type,
|
|
727
|
+
contentType: entry.contentType,
|
|
728
|
+
locale: entry.locale,
|
|
729
|
+
isEntryValid,
|
|
730
|
+
entry: {
|
|
731
|
+
id: entry.id,
|
|
732
|
+
__type: entry.contentType,
|
|
733
|
+
__pivot: { field: "entry" }
|
|
734
|
+
},
|
|
735
|
+
release: releaseId
|
|
736
|
+
},
|
|
737
|
+
populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
|
|
738
|
+
});
|
|
739
|
+
this.updateReleaseStatus(releaseId);
|
|
740
|
+
return releaseAction2;
|
|
741
|
+
},
|
|
742
|
+
async findActions(releaseId, query) {
|
|
743
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
744
|
+
fields: ["id"]
|
|
745
|
+
});
|
|
746
|
+
if (!release2) {
|
|
747
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
430
748
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
});
|
|
438
|
-
await Promise.all([
|
|
439
|
-
validateEntryContentType(action.entry.contentType),
|
|
440
|
-
validateUniqueEntry(releaseId, action)
|
|
441
|
-
]);
|
|
442
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
|
|
443
|
-
if (!release2) {
|
|
444
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
445
|
-
}
|
|
446
|
-
if (release2.releasedAt) {
|
|
447
|
-
throw new utils.errors.ValidationError("Release already published");
|
|
448
|
-
}
|
|
449
|
-
const { entry, type } = action;
|
|
450
|
-
return strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
|
|
451
|
-
data: {
|
|
452
|
-
type,
|
|
453
|
-
contentType: entry.contentType,
|
|
454
|
-
locale: entry.locale,
|
|
455
|
-
entry: {
|
|
456
|
-
id: entry.id,
|
|
457
|
-
__type: entry.contentType,
|
|
458
|
-
__pivot: { field: "entry" }
|
|
749
|
+
return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
|
|
750
|
+
...query,
|
|
751
|
+
populate: {
|
|
752
|
+
entry: {
|
|
753
|
+
populate: "*"
|
|
754
|
+
}
|
|
459
755
|
},
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
|
|
463
|
-
});
|
|
464
|
-
},
|
|
465
|
-
async findActions(releaseId, query) {
|
|
466
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
467
|
-
fields: ["id"]
|
|
468
|
-
});
|
|
469
|
-
if (!release2) {
|
|
470
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
471
|
-
}
|
|
472
|
-
return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
|
|
473
|
-
...query,
|
|
474
|
-
populate: {
|
|
475
|
-
entry: {
|
|
476
|
-
populate: "*"
|
|
756
|
+
filters: {
|
|
757
|
+
release: releaseId
|
|
477
758
|
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
async groupActions(actions, groupBy) {
|
|
488
|
-
const contentTypeUids = actions.reduce((acc, action) => {
|
|
489
|
-
if (!acc.includes(action.contentType)) {
|
|
490
|
-
acc.push(action.contentType);
|
|
491
|
-
}
|
|
492
|
-
return acc;
|
|
493
|
-
}, []);
|
|
494
|
-
const allReleaseContentTypesDictionary = await this.getContentTypesDataForActions(
|
|
495
|
-
contentTypeUids
|
|
496
|
-
);
|
|
497
|
-
const allLocalesDictionary = await this.getLocalesDataForActions();
|
|
498
|
-
const formattedData = actions.map((action) => {
|
|
499
|
-
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
500
|
-
return {
|
|
501
|
-
...action,
|
|
502
|
-
locale: action.locale ? allLocalesDictionary[action.locale] : null,
|
|
503
|
-
contentType: {
|
|
504
|
-
displayName,
|
|
505
|
-
mainFieldValue: action.entry[mainField],
|
|
506
|
-
uid: action.contentType
|
|
759
|
+
});
|
|
760
|
+
},
|
|
761
|
+
async countActions(query) {
|
|
762
|
+
return strapi2.entityService.count(RELEASE_ACTION_MODEL_UID, query);
|
|
763
|
+
},
|
|
764
|
+
async groupActions(actions, groupBy) {
|
|
765
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
766
|
+
if (!acc.includes(action.contentType)) {
|
|
767
|
+
acc.push(action.contentType);
|
|
507
768
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
const contentTypesData = {};
|
|
526
|
-
for (const contentTypeUid of contentTypesUids) {
|
|
527
|
-
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
528
|
-
uid: contentTypeUid
|
|
769
|
+
return acc;
|
|
770
|
+
}, []);
|
|
771
|
+
const allReleaseContentTypesDictionary = await this.getContentTypesDataForActions(
|
|
772
|
+
contentTypeUids
|
|
773
|
+
);
|
|
774
|
+
const allLocalesDictionary = await this.getLocalesDataForActions();
|
|
775
|
+
const formattedData = actions.map((action) => {
|
|
776
|
+
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
777
|
+
return {
|
|
778
|
+
...action,
|
|
779
|
+
locale: action.locale ? allLocalesDictionary[action.locale] : null,
|
|
780
|
+
contentType: {
|
|
781
|
+
displayName,
|
|
782
|
+
mainFieldValue: action.entry[mainField],
|
|
783
|
+
uid: action.contentType
|
|
784
|
+
}
|
|
785
|
+
};
|
|
529
786
|
});
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
},
|
|
537
|
-
getContentTypeModelsFromActions(actions) {
|
|
538
|
-
const contentTypeUids = actions.reduce((acc, action) => {
|
|
539
|
-
if (!acc.includes(action.contentType)) {
|
|
540
|
-
acc.push(action.contentType);
|
|
787
|
+
const groupName = getGroupName(groupBy);
|
|
788
|
+
return ___default.default.groupBy(groupName)(formattedData);
|
|
789
|
+
},
|
|
790
|
+
async getLocalesDataForActions() {
|
|
791
|
+
if (!strapi2.plugin("i18n")) {
|
|
792
|
+
return {};
|
|
541
793
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
(acc, contentTypeUid) => {
|
|
546
|
-
acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
|
|
794
|
+
const allLocales = await strapi2.plugin("i18n").service("locales").find() || [];
|
|
795
|
+
return allLocales.reduce((acc, locale) => {
|
|
796
|
+
acc[locale.code] = { name: locale.name, code: locale.code };
|
|
547
797
|
return acc;
|
|
548
|
-
},
|
|
549
|
-
|
|
550
|
-
)
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
798
|
+
}, {});
|
|
799
|
+
},
|
|
800
|
+
async getContentTypesDataForActions(contentTypesUids) {
|
|
801
|
+
const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
|
|
802
|
+
const contentTypesData = {};
|
|
803
|
+
for (const contentTypeUid of contentTypesUids) {
|
|
804
|
+
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
805
|
+
uid: contentTypeUid
|
|
806
|
+
});
|
|
807
|
+
contentTypesData[contentTypeUid] = {
|
|
808
|
+
mainField: contentTypeConfig.settings.mainField,
|
|
809
|
+
displayName: strapi2.getModel(contentTypeUid).info.displayName
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
return contentTypesData;
|
|
813
|
+
},
|
|
814
|
+
getContentTypeModelsFromActions(actions) {
|
|
815
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
816
|
+
if (!acc.includes(action.contentType)) {
|
|
817
|
+
acc.push(action.contentType);
|
|
818
|
+
}
|
|
559
819
|
return acc;
|
|
560
|
-
},
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
820
|
+
}, []);
|
|
821
|
+
const contentTypeModelsMap = contentTypeUids.reduce(
|
|
822
|
+
(acc, contentTypeUid) => {
|
|
823
|
+
acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
|
|
824
|
+
return acc;
|
|
825
|
+
},
|
|
826
|
+
{}
|
|
827
|
+
);
|
|
828
|
+
return contentTypeModelsMap;
|
|
829
|
+
},
|
|
830
|
+
async getAllComponents() {
|
|
831
|
+
const contentManagerComponentsService = strapi2.plugin("content-manager").service("components");
|
|
832
|
+
const components = await contentManagerComponentsService.findAllComponents();
|
|
833
|
+
const componentsMap = components.reduce(
|
|
834
|
+
(acc, component) => {
|
|
835
|
+
acc[component.uid] = component;
|
|
836
|
+
return acc;
|
|
837
|
+
},
|
|
838
|
+
{}
|
|
839
|
+
);
|
|
840
|
+
return componentsMap;
|
|
841
|
+
},
|
|
842
|
+
async delete(releaseId) {
|
|
843
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
844
|
+
populate: {
|
|
845
|
+
actions: {
|
|
846
|
+
fields: ["id"]
|
|
847
|
+
}
|
|
570
848
|
}
|
|
849
|
+
});
|
|
850
|
+
if (!release2) {
|
|
851
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
571
852
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
where: {
|
|
582
|
-
id: {
|
|
583
|
-
$in: release2.actions.map((action) => action.id)
|
|
853
|
+
if (release2.releasedAt) {
|
|
854
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
855
|
+
}
|
|
856
|
+
await strapi2.db.transaction(async () => {
|
|
857
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
858
|
+
where: {
|
|
859
|
+
id: {
|
|
860
|
+
$in: release2.actions.map((action) => action.id)
|
|
861
|
+
}
|
|
584
862
|
}
|
|
585
|
-
}
|
|
863
|
+
});
|
|
864
|
+
await strapi2.entityService.delete(RELEASE_MODEL_UID, releaseId);
|
|
586
865
|
});
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
populate: {
|
|
601
|
-
actions: {
|
|
866
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling") && release2.scheduledAt) {
|
|
867
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
868
|
+
await schedulingService.cancel(release2.id);
|
|
869
|
+
}
|
|
870
|
+
strapi2.telemetry.send("didDeleteContentRelease");
|
|
871
|
+
return release2;
|
|
872
|
+
},
|
|
873
|
+
async publish(releaseId) {
|
|
874
|
+
try {
|
|
875
|
+
const releaseWithPopulatedActionEntries = await strapi2.entityService.findOne(
|
|
876
|
+
RELEASE_MODEL_UID,
|
|
877
|
+
releaseId,
|
|
878
|
+
{
|
|
602
879
|
populate: {
|
|
603
|
-
|
|
604
|
-
|
|
880
|
+
actions: {
|
|
881
|
+
populate: {
|
|
882
|
+
entry: {
|
|
883
|
+
fields: ["id"]
|
|
884
|
+
}
|
|
885
|
+
}
|
|
605
886
|
}
|
|
606
887
|
}
|
|
607
888
|
}
|
|
889
|
+
);
|
|
890
|
+
if (!releaseWithPopulatedActionEntries) {
|
|
891
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
608
892
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
if (!releaseWithPopulatedActionEntries) {
|
|
612
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
613
|
-
}
|
|
614
|
-
if (releaseWithPopulatedActionEntries.releasedAt) {
|
|
615
|
-
throw new utils.errors.ValidationError("Release already published");
|
|
616
|
-
}
|
|
617
|
-
if (releaseWithPopulatedActionEntries.actions.length === 0) {
|
|
618
|
-
throw new utils.errors.ValidationError("No entries to publish");
|
|
619
|
-
}
|
|
620
|
-
const collectionTypeActions = {};
|
|
621
|
-
const singleTypeActions = [];
|
|
622
|
-
for (const action of releaseWithPopulatedActionEntries.actions) {
|
|
623
|
-
const contentTypeUid = action.contentType;
|
|
624
|
-
if (strapi2.contentTypes[contentTypeUid].kind === "collectionType") {
|
|
625
|
-
if (!collectionTypeActions[contentTypeUid]) {
|
|
626
|
-
collectionTypeActions[contentTypeUid] = {
|
|
627
|
-
entriestoPublishIds: [],
|
|
628
|
-
entriesToUnpublishIds: []
|
|
629
|
-
};
|
|
893
|
+
if (releaseWithPopulatedActionEntries.releasedAt) {
|
|
894
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
630
895
|
}
|
|
631
|
-
if (
|
|
632
|
-
|
|
633
|
-
} else {
|
|
634
|
-
collectionTypeActions[contentTypeUid].entriesToUnpublishIds.push(action.entry.id);
|
|
896
|
+
if (releaseWithPopulatedActionEntries.actions.length === 0) {
|
|
897
|
+
throw new utils.errors.ValidationError("No entries to publish");
|
|
635
898
|
}
|
|
636
|
-
|
|
637
|
-
singleTypeActions
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
await entityManagerService.publish(entry, uid);
|
|
899
|
+
const collectionTypeActions = {};
|
|
900
|
+
const singleTypeActions = [];
|
|
901
|
+
for (const action of releaseWithPopulatedActionEntries.actions) {
|
|
902
|
+
const contentTypeUid = action.contentType;
|
|
903
|
+
if (strapi2.contentTypes[contentTypeUid].kind === "collectionType") {
|
|
904
|
+
if (!collectionTypeActions[contentTypeUid]) {
|
|
905
|
+
collectionTypeActions[contentTypeUid] = {
|
|
906
|
+
entriestoPublishIds: [],
|
|
907
|
+
entriesToUnpublishIds: []
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
if (action.type === "publish") {
|
|
911
|
+
collectionTypeActions[contentTypeUid].entriestoPublishIds.push(action.entry.id);
|
|
912
|
+
} else {
|
|
913
|
+
collectionTypeActions[contentTypeUid].entriesToUnpublishIds.push(action.entry.id);
|
|
914
|
+
}
|
|
653
915
|
} else {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
;
|
|
659
|
-
else {
|
|
660
|
-
throw error;
|
|
916
|
+
singleTypeActions.push({
|
|
917
|
+
uid: contentTypeUid,
|
|
918
|
+
action: action.type,
|
|
919
|
+
id: action.entry.id
|
|
920
|
+
});
|
|
661
921
|
}
|
|
662
922
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
923
|
+
const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
|
|
924
|
+
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
925
|
+
await strapi2.db.transaction(async () => {
|
|
926
|
+
for (const { uid, action, id } of singleTypeActions) {
|
|
927
|
+
const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
|
|
928
|
+
const entry = await strapi2.entityService.findOne(uid, id, { populate });
|
|
929
|
+
try {
|
|
930
|
+
if (action === "publish") {
|
|
931
|
+
await entityManagerService.publish(entry, uid);
|
|
932
|
+
} else {
|
|
933
|
+
await entityManagerService.unpublish(entry, uid);
|
|
673
934
|
}
|
|
674
|
-
}
|
|
675
|
-
|
|
935
|
+
} catch (error) {
|
|
936
|
+
if (error instanceof utils.errors.ApplicationError && (error.message === "already.published" || error.message === "already.draft")) {
|
|
937
|
+
} else {
|
|
938
|
+
throw error;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
676
941
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
942
|
+
for (const contentTypeUid of Object.keys(collectionTypeActions)) {
|
|
943
|
+
const populate = await populateBuilderService(contentTypeUid).populateDeep(Infinity).build();
|
|
944
|
+
const { entriestoPublishIds, entriesToUnpublishIds } = collectionTypeActions[contentTypeUid];
|
|
945
|
+
const entriesToPublish = await strapi2.entityService.findMany(
|
|
946
|
+
contentTypeUid,
|
|
947
|
+
{
|
|
948
|
+
filters: {
|
|
949
|
+
id: {
|
|
950
|
+
$in: entriestoPublishIds
|
|
951
|
+
}
|
|
952
|
+
},
|
|
953
|
+
populate
|
|
684
954
|
}
|
|
685
|
-
|
|
686
|
-
|
|
955
|
+
);
|
|
956
|
+
const entriesToUnpublish = await strapi2.entityService.findMany(
|
|
957
|
+
contentTypeUid,
|
|
958
|
+
{
|
|
959
|
+
filters: {
|
|
960
|
+
id: {
|
|
961
|
+
$in: entriesToUnpublishIds
|
|
962
|
+
}
|
|
963
|
+
},
|
|
964
|
+
populate
|
|
965
|
+
}
|
|
966
|
+
);
|
|
967
|
+
if (entriesToPublish.length > 0) {
|
|
968
|
+
await entityManagerService.publishMany(entriesToPublish, contentTypeUid);
|
|
969
|
+
}
|
|
970
|
+
if (entriesToUnpublish.length > 0) {
|
|
971
|
+
await entityManagerService.unpublishMany(entriesToUnpublish, contentTypeUid);
|
|
972
|
+
}
|
|
687
973
|
}
|
|
688
|
-
);
|
|
689
|
-
|
|
690
|
-
|
|
974
|
+
});
|
|
975
|
+
const release2 = await strapi2.entityService.update(RELEASE_MODEL_UID, releaseId, {
|
|
976
|
+
data: {
|
|
977
|
+
/*
|
|
978
|
+
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">> looks like it's wrong
|
|
979
|
+
*/
|
|
980
|
+
// @ts-expect-error see above
|
|
981
|
+
releasedAt: /* @__PURE__ */ new Date()
|
|
982
|
+
},
|
|
983
|
+
populate: {
|
|
984
|
+
actions: {
|
|
985
|
+
// @ts-expect-error is not expecting count but it is working
|
|
986
|
+
count: true
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
991
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
992
|
+
isPublished: true,
|
|
993
|
+
release: release2
|
|
994
|
+
});
|
|
691
995
|
}
|
|
692
|
-
|
|
693
|
-
|
|
996
|
+
strapi2.telemetry.send("didPublishContentRelease");
|
|
997
|
+
return release2;
|
|
998
|
+
} catch (error) {
|
|
999
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
1000
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
1001
|
+
isPublished: false,
|
|
1002
|
+
error
|
|
1003
|
+
});
|
|
694
1004
|
}
|
|
1005
|
+
strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1006
|
+
where: { id: releaseId },
|
|
1007
|
+
data: {
|
|
1008
|
+
status: "failed"
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
1011
|
+
throw error;
|
|
695
1012
|
}
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
1013
|
+
},
|
|
1014
|
+
async updateAction(actionId, releaseId, update) {
|
|
1015
|
+
const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
1016
|
+
where: {
|
|
1017
|
+
id: actionId,
|
|
1018
|
+
release: {
|
|
1019
|
+
id: releaseId,
|
|
1020
|
+
releasedAt: {
|
|
1021
|
+
$null: true
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
},
|
|
1025
|
+
data: update
|
|
1026
|
+
});
|
|
1027
|
+
if (!updatedAction) {
|
|
1028
|
+
throw new utils.errors.NotFoundError(
|
|
1029
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
1030
|
+
);
|
|
704
1031
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
1032
|
+
return updatedAction;
|
|
1033
|
+
},
|
|
1034
|
+
async deleteAction(actionId, releaseId) {
|
|
1035
|
+
const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
|
|
1036
|
+
where: {
|
|
1037
|
+
id: actionId,
|
|
1038
|
+
release: {
|
|
1039
|
+
id: releaseId,
|
|
1040
|
+
releasedAt: {
|
|
1041
|
+
$null: true
|
|
1042
|
+
}
|
|
716
1043
|
}
|
|
717
1044
|
}
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
);
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
release: {
|
|
733
|
-
id: releaseId,
|
|
734
|
-
releasedAt: {
|
|
735
|
-
$null: true
|
|
1045
|
+
});
|
|
1046
|
+
if (!deletedAction) {
|
|
1047
|
+
throw new utils.errors.NotFoundError(
|
|
1048
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
this.updateReleaseStatus(releaseId);
|
|
1052
|
+
return deletedAction;
|
|
1053
|
+
},
|
|
1054
|
+
async updateReleaseStatus(releaseId) {
|
|
1055
|
+
const [totalActions, invalidActions] = await Promise.all([
|
|
1056
|
+
this.countActions({
|
|
1057
|
+
filters: {
|
|
1058
|
+
release: releaseId
|
|
736
1059
|
}
|
|
1060
|
+
}),
|
|
1061
|
+
this.countActions({
|
|
1062
|
+
filters: {
|
|
1063
|
+
release: releaseId,
|
|
1064
|
+
isEntryValid: false
|
|
1065
|
+
}
|
|
1066
|
+
})
|
|
1067
|
+
]);
|
|
1068
|
+
if (totalActions > 0) {
|
|
1069
|
+
if (invalidActions > 0) {
|
|
1070
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1071
|
+
where: {
|
|
1072
|
+
id: releaseId
|
|
1073
|
+
},
|
|
1074
|
+
data: {
|
|
1075
|
+
status: "blocked"
|
|
1076
|
+
}
|
|
1077
|
+
});
|
|
737
1078
|
}
|
|
1079
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1080
|
+
where: {
|
|
1081
|
+
id: releaseId
|
|
1082
|
+
},
|
|
1083
|
+
data: {
|
|
1084
|
+
status: "ready"
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
738
1087
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
1088
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1089
|
+
where: {
|
|
1090
|
+
id: releaseId
|
|
1091
|
+
},
|
|
1092
|
+
data: {
|
|
1093
|
+
status: "empty"
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
744
1096
|
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
});
|
|
1097
|
+
};
|
|
1098
|
+
};
|
|
748
1099
|
const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
749
1100
|
async validateUniqueEntry(releaseId, releaseActionArgs) {
|
|
750
1101
|
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
@@ -869,11 +1220,21 @@ const services = {
|
|
|
869
1220
|
};
|
|
870
1221
|
const RELEASE_SCHEMA = yup__namespace.object().shape({
|
|
871
1222
|
name: yup__namespace.string().trim().required(),
|
|
872
|
-
// scheduledAt is a date, but we always receive strings from the client
|
|
873
1223
|
scheduledAt: yup__namespace.string().nullable(),
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
1224
|
+
isScheduled: yup__namespace.boolean().optional(),
|
|
1225
|
+
time: yup__namespace.string().when("isScheduled", {
|
|
1226
|
+
is: true,
|
|
1227
|
+
then: yup__namespace.string().trim().required(),
|
|
1228
|
+
otherwise: yup__namespace.string().nullable()
|
|
1229
|
+
}),
|
|
1230
|
+
timezone: yup__namespace.string().when("isScheduled", {
|
|
1231
|
+
is: true,
|
|
1232
|
+
then: yup__namespace.string().required().nullable(),
|
|
1233
|
+
otherwise: yup__namespace.string().nullable()
|
|
1234
|
+
}),
|
|
1235
|
+
date: yup__namespace.string().when("isScheduled", {
|
|
1236
|
+
is: true,
|
|
1237
|
+
then: yup__namespace.string().required().nullable(),
|
|
877
1238
|
otherwise: yup__namespace.string().nullable()
|
|
878
1239
|
})
|
|
879
1240
|
}).required().noUnknown();
|
|
@@ -908,7 +1269,12 @@ const releaseController = {
|
|
|
908
1269
|
}
|
|
909
1270
|
};
|
|
910
1271
|
});
|
|
911
|
-
|
|
1272
|
+
const pendingReleasesCount = await strapi.query(RELEASE_MODEL_UID).count({
|
|
1273
|
+
where: {
|
|
1274
|
+
releasedAt: null
|
|
1275
|
+
}
|
|
1276
|
+
});
|
|
1277
|
+
ctx.body = { data, meta: { pagination, pendingReleasesCount } };
|
|
912
1278
|
}
|
|
913
1279
|
},
|
|
914
1280
|
async findOne(ctx) {
|