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