@strapi/content-releases 0.0.0-next.95a939e004e74915357523e3adb118a31fef57ed → 0.0.0-next.a9d79bec775daaf0da4e506b2aebafdb4ca95b06
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-bpzO2Ljh.mjs} +613 -367
- package/dist/_chunks/App-bpzO2Ljh.mjs.map +1 -0
- package/dist/_chunks/{App-1hHIqUoZ.js → App-p8aKBitd.js} +603 -356
- package/dist/_chunks/App-p8aKBitd.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-gkExFBa0.mjs → index-AECgcaDa.mjs} +85 -22
- package/dist/_chunks/index-AECgcaDa.mjs.map +1 -0
- package/dist/_chunks/{index-l-FvkQlQ.js → index-fP3qoWZ4.js} +74 -11
- package/dist/_chunks/index-fP3qoWZ4.js.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/server/index.js +812 -434
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +811 -434
- 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,196 @@ 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);
|
|
280
|
+
}
|
|
281
|
+
if (strapi2.plugin("graphql")) {
|
|
282
|
+
const graphqlExtensionService = strapi2.plugin("graphql").service("extension");
|
|
283
|
+
graphqlExtensionService.shadowCRUD(RELEASE_MODEL_UID).disable();
|
|
284
|
+
graphqlExtensionService.shadowCRUD(RELEASE_ACTION_MODEL_UID).disable();
|
|
108
285
|
}
|
|
109
|
-
};
|
|
110
|
-
const getService = (name, { strapi: strapi2 } = { strapi: global.strapi }) => {
|
|
111
|
-
return strapi2.plugin("content-releases").service(name);
|
|
112
286
|
};
|
|
113
287
|
const { features: features$1 } = require("@strapi/strapi/dist/utils/ee");
|
|
114
288
|
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
115
289
|
if (features$1.isEnabled("cms-content-releases")) {
|
|
290
|
+
const contentTypesWithDraftAndPublish = Object.keys(strapi2.contentTypes).filter(
|
|
291
|
+
(uid) => strapi2.contentTypes[uid]?.options?.draftAndPublish
|
|
292
|
+
);
|
|
116
293
|
strapi2.db.lifecycles.subscribe({
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
294
|
+
models: contentTypesWithDraftAndPublish,
|
|
295
|
+
async afterDelete(event) {
|
|
296
|
+
try {
|
|
297
|
+
const { model, result } = event;
|
|
298
|
+
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
299
|
+
const { id } = result;
|
|
300
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
301
|
+
where: {
|
|
302
|
+
actions: {
|
|
303
|
+
target_type: model.uid,
|
|
304
|
+
target_id: id
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
309
|
+
where: {
|
|
310
|
+
target_type: model.uid,
|
|
311
|
+
target_id: id
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
for (const release2 of releases) {
|
|
315
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
|
|
125
316
|
}
|
|
126
|
-
}
|
|
317
|
+
}
|
|
318
|
+
} catch (error) {
|
|
319
|
+
strapi2.log.error("Error while deleting release actions after entry delete", { error });
|
|
127
320
|
}
|
|
128
321
|
},
|
|
129
322
|
/**
|
|
@@ -143,18 +336,75 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
143
336
|
* We make this only after deleteMany is succesfully executed to avoid errors
|
|
144
337
|
*/
|
|
145
338
|
async afterDeleteMany(event) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
339
|
+
try {
|
|
340
|
+
const { model, state } = event;
|
|
341
|
+
const entriesToDelete = state.entriesToDelete;
|
|
342
|
+
if (entriesToDelete) {
|
|
343
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
344
|
+
where: {
|
|
345
|
+
actions: {
|
|
346
|
+
target_type: model.uid,
|
|
347
|
+
target_id: {
|
|
348
|
+
$in: entriesToDelete.map(
|
|
349
|
+
(entry) => entry.id
|
|
350
|
+
)
|
|
351
|
+
}
|
|
352
|
+
}
|
|
154
353
|
}
|
|
354
|
+
});
|
|
355
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
356
|
+
where: {
|
|
357
|
+
target_type: model.uid,
|
|
358
|
+
target_id: {
|
|
359
|
+
$in: entriesToDelete.map((entry) => entry.id)
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
for (const release2 of releases) {
|
|
364
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
|
|
155
365
|
}
|
|
366
|
+
}
|
|
367
|
+
} catch (error) {
|
|
368
|
+
strapi2.log.error("Error while deleting release actions after entry deleteMany", {
|
|
369
|
+
error
|
|
156
370
|
});
|
|
157
371
|
}
|
|
372
|
+
},
|
|
373
|
+
async afterUpdate(event) {
|
|
374
|
+
try {
|
|
375
|
+
const { model, result } = event;
|
|
376
|
+
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
377
|
+
const isEntryValid = await getEntryValidStatus(
|
|
378
|
+
model.uid,
|
|
379
|
+
result,
|
|
380
|
+
{
|
|
381
|
+
strapi: strapi2
|
|
382
|
+
}
|
|
383
|
+
);
|
|
384
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
385
|
+
where: {
|
|
386
|
+
target_type: model.uid,
|
|
387
|
+
target_id: result.id
|
|
388
|
+
},
|
|
389
|
+
data: {
|
|
390
|
+
isEntryValid
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
394
|
+
where: {
|
|
395
|
+
actions: {
|
|
396
|
+
target_type: model.uid,
|
|
397
|
+
target_id: result.id
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
for (const release2 of releases) {
|
|
402
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
} catch (error) {
|
|
406
|
+
strapi2.log.error("Error while updating release actions after entry update", { error });
|
|
407
|
+
}
|
|
158
408
|
}
|
|
159
409
|
});
|
|
160
410
|
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
@@ -164,6 +414,9 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
164
414
|
);
|
|
165
415
|
throw err;
|
|
166
416
|
});
|
|
417
|
+
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
|
418
|
+
strapi2.webhookStore.addAllowedEvent(key, value);
|
|
419
|
+
});
|
|
167
420
|
}
|
|
168
421
|
}
|
|
169
422
|
};
|
|
@@ -209,6 +462,11 @@ const schema$1 = {
|
|
|
209
462
|
timezone: {
|
|
210
463
|
type: "string"
|
|
211
464
|
},
|
|
465
|
+
status: {
|
|
466
|
+
type: "enumeration",
|
|
467
|
+
enum: ["ready", "blocked", "failed", "done", "empty"],
|
|
468
|
+
required: true
|
|
469
|
+
},
|
|
212
470
|
actions: {
|
|
213
471
|
type: "relation",
|
|
214
472
|
relation: "oneToMany",
|
|
@@ -261,6 +519,9 @@ const schema = {
|
|
|
261
519
|
relation: "manyToOne",
|
|
262
520
|
target: RELEASE_MODEL_UID,
|
|
263
521
|
inversedBy: "actions"
|
|
522
|
+
},
|
|
523
|
+
isEntryValid: {
|
|
524
|
+
type: "boolean"
|
|
264
525
|
}
|
|
265
526
|
}
|
|
266
527
|
};
|
|
@@ -283,464 +544,563 @@ const getGroupName = (queryValue) => {
|
|
|
283
544
|
return "contentType.displayName";
|
|
284
545
|
}
|
|
285
546
|
};
|
|
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
|
|
547
|
+
const createReleaseService = ({ strapi: strapi2 }) => {
|
|
548
|
+
const dispatchWebhook = (event, { isPublished, release: release2, error }) => {
|
|
549
|
+
strapi2.eventHub.emit(event, {
|
|
550
|
+
isPublished,
|
|
551
|
+
error,
|
|
552
|
+
release: release2
|
|
301
553
|
});
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
count: true
|
|
554
|
+
};
|
|
555
|
+
return {
|
|
556
|
+
async create(releaseData, { user }) {
|
|
557
|
+
const releaseWithCreatorFields = await utils.setCreatorFields({ user })(releaseData);
|
|
558
|
+
const {
|
|
559
|
+
validatePendingReleasesLimit,
|
|
560
|
+
validateUniqueNameForPendingRelease,
|
|
561
|
+
validateScheduledAtIsLaterThanNow
|
|
562
|
+
} = getService("release-validation", { strapi: strapi2 });
|
|
563
|
+
await Promise.all([
|
|
564
|
+
validatePendingReleasesLimit(),
|
|
565
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
|
|
566
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
567
|
+
]);
|
|
568
|
+
const release2 = await strapi2.entityService.create(RELEASE_MODEL_UID, {
|
|
569
|
+
data: {
|
|
570
|
+
...releaseWithCreatorFields,
|
|
571
|
+
status: "empty"
|
|
321
572
|
}
|
|
573
|
+
});
|
|
574
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling") && releaseWithCreatorFields.scheduledAt) {
|
|
575
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
576
|
+
await schedulingService.set(release2.id, release2.scheduledAt);
|
|
322
577
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
578
|
+
strapi2.telemetry.send("didCreateContentRelease");
|
|
579
|
+
return release2;
|
|
580
|
+
},
|
|
581
|
+
async findOne(id, query = {}) {
|
|
582
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id, {
|
|
583
|
+
...query
|
|
584
|
+
});
|
|
585
|
+
return release2;
|
|
586
|
+
},
|
|
587
|
+
findPage(query) {
|
|
588
|
+
return strapi2.entityService.findPage(RELEASE_MODEL_UID, {
|
|
589
|
+
...query,
|
|
590
|
+
populate: {
|
|
591
|
+
actions: {
|
|
592
|
+
// @ts-expect-error Ignore missing properties
|
|
593
|
+
count: true
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
},
|
|
598
|
+
async findManyWithContentTypeEntryAttached(contentTypeUid, entryId) {
|
|
599
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
600
|
+
where: {
|
|
601
|
+
actions: {
|
|
602
|
+
target_type: contentTypeUid,
|
|
603
|
+
target_id: entryId
|
|
604
|
+
},
|
|
605
|
+
releasedAt: {
|
|
606
|
+
$null: true
|
|
607
|
+
}
|
|
331
608
|
},
|
|
332
|
-
|
|
333
|
-
|
|
609
|
+
populate: {
|
|
610
|
+
// Filter the action to get only the content type entry
|
|
611
|
+
actions: {
|
|
612
|
+
where: {
|
|
613
|
+
target_type: contentTypeUid,
|
|
614
|
+
target_id: entryId
|
|
615
|
+
}
|
|
616
|
+
}
|
|
334
617
|
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
618
|
+
});
|
|
619
|
+
return releases.map((release2) => {
|
|
620
|
+
if (release2.actions?.length) {
|
|
621
|
+
const [actionForEntry] = release2.actions;
|
|
622
|
+
delete release2.actions;
|
|
623
|
+
return {
|
|
624
|
+
...release2,
|
|
625
|
+
action: actionForEntry
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
return release2;
|
|
629
|
+
});
|
|
630
|
+
},
|
|
631
|
+
async findManyWithoutContentTypeEntryAttached(contentTypeUid, entryId) {
|
|
632
|
+
const releasesRelated = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
633
|
+
where: {
|
|
634
|
+
releasedAt: {
|
|
635
|
+
$null: true
|
|
636
|
+
},
|
|
637
|
+
actions: {
|
|
340
638
|
target_type: contentTypeUid,
|
|
341
639
|
target_id: entryId
|
|
342
640
|
}
|
|
343
641
|
}
|
|
642
|
+
});
|
|
643
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
644
|
+
where: {
|
|
645
|
+
$or: [
|
|
646
|
+
{
|
|
647
|
+
id: {
|
|
648
|
+
$notIn: releasesRelated.map((release2) => release2.id)
|
|
649
|
+
}
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
actions: null
|
|
653
|
+
}
|
|
654
|
+
],
|
|
655
|
+
releasedAt: {
|
|
656
|
+
$null: true
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
return releases.map((release2) => {
|
|
661
|
+
if (release2.actions?.length) {
|
|
662
|
+
const [actionForEntry] = release2.actions;
|
|
663
|
+
delete release2.actions;
|
|
664
|
+
return {
|
|
665
|
+
...release2,
|
|
666
|
+
action: actionForEntry
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
return release2;
|
|
670
|
+
});
|
|
671
|
+
},
|
|
672
|
+
async update(id, releaseData, { user }) {
|
|
673
|
+
const releaseWithCreatorFields = await utils.setCreatorFields({ user, isEdition: true })(
|
|
674
|
+
releaseData
|
|
675
|
+
);
|
|
676
|
+
const { validateUniqueNameForPendingRelease, validateScheduledAtIsLaterThanNow } = getService(
|
|
677
|
+
"release-validation",
|
|
678
|
+
{ strapi: strapi2 }
|
|
679
|
+
);
|
|
680
|
+
await Promise.all([
|
|
681
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name, id),
|
|
682
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
683
|
+
]);
|
|
684
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id);
|
|
685
|
+
if (!release2) {
|
|
686
|
+
throw new utils.errors.NotFoundError(`No release found for id ${id}`);
|
|
344
687
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if (release2.actions?.length) {
|
|
348
|
-
const [actionForEntry] = release2.actions;
|
|
349
|
-
delete release2.actions;
|
|
350
|
-
return {
|
|
351
|
-
...release2,
|
|
352
|
-
action: actionForEntry
|
|
353
|
-
};
|
|
688
|
+
if (release2.releasedAt) {
|
|
689
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
354
690
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
691
|
+
const updatedRelease = await strapi2.entityService.update(RELEASE_MODEL_UID, id, {
|
|
692
|
+
/*
|
|
693
|
+
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">>
|
|
694
|
+
* is not compatible with the type we are passing here: UpdateRelease.Request['body']
|
|
695
|
+
*/
|
|
696
|
+
// @ts-expect-error see above
|
|
697
|
+
data: releaseWithCreatorFields
|
|
698
|
+
});
|
|
699
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
700
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
701
|
+
if (releaseData.scheduledAt) {
|
|
702
|
+
await schedulingService.set(id, releaseData.scheduledAt);
|
|
703
|
+
} else if (release2.scheduledAt) {
|
|
704
|
+
schedulingService.cancel(id);
|
|
367
705
|
}
|
|
368
706
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
707
|
+
this.updateReleaseStatus(id);
|
|
708
|
+
strapi2.telemetry.send("didUpdateContentRelease");
|
|
709
|
+
return updatedRelease;
|
|
710
|
+
},
|
|
711
|
+
async createAction(releaseId, action) {
|
|
712
|
+
const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
|
|
713
|
+
strapi: strapi2
|
|
714
|
+
});
|
|
715
|
+
await Promise.all([
|
|
716
|
+
validateEntryContentType(action.entry.contentType),
|
|
717
|
+
validateUniqueEntry(releaseId, action)
|
|
718
|
+
]);
|
|
719
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
|
|
720
|
+
if (!release2) {
|
|
721
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
385
722
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
if (release2.actions?.length) {
|
|
389
|
-
const [actionForEntry] = release2.actions;
|
|
390
|
-
delete release2.actions;
|
|
391
|
-
return {
|
|
392
|
-
...release2,
|
|
393
|
-
action: actionForEntry
|
|
394
|
-
};
|
|
723
|
+
if (release2.releasedAt) {
|
|
724
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
395
725
|
}
|
|
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);
|
|
726
|
+
const { entry, type } = action;
|
|
727
|
+
const populatedEntry = await getPopulatedEntry(entry.contentType, entry.id, { strapi: strapi2 });
|
|
728
|
+
const isEntryValid = await getEntryValidStatus(entry.contentType, populatedEntry, { strapi: strapi2 });
|
|
729
|
+
const releaseAction2 = await strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
|
|
730
|
+
data: {
|
|
731
|
+
type,
|
|
732
|
+
contentType: entry.contentType,
|
|
733
|
+
locale: entry.locale,
|
|
734
|
+
isEntryValid,
|
|
735
|
+
entry: {
|
|
736
|
+
id: entry.id,
|
|
737
|
+
__type: entry.contentType,
|
|
738
|
+
__pivot: { field: "entry" }
|
|
739
|
+
},
|
|
740
|
+
release: releaseId
|
|
741
|
+
},
|
|
742
|
+
populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
|
|
743
|
+
});
|
|
744
|
+
this.updateReleaseStatus(releaseId);
|
|
745
|
+
return releaseAction2;
|
|
746
|
+
},
|
|
747
|
+
async findActions(releaseId, query) {
|
|
748
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
749
|
+
fields: ["id"]
|
|
750
|
+
});
|
|
751
|
+
if (!release2) {
|
|
752
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
430
753
|
}
|
|
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" }
|
|
754
|
+
return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
|
|
755
|
+
...query,
|
|
756
|
+
populate: {
|
|
757
|
+
entry: {
|
|
758
|
+
populate: "*"
|
|
759
|
+
}
|
|
459
760
|
},
|
|
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: "*"
|
|
761
|
+
filters: {
|
|
762
|
+
release: releaseId
|
|
477
763
|
}
|
|
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
|
|
764
|
+
});
|
|
765
|
+
},
|
|
766
|
+
async countActions(query) {
|
|
767
|
+
return strapi2.entityService.count(RELEASE_ACTION_MODEL_UID, query);
|
|
768
|
+
},
|
|
769
|
+
async groupActions(actions, groupBy) {
|
|
770
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
771
|
+
if (!acc.includes(action.contentType)) {
|
|
772
|
+
acc.push(action.contentType);
|
|
507
773
|
}
|
|
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
|
|
774
|
+
return acc;
|
|
775
|
+
}, []);
|
|
776
|
+
const allReleaseContentTypesDictionary = await this.getContentTypesDataForActions(
|
|
777
|
+
contentTypeUids
|
|
778
|
+
);
|
|
779
|
+
const allLocalesDictionary = await this.getLocalesDataForActions();
|
|
780
|
+
const formattedData = actions.map((action) => {
|
|
781
|
+
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
782
|
+
return {
|
|
783
|
+
...action,
|
|
784
|
+
locale: action.locale ? allLocalesDictionary[action.locale] : null,
|
|
785
|
+
contentType: {
|
|
786
|
+
displayName,
|
|
787
|
+
mainFieldValue: action.entry[mainField],
|
|
788
|
+
uid: action.contentType
|
|
789
|
+
}
|
|
790
|
+
};
|
|
529
791
|
});
|
|
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);
|
|
792
|
+
const groupName = getGroupName(groupBy);
|
|
793
|
+
return ___default.default.groupBy(groupName)(formattedData);
|
|
794
|
+
},
|
|
795
|
+
async getLocalesDataForActions() {
|
|
796
|
+
if (!strapi2.plugin("i18n")) {
|
|
797
|
+
return {};
|
|
541
798
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
(acc, contentTypeUid) => {
|
|
546
|
-
acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
|
|
799
|
+
const allLocales = await strapi2.plugin("i18n").service("locales").find() || [];
|
|
800
|
+
return allLocales.reduce((acc, locale) => {
|
|
801
|
+
acc[locale.code] = { name: locale.name, code: locale.code };
|
|
547
802
|
return acc;
|
|
548
|
-
},
|
|
549
|
-
|
|
550
|
-
)
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
803
|
+
}, {});
|
|
804
|
+
},
|
|
805
|
+
async getContentTypesDataForActions(contentTypesUids) {
|
|
806
|
+
const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
|
|
807
|
+
const contentTypesData = {};
|
|
808
|
+
for (const contentTypeUid of contentTypesUids) {
|
|
809
|
+
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
810
|
+
uid: contentTypeUid
|
|
811
|
+
});
|
|
812
|
+
contentTypesData[contentTypeUid] = {
|
|
813
|
+
mainField: contentTypeConfig.settings.mainField,
|
|
814
|
+
displayName: strapi2.getModel(contentTypeUid).info.displayName
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
return contentTypesData;
|
|
818
|
+
},
|
|
819
|
+
getContentTypeModelsFromActions(actions) {
|
|
820
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
821
|
+
if (!acc.includes(action.contentType)) {
|
|
822
|
+
acc.push(action.contentType);
|
|
823
|
+
}
|
|
559
824
|
return acc;
|
|
560
|
-
},
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
825
|
+
}, []);
|
|
826
|
+
const contentTypeModelsMap = contentTypeUids.reduce(
|
|
827
|
+
(acc, contentTypeUid) => {
|
|
828
|
+
acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
|
|
829
|
+
return acc;
|
|
830
|
+
},
|
|
831
|
+
{}
|
|
832
|
+
);
|
|
833
|
+
return contentTypeModelsMap;
|
|
834
|
+
},
|
|
835
|
+
async getAllComponents() {
|
|
836
|
+
const contentManagerComponentsService = strapi2.plugin("content-manager").service("components");
|
|
837
|
+
const components = await contentManagerComponentsService.findAllComponents();
|
|
838
|
+
const componentsMap = components.reduce(
|
|
839
|
+
(acc, component) => {
|
|
840
|
+
acc[component.uid] = component;
|
|
841
|
+
return acc;
|
|
842
|
+
},
|
|
843
|
+
{}
|
|
844
|
+
);
|
|
845
|
+
return componentsMap;
|
|
846
|
+
},
|
|
847
|
+
async delete(releaseId) {
|
|
848
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
849
|
+
populate: {
|
|
850
|
+
actions: {
|
|
851
|
+
fields: ["id"]
|
|
852
|
+
}
|
|
570
853
|
}
|
|
854
|
+
});
|
|
855
|
+
if (!release2) {
|
|
856
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
571
857
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
where: {
|
|
582
|
-
id: {
|
|
583
|
-
$in: release2.actions.map((action) => action.id)
|
|
858
|
+
if (release2.releasedAt) {
|
|
859
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
860
|
+
}
|
|
861
|
+
await strapi2.db.transaction(async () => {
|
|
862
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
863
|
+
where: {
|
|
864
|
+
id: {
|
|
865
|
+
$in: release2.actions.map((action) => action.id)
|
|
866
|
+
}
|
|
584
867
|
}
|
|
585
|
-
}
|
|
868
|
+
});
|
|
869
|
+
await strapi2.entityService.delete(RELEASE_MODEL_UID, releaseId);
|
|
586
870
|
});
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
{
|
|
596
|
-
|
|
597
|
-
|
|
871
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling") && release2.scheduledAt) {
|
|
872
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
873
|
+
await schedulingService.cancel(release2.id);
|
|
874
|
+
}
|
|
875
|
+
strapi2.telemetry.send("didDeleteContentRelease");
|
|
876
|
+
return release2;
|
|
877
|
+
},
|
|
878
|
+
async publish(releaseId) {
|
|
879
|
+
try {
|
|
880
|
+
const releaseWithPopulatedActionEntries = await strapi2.entityService.findOne(
|
|
881
|
+
RELEASE_MODEL_UID,
|
|
882
|
+
releaseId,
|
|
883
|
+
{
|
|
598
884
|
populate: {
|
|
599
|
-
|
|
600
|
-
|
|
885
|
+
actions: {
|
|
886
|
+
populate: {
|
|
887
|
+
entry: {
|
|
888
|
+
fields: ["id"]
|
|
889
|
+
}
|
|
890
|
+
}
|
|
601
891
|
}
|
|
602
892
|
}
|
|
603
893
|
}
|
|
894
|
+
);
|
|
895
|
+
if (!releaseWithPopulatedActionEntries) {
|
|
896
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
604
897
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
if (!releaseWithPopulatedActionEntries) {
|
|
608
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
609
|
-
}
|
|
610
|
-
if (releaseWithPopulatedActionEntries.releasedAt) {
|
|
611
|
-
throw new utils.errors.ValidationError("Release already published");
|
|
612
|
-
}
|
|
613
|
-
if (releaseWithPopulatedActionEntries.actions.length === 0) {
|
|
614
|
-
throw new utils.errors.ValidationError("No entries to publish");
|
|
615
|
-
}
|
|
616
|
-
const collectionTypeActions = {};
|
|
617
|
-
const singleTypeActions = [];
|
|
618
|
-
for (const action of releaseWithPopulatedActionEntries.actions) {
|
|
619
|
-
const contentTypeUid = action.contentType;
|
|
620
|
-
if (strapi2.contentTypes[contentTypeUid].kind === "collectionType") {
|
|
621
|
-
if (!collectionTypeActions[contentTypeUid]) {
|
|
622
|
-
collectionTypeActions[contentTypeUid] = {
|
|
623
|
-
entriestoPublishIds: [],
|
|
624
|
-
entriesToUnpublishIds: []
|
|
625
|
-
};
|
|
898
|
+
if (releaseWithPopulatedActionEntries.releasedAt) {
|
|
899
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
626
900
|
}
|
|
627
|
-
if (
|
|
628
|
-
|
|
629
|
-
} else {
|
|
630
|
-
collectionTypeActions[contentTypeUid].entriesToUnpublishIds.push(action.entry.id);
|
|
901
|
+
if (releaseWithPopulatedActionEntries.actions.length === 0) {
|
|
902
|
+
throw new utils.errors.ValidationError("No entries to publish");
|
|
631
903
|
}
|
|
632
|
-
|
|
633
|
-
singleTypeActions
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
await entityManagerService.publish(entry, uid);
|
|
904
|
+
const collectionTypeActions = {};
|
|
905
|
+
const singleTypeActions = [];
|
|
906
|
+
for (const action of releaseWithPopulatedActionEntries.actions) {
|
|
907
|
+
const contentTypeUid = action.contentType;
|
|
908
|
+
if (strapi2.contentTypes[contentTypeUid].kind === "collectionType") {
|
|
909
|
+
if (!collectionTypeActions[contentTypeUid]) {
|
|
910
|
+
collectionTypeActions[contentTypeUid] = {
|
|
911
|
+
entriestoPublishIds: [],
|
|
912
|
+
entriesToUnpublishIds: []
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
if (action.type === "publish") {
|
|
916
|
+
collectionTypeActions[contentTypeUid].entriestoPublishIds.push(action.entry.id);
|
|
917
|
+
} else {
|
|
918
|
+
collectionTypeActions[contentTypeUid].entriesToUnpublishIds.push(action.entry.id);
|
|
919
|
+
}
|
|
649
920
|
} else {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
;
|
|
655
|
-
else {
|
|
656
|
-
throw error;
|
|
921
|
+
singleTypeActions.push({
|
|
922
|
+
uid: contentTypeUid,
|
|
923
|
+
action: action.type,
|
|
924
|
+
id: action.entry.id
|
|
925
|
+
});
|
|
657
926
|
}
|
|
658
927
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
928
|
+
const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
|
|
929
|
+
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
930
|
+
await strapi2.db.transaction(async () => {
|
|
931
|
+
for (const { uid, action, id } of singleTypeActions) {
|
|
932
|
+
const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
|
|
933
|
+
const entry = await strapi2.entityService.findOne(uid, id, { populate });
|
|
934
|
+
try {
|
|
935
|
+
if (action === "publish") {
|
|
936
|
+
await entityManagerService.publish(entry, uid);
|
|
937
|
+
} else {
|
|
938
|
+
await entityManagerService.unpublish(entry, uid);
|
|
669
939
|
}
|
|
670
|
-
}
|
|
671
|
-
|
|
940
|
+
} catch (error) {
|
|
941
|
+
if (error instanceof utils.errors.ApplicationError && (error.message === "already.published" || error.message === "already.draft")) {
|
|
942
|
+
} else {
|
|
943
|
+
throw error;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
672
946
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
947
|
+
for (const contentTypeUid of Object.keys(collectionTypeActions)) {
|
|
948
|
+
const populate = await populateBuilderService(contentTypeUid).populateDeep(Infinity).build();
|
|
949
|
+
const { entriestoPublishIds, entriesToUnpublishIds } = collectionTypeActions[contentTypeUid];
|
|
950
|
+
const entriesToPublish = await strapi2.entityService.findMany(
|
|
951
|
+
contentTypeUid,
|
|
952
|
+
{
|
|
953
|
+
filters: {
|
|
954
|
+
id: {
|
|
955
|
+
$in: entriestoPublishIds
|
|
956
|
+
}
|
|
957
|
+
},
|
|
958
|
+
populate
|
|
680
959
|
}
|
|
681
|
-
|
|
682
|
-
|
|
960
|
+
);
|
|
961
|
+
const entriesToUnpublish = await strapi2.entityService.findMany(
|
|
962
|
+
contentTypeUid,
|
|
963
|
+
{
|
|
964
|
+
filters: {
|
|
965
|
+
id: {
|
|
966
|
+
$in: entriesToUnpublishIds
|
|
967
|
+
}
|
|
968
|
+
},
|
|
969
|
+
populate
|
|
970
|
+
}
|
|
971
|
+
);
|
|
972
|
+
if (entriesToPublish.length > 0) {
|
|
973
|
+
await entityManagerService.publishMany(entriesToPublish, contentTypeUid);
|
|
974
|
+
}
|
|
975
|
+
if (entriesToUnpublish.length > 0) {
|
|
976
|
+
await entityManagerService.unpublishMany(entriesToUnpublish, contentTypeUid);
|
|
977
|
+
}
|
|
683
978
|
}
|
|
684
|
-
);
|
|
685
|
-
|
|
686
|
-
|
|
979
|
+
});
|
|
980
|
+
const release2 = await strapi2.entityService.update(RELEASE_MODEL_UID, releaseId, {
|
|
981
|
+
data: {
|
|
982
|
+
/*
|
|
983
|
+
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">> looks like it's wrong
|
|
984
|
+
*/
|
|
985
|
+
// @ts-expect-error see above
|
|
986
|
+
releasedAt: /* @__PURE__ */ new Date()
|
|
987
|
+
},
|
|
988
|
+
populate: {
|
|
989
|
+
actions: {
|
|
990
|
+
// @ts-expect-error is not expecting count but it is working
|
|
991
|
+
count: true
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
});
|
|
995
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
996
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
997
|
+
isPublished: true,
|
|
998
|
+
release: release2
|
|
999
|
+
});
|
|
687
1000
|
}
|
|
688
|
-
|
|
689
|
-
|
|
1001
|
+
strapi2.telemetry.send("didPublishContentRelease");
|
|
1002
|
+
return release2;
|
|
1003
|
+
} catch (error) {
|
|
1004
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
1005
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
1006
|
+
isPublished: false,
|
|
1007
|
+
error
|
|
1008
|
+
});
|
|
690
1009
|
}
|
|
1010
|
+
strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1011
|
+
where: { id: releaseId },
|
|
1012
|
+
data: {
|
|
1013
|
+
status: "failed"
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
1016
|
+
throw error;
|
|
691
1017
|
}
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
1018
|
+
},
|
|
1019
|
+
async updateAction(actionId, releaseId, update) {
|
|
1020
|
+
const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
1021
|
+
where: {
|
|
1022
|
+
id: actionId,
|
|
1023
|
+
release: {
|
|
1024
|
+
id: releaseId,
|
|
1025
|
+
releasedAt: {
|
|
1026
|
+
$null: true
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
},
|
|
1030
|
+
data: update
|
|
1031
|
+
});
|
|
1032
|
+
if (!updatedAction) {
|
|
1033
|
+
throw new utils.errors.NotFoundError(
|
|
1034
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
1035
|
+
);
|
|
700
1036
|
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
1037
|
+
return updatedAction;
|
|
1038
|
+
},
|
|
1039
|
+
async deleteAction(actionId, releaseId) {
|
|
1040
|
+
const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
|
|
1041
|
+
where: {
|
|
1042
|
+
id: actionId,
|
|
1043
|
+
release: {
|
|
1044
|
+
id: releaseId,
|
|
1045
|
+
releasedAt: {
|
|
1046
|
+
$null: true
|
|
1047
|
+
}
|
|
712
1048
|
}
|
|
713
1049
|
}
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
);
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
release: {
|
|
729
|
-
id: releaseId,
|
|
730
|
-
releasedAt: {
|
|
731
|
-
$null: true
|
|
1050
|
+
});
|
|
1051
|
+
if (!deletedAction) {
|
|
1052
|
+
throw new utils.errors.NotFoundError(
|
|
1053
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
this.updateReleaseStatus(releaseId);
|
|
1057
|
+
return deletedAction;
|
|
1058
|
+
},
|
|
1059
|
+
async updateReleaseStatus(releaseId) {
|
|
1060
|
+
const [totalActions, invalidActions] = await Promise.all([
|
|
1061
|
+
this.countActions({
|
|
1062
|
+
filters: {
|
|
1063
|
+
release: releaseId
|
|
732
1064
|
}
|
|
1065
|
+
}),
|
|
1066
|
+
this.countActions({
|
|
1067
|
+
filters: {
|
|
1068
|
+
release: releaseId,
|
|
1069
|
+
isEntryValid: false
|
|
1070
|
+
}
|
|
1071
|
+
})
|
|
1072
|
+
]);
|
|
1073
|
+
if (totalActions > 0) {
|
|
1074
|
+
if (invalidActions > 0) {
|
|
1075
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1076
|
+
where: {
|
|
1077
|
+
id: releaseId
|
|
1078
|
+
},
|
|
1079
|
+
data: {
|
|
1080
|
+
status: "blocked"
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
733
1083
|
}
|
|
1084
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1085
|
+
where: {
|
|
1086
|
+
id: releaseId
|
|
1087
|
+
},
|
|
1088
|
+
data: {
|
|
1089
|
+
status: "ready"
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
734
1092
|
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
1093
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1094
|
+
where: {
|
|
1095
|
+
id: releaseId
|
|
1096
|
+
},
|
|
1097
|
+
data: {
|
|
1098
|
+
status: "empty"
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
740
1101
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
});
|
|
1102
|
+
};
|
|
1103
|
+
};
|
|
744
1104
|
const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
745
1105
|
async validateUniqueEntry(releaseId, releaseActionArgs) {
|
|
746
1106
|
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
@@ -865,11 +1225,21 @@ const services = {
|
|
|
865
1225
|
};
|
|
866
1226
|
const RELEASE_SCHEMA = yup__namespace.object().shape({
|
|
867
1227
|
name: yup__namespace.string().trim().required(),
|
|
868
|
-
// scheduledAt is a date, but we always receive strings from the client
|
|
869
1228
|
scheduledAt: yup__namespace.string().nullable(),
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
1229
|
+
isScheduled: yup__namespace.boolean().optional(),
|
|
1230
|
+
time: yup__namespace.string().when("isScheduled", {
|
|
1231
|
+
is: true,
|
|
1232
|
+
then: yup__namespace.string().trim().required(),
|
|
1233
|
+
otherwise: yup__namespace.string().nullable()
|
|
1234
|
+
}),
|
|
1235
|
+
timezone: yup__namespace.string().when("isScheduled", {
|
|
1236
|
+
is: true,
|
|
1237
|
+
then: yup__namespace.string().required().nullable(),
|
|
1238
|
+
otherwise: yup__namespace.string().nullable()
|
|
1239
|
+
}),
|
|
1240
|
+
date: yup__namespace.string().when("isScheduled", {
|
|
1241
|
+
is: true,
|
|
1242
|
+
then: yup__namespace.string().required().nullable(),
|
|
873
1243
|
otherwise: yup__namespace.string().nullable()
|
|
874
1244
|
})
|
|
875
1245
|
}).required().noUnknown();
|
|
@@ -904,7 +1274,12 @@ const releaseController = {
|
|
|
904
1274
|
}
|
|
905
1275
|
};
|
|
906
1276
|
});
|
|
907
|
-
|
|
1277
|
+
const pendingReleasesCount = await strapi.query(RELEASE_MODEL_UID).count({
|
|
1278
|
+
where: {
|
|
1279
|
+
releasedAt: null
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
ctx.body = { data, meta: { pagination, pendingReleasesCount } };
|
|
908
1283
|
}
|
|
909
1284
|
},
|
|
910
1285
|
async findOne(ctx) {
|
|
@@ -1275,6 +1650,9 @@ const getPlugin = () => {
|
|
|
1275
1650
|
};
|
|
1276
1651
|
}
|
|
1277
1652
|
return {
|
|
1653
|
+
// Always return register, it handles its own feature check
|
|
1654
|
+
register,
|
|
1655
|
+
// Always return contentTypes to avoid losing data when the feature is disabled
|
|
1278
1656
|
contentTypes
|
|
1279
1657
|
};
|
|
1280
1658
|
};
|