@strapi/content-releases 0.0.0-next.e1ede8c55a0e1e22ce20137bf238fc374bd5dd51 → 0.0.0-next.f8af92b375dc730ba47ed2117f25df893aae696c
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-o5_WfqR-.js → App-OK4Xac-O.js} +572 -224
- package/dist/_chunks/App-OK4Xac-O.js.map +1 -0
- package/dist/_chunks/App-xAkiD42p.mjs +1292 -0
- package/dist/_chunks/App-xAkiD42p.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-haKSQIo8.js → en-r0otWaln.js} +19 -4
- package/dist/_chunks/en-r0otWaln.js.map +1 -0
- package/dist/_chunks/{en-ngTk74JV.mjs → en-veqvqeEr.mjs} +19 -4
- package/dist/_chunks/en-veqvqeEr.mjs.map +1 -0
- package/dist/_chunks/{index-EdBmRHRU.js → index-JvA2_26n.js} +220 -54
- package/dist/_chunks/index-JvA2_26n.js.map +1 -0
- package/dist/_chunks/{index-XAQOX_IB.mjs → index-exoiSU3V.mjs} +231 -65
- package/dist/_chunks/index-exoiSU3V.mjs.map +1 -0
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +3 -2
- package/dist/admin/index.mjs.map +1 -1
- package/dist/server/index.js +749 -302
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +749 -303
- package/dist/server/index.mjs.map +1 -1
- package/package.json +13 -9
- package/dist/_chunks/App-g2P5kbSm.mjs +0 -945
- package/dist/_chunks/App-g2P5kbSm.mjs.map +0 -1
- package/dist/_chunks/App-o5_WfqR-.js.map +0 -1
- package/dist/_chunks/en-haKSQIo8.js.map +0 -1
- package/dist/_chunks/en-ngTk74JV.mjs.map +0 -1
- package/dist/_chunks/index-EdBmRHRU.js.map +0 -1
- package/dist/_chunks/index-XAQOX_IB.mjs.map +0 -1
package/dist/server/index.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { setCreatorFields, errors, validateYupSchema, yup as yup$1 } from "@strapi/utils";
|
|
1
|
+
import { contentTypes as contentTypes$1, mapAsync, setCreatorFields, errors, validateYupSchema, yup as yup$1 } from "@strapi/utils";
|
|
2
|
+
import { difference, keys } from "lodash";
|
|
2
3
|
import _ from "lodash/fp";
|
|
4
|
+
import EE from "@strapi/strapi/dist/utils/ee";
|
|
5
|
+
import { scheduleJob } from "node-schedule";
|
|
3
6
|
import * as yup from "yup";
|
|
4
7
|
const RELEASE_MODEL_UID = "plugin::content-releases.release";
|
|
5
8
|
const RELEASE_ACTION_MODEL_UID = "plugin::content-releases.release-action";
|
|
@@ -47,10 +50,114 @@ const ACTIONS = [
|
|
|
47
50
|
pluginName: "content-releases"
|
|
48
51
|
}
|
|
49
52
|
];
|
|
50
|
-
const
|
|
53
|
+
const ALLOWED_WEBHOOK_EVENTS = {
|
|
54
|
+
RELEASES_PUBLISH: "releases.publish"
|
|
55
|
+
};
|
|
56
|
+
async function deleteActionsOnDisableDraftAndPublish({
|
|
57
|
+
oldContentTypes,
|
|
58
|
+
contentTypes: contentTypes2
|
|
59
|
+
}) {
|
|
60
|
+
if (!oldContentTypes) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (const uid in contentTypes2) {
|
|
64
|
+
if (!oldContentTypes[uid]) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const oldContentType = oldContentTypes[uid];
|
|
68
|
+
const contentType = contentTypes2[uid];
|
|
69
|
+
if (contentTypes$1.hasDraftAndPublish(oldContentType) && !contentTypes$1.hasDraftAndPublish(contentType)) {
|
|
70
|
+
await strapi.db?.queryBuilder(RELEASE_ACTION_MODEL_UID).delete().where({ contentType: uid }).execute();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function deleteActionsOnDeleteContentType({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
75
|
+
const deletedContentTypes = difference(keys(oldContentTypes), keys(contentTypes2)) ?? [];
|
|
76
|
+
if (deletedContentTypes.length) {
|
|
77
|
+
await mapAsync(deletedContentTypes, async (deletedContentTypeUID) => {
|
|
78
|
+
return strapi.db?.queryBuilder(RELEASE_ACTION_MODEL_UID).delete().where({ contentType: deletedContentTypeUID }).execute();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const { features: features$2 } = require("@strapi/strapi/dist/utils/ee");
|
|
51
83
|
const register = async ({ strapi: strapi2 }) => {
|
|
52
|
-
if (features$
|
|
84
|
+
if (features$2.isEnabled("cms-content-releases")) {
|
|
53
85
|
await strapi2.admin.services.permission.actionProvider.registerMany(ACTIONS);
|
|
86
|
+
strapi2.hook("strapi::content-types.beforeSync").register(deleteActionsOnDisableDraftAndPublish);
|
|
87
|
+
strapi2.hook("strapi::content-types.afterSync").register(deleteActionsOnDeleteContentType);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const getService = (name, { strapi: strapi2 } = { strapi: global.strapi }) => {
|
|
91
|
+
return strapi2.plugin("content-releases").service(name);
|
|
92
|
+
};
|
|
93
|
+
const { features: features$1 } = require("@strapi/strapi/dist/utils/ee");
|
|
94
|
+
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
95
|
+
if (features$1.isEnabled("cms-content-releases")) {
|
|
96
|
+
strapi2.db.lifecycles.subscribe({
|
|
97
|
+
afterDelete(event) {
|
|
98
|
+
const { model, result } = event;
|
|
99
|
+
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
100
|
+
const { id } = result;
|
|
101
|
+
strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
102
|
+
where: {
|
|
103
|
+
target_type: model.uid,
|
|
104
|
+
target_id: id
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
/**
|
|
110
|
+
* deleteMany hook doesn't return the deleted entries ids
|
|
111
|
+
* so we need to fetch them before deleting the entries to save the ids on our state
|
|
112
|
+
*/
|
|
113
|
+
async beforeDeleteMany(event) {
|
|
114
|
+
const { model, params } = event;
|
|
115
|
+
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
116
|
+
const { where } = params;
|
|
117
|
+
const entriesToDelete = await strapi2.db.query(model.uid).findMany({ select: ["id"], where });
|
|
118
|
+
event.state.entriesToDelete = entriesToDelete;
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* We delete the release actions related to deleted entries
|
|
123
|
+
* We make this only after deleteMany is succesfully executed to avoid errors
|
|
124
|
+
*/
|
|
125
|
+
async afterDeleteMany(event) {
|
|
126
|
+
const { model, state } = event;
|
|
127
|
+
const entriesToDelete = state.entriesToDelete;
|
|
128
|
+
if (entriesToDelete) {
|
|
129
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
130
|
+
where: {
|
|
131
|
+
target_type: model.uid,
|
|
132
|
+
target_id: {
|
|
133
|
+
$in: entriesToDelete.map((entry) => entry.id)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
141
|
+
getService("scheduling", { strapi: strapi2 }).syncFromDatabase().catch((err) => {
|
|
142
|
+
strapi2.log.error(
|
|
143
|
+
"Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling."
|
|
144
|
+
);
|
|
145
|
+
throw err;
|
|
146
|
+
});
|
|
147
|
+
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
|
148
|
+
strapi2.webhookStore.addAllowedEvent(key, value);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const destroy = async ({ strapi: strapi2 }) => {
|
|
154
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
155
|
+
const scheduledJobs = getService("scheduling", {
|
|
156
|
+
strapi: strapi2
|
|
157
|
+
}).getAll();
|
|
158
|
+
for (const [, job] of scheduledJobs) {
|
|
159
|
+
job.cancel();
|
|
160
|
+
}
|
|
54
161
|
}
|
|
55
162
|
};
|
|
56
163
|
const schema$1 = {
|
|
@@ -79,6 +186,12 @@ const schema$1 = {
|
|
|
79
186
|
releasedAt: {
|
|
80
187
|
type: "datetime"
|
|
81
188
|
},
|
|
189
|
+
scheduledAt: {
|
|
190
|
+
type: "datetime"
|
|
191
|
+
},
|
|
192
|
+
timezone: {
|
|
193
|
+
type: "string"
|
|
194
|
+
},
|
|
82
195
|
actions: {
|
|
83
196
|
type: "relation",
|
|
84
197
|
relation: "oneToMany",
|
|
@@ -141,327 +254,516 @@ const contentTypes = {
|
|
|
141
254
|
release: release$1,
|
|
142
255
|
"release-action": releaseAction$1
|
|
143
256
|
};
|
|
144
|
-
const getService = (name, { strapi: strapi2 } = { strapi: global.strapi }) => {
|
|
145
|
-
return strapi2.plugin("content-releases").service(name);
|
|
146
|
-
};
|
|
147
257
|
const getGroupName = (queryValue) => {
|
|
148
258
|
switch (queryValue) {
|
|
149
259
|
case "contentType":
|
|
150
|
-
return "
|
|
260
|
+
return "contentType.displayName";
|
|
151
261
|
case "action":
|
|
152
262
|
return "type";
|
|
153
263
|
case "locale":
|
|
154
|
-
return _.getOr("No locale", "
|
|
264
|
+
return _.getOr("No locale", "locale.name");
|
|
155
265
|
default:
|
|
156
|
-
return "
|
|
266
|
+
return "contentType.displayName";
|
|
157
267
|
}
|
|
158
268
|
};
|
|
159
|
-
const createReleaseService = ({ strapi: strapi2 }) =>
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
269
|
+
const createReleaseService = ({ strapi: strapi2 }) => {
|
|
270
|
+
const dispatchWebhook = (event, { isPublished, release: release2, error }) => {
|
|
271
|
+
strapi2.eventHub.emit(event, {
|
|
272
|
+
isPublished,
|
|
273
|
+
error,
|
|
274
|
+
release: release2
|
|
164
275
|
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
276
|
+
};
|
|
277
|
+
return {
|
|
278
|
+
async create(releaseData, { user }) {
|
|
279
|
+
const releaseWithCreatorFields = await setCreatorFields({ user })(releaseData);
|
|
280
|
+
const {
|
|
281
|
+
validatePendingReleasesLimit,
|
|
282
|
+
validateUniqueNameForPendingRelease,
|
|
283
|
+
validateScheduledAtIsLaterThanNow
|
|
284
|
+
} = getService("release-validation", { strapi: strapi2 });
|
|
285
|
+
await Promise.all([
|
|
286
|
+
validatePendingReleasesLimit(),
|
|
287
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
|
|
288
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
289
|
+
]);
|
|
290
|
+
const release2 = await strapi2.entityService.create(RELEASE_MODEL_UID, {
|
|
291
|
+
data: releaseWithCreatorFields
|
|
292
|
+
});
|
|
293
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling") && releaseWithCreatorFields.scheduledAt) {
|
|
294
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
295
|
+
await schedulingService.set(release2.id, release2.scheduledAt);
|
|
180
296
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
297
|
+
strapi2.telemetry.send("didCreateContentRelease");
|
|
298
|
+
return release2;
|
|
299
|
+
},
|
|
300
|
+
async findOne(id, query = {}) {
|
|
301
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id, {
|
|
302
|
+
...query
|
|
303
|
+
});
|
|
304
|
+
return release2;
|
|
305
|
+
},
|
|
306
|
+
findPage(query) {
|
|
307
|
+
return strapi2.entityService.findPage(RELEASE_MODEL_UID, {
|
|
308
|
+
...query,
|
|
309
|
+
populate: {
|
|
310
|
+
actions: {
|
|
311
|
+
// @ts-expect-error Ignore missing properties
|
|
312
|
+
count: true
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
},
|
|
317
|
+
async findManyWithContentTypeEntryAttached(contentTypeUid, entryId) {
|
|
318
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
319
|
+
where: {
|
|
320
|
+
actions: {
|
|
321
|
+
target_type: contentTypeUid,
|
|
322
|
+
target_id: entryId
|
|
323
|
+
},
|
|
324
|
+
releasedAt: {
|
|
325
|
+
$null: true
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
populate: {
|
|
329
|
+
// Filter the action to get only the content type entry
|
|
330
|
+
actions: {
|
|
331
|
+
where: {
|
|
200
332
|
target_type: contentTypeUid,
|
|
201
333
|
target_id: entryId
|
|
202
334
|
}
|
|
203
335
|
}
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
actions: null
|
|
207
336
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
337
|
+
});
|
|
338
|
+
return releases.map((release2) => {
|
|
339
|
+
if (release2.actions?.length) {
|
|
340
|
+
const [actionForEntry] = release2.actions;
|
|
341
|
+
delete release2.actions;
|
|
342
|
+
return {
|
|
343
|
+
...release2,
|
|
344
|
+
action: actionForEntry
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
return release2;
|
|
348
|
+
});
|
|
349
|
+
},
|
|
350
|
+
async findManyWithoutContentTypeEntryAttached(contentTypeUid, entryId) {
|
|
351
|
+
const releasesRelated = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
352
|
+
where: {
|
|
353
|
+
releasedAt: {
|
|
354
|
+
$null: true
|
|
355
|
+
},
|
|
356
|
+
actions: {
|
|
357
|
+
target_type: contentTypeUid,
|
|
358
|
+
target_id: entryId
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
213
363
|
where: {
|
|
214
|
-
|
|
215
|
-
|
|
364
|
+
$or: [
|
|
365
|
+
{
|
|
366
|
+
id: {
|
|
367
|
+
$notIn: releasesRelated.map((release2) => release2.id)
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
actions: null
|
|
372
|
+
}
|
|
373
|
+
],
|
|
374
|
+
releasedAt: {
|
|
375
|
+
$null: true
|
|
376
|
+
}
|
|
216
377
|
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
378
|
+
});
|
|
379
|
+
return releases.map((release2) => {
|
|
380
|
+
if (release2.actions?.length) {
|
|
381
|
+
const [actionForEntry] = release2.actions;
|
|
382
|
+
delete release2.actions;
|
|
383
|
+
return {
|
|
384
|
+
...release2,
|
|
385
|
+
action: actionForEntry
|
|
386
|
+
};
|
|
224
387
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
388
|
+
return release2;
|
|
389
|
+
});
|
|
390
|
+
},
|
|
391
|
+
async update(id, releaseData, { user }) {
|
|
392
|
+
const releaseWithCreatorFields = await setCreatorFields({ user, isEdition: true })(
|
|
393
|
+
releaseData
|
|
394
|
+
);
|
|
395
|
+
const { validateUniqueNameForPendingRelease, validateScheduledAtIsLaterThanNow } = getService(
|
|
396
|
+
"release-validation",
|
|
397
|
+
{ strapi: strapi2 }
|
|
398
|
+
);
|
|
399
|
+
await Promise.all([
|
|
400
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name, id),
|
|
401
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
402
|
+
]);
|
|
403
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id);
|
|
404
|
+
if (!release2) {
|
|
405
|
+
throw new errors.NotFoundError(`No release found for id ${id}`);
|
|
228
406
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (release2.actions?.length) {
|
|
232
|
-
const [actionForEntry] = release2.actions;
|
|
233
|
-
delete release2.actions;
|
|
234
|
-
return {
|
|
235
|
-
...release2,
|
|
236
|
-
action: actionForEntry
|
|
237
|
-
};
|
|
407
|
+
if (release2.releasedAt) {
|
|
408
|
+
throw new errors.ValidationError("Release already published");
|
|
238
409
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
return release2;
|
|
256
|
-
},
|
|
257
|
-
async createAction(releaseId, action) {
|
|
258
|
-
const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
|
|
259
|
-
strapi: strapi2
|
|
260
|
-
});
|
|
261
|
-
await Promise.all([
|
|
262
|
-
validateEntryContentType(action.entry.contentType),
|
|
263
|
-
validateUniqueEntry(releaseId, action)
|
|
264
|
-
]);
|
|
265
|
-
const { entry, type } = action;
|
|
266
|
-
return strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
|
|
267
|
-
data: {
|
|
268
|
-
type,
|
|
269
|
-
contentType: entry.contentType,
|
|
270
|
-
locale: entry.locale,
|
|
271
|
-
entry: {
|
|
272
|
-
id: entry.id,
|
|
273
|
-
__type: entry.contentType,
|
|
274
|
-
__pivot: { field: "entry" }
|
|
275
|
-
},
|
|
276
|
-
release: releaseId
|
|
277
|
-
},
|
|
278
|
-
populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
|
|
279
|
-
});
|
|
280
|
-
},
|
|
281
|
-
async findActions(releaseId, query) {
|
|
282
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
283
|
-
fields: ["id"]
|
|
284
|
-
});
|
|
285
|
-
if (!release2) {
|
|
286
|
-
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
287
|
-
}
|
|
288
|
-
return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
|
|
289
|
-
...query,
|
|
290
|
-
populate: {
|
|
291
|
-
entry: true
|
|
292
|
-
},
|
|
293
|
-
filters: {
|
|
294
|
-
release: releaseId
|
|
410
|
+
const updatedRelease = await strapi2.entityService.update(RELEASE_MODEL_UID, id, {
|
|
411
|
+
/*
|
|
412
|
+
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">>
|
|
413
|
+
* is not compatible with the type we are passing here: UpdateRelease.Request['body']
|
|
414
|
+
*/
|
|
415
|
+
// @ts-expect-error see above
|
|
416
|
+
data: releaseWithCreatorFields
|
|
417
|
+
});
|
|
418
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
419
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
420
|
+
if (releaseData.scheduledAt) {
|
|
421
|
+
await schedulingService.set(id, releaseData.scheduledAt);
|
|
422
|
+
} else if (release2.scheduledAt) {
|
|
423
|
+
schedulingService.cancel(id);
|
|
424
|
+
}
|
|
295
425
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
426
|
+
strapi2.telemetry.send("didUpdateContentRelease");
|
|
427
|
+
return updatedRelease;
|
|
428
|
+
},
|
|
429
|
+
async createAction(releaseId, action) {
|
|
430
|
+
const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
|
|
431
|
+
strapi: strapi2
|
|
432
|
+
});
|
|
433
|
+
await Promise.all([
|
|
434
|
+
validateEntryContentType(action.entry.contentType),
|
|
435
|
+
validateUniqueEntry(releaseId, action)
|
|
436
|
+
]);
|
|
437
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
|
|
438
|
+
if (!release2) {
|
|
439
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
305
440
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
...action,
|
|
320
|
-
entry: {
|
|
321
|
-
id: action.entry.id,
|
|
322
|
-
contentType: {
|
|
323
|
-
displayName,
|
|
324
|
-
mainFieldValue: action.entry[mainField]
|
|
441
|
+
if (release2.releasedAt) {
|
|
442
|
+
throw new errors.ValidationError("Release already published");
|
|
443
|
+
}
|
|
444
|
+
const { entry, type } = action;
|
|
445
|
+
return strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
|
|
446
|
+
data: {
|
|
447
|
+
type,
|
|
448
|
+
contentType: entry.contentType,
|
|
449
|
+
locale: entry.locale,
|
|
450
|
+
entry: {
|
|
451
|
+
id: entry.id,
|
|
452
|
+
__type: entry.contentType,
|
|
453
|
+
__pivot: { field: "entry" }
|
|
325
454
|
},
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
});
|
|
331
|
-
const groupName = getGroupName(groupBy);
|
|
332
|
-
return _.groupBy(groupName)(formattedData);
|
|
333
|
-
},
|
|
334
|
-
async getContentTypesDataForActions(contentTypesUids) {
|
|
335
|
-
const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
|
|
336
|
-
const contentTypesData = {};
|
|
337
|
-
for (const contentTypeUid of contentTypesUids) {
|
|
338
|
-
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
339
|
-
uid: contentTypeUid
|
|
455
|
+
release: releaseId
|
|
456
|
+
},
|
|
457
|
+
populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
|
|
340
458
|
});
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
async delete(releaseId) {
|
|
349
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
350
|
-
populate: {
|
|
351
|
-
actions: {
|
|
352
|
-
fields: ["id"]
|
|
353
|
-
}
|
|
459
|
+
},
|
|
460
|
+
async findActions(releaseId, query) {
|
|
461
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
462
|
+
fields: ["id"]
|
|
463
|
+
});
|
|
464
|
+
if (!release2) {
|
|
465
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
354
466
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
throw new errors.ValidationError("Release already published");
|
|
361
|
-
}
|
|
362
|
-
await strapi2.db.transaction(async () => {
|
|
363
|
-
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
364
|
-
where: {
|
|
365
|
-
id: {
|
|
366
|
-
$in: release2.actions.map((action) => action.id)
|
|
467
|
+
return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
|
|
468
|
+
...query,
|
|
469
|
+
populate: {
|
|
470
|
+
entry: {
|
|
471
|
+
populate: "*"
|
|
367
472
|
}
|
|
473
|
+
},
|
|
474
|
+
filters: {
|
|
475
|
+
release: releaseId
|
|
368
476
|
}
|
|
369
477
|
});
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
478
|
+
},
|
|
479
|
+
async countActions(query) {
|
|
480
|
+
return strapi2.entityService.count(RELEASE_ACTION_MODEL_UID, query);
|
|
481
|
+
},
|
|
482
|
+
async groupActions(actions, groupBy) {
|
|
483
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
484
|
+
if (!acc.includes(action.contentType)) {
|
|
485
|
+
acc.push(action.contentType);
|
|
486
|
+
}
|
|
487
|
+
return acc;
|
|
488
|
+
}, []);
|
|
489
|
+
const allReleaseContentTypesDictionary = await this.getContentTypesDataForActions(
|
|
490
|
+
contentTypeUids
|
|
491
|
+
);
|
|
492
|
+
const allLocalesDictionary = await this.getLocalesDataForActions();
|
|
493
|
+
const formattedData = actions.map((action) => {
|
|
494
|
+
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
495
|
+
return {
|
|
496
|
+
...action,
|
|
497
|
+
locale: action.locale ? allLocalesDictionary[action.locale] : null,
|
|
498
|
+
contentType: {
|
|
499
|
+
displayName,
|
|
500
|
+
mainFieldValue: action.entry[mainField],
|
|
501
|
+
uid: action.contentType
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
});
|
|
505
|
+
const groupName = getGroupName(groupBy);
|
|
506
|
+
return _.groupBy(groupName)(formattedData);
|
|
507
|
+
},
|
|
508
|
+
async getLocalesDataForActions() {
|
|
509
|
+
if (!strapi2.plugin("i18n")) {
|
|
510
|
+
return {};
|
|
511
|
+
}
|
|
512
|
+
const allLocales = await strapi2.plugin("i18n").service("locales").find() || [];
|
|
513
|
+
return allLocales.reduce((acc, locale) => {
|
|
514
|
+
acc[locale.code] = { name: locale.name, code: locale.code };
|
|
515
|
+
return acc;
|
|
516
|
+
}, {});
|
|
517
|
+
},
|
|
518
|
+
async getContentTypesDataForActions(contentTypesUids) {
|
|
519
|
+
const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
|
|
520
|
+
const contentTypesData = {};
|
|
521
|
+
for (const contentTypeUid of contentTypesUids) {
|
|
522
|
+
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
523
|
+
uid: contentTypeUid
|
|
524
|
+
});
|
|
525
|
+
contentTypesData[contentTypeUid] = {
|
|
526
|
+
mainField: contentTypeConfig.settings.mainField,
|
|
527
|
+
displayName: strapi2.getModel(contentTypeUid).info.displayName
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
return contentTypesData;
|
|
531
|
+
},
|
|
532
|
+
getContentTypeModelsFromActions(actions) {
|
|
533
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
534
|
+
if (!acc.includes(action.contentType)) {
|
|
535
|
+
acc.push(action.contentType);
|
|
536
|
+
}
|
|
537
|
+
return acc;
|
|
538
|
+
}, []);
|
|
539
|
+
const contentTypeModelsMap = contentTypeUids.reduce(
|
|
540
|
+
(acc, contentTypeUid) => {
|
|
541
|
+
acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
|
|
542
|
+
return acc;
|
|
543
|
+
},
|
|
544
|
+
{}
|
|
545
|
+
);
|
|
546
|
+
return contentTypeModelsMap;
|
|
547
|
+
},
|
|
548
|
+
async getAllComponents() {
|
|
549
|
+
const contentManagerComponentsService = strapi2.plugin("content-manager").service("components");
|
|
550
|
+
const components = await contentManagerComponentsService.findAllComponents();
|
|
551
|
+
const componentsMap = components.reduce(
|
|
552
|
+
(acc, component) => {
|
|
553
|
+
acc[component.uid] = component;
|
|
554
|
+
return acc;
|
|
555
|
+
},
|
|
556
|
+
{}
|
|
557
|
+
);
|
|
558
|
+
return componentsMap;
|
|
559
|
+
},
|
|
560
|
+
async delete(releaseId) {
|
|
561
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
379
562
|
populate: {
|
|
380
563
|
actions: {
|
|
381
|
-
|
|
382
|
-
entry: true
|
|
383
|
-
}
|
|
564
|
+
fields: ["id"]
|
|
384
565
|
}
|
|
385
566
|
}
|
|
567
|
+
});
|
|
568
|
+
if (!release2) {
|
|
569
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
386
570
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
390
|
-
}
|
|
391
|
-
if (releaseWithPopulatedActionEntries.releasedAt) {
|
|
392
|
-
throw new errors.ValidationError("Release already published");
|
|
393
|
-
}
|
|
394
|
-
if (releaseWithPopulatedActionEntries.actions.length === 0) {
|
|
395
|
-
throw new errors.ValidationError("No entries to publish");
|
|
396
|
-
}
|
|
397
|
-
const actions = {};
|
|
398
|
-
for (const action of releaseWithPopulatedActionEntries.actions) {
|
|
399
|
-
const contentTypeUid = action.contentType;
|
|
400
|
-
if (!actions[contentTypeUid]) {
|
|
401
|
-
actions[contentTypeUid] = {
|
|
402
|
-
publish: [],
|
|
403
|
-
unpublish: []
|
|
404
|
-
};
|
|
571
|
+
if (release2.releasedAt) {
|
|
572
|
+
throw new errors.ValidationError("Release already published");
|
|
405
573
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
574
|
+
await strapi2.db.transaction(async () => {
|
|
575
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
576
|
+
where: {
|
|
577
|
+
id: {
|
|
578
|
+
$in: release2.actions.map((action) => action.id)
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
await strapi2.entityService.delete(RELEASE_MODEL_UID, releaseId);
|
|
583
|
+
});
|
|
584
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling") && release2.scheduledAt) {
|
|
585
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
586
|
+
await schedulingService.cancel(release2.id);
|
|
410
587
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
588
|
+
strapi2.telemetry.send("didDeleteContentRelease");
|
|
589
|
+
return release2;
|
|
590
|
+
},
|
|
591
|
+
async publish(releaseId) {
|
|
592
|
+
try {
|
|
593
|
+
const releaseWithPopulatedActionEntries = await strapi2.entityService.findOne(
|
|
594
|
+
RELEASE_MODEL_UID,
|
|
595
|
+
releaseId,
|
|
596
|
+
{
|
|
597
|
+
populate: {
|
|
598
|
+
actions: {
|
|
599
|
+
populate: {
|
|
600
|
+
entry: {
|
|
601
|
+
fields: ["id"]
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
);
|
|
608
|
+
if (!releaseWithPopulatedActionEntries) {
|
|
609
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
610
|
+
}
|
|
611
|
+
if (releaseWithPopulatedActionEntries.releasedAt) {
|
|
612
|
+
throw new errors.ValidationError("Release already published");
|
|
613
|
+
}
|
|
614
|
+
if (releaseWithPopulatedActionEntries.actions.length === 0) {
|
|
615
|
+
throw new errors.ValidationError("No entries to publish");
|
|
616
|
+
}
|
|
617
|
+
const collectionTypeActions = {};
|
|
618
|
+
const singleTypeActions = [];
|
|
619
|
+
for (const action of releaseWithPopulatedActionEntries.actions) {
|
|
620
|
+
const contentTypeUid = action.contentType;
|
|
621
|
+
if (strapi2.contentTypes[contentTypeUid].kind === "collectionType") {
|
|
622
|
+
if (!collectionTypeActions[contentTypeUid]) {
|
|
623
|
+
collectionTypeActions[contentTypeUid] = {
|
|
624
|
+
entriestoPublishIds: [],
|
|
625
|
+
entriesToUnpublishIds: []
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
if (action.type === "publish") {
|
|
629
|
+
collectionTypeActions[contentTypeUid].entriestoPublishIds.push(action.entry.id);
|
|
630
|
+
} else {
|
|
631
|
+
collectionTypeActions[contentTypeUid].entriesToUnpublishIds.push(action.entry.id);
|
|
632
|
+
}
|
|
633
|
+
} else {
|
|
634
|
+
singleTypeActions.push({
|
|
635
|
+
uid: contentTypeUid,
|
|
636
|
+
action: action.type,
|
|
637
|
+
id: action.entry.id
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
|
|
642
|
+
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
643
|
+
await strapi2.db.transaction(async () => {
|
|
644
|
+
for (const { uid, action, id } of singleTypeActions) {
|
|
645
|
+
const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
|
|
646
|
+
const entry = await strapi2.entityService.findOne(uid, id, { populate });
|
|
647
|
+
try {
|
|
648
|
+
if (action === "publish") {
|
|
649
|
+
await entityManagerService.publish(entry, uid);
|
|
650
|
+
} else {
|
|
651
|
+
await entityManagerService.unpublish(entry, uid);
|
|
652
|
+
}
|
|
653
|
+
} catch (error) {
|
|
654
|
+
if (error instanceof errors.ApplicationError && (error.message === "already.published" || error.message === "already.draft")) {
|
|
655
|
+
} else {
|
|
656
|
+
throw error;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
for (const contentTypeUid of Object.keys(collectionTypeActions)) {
|
|
661
|
+
const populate = await populateBuilderService(contentTypeUid).populateDeep(Infinity).build();
|
|
662
|
+
const { entriestoPublishIds, entriesToUnpublishIds } = collectionTypeActions[contentTypeUid];
|
|
663
|
+
const entriesToPublish = await strapi2.entityService.findMany(
|
|
664
|
+
contentTypeUid,
|
|
665
|
+
{
|
|
666
|
+
filters: {
|
|
667
|
+
id: {
|
|
668
|
+
$in: entriestoPublishIds
|
|
669
|
+
}
|
|
670
|
+
},
|
|
671
|
+
populate
|
|
672
|
+
}
|
|
673
|
+
);
|
|
674
|
+
const entriesToUnpublish = await strapi2.entityService.findMany(
|
|
675
|
+
contentTypeUid,
|
|
676
|
+
{
|
|
677
|
+
filters: {
|
|
678
|
+
id: {
|
|
679
|
+
$in: entriesToUnpublishIds
|
|
680
|
+
}
|
|
681
|
+
},
|
|
682
|
+
populate
|
|
683
|
+
}
|
|
684
|
+
);
|
|
685
|
+
if (entriesToPublish.length > 0) {
|
|
686
|
+
await entityManagerService.publishMany(entriesToPublish, contentTypeUid);
|
|
687
|
+
}
|
|
688
|
+
if (entriesToUnpublish.length > 0) {
|
|
689
|
+
await entityManagerService.unpublishMany(entriesToUnpublish, contentTypeUid);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
const release2 = await strapi2.entityService.update(RELEASE_MODEL_UID, releaseId, {
|
|
694
|
+
data: {
|
|
695
|
+
/*
|
|
696
|
+
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">> looks like it's wrong
|
|
697
|
+
*/
|
|
698
|
+
// @ts-expect-error see above
|
|
699
|
+
releasedAt: /* @__PURE__ */ new Date()
|
|
700
|
+
},
|
|
701
|
+
populate: {
|
|
702
|
+
actions: {
|
|
703
|
+
// @ts-expect-error is not expecting count but it is working
|
|
704
|
+
count: true
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
709
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
710
|
+
isPublished: true,
|
|
711
|
+
release: release2
|
|
712
|
+
});
|
|
418
713
|
}
|
|
419
|
-
|
|
420
|
-
|
|
714
|
+
strapi2.telemetry.send("didPublishContentRelease");
|
|
715
|
+
return release2;
|
|
716
|
+
} catch (error) {
|
|
717
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
718
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
719
|
+
isPublished: false,
|
|
720
|
+
error
|
|
721
|
+
});
|
|
421
722
|
}
|
|
723
|
+
throw error;
|
|
422
724
|
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
725
|
+
},
|
|
726
|
+
async updateAction(actionId, releaseId, update) {
|
|
727
|
+
const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
728
|
+
where: {
|
|
729
|
+
id: actionId,
|
|
730
|
+
release: {
|
|
731
|
+
id: releaseId,
|
|
732
|
+
releasedAt: {
|
|
733
|
+
$null: true
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
},
|
|
737
|
+
data: update
|
|
738
|
+
});
|
|
739
|
+
if (!updatedAction) {
|
|
740
|
+
throw new errors.NotFoundError(
|
|
741
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
742
|
+
);
|
|
431
743
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
)
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
async deleteAction(actionId, releaseId) {
|
|
451
|
-
const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
|
|
452
|
-
where: {
|
|
453
|
-
id: actionId,
|
|
454
|
-
release: releaseId
|
|
744
|
+
return updatedAction;
|
|
745
|
+
},
|
|
746
|
+
async deleteAction(actionId, releaseId) {
|
|
747
|
+
const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
|
|
748
|
+
where: {
|
|
749
|
+
id: actionId,
|
|
750
|
+
release: {
|
|
751
|
+
id: releaseId,
|
|
752
|
+
releasedAt: {
|
|
753
|
+
$null: true
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
if (!deletedAction) {
|
|
759
|
+
throw new errors.NotFoundError(
|
|
760
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
761
|
+
);
|
|
455
762
|
}
|
|
456
|
-
|
|
457
|
-
if (!deletedAction) {
|
|
458
|
-
throw new errors.NotFoundError(
|
|
459
|
-
`Action with id ${actionId} not found in release with id ${releaseId}`
|
|
460
|
-
);
|
|
763
|
+
return deletedAction;
|
|
461
764
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
});
|
|
765
|
+
};
|
|
766
|
+
};
|
|
465
767
|
const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
466
768
|
async validateUniqueEntry(releaseId, releaseActionArgs) {
|
|
467
769
|
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
@@ -489,11 +791,120 @@ const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
|
489
791
|
`Content type with uid ${contentTypeUid} does not have draftAndPublish enabled`
|
|
490
792
|
);
|
|
491
793
|
}
|
|
794
|
+
},
|
|
795
|
+
async validatePendingReleasesLimit() {
|
|
796
|
+
const maximumPendingReleases = (
|
|
797
|
+
// @ts-expect-error - options is not typed into features
|
|
798
|
+
EE.features.get("cms-content-releases")?.options?.maximumReleases || 3
|
|
799
|
+
);
|
|
800
|
+
const [, pendingReleasesCount] = await strapi2.db.query(RELEASE_MODEL_UID).findWithCount({
|
|
801
|
+
filters: {
|
|
802
|
+
releasedAt: {
|
|
803
|
+
$null: true
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
if (pendingReleasesCount >= maximumPendingReleases) {
|
|
808
|
+
throw new errors.ValidationError("You have reached the maximum number of pending releases");
|
|
809
|
+
}
|
|
810
|
+
},
|
|
811
|
+
async validateUniqueNameForPendingRelease(name, id) {
|
|
812
|
+
const pendingReleases = await strapi2.entityService.findMany(RELEASE_MODEL_UID, {
|
|
813
|
+
filters: {
|
|
814
|
+
releasedAt: {
|
|
815
|
+
$null: true
|
|
816
|
+
},
|
|
817
|
+
name,
|
|
818
|
+
...id && { id: { $ne: id } }
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
const isNameUnique = pendingReleases.length === 0;
|
|
822
|
+
if (!isNameUnique) {
|
|
823
|
+
throw new errors.ValidationError(`Release with name ${name} already exists`);
|
|
824
|
+
}
|
|
825
|
+
},
|
|
826
|
+
async validateScheduledAtIsLaterThanNow(scheduledAt) {
|
|
827
|
+
if (scheduledAt && new Date(scheduledAt) <= /* @__PURE__ */ new Date()) {
|
|
828
|
+
throw new errors.ValidationError("Scheduled at must be later than now");
|
|
829
|
+
}
|
|
492
830
|
}
|
|
493
831
|
});
|
|
494
|
-
const
|
|
832
|
+
const createSchedulingService = ({ strapi: strapi2 }) => {
|
|
833
|
+
const scheduledJobs = /* @__PURE__ */ new Map();
|
|
834
|
+
return {
|
|
835
|
+
async set(releaseId, scheduleDate) {
|
|
836
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id: releaseId, releasedAt: null } });
|
|
837
|
+
if (!release2) {
|
|
838
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
839
|
+
}
|
|
840
|
+
const job = scheduleJob(scheduleDate, async () => {
|
|
841
|
+
try {
|
|
842
|
+
await getService("release").publish(releaseId);
|
|
843
|
+
} catch (error) {
|
|
844
|
+
}
|
|
845
|
+
this.cancel(releaseId);
|
|
846
|
+
});
|
|
847
|
+
if (scheduledJobs.has(releaseId)) {
|
|
848
|
+
this.cancel(releaseId);
|
|
849
|
+
}
|
|
850
|
+
scheduledJobs.set(releaseId, job);
|
|
851
|
+
return scheduledJobs;
|
|
852
|
+
},
|
|
853
|
+
cancel(releaseId) {
|
|
854
|
+
if (scheduledJobs.has(releaseId)) {
|
|
855
|
+
scheduledJobs.get(releaseId).cancel();
|
|
856
|
+
scheduledJobs.delete(releaseId);
|
|
857
|
+
}
|
|
858
|
+
return scheduledJobs;
|
|
859
|
+
},
|
|
860
|
+
getAll() {
|
|
861
|
+
return scheduledJobs;
|
|
862
|
+
},
|
|
863
|
+
/**
|
|
864
|
+
* On bootstrap, we can use this function to make sure to sync the scheduled jobs from the database that are not yet released
|
|
865
|
+
* This is useful in case the server was restarted and the scheduled jobs were lost
|
|
866
|
+
* This also could be used to sync different Strapi instances in case of a cluster
|
|
867
|
+
*/
|
|
868
|
+
async syncFromDatabase() {
|
|
869
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
870
|
+
where: {
|
|
871
|
+
scheduledAt: {
|
|
872
|
+
$gte: /* @__PURE__ */ new Date()
|
|
873
|
+
},
|
|
874
|
+
releasedAt: null
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
for (const release2 of releases) {
|
|
878
|
+
this.set(release2.id, release2.scheduledAt);
|
|
879
|
+
}
|
|
880
|
+
return scheduledJobs;
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
};
|
|
884
|
+
const services = {
|
|
885
|
+
release: createReleaseService,
|
|
886
|
+
"release-validation": createReleaseValidationService,
|
|
887
|
+
...strapi.features.future.isEnabled("contentReleasesScheduling") ? { scheduling: createSchedulingService } : {}
|
|
888
|
+
};
|
|
495
889
|
const RELEASE_SCHEMA = yup.object().shape({
|
|
496
|
-
name: yup.string().trim().required()
|
|
890
|
+
name: yup.string().trim().required(),
|
|
891
|
+
scheduledAt: yup.string().nullable(),
|
|
892
|
+
isScheduled: yup.boolean().optional(),
|
|
893
|
+
time: yup.string().when("isScheduled", {
|
|
894
|
+
is: true,
|
|
895
|
+
then: yup.string().trim().required(),
|
|
896
|
+
otherwise: yup.string().nullable()
|
|
897
|
+
}),
|
|
898
|
+
timezone: yup.string().when("isScheduled", {
|
|
899
|
+
is: true,
|
|
900
|
+
then: yup.string().required().nullable(),
|
|
901
|
+
otherwise: yup.string().nullable()
|
|
902
|
+
}),
|
|
903
|
+
date: yup.string().when("isScheduled", {
|
|
904
|
+
is: true,
|
|
905
|
+
then: yup.string().required().nullable(),
|
|
906
|
+
otherwise: yup.string().nullable()
|
|
907
|
+
})
|
|
497
908
|
}).required().noUnknown();
|
|
498
909
|
const validateRelease = validateYupSchema(RELEASE_SCHEMA);
|
|
499
910
|
const releaseController = {
|
|
@@ -510,9 +921,7 @@ const releaseController = {
|
|
|
510
921
|
const contentTypeUid = query.contentTypeUid;
|
|
511
922
|
const entryId = query.entryId;
|
|
512
923
|
const hasEntryAttached = typeof query.hasEntryAttached === "string" ? JSON.parse(query.hasEntryAttached) : false;
|
|
513
|
-
const data = await releaseService.
|
|
514
|
-
hasEntryAttached
|
|
515
|
-
});
|
|
924
|
+
const data = hasEntryAttached ? await releaseService.findManyWithContentTypeEntryAttached(contentTypeUid, entryId) : await releaseService.findManyWithoutContentTypeEntryAttached(contentTypeUid, entryId);
|
|
516
925
|
ctx.body = { data };
|
|
517
926
|
} else {
|
|
518
927
|
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
@@ -535,19 +944,18 @@ const releaseController = {
|
|
|
535
944
|
const id = ctx.params.id;
|
|
536
945
|
const releaseService = getService("release", { strapi });
|
|
537
946
|
const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
});
|
|
542
|
-
const sanitizedRelease = await permissionsManager.sanitizeOutput(release2);
|
|
947
|
+
if (!release2) {
|
|
948
|
+
throw new errors.NotFoundError(`Release not found for id: ${id}`);
|
|
949
|
+
}
|
|
543
950
|
const count = await releaseService.countActions({
|
|
544
951
|
filters: {
|
|
545
952
|
release: id
|
|
546
953
|
}
|
|
547
954
|
});
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
955
|
+
const sanitizedRelease = {
|
|
956
|
+
...release2,
|
|
957
|
+
createdBy: release2.createdBy ? strapi.admin.services.user.sanitizeUser(release2.createdBy) : null
|
|
958
|
+
};
|
|
551
959
|
const data = {
|
|
552
960
|
...sanitizedRelease,
|
|
553
961
|
actions: {
|
|
@@ -600,8 +1008,27 @@ const releaseController = {
|
|
|
600
1008
|
const id = ctx.params.id;
|
|
601
1009
|
const releaseService = getService("release", { strapi });
|
|
602
1010
|
const release2 = await releaseService.publish(id, { user });
|
|
1011
|
+
const [countPublishActions, countUnpublishActions] = await Promise.all([
|
|
1012
|
+
releaseService.countActions({
|
|
1013
|
+
filters: {
|
|
1014
|
+
release: id,
|
|
1015
|
+
type: "publish"
|
|
1016
|
+
}
|
|
1017
|
+
}),
|
|
1018
|
+
releaseService.countActions({
|
|
1019
|
+
filters: {
|
|
1020
|
+
release: id,
|
|
1021
|
+
type: "unpublish"
|
|
1022
|
+
}
|
|
1023
|
+
})
|
|
1024
|
+
]);
|
|
603
1025
|
ctx.body = {
|
|
604
|
-
data: release2
|
|
1026
|
+
data: release2,
|
|
1027
|
+
meta: {
|
|
1028
|
+
totalEntries: countPublishActions + countUnpublishActions,
|
|
1029
|
+
totalPublishedEntries: countPublishActions,
|
|
1030
|
+
totalUnpublishedEntries: countUnpublishActions
|
|
1031
|
+
}
|
|
605
1032
|
};
|
|
606
1033
|
}
|
|
607
1034
|
};
|
|
@@ -640,11 +1067,30 @@ const releaseActionController = {
|
|
|
640
1067
|
sort: query.groupBy === "action" ? "type" : query.groupBy,
|
|
641
1068
|
...query
|
|
642
1069
|
});
|
|
643
|
-
const
|
|
1070
|
+
const contentTypeOutputSanitizers = results.reduce((acc, action) => {
|
|
1071
|
+
if (acc[action.contentType]) {
|
|
1072
|
+
return acc;
|
|
1073
|
+
}
|
|
1074
|
+
const contentTypePermissionsManager = strapi.admin.services.permission.createPermissionsManager({
|
|
1075
|
+
ability: ctx.state.userAbility,
|
|
1076
|
+
model: action.contentType
|
|
1077
|
+
});
|
|
1078
|
+
acc[action.contentType] = contentTypePermissionsManager.sanitizeOutput;
|
|
1079
|
+
return acc;
|
|
1080
|
+
}, {});
|
|
1081
|
+
const sanitizedResults = await mapAsync(results, async (action) => ({
|
|
1082
|
+
...action,
|
|
1083
|
+
entry: await contentTypeOutputSanitizers[action.contentType](action.entry)
|
|
1084
|
+
}));
|
|
1085
|
+
const groupedData = await releaseService.groupActions(sanitizedResults, query.groupBy);
|
|
1086
|
+
const contentTypes2 = releaseService.getContentTypeModelsFromActions(results);
|
|
1087
|
+
const components = await releaseService.getAllComponents();
|
|
644
1088
|
ctx.body = {
|
|
645
1089
|
data: groupedData,
|
|
646
1090
|
meta: {
|
|
647
|
-
pagination
|
|
1091
|
+
pagination,
|
|
1092
|
+
contentTypes: contentTypes2,
|
|
1093
|
+
components
|
|
648
1094
|
}
|
|
649
1095
|
};
|
|
650
1096
|
},
|
|
@@ -666,10 +1112,8 @@ const releaseActionController = {
|
|
|
666
1112
|
async delete(ctx) {
|
|
667
1113
|
const actionId = ctx.params.actionId;
|
|
668
1114
|
const releaseId = ctx.params.releaseId;
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
releaseId
|
|
672
|
-
);
|
|
1115
|
+
const releaseService = getService("release", { strapi });
|
|
1116
|
+
const deletedReleaseAction = await releaseService.deleteAction(actionId, releaseId);
|
|
673
1117
|
ctx.body = {
|
|
674
1118
|
data: deletedReleaseAction
|
|
675
1119
|
};
|
|
@@ -852,9 +1296,11 @@ const routes = {
|
|
|
852
1296
|
};
|
|
853
1297
|
const { features } = require("@strapi/strapi/dist/utils/ee");
|
|
854
1298
|
const getPlugin = () => {
|
|
855
|
-
if (features.isEnabled("cms-content-releases")
|
|
1299
|
+
if (features.isEnabled("cms-content-releases")) {
|
|
856
1300
|
return {
|
|
857
1301
|
register,
|
|
1302
|
+
bootstrap,
|
|
1303
|
+
destroy,
|
|
858
1304
|
contentTypes,
|
|
859
1305
|
services,
|
|
860
1306
|
controllers,
|