@strapi/content-releases 0.0.0-experimental.check-license → 4.16.1
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-b6df6b60.js +797 -0
- package/dist/_chunks/App-b6df6b60.js.map +1 -0
- package/dist/_chunks/App-b83f4a97.mjs +775 -0
- package/dist/_chunks/App-b83f4a97.mjs.map +1 -0
- package/dist/_chunks/en-b5dfabe6.js +47 -0
- package/dist/_chunks/en-b5dfabe6.js.map +1 -0
- package/dist/_chunks/en-d837b82d.mjs +47 -0
- package/dist/_chunks/en-d837b82d.mjs.map +1 -0
- package/dist/_chunks/index-28e99164.js +784 -0
- package/dist/_chunks/index-28e99164.js.map +1 -0
- package/dist/_chunks/index-c39292e3.mjs +763 -0
- package/dist/_chunks/index-c39292e3.mjs.map +1 -0
- package/dist/admin/index.js +16 -35
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +16 -35
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/src/components/CMReleasesContainer.d.ts +1 -0
- package/dist/admin/src/components/ReleaseActionMenu.d.ts +7 -0
- package/dist/admin/src/components/ReleaseActionOptions.d.ts +8 -0
- package/dist/admin/src/components/ReleaseModal.d.ts +11 -0
- package/dist/admin/src/constants.d.ts +13 -0
- package/dist/admin/src/index.d.ts +3 -15
- package/dist/admin/src/pages/App.d.ts +1 -0
- package/dist/admin/src/pages/ReleaseDetailsPage.d.ts +10 -0
- package/dist/admin/src/pages/ReleasesPage.d.ts +11 -0
- package/dist/admin/src/pages/tests/mockReleaseDetailsPageData.d.ts +104 -0
- package/dist/admin/src/pages/tests/mockReleasesPageData.d.ts +38 -0
- package/dist/admin/src/pluginId.d.ts +1 -0
- package/dist/admin/src/services/axios.d.ts +29 -0
- package/dist/admin/src/services/release.d.ts +348 -0
- package/dist/server/index.js +861 -6
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +842 -6
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/constants.d.ts +9 -0
- package/dist/server/src/constants.d.ts.map +1 -0
- package/dist/server/src/content-types/index.d.ts +82 -0
- package/dist/server/src/content-types/index.d.ts.map +1 -0
- package/dist/server/src/content-types/release/index.d.ts +37 -0
- package/dist/server/src/content-types/release/index.d.ts.map +1 -0
- package/dist/server/src/content-types/release/schema.d.ts +36 -0
- package/dist/server/src/content-types/release/schema.d.ts.map +1 -0
- package/dist/server/src/content-types/release-action/index.d.ts +44 -0
- package/dist/server/src/content-types/release-action/index.d.ts.map +1 -0
- package/dist/server/src/content-types/release-action/schema.d.ts +43 -0
- package/dist/server/src/content-types/release-action/schema.d.ts.map +1 -0
- package/dist/server/src/controllers/index.d.ts +18 -0
- package/dist/server/src/controllers/index.d.ts.map +1 -0
- package/dist/server/src/controllers/release-action.d.ts +9 -0
- package/dist/server/src/controllers/release-action.d.ts.map +1 -0
- package/dist/server/src/controllers/release.d.ts +11 -0
- package/dist/server/src/controllers/release.d.ts.map +1 -0
- package/dist/server/src/controllers/validation/release-action.d.ts +3 -0
- package/dist/server/src/controllers/validation/release-action.d.ts.map +1 -0
- package/dist/server/src/controllers/validation/release.d.ts +2 -0
- package/dist/server/src/controllers/validation/release.d.ts.map +1 -0
- package/dist/server/src/index.d.ts +298 -1
- package/dist/server/src/index.d.ts.map +1 -0
- package/dist/server/src/register.d.ts +5 -1
- package/dist/server/src/register.d.ts.map +1 -0
- package/dist/server/src/routes/index.d.ts +35 -0
- package/dist/server/src/routes/index.d.ts.map +1 -0
- package/dist/server/src/routes/release-action.d.ts +18 -0
- package/dist/server/src/routes/release-action.d.ts.map +1 -0
- package/dist/server/src/routes/release.d.ts +18 -0
- package/dist/server/src/routes/release.d.ts.map +1 -0
- package/dist/server/src/services/index.d.ts +77 -0
- package/dist/server/src/services/index.d.ts.map +1 -0
- package/dist/server/src/services/release.d.ts +55 -0
- package/dist/server/src/services/release.d.ts.map +1 -0
- package/dist/server/src/services/validation.d.ts +10 -0
- package/dist/server/src/services/validation.d.ts.map +1 -0
- package/dist/server/src/utils/index.d.ts +4 -0
- package/dist/server/src/utils/index.d.ts.map +1 -0
- package/dist/shared/contracts/release-actions.d.ts +95 -0
- package/dist/shared/contracts/release-actions.d.ts.map +1 -0
- package/dist/shared/contracts/releases.d.ts +153 -0
- package/dist/shared/contracts/releases.d.ts.map +1 -0
- package/dist/shared/types.d.ts +24 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/validation-schemas.d.ts +2 -0
- package/dist/shared/validation-schemas.d.ts.map +1 -0
- package/package.json +29 -18
- package/dist/_chunks/en-21947221.js +0 -5
- package/dist/_chunks/en-21947221.js.map +0 -1
- package/dist/_chunks/en-92157b33.mjs +0 -5
- package/dist/_chunks/en-92157b33.mjs.map +0 -1
- package/dist/admin/src/tests/index.test.d.ts +0 -0
- package/dist/server/src/__tests__/index.test.d.ts +0 -2
package/dist/server/index.js
CHANGED
|
@@ -1,12 +1,867 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const utils = require("@strapi/utils");
|
|
3
|
+
const yup = require("yup");
|
|
4
|
+
function _interopNamespace(e) {
|
|
5
|
+
if (e && e.__esModule)
|
|
6
|
+
return e;
|
|
7
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
|
+
if (e) {
|
|
9
|
+
for (const k in e) {
|
|
10
|
+
if (k !== "default") {
|
|
11
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: () => e[k]
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
23
|
+
const RELEASE_MODEL_UID = "plugin::content-releases.release";
|
|
24
|
+
const RELEASE_ACTION_MODEL_UID = "plugin::content-releases.release-action";
|
|
25
|
+
const ACTIONS = [
|
|
26
|
+
{
|
|
27
|
+
section: "plugins",
|
|
28
|
+
displayName: "Read",
|
|
29
|
+
uid: "read",
|
|
30
|
+
pluginName: "content-releases"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
section: "plugins",
|
|
34
|
+
displayName: "Create",
|
|
35
|
+
uid: "create",
|
|
36
|
+
pluginName: "content-releases"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
section: "plugins",
|
|
40
|
+
displayName: "Edit",
|
|
41
|
+
uid: "update",
|
|
42
|
+
pluginName: "content-releases"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
section: "plugins",
|
|
46
|
+
displayName: "Delete",
|
|
47
|
+
uid: "delete",
|
|
48
|
+
pluginName: "content-releases"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
section: "plugins",
|
|
52
|
+
displayName: "Publish",
|
|
53
|
+
uid: "publish",
|
|
54
|
+
pluginName: "content-releases"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
section: "plugins",
|
|
58
|
+
displayName: "Remove an entry from a release",
|
|
59
|
+
uid: "delete-action",
|
|
60
|
+
pluginName: "content-releases"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
section: "plugins",
|
|
64
|
+
displayName: "Add an entry to a release",
|
|
65
|
+
uid: "create-action",
|
|
66
|
+
pluginName: "content-releases"
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
const { features: features$1 } = require("@strapi/strapi/dist/utils/ee");
|
|
70
|
+
const register = async ({ strapi: strapi2 }) => {
|
|
71
|
+
if (features$1.isEnabled("cms-content-releases") && strapi2.features.future.isEnabled("contentReleases")) {
|
|
72
|
+
await strapi2.admin.services.permission.actionProvider.registerMany(ACTIONS);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const schema$1 = {
|
|
76
|
+
collectionName: "strapi_releases",
|
|
77
|
+
info: {
|
|
78
|
+
singularName: "release",
|
|
79
|
+
pluralName: "releases",
|
|
80
|
+
displayName: "Release"
|
|
81
|
+
},
|
|
82
|
+
options: {
|
|
83
|
+
draftAndPublish: false
|
|
84
|
+
},
|
|
85
|
+
pluginOptions: {
|
|
86
|
+
"content-manager": {
|
|
87
|
+
visible: false
|
|
88
|
+
},
|
|
89
|
+
"content-type-builder": {
|
|
90
|
+
visible: false
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
attributes: {
|
|
94
|
+
name: {
|
|
95
|
+
type: "string",
|
|
96
|
+
required: true
|
|
97
|
+
},
|
|
98
|
+
releasedAt: {
|
|
99
|
+
type: "datetime"
|
|
100
|
+
},
|
|
101
|
+
actions: {
|
|
102
|
+
type: "relation",
|
|
103
|
+
relation: "oneToMany",
|
|
104
|
+
target: RELEASE_ACTION_MODEL_UID,
|
|
105
|
+
mappedBy: "release"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const release$1 = {
|
|
110
|
+
schema: schema$1
|
|
111
|
+
};
|
|
112
|
+
const schema = {
|
|
113
|
+
collectionName: "strapi_release_actions",
|
|
114
|
+
info: {
|
|
115
|
+
singularName: "release-action",
|
|
116
|
+
pluralName: "release-actions",
|
|
117
|
+
displayName: "Release Action"
|
|
118
|
+
},
|
|
119
|
+
options: {
|
|
120
|
+
draftAndPublish: false
|
|
121
|
+
},
|
|
122
|
+
pluginOptions: {
|
|
123
|
+
"content-manager": {
|
|
124
|
+
visible: false
|
|
125
|
+
},
|
|
126
|
+
"content-type-builder": {
|
|
127
|
+
visible: false
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
attributes: {
|
|
131
|
+
type: {
|
|
132
|
+
type: "enumeration",
|
|
133
|
+
enum: ["publish", "unpublish"],
|
|
134
|
+
required: true
|
|
135
|
+
},
|
|
136
|
+
entry: {
|
|
137
|
+
type: "relation",
|
|
138
|
+
relation: "morphToOne",
|
|
139
|
+
configurable: false
|
|
140
|
+
},
|
|
141
|
+
contentType: {
|
|
142
|
+
type: "string",
|
|
143
|
+
required: true
|
|
144
|
+
},
|
|
145
|
+
release: {
|
|
146
|
+
type: "relation",
|
|
147
|
+
relation: "manyToOne",
|
|
148
|
+
target: RELEASE_MODEL_UID,
|
|
149
|
+
inversedBy: "actions"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const releaseAction$1 = {
|
|
154
|
+
schema
|
|
155
|
+
};
|
|
156
|
+
const contentTypes = {
|
|
157
|
+
release: release$1,
|
|
158
|
+
"release-action": releaseAction$1
|
|
159
|
+
};
|
|
160
|
+
const getService = (name, { strapi: strapi2 } = { strapi: global.strapi }) => {
|
|
161
|
+
return strapi2.plugin("content-releases").service(name);
|
|
162
|
+
};
|
|
163
|
+
const createReleaseService = ({ strapi: strapi2 }) => ({
|
|
164
|
+
async create(releaseData, { user }) {
|
|
165
|
+
const releaseWithCreatorFields = await utils.setCreatorFields({ user })(releaseData);
|
|
166
|
+
return strapi2.entityService.create(RELEASE_MODEL_UID, {
|
|
167
|
+
data: releaseWithCreatorFields
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
async findOne(id, query = {}) {
|
|
171
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id, {
|
|
172
|
+
...query
|
|
173
|
+
});
|
|
174
|
+
return release2;
|
|
175
|
+
},
|
|
176
|
+
findPage(query) {
|
|
177
|
+
return strapi2.entityService.findPage(RELEASE_MODEL_UID, {
|
|
178
|
+
...query,
|
|
179
|
+
populate: {
|
|
180
|
+
actions: {
|
|
181
|
+
// @ts-expect-error Ignore missing properties
|
|
182
|
+
count: true
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
async findManyForContentTypeEntry(contentTypeUid, entryId, {
|
|
188
|
+
hasEntryAttached
|
|
189
|
+
} = {
|
|
190
|
+
hasEntryAttached: false
|
|
191
|
+
}) {
|
|
192
|
+
const whereActions = hasEntryAttached ? {
|
|
193
|
+
// Find all Releases where the content type entry is present
|
|
194
|
+
actions: {
|
|
195
|
+
target_type: contentTypeUid,
|
|
196
|
+
target_id: entryId
|
|
197
|
+
}
|
|
198
|
+
} : {
|
|
199
|
+
// Find all Releases where the content type entry is not present
|
|
200
|
+
$or: [
|
|
201
|
+
{
|
|
202
|
+
$not: {
|
|
203
|
+
actions: {
|
|
204
|
+
target_type: contentTypeUid,
|
|
205
|
+
target_id: entryId
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
actions: null
|
|
211
|
+
}
|
|
212
|
+
]
|
|
213
|
+
};
|
|
214
|
+
const populateAttachedAction = hasEntryAttached ? {
|
|
215
|
+
// Filter the action to get only the content type entry
|
|
216
|
+
actions: {
|
|
217
|
+
where: {
|
|
218
|
+
target_type: contentTypeUid,
|
|
219
|
+
target_id: entryId
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
} : {};
|
|
223
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
224
|
+
where: {
|
|
225
|
+
...whereActions,
|
|
226
|
+
releasedAt: {
|
|
227
|
+
$null: true
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
populate: {
|
|
231
|
+
...populateAttachedAction
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
return releases.map((release2) => {
|
|
235
|
+
if (release2.actions?.length) {
|
|
236
|
+
const [actionForEntry] = release2.actions;
|
|
237
|
+
delete release2.actions;
|
|
238
|
+
return {
|
|
239
|
+
...release2,
|
|
240
|
+
action: actionForEntry
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
return release2;
|
|
244
|
+
});
|
|
245
|
+
},
|
|
246
|
+
async update(id, releaseData, { user }) {
|
|
247
|
+
const updatedRelease = await utils.setCreatorFields({ user, isEdition: true })(releaseData);
|
|
248
|
+
const release2 = await strapi2.entityService.update(RELEASE_MODEL_UID, id, {
|
|
249
|
+
/*
|
|
250
|
+
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">>
|
|
251
|
+
* is not compatible with the type we are passing here: UpdateRelease.Request['body']
|
|
252
|
+
*/
|
|
253
|
+
// @ts-expect-error see above
|
|
254
|
+
data: updatedRelease
|
|
255
|
+
});
|
|
256
|
+
if (!release2) {
|
|
257
|
+
throw new utils.errors.NotFoundError(`No release found for id ${id}`);
|
|
258
|
+
}
|
|
259
|
+
return release2;
|
|
260
|
+
},
|
|
261
|
+
async createAction(releaseId, action) {
|
|
262
|
+
const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
|
|
263
|
+
strapi: strapi2
|
|
264
|
+
});
|
|
265
|
+
await Promise.all([
|
|
266
|
+
validateEntryContentType(action.entry.contentType),
|
|
267
|
+
validateUniqueEntry(releaseId, action)
|
|
268
|
+
]);
|
|
269
|
+
const { entry, type } = action;
|
|
270
|
+
return strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
|
|
271
|
+
data: {
|
|
272
|
+
type,
|
|
273
|
+
contentType: entry.contentType,
|
|
274
|
+
entry: {
|
|
275
|
+
id: entry.id,
|
|
276
|
+
__type: entry.contentType,
|
|
277
|
+
__pivot: { field: "entry" }
|
|
278
|
+
},
|
|
279
|
+
release: releaseId
|
|
280
|
+
},
|
|
281
|
+
populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
|
|
282
|
+
});
|
|
283
|
+
},
|
|
284
|
+
async findActions(releaseId, query) {
|
|
285
|
+
const result = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
|
|
286
|
+
if (!result) {
|
|
287
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
288
|
+
}
|
|
289
|
+
return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
|
|
290
|
+
...query,
|
|
291
|
+
populate: {
|
|
292
|
+
entry: true
|
|
293
|
+
},
|
|
294
|
+
filters: {
|
|
295
|
+
release: releaseId
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
},
|
|
299
|
+
async countActions(query) {
|
|
300
|
+
return strapi2.entityService.count(RELEASE_ACTION_MODEL_UID, query);
|
|
301
|
+
},
|
|
302
|
+
async getAllContentTypeUids(releaseId) {
|
|
303
|
+
const contentTypesFromReleaseActions = await strapi2.db.queryBuilder(RELEASE_ACTION_MODEL_UID).select("content_type").where({
|
|
304
|
+
$and: [
|
|
305
|
+
{
|
|
306
|
+
release: releaseId
|
|
307
|
+
}
|
|
308
|
+
]
|
|
309
|
+
}).groupBy("content_type").execute();
|
|
310
|
+
return contentTypesFromReleaseActions.map(({ contentType: contentTypeUid }) => contentTypeUid);
|
|
311
|
+
},
|
|
312
|
+
async getContentTypesDataForActions(releaseId) {
|
|
313
|
+
const contentTypesUids = await this.getAllContentTypeUids(releaseId);
|
|
314
|
+
const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
|
|
315
|
+
const contentTypesData = {};
|
|
316
|
+
for (const contentTypeUid of contentTypesUids) {
|
|
317
|
+
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
318
|
+
uid: contentTypeUid
|
|
319
|
+
});
|
|
320
|
+
contentTypesData[contentTypeUid] = {
|
|
321
|
+
mainField: contentTypeConfig.settings.mainField,
|
|
322
|
+
displayName: strapi2.getModel(contentTypeUid).info.displayName
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
return contentTypesData;
|
|
326
|
+
},
|
|
327
|
+
async delete(releaseId) {
|
|
328
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
329
|
+
populate: {
|
|
330
|
+
actions: {
|
|
331
|
+
fields: ["id"]
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
if (!release2) {
|
|
336
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
337
|
+
}
|
|
338
|
+
if (release2.releasedAt) {
|
|
339
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
340
|
+
}
|
|
341
|
+
await strapi2.db.transaction(async () => {
|
|
342
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
343
|
+
where: {
|
|
344
|
+
id: {
|
|
345
|
+
$in: release2.actions.map((action) => action.id)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
await strapi2.entityService.delete(RELEASE_MODEL_UID, releaseId);
|
|
350
|
+
});
|
|
351
|
+
return release2;
|
|
352
|
+
},
|
|
353
|
+
async publish(releaseId) {
|
|
354
|
+
const releaseWithPopulatedActionEntries = await strapi2.entityService.findOne(
|
|
355
|
+
RELEASE_MODEL_UID,
|
|
356
|
+
releaseId,
|
|
357
|
+
{
|
|
358
|
+
populate: {
|
|
359
|
+
actions: {
|
|
360
|
+
populate: {
|
|
361
|
+
entry: true
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
);
|
|
367
|
+
if (!releaseWithPopulatedActionEntries) {
|
|
368
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
369
|
+
}
|
|
370
|
+
if (releaseWithPopulatedActionEntries.releasedAt) {
|
|
371
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
372
|
+
}
|
|
373
|
+
if (releaseWithPopulatedActionEntries.actions.length === 0) {
|
|
374
|
+
throw new utils.errors.ValidationError("No entries to publish");
|
|
375
|
+
}
|
|
376
|
+
const actions = {};
|
|
377
|
+
for (const action of releaseWithPopulatedActionEntries.actions) {
|
|
378
|
+
const contentTypeUid = action.contentType;
|
|
379
|
+
if (!actions[contentTypeUid]) {
|
|
380
|
+
actions[contentTypeUid] = {
|
|
381
|
+
publish: [],
|
|
382
|
+
unpublish: []
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
if (action.type === "publish") {
|
|
386
|
+
actions[contentTypeUid].publish.push(action.entry);
|
|
387
|
+
} else {
|
|
388
|
+
actions[contentTypeUid].unpublish.push(action.entry);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
|
|
392
|
+
await strapi2.db.transaction(async () => {
|
|
393
|
+
for (const contentTypeUid of Object.keys(actions)) {
|
|
394
|
+
const { publish, unpublish } = actions[contentTypeUid];
|
|
395
|
+
if (publish.length > 0) {
|
|
396
|
+
await entityManagerService.publishMany(publish, contentTypeUid);
|
|
397
|
+
}
|
|
398
|
+
if (unpublish.length > 0) {
|
|
399
|
+
await entityManagerService.unpublishMany(unpublish, contentTypeUid);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
const release2 = await strapi2.entityService.update(RELEASE_MODEL_UID, releaseId, {
|
|
404
|
+
data: {
|
|
405
|
+
/*
|
|
406
|
+
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">> looks like it's wrong
|
|
407
|
+
*/
|
|
408
|
+
// @ts-expect-error see above
|
|
409
|
+
releasedAt: /* @__PURE__ */ new Date()
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
return release2;
|
|
413
|
+
},
|
|
414
|
+
async updateAction(actionId, releaseId, update) {
|
|
415
|
+
const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
416
|
+
where: {
|
|
417
|
+
id: actionId,
|
|
418
|
+
release: releaseId
|
|
419
|
+
},
|
|
420
|
+
data: update
|
|
421
|
+
});
|
|
422
|
+
if (!updatedAction) {
|
|
423
|
+
throw new utils.errors.NotFoundError(
|
|
424
|
+
`Action with id ${actionId} not found in release with id ${releaseId}`
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
return updatedAction;
|
|
428
|
+
},
|
|
429
|
+
async deleteAction(actionId, releaseId) {
|
|
430
|
+
const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
|
|
431
|
+
where: {
|
|
432
|
+
id: actionId,
|
|
433
|
+
release: releaseId
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
if (!deletedAction) {
|
|
437
|
+
throw new utils.errors.NotFoundError(
|
|
438
|
+
`Action with id ${actionId} not found in release with id ${releaseId}`
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
return deletedAction;
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
445
|
+
async validateUniqueEntry(releaseId, releaseActionArgs) {
|
|
446
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
447
|
+
populate: { actions: { populate: { entry: { fields: ["id"] } } } }
|
|
448
|
+
});
|
|
449
|
+
if (!release2) {
|
|
450
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
451
|
+
}
|
|
452
|
+
const isEntryInRelease = release2.actions.some(
|
|
453
|
+
(action) => Number(action.entry.id) === Number(releaseActionArgs.entry.id) && action.contentType === releaseActionArgs.entry.contentType
|
|
454
|
+
);
|
|
455
|
+
if (isEntryInRelease) {
|
|
456
|
+
throw new utils.errors.ValidationError(
|
|
457
|
+
`Entry with id ${releaseActionArgs.entry.id} and contentType ${releaseActionArgs.entry.contentType} already exists in release with id ${releaseId}`
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
validateEntryContentType(contentTypeUid) {
|
|
462
|
+
const contentType = strapi2.contentType(contentTypeUid);
|
|
463
|
+
if (!contentType) {
|
|
464
|
+
throw new utils.errors.NotFoundError(`No content type found for uid ${contentTypeUid}`);
|
|
465
|
+
}
|
|
466
|
+
if (!contentType.options?.draftAndPublish) {
|
|
467
|
+
throw new utils.errors.ValidationError(
|
|
468
|
+
`Content type with uid ${contentTypeUid} does not have draftAndPublish enabled`
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
const services = { release: createReleaseService, "release-validation": createReleaseValidationService };
|
|
474
|
+
const RELEASE_SCHEMA = yup__namespace.object().shape({
|
|
475
|
+
name: yup__namespace.string().trim().required()
|
|
476
|
+
}).required().noUnknown();
|
|
477
|
+
const validateRelease = utils.validateYupSchema(RELEASE_SCHEMA);
|
|
478
|
+
const releaseController = {
|
|
479
|
+
async findMany(ctx) {
|
|
480
|
+
const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
|
|
481
|
+
ability: ctx.state.userAbility,
|
|
482
|
+
model: RELEASE_MODEL_UID
|
|
483
|
+
});
|
|
484
|
+
await permissionsManager.validateQuery(ctx.query);
|
|
485
|
+
const releaseService = getService("release", { strapi });
|
|
486
|
+
const isFindManyForContentTypeEntry = Boolean(ctx.query?.contentTypeUid && ctx.query?.entryId);
|
|
487
|
+
if (isFindManyForContentTypeEntry) {
|
|
488
|
+
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
489
|
+
const contentTypeUid = query.contentTypeUid;
|
|
490
|
+
const entryId = query.entryId;
|
|
491
|
+
const hasEntryAttached = typeof query.hasEntryAttached === "string" ? JSON.parse(query.hasEntryAttached) : false;
|
|
492
|
+
const data = await releaseService.findManyForContentTypeEntry(contentTypeUid, entryId, {
|
|
493
|
+
hasEntryAttached
|
|
494
|
+
});
|
|
495
|
+
ctx.body = { data };
|
|
496
|
+
} else {
|
|
497
|
+
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
498
|
+
const { results, pagination } = await releaseService.findPage(query);
|
|
499
|
+
const data = results.map((release2) => {
|
|
500
|
+
const { actions, ...releaseData } = release2;
|
|
501
|
+
return {
|
|
502
|
+
...releaseData,
|
|
503
|
+
actions: {
|
|
504
|
+
meta: {
|
|
505
|
+
count: actions.count
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
});
|
|
510
|
+
ctx.body = { data, meta: { pagination } };
|
|
511
|
+
}
|
|
512
|
+
},
|
|
513
|
+
async findOne(ctx) {
|
|
514
|
+
const id = ctx.params.id;
|
|
515
|
+
const releaseService = getService("release", { strapi });
|
|
516
|
+
const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
|
|
517
|
+
const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
|
|
518
|
+
ability: ctx.state.userAbility,
|
|
519
|
+
model: RELEASE_MODEL_UID
|
|
520
|
+
});
|
|
521
|
+
const sanitizedRelease = await permissionsManager.sanitizeOutput(release2);
|
|
522
|
+
const count = await releaseService.countActions({
|
|
523
|
+
filters: {
|
|
524
|
+
release: id
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
if (!release2) {
|
|
528
|
+
throw new utils.errors.NotFoundError(`Release not found for id: ${id}`);
|
|
529
|
+
}
|
|
530
|
+
const data = {
|
|
531
|
+
...sanitizedRelease,
|
|
532
|
+
actions: {
|
|
533
|
+
meta: {
|
|
534
|
+
count
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
ctx.body = { data };
|
|
539
|
+
},
|
|
540
|
+
async create(ctx) {
|
|
541
|
+
const user = ctx.state.user;
|
|
542
|
+
const releaseArgs = ctx.request.body;
|
|
543
|
+
await validateRelease(releaseArgs);
|
|
544
|
+
const releaseService = getService("release", { strapi });
|
|
545
|
+
const release2 = await releaseService.create(releaseArgs, { user });
|
|
546
|
+
const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
|
|
547
|
+
ability: ctx.state.userAbility,
|
|
548
|
+
model: RELEASE_MODEL_UID
|
|
549
|
+
});
|
|
550
|
+
ctx.body = {
|
|
551
|
+
data: await permissionsManager.sanitizeOutput(release2)
|
|
552
|
+
};
|
|
553
|
+
},
|
|
554
|
+
async update(ctx) {
|
|
555
|
+
const user = ctx.state.user;
|
|
556
|
+
const releaseArgs = ctx.request.body;
|
|
557
|
+
const id = ctx.params.id;
|
|
558
|
+
await validateRelease(releaseArgs);
|
|
559
|
+
const releaseService = getService("release", { strapi });
|
|
560
|
+
const release2 = await releaseService.update(id, releaseArgs, { user });
|
|
561
|
+
const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
|
|
562
|
+
ability: ctx.state.userAbility,
|
|
563
|
+
model: RELEASE_MODEL_UID
|
|
564
|
+
});
|
|
565
|
+
ctx.body = {
|
|
566
|
+
data: await permissionsManager.sanitizeOutput(release2)
|
|
567
|
+
};
|
|
568
|
+
},
|
|
569
|
+
async delete(ctx) {
|
|
570
|
+
const id = ctx.params.id;
|
|
571
|
+
const releaseService = getService("release", { strapi });
|
|
572
|
+
const release2 = await releaseService.delete(id);
|
|
573
|
+
ctx.body = {
|
|
574
|
+
data: release2
|
|
575
|
+
};
|
|
576
|
+
},
|
|
577
|
+
async publish(ctx) {
|
|
578
|
+
const user = ctx.state.user;
|
|
579
|
+
const id = ctx.params.id;
|
|
580
|
+
const releaseService = getService("release", { strapi });
|
|
581
|
+
const release2 = await releaseService.publish(id, { user });
|
|
582
|
+
ctx.body = {
|
|
583
|
+
data: release2
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
const RELEASE_ACTION_SCHEMA = utils.yup.object().shape({
|
|
588
|
+
entry: utils.yup.object().shape({
|
|
589
|
+
id: utils.yup.strapiID().required(),
|
|
590
|
+
contentType: utils.yup.string().required()
|
|
591
|
+
}).required(),
|
|
592
|
+
type: utils.yup.string().oneOf(["publish", "unpublish"]).required()
|
|
593
|
+
});
|
|
594
|
+
const RELEASE_ACTION_UPDATE_SCHEMA = utils.yup.object().shape({
|
|
595
|
+
type: utils.yup.string().oneOf(["publish", "unpublish"]).required()
|
|
596
|
+
});
|
|
597
|
+
const validateReleaseAction = utils.validateYupSchema(RELEASE_ACTION_SCHEMA);
|
|
598
|
+
const validateReleaseActionUpdateSchema = utils.validateYupSchema(RELEASE_ACTION_UPDATE_SCHEMA);
|
|
599
|
+
const releaseActionController = {
|
|
600
|
+
async create(ctx) {
|
|
601
|
+
const releaseId = ctx.params.releaseId;
|
|
602
|
+
const releaseActionArgs = ctx.request.body;
|
|
603
|
+
await validateReleaseAction(releaseActionArgs);
|
|
604
|
+
const releaseService = getService("release", { strapi });
|
|
605
|
+
const releaseAction2 = await releaseService.createAction(releaseId, releaseActionArgs);
|
|
606
|
+
ctx.body = {
|
|
607
|
+
data: releaseAction2
|
|
608
|
+
};
|
|
609
|
+
},
|
|
610
|
+
async findMany(ctx) {
|
|
611
|
+
const releaseId = ctx.params.releaseId;
|
|
612
|
+
const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
|
|
613
|
+
ability: ctx.state.userAbility,
|
|
614
|
+
model: RELEASE_ACTION_MODEL_UID
|
|
615
|
+
});
|
|
616
|
+
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
617
|
+
const releaseService = getService("release", { strapi });
|
|
618
|
+
const { results, pagination } = await releaseService.findActions(releaseId, query);
|
|
619
|
+
const allReleaseContentTypesDictionary = await releaseService.getContentTypesDataForActions(
|
|
620
|
+
releaseId
|
|
621
|
+
);
|
|
622
|
+
const allLocales = await strapi.plugin("i18n").service("locales").find();
|
|
623
|
+
const allLocalesDictionary = allLocales.reduce((acc, locale) => {
|
|
624
|
+
acc[locale.code] = { name: locale.name, code: locale.code };
|
|
625
|
+
return acc;
|
|
626
|
+
}, {});
|
|
627
|
+
const data = results.map((action) => {
|
|
628
|
+
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
629
|
+
return {
|
|
630
|
+
...action,
|
|
631
|
+
entry: {
|
|
632
|
+
id: action.entry.id,
|
|
633
|
+
contentType: {
|
|
634
|
+
displayName,
|
|
635
|
+
mainFieldValue: action.entry[mainField]
|
|
636
|
+
},
|
|
637
|
+
locale: allLocalesDictionary[action.entry.locale]
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
});
|
|
641
|
+
ctx.body = {
|
|
642
|
+
data,
|
|
643
|
+
meta: {
|
|
644
|
+
pagination
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
},
|
|
648
|
+
async update(ctx) {
|
|
649
|
+
const actionId = ctx.params.actionId;
|
|
650
|
+
const releaseId = ctx.params.releaseId;
|
|
651
|
+
const releaseActionUpdateArgs = ctx.request.body;
|
|
652
|
+
await validateReleaseActionUpdateSchema(releaseActionUpdateArgs);
|
|
653
|
+
const releaseService = getService("release", { strapi });
|
|
654
|
+
const updatedAction = await releaseService.updateAction(
|
|
655
|
+
actionId,
|
|
656
|
+
releaseId,
|
|
657
|
+
releaseActionUpdateArgs
|
|
658
|
+
);
|
|
659
|
+
ctx.body = {
|
|
660
|
+
data: updatedAction
|
|
661
|
+
};
|
|
662
|
+
},
|
|
663
|
+
async delete(ctx) {
|
|
664
|
+
const actionId = ctx.params.actionId;
|
|
665
|
+
const releaseId = ctx.params.releaseId;
|
|
666
|
+
const deletedReleaseAction = await getService("release", { strapi }).deleteAction(
|
|
667
|
+
actionId,
|
|
668
|
+
releaseId
|
|
669
|
+
);
|
|
670
|
+
ctx.body = {
|
|
671
|
+
data: deletedReleaseAction
|
|
672
|
+
};
|
|
6
673
|
}
|
|
7
674
|
};
|
|
8
|
-
const
|
|
9
|
-
|
|
675
|
+
const controllers = { release: releaseController, "release-action": releaseActionController };
|
|
676
|
+
const release = {
|
|
677
|
+
type: "admin",
|
|
678
|
+
routes: [
|
|
679
|
+
{
|
|
680
|
+
method: "POST",
|
|
681
|
+
path: "/",
|
|
682
|
+
handler: "release.create",
|
|
683
|
+
config: {
|
|
684
|
+
policies: [
|
|
685
|
+
"admin::isAuthenticatedAdmin",
|
|
686
|
+
{
|
|
687
|
+
name: "admin::hasPermissions",
|
|
688
|
+
config: {
|
|
689
|
+
actions: ["plugin::content-releases.create"]
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
]
|
|
693
|
+
}
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
method: "GET",
|
|
697
|
+
path: "/",
|
|
698
|
+
handler: "release.findMany",
|
|
699
|
+
config: {
|
|
700
|
+
policies: [
|
|
701
|
+
"admin::isAuthenticatedAdmin",
|
|
702
|
+
{
|
|
703
|
+
name: "admin::hasPermissions",
|
|
704
|
+
config: {
|
|
705
|
+
actions: ["plugin::content-releases.read"]
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
]
|
|
709
|
+
}
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
method: "GET",
|
|
713
|
+
path: "/:id",
|
|
714
|
+
handler: "release.findOne",
|
|
715
|
+
config: {
|
|
716
|
+
policies: [
|
|
717
|
+
"admin::isAuthenticatedAdmin",
|
|
718
|
+
{
|
|
719
|
+
name: "admin::hasPermissions",
|
|
720
|
+
config: {
|
|
721
|
+
actions: ["plugin::content-releases.read"]
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
]
|
|
725
|
+
}
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
method: "PUT",
|
|
729
|
+
path: "/:id",
|
|
730
|
+
handler: "release.update",
|
|
731
|
+
config: {
|
|
732
|
+
policies: [
|
|
733
|
+
"admin::isAuthenticatedAdmin",
|
|
734
|
+
{
|
|
735
|
+
name: "admin::hasPermissions",
|
|
736
|
+
config: {
|
|
737
|
+
actions: ["plugin::content-releases.update"]
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
]
|
|
741
|
+
}
|
|
742
|
+
},
|
|
743
|
+
{
|
|
744
|
+
method: "DELETE",
|
|
745
|
+
path: "/:id",
|
|
746
|
+
handler: "release.delete",
|
|
747
|
+
config: {
|
|
748
|
+
policies: [
|
|
749
|
+
"admin::isAuthenticatedAdmin",
|
|
750
|
+
{
|
|
751
|
+
name: "admin::hasPermissions",
|
|
752
|
+
config: {
|
|
753
|
+
actions: ["plugin::content-releases.delete"]
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
]
|
|
757
|
+
}
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
method: "POST",
|
|
761
|
+
path: "/:id/publish",
|
|
762
|
+
handler: "release.publish",
|
|
763
|
+
config: {
|
|
764
|
+
policies: [
|
|
765
|
+
"admin::isAuthenticatedAdmin",
|
|
766
|
+
{
|
|
767
|
+
name: "admin::hasPermissions",
|
|
768
|
+
config: {
|
|
769
|
+
actions: ["plugin::content-releases.publish"]
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
]
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
]
|
|
776
|
+
};
|
|
777
|
+
const releaseAction = {
|
|
778
|
+
type: "admin",
|
|
779
|
+
routes: [
|
|
780
|
+
{
|
|
781
|
+
method: "POST",
|
|
782
|
+
path: "/:releaseId/actions",
|
|
783
|
+
handler: "release-action.create",
|
|
784
|
+
config: {
|
|
785
|
+
policies: [
|
|
786
|
+
"admin::isAuthenticatedAdmin",
|
|
787
|
+
{
|
|
788
|
+
name: "admin::hasPermissions",
|
|
789
|
+
config: {
|
|
790
|
+
actions: ["plugin::content-releases.create-action"]
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
]
|
|
794
|
+
}
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
method: "GET",
|
|
798
|
+
path: "/:releaseId/actions",
|
|
799
|
+
handler: "release-action.findMany",
|
|
800
|
+
config: {
|
|
801
|
+
policies: [
|
|
802
|
+
"admin::isAuthenticatedAdmin",
|
|
803
|
+
{
|
|
804
|
+
name: "admin::hasPermissions",
|
|
805
|
+
config: {
|
|
806
|
+
actions: ["plugin::content-releases.read"]
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
]
|
|
810
|
+
}
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
method: "PUT",
|
|
814
|
+
path: "/:releaseId/actions/:actionId",
|
|
815
|
+
handler: "release-action.update",
|
|
816
|
+
config: {
|
|
817
|
+
policies: [
|
|
818
|
+
"admin::isAuthenticatedAdmin",
|
|
819
|
+
{
|
|
820
|
+
name: "admin::hasPermissions",
|
|
821
|
+
config: {
|
|
822
|
+
actions: ["plugin::content-releases.update"]
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
]
|
|
826
|
+
}
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
method: "DELETE",
|
|
830
|
+
path: "/:releaseId/actions/:actionId",
|
|
831
|
+
handler: "release-action.delete",
|
|
832
|
+
config: {
|
|
833
|
+
policies: [
|
|
834
|
+
"admin::isAuthenticatedAdmin",
|
|
835
|
+
{
|
|
836
|
+
name: "admin::hasPermissions",
|
|
837
|
+
config: {
|
|
838
|
+
actions: ["plugin::content-releases.delete-action"]
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
]
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
]
|
|
845
|
+
};
|
|
846
|
+
const routes = {
|
|
847
|
+
release,
|
|
848
|
+
"release-action": releaseAction
|
|
849
|
+
};
|
|
850
|
+
const { features } = require("@strapi/strapi/dist/utils/ee");
|
|
851
|
+
const getPlugin = () => {
|
|
852
|
+
if (features.isEnabled("cms-content-releases") && strapi.features.future.isEnabled("contentReleases")) {
|
|
853
|
+
return {
|
|
854
|
+
register,
|
|
855
|
+
contentTypes,
|
|
856
|
+
services,
|
|
857
|
+
controllers,
|
|
858
|
+
routes
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
return {
|
|
862
|
+
contentTypes
|
|
863
|
+
};
|
|
10
864
|
};
|
|
865
|
+
const index = getPlugin();
|
|
11
866
|
module.exports = index;
|
|
12
867
|
//# sourceMappingURL=index.js.map
|