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