@strapi/content-releases 0.0.0-next.eedb036f0a7ac282d2a645d8a40625091bd28b1e → 0.0.0-next.ef9237644b07791c05e1b7edc54d1921e59565ae
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/admin/chunks/App-BEyv0kMo.mjs +1845 -0
- package/dist/admin/chunks/App-BEyv0kMo.mjs.map +1 -0
- package/dist/admin/chunks/App-BG-3LItb.js +1866 -0
- package/dist/admin/chunks/App-BG-3LItb.js.map +1 -0
- package/dist/admin/chunks/PurchaseContentReleases-U5sGMPgR.mjs +173 -0
- package/dist/admin/chunks/PurchaseContentReleases-U5sGMPgR.mjs.map +1 -0
- package/dist/admin/chunks/PurchaseContentReleases-hRg6ejD7.js +175 -0
- package/dist/admin/chunks/PurchaseContentReleases-hRg6ejD7.js.map +1 -0
- package/dist/admin/chunks/ReleasesSettingsPage-DV_y1NJZ.js +207 -0
- package/dist/admin/chunks/ReleasesSettingsPage-DV_y1NJZ.js.map +1 -0
- package/dist/admin/chunks/ReleasesSettingsPage-lky_0-wG.mjs +205 -0
- package/dist/admin/chunks/ReleasesSettingsPage-lky_0-wG.mjs.map +1 -0
- package/dist/admin/chunks/en-BOpqX2t_.js +108 -0
- package/dist/admin/chunks/en-BOpqX2t_.js.map +1 -0
- package/dist/admin/chunks/en-aQo8Bn_U.mjs +106 -0
- package/dist/admin/chunks/en-aQo8Bn_U.mjs.map +1 -0
- package/dist/admin/chunks/hooks-CFk_8Q0b.mjs +6 -0
- package/dist/admin/chunks/hooks-CFk_8Q0b.mjs.map +1 -0
- package/dist/admin/chunks/hooks-DA5VbUAp.js +8 -0
- package/dist/admin/chunks/hooks-DA5VbUAp.js.map +1 -0
- package/dist/admin/chunks/index-BZaFIG8z.js +1658 -0
- package/dist/admin/chunks/index-BZaFIG8z.js.map +1 -0
- package/dist/admin/chunks/index-DEy-8PzZ.mjs +1619 -0
- package/dist/admin/chunks/index-DEy-8PzZ.mjs.map +1 -0
- package/dist/admin/chunks/schemas-DMt8h1z-.mjs +43 -0
- package/dist/admin/chunks/schemas-DMt8h1z-.mjs.map +1 -0
- package/dist/admin/chunks/schemas-DS7NeFDN.js +65 -0
- package/dist/admin/chunks/schemas-DS7NeFDN.js.map +1 -0
- package/dist/admin/chunks/uk-9T9su-bj.js +103 -0
- package/dist/{_chunks/en-BWPPsSH-.js.map → admin/chunks/uk-9T9su-bj.js.map} +1 -1
- package/dist/admin/chunks/uk-Bp9HotPq.mjs +101 -0
- package/dist/{_chunks/en-D9Q4YW03.mjs.map → admin/chunks/uk-Bp9HotPq.mjs.map} +1 -1
- package/dist/admin/index.js +18 -3
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +13 -5
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/src/components/ReleaseListCell.d.ts +1 -1
- package/dist/server/index.js +2166 -1871
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +2156 -1861
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/destroy.d.ts +1 -1
- package/dist/server/src/destroy.d.ts.map +1 -1
- package/dist/server/src/middlewares/documents.d.ts +1 -1
- package/dist/server/src/middlewares/documents.d.ts.map +1 -1
- package/dist/server/src/services/scheduling.d.ts +1 -1
- package/dist/server/src/services/scheduling.d.ts.map +1 -1
- package/dist/server/src/services/validation.d.ts +1 -1
- package/dist/server/src/services/validation.d.ts.map +1 -1
- package/dist/shared/contracts/release-actions.d.ts +0 -1
- package/dist/shared/contracts/releases.d.ts +0 -1
- package/dist/shared/contracts/settings.d.ts +1 -2
- package/dist/shared/contracts/settings.d.ts.map +1 -1
- package/dist/shared/types.d.ts +0 -1
- package/package.json +18 -16
- package/dist/_chunks/App-FQyYFBJT.mjs +0 -1559
- package/dist/_chunks/App-FQyYFBJT.mjs.map +0 -1
- package/dist/_chunks/App-lx4Ucy9W.js +0 -1580
- package/dist/_chunks/App-lx4Ucy9W.js.map +0 -1
- package/dist/_chunks/PurchaseContentReleases-Be3acS2L.js +0 -52
- package/dist/_chunks/PurchaseContentReleases-Be3acS2L.js.map +0 -1
- package/dist/_chunks/PurchaseContentReleases-_MxP6-Dt.mjs +0 -52
- package/dist/_chunks/PurchaseContentReleases-_MxP6-Dt.mjs.map +0 -1
- package/dist/_chunks/ReleasesSettingsPage-DqBxvJ9i.mjs +0 -178
- package/dist/_chunks/ReleasesSettingsPage-DqBxvJ9i.mjs.map +0 -1
- package/dist/_chunks/ReleasesSettingsPage-T5VEAV03.js +0 -178
- package/dist/_chunks/ReleasesSettingsPage-T5VEAV03.js.map +0 -1
- package/dist/_chunks/en-BWPPsSH-.js +0 -102
- package/dist/_chunks/en-D9Q4YW03.mjs +0 -102
- package/dist/_chunks/index-CK9G80CL.mjs +0 -1380
- package/dist/_chunks/index-CK9G80CL.mjs.map +0 -1
- package/dist/_chunks/index-Cl3tM1YW.js +0 -1399
- package/dist/_chunks/index-Cl3tM1YW.js.map +0 -1
- package/dist/_chunks/schemas-BE1LxE9J.js +0 -62
- package/dist/_chunks/schemas-BE1LxE9J.js.map +0 -1
- package/dist/_chunks/schemas-DdA2ic2U.mjs +0 -44
- package/dist/_chunks/schemas-DdA2ic2U.mjs.map +0 -1
package/dist/server/index.js
CHANGED
|
@@ -1,2058 +1,2353 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('@strapi/utils');
|
|
4
|
+
var isEqual = require('lodash/isEqual');
|
|
5
|
+
var lodash = require('lodash');
|
|
6
|
+
var _ = require('lodash/fp');
|
|
7
|
+
var nodeSchedule = require('node-schedule');
|
|
8
|
+
var yup = require('yup');
|
|
9
|
+
|
|
10
|
+
function _interopNamespaceDefault(e) {
|
|
11
|
+
var n = Object.create(null);
|
|
13
12
|
if (e) {
|
|
14
|
-
|
|
15
|
-
if (k !==
|
|
16
|
-
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
16
|
Object.defineProperty(n, k, d.get ? d : {
|
|
18
17
|
enumerable: true,
|
|
19
|
-
get: ()
|
|
18
|
+
get: function () { return e[k]; }
|
|
20
19
|
});
|
|
21
20
|
}
|
|
22
|
-
}
|
|
21
|
+
});
|
|
23
22
|
}
|
|
24
23
|
n.default = e;
|
|
25
24
|
return Object.freeze(n);
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const RELEASE_MODEL_UID =
|
|
31
|
-
const RELEASE_ACTION_MODEL_UID =
|
|
26
|
+
|
|
27
|
+
var yup__namespace = /*#__PURE__*/_interopNamespaceDefault(yup);
|
|
28
|
+
|
|
29
|
+
const RELEASE_MODEL_UID = 'plugin::content-releases.release';
|
|
30
|
+
const RELEASE_ACTION_MODEL_UID = 'plugin::content-releases.release-action';
|
|
32
31
|
const ACTIONS = [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
32
|
+
{
|
|
33
|
+
section: 'plugins',
|
|
34
|
+
displayName: 'Read',
|
|
35
|
+
uid: 'read',
|
|
36
|
+
pluginName: 'content-releases'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
section: 'plugins',
|
|
40
|
+
displayName: 'Create',
|
|
41
|
+
uid: 'create',
|
|
42
|
+
pluginName: 'content-releases'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
section: 'plugins',
|
|
46
|
+
displayName: 'Edit',
|
|
47
|
+
uid: 'update',
|
|
48
|
+
pluginName: 'content-releases'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
section: 'plugins',
|
|
52
|
+
displayName: 'Delete',
|
|
53
|
+
uid: 'delete',
|
|
54
|
+
pluginName: 'content-releases'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
section: 'plugins',
|
|
58
|
+
displayName: 'Publish',
|
|
59
|
+
uid: 'publish',
|
|
60
|
+
pluginName: 'content-releases'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
section: 'plugins',
|
|
64
|
+
displayName: 'Remove an entry from a release',
|
|
65
|
+
uid: 'delete-action',
|
|
66
|
+
pluginName: 'content-releases'
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
section: 'plugins',
|
|
70
|
+
displayName: 'Add an entry to a release',
|
|
71
|
+
uid: 'create-action',
|
|
72
|
+
pluginName: 'content-releases'
|
|
73
|
+
},
|
|
74
|
+
// Settings
|
|
75
|
+
{
|
|
76
|
+
uid: 'settings.read',
|
|
77
|
+
section: 'settings',
|
|
78
|
+
displayName: 'Read',
|
|
79
|
+
category: 'content releases',
|
|
80
|
+
subCategory: 'options',
|
|
81
|
+
pluginName: 'content-releases'
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
uid: 'settings.update',
|
|
85
|
+
section: 'settings',
|
|
86
|
+
displayName: 'Edit',
|
|
87
|
+
category: 'content releases',
|
|
88
|
+
subCategory: 'options',
|
|
89
|
+
pluginName: 'content-releases'
|
|
90
|
+
}
|
|
92
91
|
];
|
|
93
92
|
const ALLOWED_WEBHOOK_EVENTS = {
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
const getService = (name, { strapi: strapi2 }) => {
|
|
97
|
-
return strapi2.plugin("content-releases").service(name);
|
|
93
|
+
RELEASES_PUBLISH: 'releases.publish'
|
|
98
94
|
};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const entry = await getEntry({ contentType, documentId, locale, populate }, { strapi: strapi2 });
|
|
103
|
-
return isEntryValid(contentType, entry, { strapi: strapi2 });
|
|
95
|
+
|
|
96
|
+
const getService = (name, { strapi: strapi1 })=>{
|
|
97
|
+
return strapi1.plugin('content-releases').service(name);
|
|
104
98
|
};
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
populate: "stageRequiredToPublish"
|
|
99
|
+
const getDraftEntryValidStatus = async ({ contentType, documentId, locale }, { strapi: strapi1 })=>{
|
|
100
|
+
const populateBuilderService = strapi1.plugin('content-manager').service('populate-builder');
|
|
101
|
+
// @ts-expect-error - populateBuilderService should be a function but is returning service
|
|
102
|
+
const populate = await populateBuilderService(contentType).populateDeep(Infinity).build();
|
|
103
|
+
const entry = await getEntry({
|
|
104
|
+
contentType,
|
|
105
|
+
documentId,
|
|
106
|
+
locale,
|
|
107
|
+
populate
|
|
108
|
+
}, {
|
|
109
|
+
strapi: strapi1
|
|
117
110
|
});
|
|
118
|
-
|
|
119
|
-
|
|
111
|
+
return isEntryValid(contentType, entry, {
|
|
112
|
+
strapi: strapi1
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
const isEntryValid = async (contentTypeUid, entry, { strapi: strapi1 })=>{
|
|
116
|
+
try {
|
|
117
|
+
// @TODO: When documents service has validateEntityCreation method, use it instead
|
|
118
|
+
await strapi1.entityValidator.validateEntityCreation(strapi1.getModel(contentTypeUid), entry, undefined, // @ts-expect-error - FIXME: entity here is unnecessary
|
|
119
|
+
entry);
|
|
120
|
+
const workflowsService = strapi1.plugin('review-workflows').service('workflows');
|
|
121
|
+
const workflow = await workflowsService.getAssignedWorkflow(contentTypeUid, {
|
|
122
|
+
populate: 'stageRequiredToPublish'
|
|
123
|
+
});
|
|
124
|
+
if (workflow?.stageRequiredToPublish) {
|
|
125
|
+
return entry.strapi_stage.id === workflow.stageRequiredToPublish.id;
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
120
130
|
}
|
|
121
|
-
return true;
|
|
122
|
-
} catch {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
131
|
};
|
|
126
|
-
const getEntry = async ({
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
const getEntry = async ({ contentType, documentId, locale, populate, status = 'draft' }, { strapi: strapi1 })=>{
|
|
133
|
+
if (documentId) {
|
|
134
|
+
// Try to get an existing draft or published document
|
|
135
|
+
const entry = await strapi1.documents(contentType).findOne({
|
|
136
|
+
documentId,
|
|
137
|
+
locale,
|
|
138
|
+
populate,
|
|
139
|
+
status
|
|
140
|
+
});
|
|
141
|
+
// The document isn't published yet, but the action is to publish it, fetch the draft
|
|
142
|
+
if (status === 'published' && !entry) {
|
|
143
|
+
return strapi1.documents(contentType).findOne({
|
|
144
|
+
documentId,
|
|
145
|
+
locale,
|
|
146
|
+
populate,
|
|
147
|
+
status: 'draft'
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return entry;
|
|
137
151
|
}
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
152
|
+
return strapi1.documents(contentType).findFirst({
|
|
153
|
+
locale,
|
|
154
|
+
populate,
|
|
155
|
+
status
|
|
156
|
+
});
|
|
141
157
|
};
|
|
142
|
-
const getEntryStatus = async (contentType, entry)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
const getEntryStatus = async (contentType, entry)=>{
|
|
159
|
+
if (entry.publishedAt) {
|
|
160
|
+
return 'published';
|
|
161
|
+
}
|
|
162
|
+
const publishedEntry = await strapi.documents(contentType).findOne({
|
|
163
|
+
documentId: entry.documentId,
|
|
164
|
+
locale: entry.locale,
|
|
165
|
+
status: 'published',
|
|
166
|
+
fields: [
|
|
167
|
+
'updatedAt'
|
|
168
|
+
]
|
|
169
|
+
});
|
|
170
|
+
if (!publishedEntry) {
|
|
171
|
+
return 'draft';
|
|
172
|
+
}
|
|
173
|
+
const entryUpdatedAt = new Date(entry.updatedAt).getTime();
|
|
174
|
+
const publishedEntryUpdatedAt = new Date(publishedEntry.updatedAt).getTime();
|
|
175
|
+
if (entryUpdatedAt > publishedEntryUpdatedAt) {
|
|
176
|
+
return 'modified';
|
|
177
|
+
}
|
|
178
|
+
return 'published';
|
|
161
179
|
};
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (!oldContentTypes) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
for (const uid in contentTypes2) {
|
|
170
|
-
if (!oldContentTypes[uid]) {
|
|
171
|
-
continue;
|
|
180
|
+
|
|
181
|
+
async function deleteActionsOnDisableDraftAndPublish({ oldContentTypes, contentTypes }) {
|
|
182
|
+
if (!oldContentTypes) {
|
|
183
|
+
return;
|
|
172
184
|
}
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
185
|
+
for(const uid in contentTypes){
|
|
186
|
+
if (!oldContentTypes[uid]) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const oldContentType = oldContentTypes[uid];
|
|
190
|
+
const contentType = contentTypes[uid];
|
|
191
|
+
if (utils.contentTypes.hasDraftAndPublish(oldContentType) && !utils.contentTypes.hasDraftAndPublish(contentType)) {
|
|
192
|
+
await strapi.db?.queryBuilder(RELEASE_ACTION_MODEL_UID).delete().where({
|
|
193
|
+
contentType: uid
|
|
194
|
+
}).execute();
|
|
195
|
+
}
|
|
177
196
|
}
|
|
178
|
-
}
|
|
179
197
|
}
|
|
180
|
-
async function deleteActionsOnDeleteContentType({ oldContentTypes, contentTypes
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
198
|
+
async function deleteActionsOnDeleteContentType({ oldContentTypes, contentTypes }) {
|
|
199
|
+
const deletedContentTypes = lodash.difference(lodash.keys(oldContentTypes), lodash.keys(contentTypes)) ?? [];
|
|
200
|
+
if (deletedContentTypes.length) {
|
|
201
|
+
await utils.async.map(deletedContentTypes, async (deletedContentTypeUID)=>{
|
|
202
|
+
return strapi.db?.queryBuilder(RELEASE_ACTION_MODEL_UID).delete().where({
|
|
203
|
+
contentType: deletedContentTypeUID
|
|
204
|
+
}).execute();
|
|
205
|
+
});
|
|
206
|
+
}
|
|
187
207
|
}
|
|
188
208
|
async function migrateIsValidAndStatusReleases() {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
populate: {
|
|
195
|
-
actions: {
|
|
209
|
+
const releasesWithoutStatus = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
210
|
+
where: {
|
|
211
|
+
status: null,
|
|
212
|
+
releasedAt: null
|
|
213
|
+
},
|
|
196
214
|
populate: {
|
|
197
|
-
|
|
215
|
+
actions: {
|
|
216
|
+
populate: {
|
|
217
|
+
entry: true
|
|
218
|
+
}
|
|
219
|
+
}
|
|
198
220
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
221
|
+
});
|
|
222
|
+
utils.async.map(releasesWithoutStatus, async (release)=>{
|
|
223
|
+
const actions = release.actions;
|
|
224
|
+
const notValidatedActions = actions.filter((action)=>action.isEntryValid === null);
|
|
225
|
+
for (const action of notValidatedActions){
|
|
226
|
+
// We need to check the Action is related to a valid entry because we can't assume this is gonna be always the case
|
|
227
|
+
// example: users could make changes directly to their database, or data could be lost
|
|
228
|
+
if (action.entry) {
|
|
229
|
+
const isEntryValid = getDraftEntryValidStatus({
|
|
230
|
+
contentType: action.contentType,
|
|
231
|
+
documentId: action.entryDocumentId,
|
|
232
|
+
locale: action.locale
|
|
233
|
+
}, {
|
|
234
|
+
strapi
|
|
235
|
+
});
|
|
236
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
237
|
+
where: {
|
|
238
|
+
id: action.id
|
|
239
|
+
},
|
|
240
|
+
data: {
|
|
241
|
+
isEntryValid
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return getService('release', {
|
|
247
|
+
strapi
|
|
248
|
+
}).updateReleaseStatus(release.id);
|
|
249
|
+
});
|
|
250
|
+
const publishedReleases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
251
|
+
where: {
|
|
252
|
+
status: null,
|
|
253
|
+
releasedAt: {
|
|
254
|
+
$notNull: true
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
utils.async.map(publishedReleases, async (release)=>{
|
|
259
|
+
return strapi.db.query(RELEASE_MODEL_UID).update({
|
|
260
|
+
where: {
|
|
261
|
+
id: release.id
|
|
262
|
+
},
|
|
263
|
+
data: {
|
|
264
|
+
status: 'done'
|
|
265
|
+
}
|
|
222
266
|
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
226
|
-
});
|
|
227
|
-
const publishedReleases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
228
|
-
where: {
|
|
229
|
-
status: null,
|
|
230
|
-
releasedAt: {
|
|
231
|
-
$notNull: true
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
utils.async.map(publishedReleases, async (release2) => {
|
|
236
|
-
return strapi.db.query(RELEASE_MODEL_UID).update({
|
|
237
|
-
where: {
|
|
238
|
-
id: release2.id
|
|
239
|
-
},
|
|
240
|
-
data: {
|
|
241
|
-
status: "done"
|
|
242
|
-
}
|
|
243
267
|
});
|
|
244
|
-
});
|
|
245
268
|
}
|
|
246
|
-
async function revalidateChangedContentTypes({ oldContentTypes, contentTypes
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
269
|
+
async function revalidateChangedContentTypes({ oldContentTypes, contentTypes }) {
|
|
270
|
+
if (oldContentTypes !== undefined && contentTypes !== undefined) {
|
|
271
|
+
const contentTypesWithDraftAndPublish = Object.keys(oldContentTypes).filter((uid)=>oldContentTypes[uid]?.options?.draftAndPublish);
|
|
272
|
+
const releasesAffected = new Set();
|
|
273
|
+
utils.async.map(contentTypesWithDraftAndPublish, async (contentTypeUID)=>{
|
|
274
|
+
const oldContentType = oldContentTypes[contentTypeUID];
|
|
275
|
+
const contentType = contentTypes[contentTypeUID];
|
|
276
|
+
// If attributes have changed, we need to revalidate actions because maybe validations rules are different
|
|
277
|
+
if (!isEqual(oldContentType?.attributes, contentType?.attributes)) {
|
|
278
|
+
const actions = await strapi.db.query(RELEASE_ACTION_MODEL_UID).findMany({
|
|
279
|
+
where: {
|
|
280
|
+
contentType: contentTypeUID
|
|
281
|
+
},
|
|
282
|
+
populate: {
|
|
283
|
+
entry: true,
|
|
284
|
+
release: true
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
await utils.async.map(actions, async (action)=>{
|
|
288
|
+
if (action.entry && action.release && action.type === 'publish') {
|
|
289
|
+
const isEntryValid = await getDraftEntryValidStatus({
|
|
290
|
+
contentType: contentTypeUID,
|
|
291
|
+
documentId: action.entryDocumentId,
|
|
292
|
+
locale: action.locale
|
|
293
|
+
}, {
|
|
294
|
+
strapi
|
|
295
|
+
});
|
|
296
|
+
releasesAffected.add(action.release.id);
|
|
297
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
298
|
+
where: {
|
|
299
|
+
id: action.id
|
|
300
|
+
},
|
|
301
|
+
data: {
|
|
302
|
+
isEntryValid
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}).then(()=>{
|
|
309
|
+
// We need to update the status of the releases affected
|
|
310
|
+
utils.async.map(releasesAffected, async (releaseId)=>{
|
|
311
|
+
return getService('release', {
|
|
312
|
+
strapi
|
|
313
|
+
}).updateReleaseStatus(releaseId);
|
|
283
314
|
});
|
|
284
|
-
}
|
|
285
315
|
});
|
|
286
|
-
|
|
287
|
-
}).then(() => {
|
|
288
|
-
utils.async.map(releasesAffected, async (releaseId) => {
|
|
289
|
-
return getService("release", { strapi }).updateReleaseStatus(releaseId);
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
}
|
|
316
|
+
}
|
|
293
317
|
}
|
|
294
|
-
async function disableContentTypeLocalized({ oldContentTypes, contentTypes
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
const i18nPlugin = strapi.plugin("i18n");
|
|
299
|
-
if (!i18nPlugin) {
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
for (const uid in contentTypes2) {
|
|
303
|
-
if (!oldContentTypes[uid]) {
|
|
304
|
-
continue;
|
|
318
|
+
async function disableContentTypeLocalized({ oldContentTypes, contentTypes }) {
|
|
319
|
+
if (!oldContentTypes) {
|
|
320
|
+
return;
|
|
305
321
|
}
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
322
|
+
const i18nPlugin = strapi.plugin('i18n');
|
|
323
|
+
if (!i18nPlugin) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
for(const uid in contentTypes){
|
|
327
|
+
if (!oldContentTypes[uid]) {
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
const oldContentType = oldContentTypes[uid];
|
|
331
|
+
const contentType = contentTypes[uid];
|
|
332
|
+
const { isLocalizedContentType } = i18nPlugin.service('content-types');
|
|
333
|
+
// if i18N is disabled remove non default locales before sync
|
|
334
|
+
if (isLocalizedContentType(oldContentType) && !isLocalizedContentType(contentType)) {
|
|
335
|
+
await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
|
|
336
|
+
locale: null
|
|
337
|
+
}).where({
|
|
338
|
+
contentType: uid
|
|
339
|
+
}).execute();
|
|
340
|
+
}
|
|
313
341
|
}
|
|
314
|
-
}
|
|
315
342
|
}
|
|
316
|
-
async function enableContentTypeLocalized({ oldContentTypes, contentTypes
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
const i18nPlugin = strapi.plugin("i18n");
|
|
321
|
-
if (!i18nPlugin) {
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
for (const uid in contentTypes2) {
|
|
325
|
-
if (!oldContentTypes[uid]) {
|
|
326
|
-
continue;
|
|
343
|
+
async function enableContentTypeLocalized({ oldContentTypes, contentTypes }) {
|
|
344
|
+
if (!oldContentTypes) {
|
|
345
|
+
return;
|
|
327
346
|
}
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const { getDefaultLocale } = i18nPlugin.service("locales");
|
|
332
|
-
if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {
|
|
333
|
-
const defaultLocale = await getDefaultLocale();
|
|
334
|
-
await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
|
|
335
|
-
locale: defaultLocale
|
|
336
|
-
}).where({ contentType: uid }).execute();
|
|
347
|
+
const i18nPlugin = strapi.plugin('i18n');
|
|
348
|
+
if (!i18nPlugin) {
|
|
349
|
+
return;
|
|
337
350
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
351
|
+
for(const uid in contentTypes){
|
|
352
|
+
if (!oldContentTypes[uid]) {
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
const oldContentType = oldContentTypes[uid];
|
|
356
|
+
const contentType = contentTypes[uid];
|
|
357
|
+
const { isLocalizedContentType } = i18nPlugin.service('content-types');
|
|
358
|
+
const { getDefaultLocale } = i18nPlugin.service('locales');
|
|
359
|
+
// if i18N is enabled remove non default locales before sync
|
|
360
|
+
if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {
|
|
361
|
+
const defaultLocale = await getDefaultLocale();
|
|
362
|
+
await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
|
|
363
|
+
locale: defaultLocale
|
|
364
|
+
}).where({
|
|
365
|
+
contentType: uid
|
|
366
|
+
}).execute();
|
|
367
|
+
}
|
|
346
368
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* On v4, release actions are linked with entries using the built in Polymorphic relations.
|
|
373
|
+
*
|
|
374
|
+
* On v5, we are going to save entryDocumentId on the release action and make the link manually.
|
|
375
|
+
* This because entryId is not a reliable way to link documents, as it can change.
|
|
376
|
+
*/ const addEntryDocumentToReleaseActions = {
|
|
377
|
+
name: 'content-releases::5.0.0-add-entry-document-id-to-release-actions',
|
|
378
|
+
async up (trx, db) {
|
|
379
|
+
// Check if the table exists
|
|
380
|
+
const hasTable = await trx.schema.hasTable('strapi_release_actions');
|
|
381
|
+
if (!hasTable) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
const hasPolymorphicColumn = await trx.schema.hasColumn('strapi_release_actions', 'target_id');
|
|
385
|
+
// If user has PolymorphicColumn means that is coming from v4
|
|
386
|
+
if (hasPolymorphicColumn) {
|
|
387
|
+
// First time coming from v4 user doesn't have entryDocumentId
|
|
388
|
+
// but we double check to avoid errors
|
|
389
|
+
const hasEntryDocumentIdColumn = await trx.schema.hasColumn('strapi_release_actions', 'entry_document_id');
|
|
390
|
+
if (!hasEntryDocumentIdColumn) {
|
|
391
|
+
await trx.schema.alterTable('strapi_release_actions', (table)=>{
|
|
392
|
+
table.string('entry_document_id');
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
const releaseActions = await trx.select('*').from('strapi_release_actions');
|
|
396
|
+
utils.async.map(releaseActions, async (action)=>{
|
|
397
|
+
const { target_type, target_id } = action;
|
|
398
|
+
const entry = await db.query(target_type).findOne({
|
|
399
|
+
where: {
|
|
400
|
+
id: target_id
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
if (entry) {
|
|
404
|
+
await trx('strapi_release_actions').update({
|
|
405
|
+
entry_document_id: entry.documentId
|
|
406
|
+
}).where('id', action.id);
|
|
407
|
+
}
|
|
408
|
+
});
|
|
364
409
|
}
|
|
365
|
-
|
|
410
|
+
},
|
|
411
|
+
async down () {
|
|
412
|
+
throw new Error('not implemented');
|
|
366
413
|
}
|
|
367
|
-
},
|
|
368
|
-
async down() {
|
|
369
|
-
throw new Error("not implemented");
|
|
370
|
-
}
|
|
371
414
|
};
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
if (strapi2.plugin("graphql")) {
|
|
380
|
-
const graphqlExtensionService = strapi2.plugin("graphql").service("extension");
|
|
381
|
-
graphqlExtensionService.shadowCRUD(RELEASE_MODEL_UID).disable();
|
|
382
|
-
graphqlExtensionService.shadowCRUD(RELEASE_ACTION_MODEL_UID).disable();
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
const updateActionsStatusAndUpdateReleaseStatus = async (contentType, entry) => {
|
|
386
|
-
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
387
|
-
where: {
|
|
388
|
-
releasedAt: null,
|
|
389
|
-
actions: {
|
|
390
|
-
contentType,
|
|
391
|
-
entryDocumentId: entry.documentId,
|
|
392
|
-
locale: entry.locale
|
|
393
|
-
}
|
|
415
|
+
|
|
416
|
+
const register = async ({ strapi })=>{
|
|
417
|
+
if (strapi.ee.features.isEnabled('cms-content-releases')) {
|
|
418
|
+
await strapi.service('admin::permission').actionProvider.registerMany(ACTIONS);
|
|
419
|
+
strapi.db.migrations.providers.internal.register(addEntryDocumentToReleaseActions);
|
|
420
|
+
strapi.hook('strapi::content-types.beforeSync').register(disableContentTypeLocalized).register(deleteActionsOnDisableDraftAndPublish);
|
|
421
|
+
strapi.hook('strapi::content-types.afterSync').register(deleteActionsOnDeleteContentType).register(enableContentTypeLocalized).register(revalidateChangedContentTypes).register(migrateIsValidAndStatusReleases);
|
|
394
422
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
entryDocumentId: entry.documentId,
|
|
401
|
-
locale: entry.locale
|
|
402
|
-
},
|
|
403
|
-
data: {
|
|
404
|
-
isEntryValid: entryStatus
|
|
423
|
+
if (strapi.plugin('graphql')) {
|
|
424
|
+
const graphqlExtensionService = strapi.plugin('graphql').service('extension');
|
|
425
|
+
// Exclude the release and release action models from the GraphQL schema
|
|
426
|
+
graphqlExtensionService.shadowCRUD(RELEASE_MODEL_UID).disable();
|
|
427
|
+
graphqlExtensionService.shadowCRUD(RELEASE_ACTION_MODEL_UID).disable();
|
|
405
428
|
}
|
|
406
|
-
});
|
|
407
|
-
for (const release2 of releases) {
|
|
408
|
-
getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
409
|
-
}
|
|
410
429
|
};
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
430
|
+
|
|
431
|
+
const updateActionsStatusAndUpdateReleaseStatus = async (contentType, entry)=>{
|
|
432
|
+
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
433
|
+
where: {
|
|
434
|
+
releasedAt: null,
|
|
435
|
+
actions: {
|
|
436
|
+
contentType,
|
|
437
|
+
entryDocumentId: entry.documentId,
|
|
438
|
+
locale: entry.locale
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
const entryStatus = await isEntryValid(contentType, entry, {
|
|
443
|
+
strapi
|
|
444
|
+
});
|
|
445
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).updateMany({
|
|
446
|
+
where: {
|
|
447
|
+
contentType,
|
|
448
|
+
entryDocumentId: entry.documentId,
|
|
449
|
+
locale: entry.locale
|
|
450
|
+
},
|
|
451
|
+
data: {
|
|
452
|
+
isEntryValid: entryStatus
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
for (const release of releases){
|
|
456
|
+
getService('release', {
|
|
457
|
+
strapi
|
|
458
|
+
}).updateReleaseStatus(release.id);
|
|
415
459
|
}
|
|
416
|
-
});
|
|
417
|
-
await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
418
|
-
where: params
|
|
419
|
-
});
|
|
420
|
-
for (const release2 of releases) {
|
|
421
|
-
getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
422
|
-
}
|
|
423
460
|
};
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
return next();
|
|
430
|
-
}
|
|
431
|
-
const contentType = ctx.contentType.uid;
|
|
432
|
-
const { documentId, locale } = ctx.params;
|
|
433
|
-
const result = await next();
|
|
434
|
-
if (!result) {
|
|
435
|
-
return result;
|
|
436
|
-
}
|
|
437
|
-
try {
|
|
438
|
-
deleteActionsAndUpdateReleaseStatus({
|
|
439
|
-
contentType,
|
|
440
|
-
entryDocumentId: documentId,
|
|
441
|
-
...locale !== "*" && { locale }
|
|
461
|
+
const deleteActionsAndUpdateReleaseStatus = async (params)=>{
|
|
462
|
+
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
463
|
+
where: {
|
|
464
|
+
actions: params
|
|
465
|
+
}
|
|
442
466
|
});
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
error
|
|
467
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
468
|
+
where: params
|
|
446
469
|
});
|
|
447
|
-
|
|
448
|
-
|
|
470
|
+
for (const release of releases){
|
|
471
|
+
getService('release', {
|
|
472
|
+
strapi
|
|
473
|
+
}).updateReleaseStatus(release.id);
|
|
474
|
+
}
|
|
449
475
|
};
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
476
|
+
const deleteActionsOnDelete = async (ctx, next)=>{
|
|
477
|
+
if (ctx.action !== 'delete') {
|
|
478
|
+
return next();
|
|
479
|
+
}
|
|
480
|
+
if (!utils.contentTypes.hasDraftAndPublish(ctx.contentType)) {
|
|
481
|
+
return next();
|
|
482
|
+
}
|
|
483
|
+
const contentType = ctx.contentType.uid;
|
|
484
|
+
const { documentId, locale } = ctx.params;
|
|
485
|
+
const result = await next();
|
|
486
|
+
if (!result) {
|
|
487
|
+
return result;
|
|
488
|
+
}
|
|
489
|
+
try {
|
|
490
|
+
deleteActionsAndUpdateReleaseStatus({
|
|
491
|
+
contentType,
|
|
492
|
+
entryDocumentId: documentId,
|
|
493
|
+
...locale !== '*' && {
|
|
494
|
+
locale
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
} catch (error) {
|
|
498
|
+
strapi.log.error('Error while deleting release actions after delete', {
|
|
499
|
+
error
|
|
500
|
+
});
|
|
501
|
+
}
|
|
460
502
|
return result;
|
|
461
|
-
}
|
|
462
|
-
try {
|
|
463
|
-
updateActionsStatusAndUpdateReleaseStatus(contentType, result);
|
|
464
|
-
} catch (error) {
|
|
465
|
-
strapi.log.error("Error while updating release actions after update", {
|
|
466
|
-
error
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
return result;
|
|
470
503
|
};
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
actions: params
|
|
504
|
+
const updateActionsOnUpdate = async (ctx, next)=>{
|
|
505
|
+
if (ctx.action !== 'update') {
|
|
506
|
+
return next();
|
|
475
507
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
);
|
|
489
|
-
strapi2.db.lifecycles.subscribe({
|
|
490
|
-
models: contentTypesWithDraftAndPublish,
|
|
491
|
-
/**
|
|
492
|
-
* deleteMany is still used outside documents service, for example when deleting a locale
|
|
493
|
-
*/
|
|
494
|
-
async afterDeleteMany(event) {
|
|
495
|
-
try {
|
|
496
|
-
const model = strapi2.getModel(event.model.uid);
|
|
497
|
-
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
498
|
-
const { where } = event.params;
|
|
499
|
-
deleteReleasesActionsAndUpdateReleaseStatus({
|
|
500
|
-
contentType: model.uid,
|
|
501
|
-
locale: where?.locale ?? null,
|
|
502
|
-
...where?.documentId && { entryDocumentId: where.documentId }
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
} catch (error) {
|
|
506
|
-
strapi2.log.error("Error while deleting release actions after entry deleteMany", {
|
|
508
|
+
if (!utils.contentTypes.hasDraftAndPublish(ctx.contentType)) {
|
|
509
|
+
return next();
|
|
510
|
+
}
|
|
511
|
+
const contentType = ctx.contentType.uid;
|
|
512
|
+
const result = await next();
|
|
513
|
+
if (!result) {
|
|
514
|
+
return result;
|
|
515
|
+
}
|
|
516
|
+
try {
|
|
517
|
+
updateActionsStatusAndUpdateReleaseStatus(contentType, result);
|
|
518
|
+
} catch (error) {
|
|
519
|
+
strapi.log.error('Error while updating release actions after update', {
|
|
507
520
|
error
|
|
508
|
-
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
return result;
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
const deleteReleasesActionsAndUpdateReleaseStatus = async (params)=>{
|
|
527
|
+
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
528
|
+
where: {
|
|
529
|
+
actions: params
|
|
509
530
|
}
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
strapi2.documents.use(deleteActionsOnDelete);
|
|
513
|
-
strapi2.documents.use(updateActionsOnUpdate);
|
|
514
|
-
getService("scheduling", { strapi: strapi2 }).syncFromDatabase().catch((err) => {
|
|
515
|
-
strapi2.log.error(
|
|
516
|
-
"Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling."
|
|
517
|
-
);
|
|
518
|
-
throw err;
|
|
519
531
|
});
|
|
520
|
-
|
|
521
|
-
|
|
532
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
533
|
+
where: params
|
|
522
534
|
});
|
|
523
|
-
|
|
535
|
+
// We update the status of each release after delete the actions
|
|
536
|
+
for (const release of releases){
|
|
537
|
+
getService('release', {
|
|
538
|
+
strapi
|
|
539
|
+
}).updateReleaseStatus(release.id);
|
|
540
|
+
}
|
|
524
541
|
};
|
|
525
|
-
const
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
542
|
+
const bootstrap = async ({ strapi: strapi1 })=>{
|
|
543
|
+
if (strapi1.ee.features.isEnabled('cms-content-releases')) {
|
|
544
|
+
const contentTypesWithDraftAndPublish = Object.keys(strapi1.contentTypes).filter((uid)=>strapi1.contentTypes[uid]?.options?.draftAndPublish);
|
|
545
|
+
strapi1.db.lifecycles.subscribe({
|
|
546
|
+
models: contentTypesWithDraftAndPublish,
|
|
547
|
+
/**
|
|
548
|
+
* deleteMany is still used outside documents service, for example when deleting a locale
|
|
549
|
+
*/ async afterDeleteMany (event) {
|
|
550
|
+
try {
|
|
551
|
+
const model = strapi1.getModel(event.model.uid);
|
|
552
|
+
// @ts-expect-error TODO: lifecycles types looks like are not 100% finished
|
|
553
|
+
if (model.kind === 'collectionType' && model.options?.draftAndPublish) {
|
|
554
|
+
const { where } = event.params;
|
|
555
|
+
deleteReleasesActionsAndUpdateReleaseStatus({
|
|
556
|
+
contentType: model.uid,
|
|
557
|
+
locale: where?.locale ?? null,
|
|
558
|
+
...where?.documentId && {
|
|
559
|
+
entryDocumentId: where.documentId
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
} catch (error) {
|
|
564
|
+
// If an error happens we don't want to block the delete entry flow, but we log the error
|
|
565
|
+
strapi1.log.error('Error while deleting release actions after entry deleteMany', {
|
|
566
|
+
error
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
// We register middleware to handle ReleaseActions when changes on documents are made
|
|
572
|
+
strapi1.documents.use(deleteActionsOnDelete);
|
|
573
|
+
strapi1.documents.use(updateActionsOnUpdate);
|
|
574
|
+
getService('scheduling', {
|
|
575
|
+
strapi: strapi1
|
|
576
|
+
}).syncFromDatabase().catch((err)=>{
|
|
577
|
+
strapi1.log.error('Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling.');
|
|
578
|
+
throw err;
|
|
579
|
+
});
|
|
580
|
+
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value])=>{
|
|
581
|
+
strapi1.get('webhookStore').addAllowedEvent(key, value);
|
|
582
|
+
});
|
|
583
|
+
}
|
|
532
584
|
};
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
options: {
|
|
541
|
-
draftAndPublish: false
|
|
542
|
-
},
|
|
543
|
-
pluginOptions: {
|
|
544
|
-
"content-manager": {
|
|
545
|
-
visible: false
|
|
546
|
-
},
|
|
547
|
-
"content-type-builder": {
|
|
548
|
-
visible: false
|
|
585
|
+
|
|
586
|
+
const destroy = async ({ strapi })=>{
|
|
587
|
+
const scheduledJobs = getService('scheduling', {
|
|
588
|
+
strapi
|
|
589
|
+
}).getAll();
|
|
590
|
+
for (const [, job] of scheduledJobs){
|
|
591
|
+
job.cancel();
|
|
549
592
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
},
|
|
559
|
-
scheduledAt: {
|
|
560
|
-
type: "datetime"
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
var schema$1 = {
|
|
596
|
+
collectionName: 'strapi_releases',
|
|
597
|
+
info: {
|
|
598
|
+
singularName: 'release',
|
|
599
|
+
pluralName: 'releases',
|
|
600
|
+
displayName: 'Release'
|
|
561
601
|
},
|
|
562
|
-
|
|
563
|
-
|
|
602
|
+
options: {
|
|
603
|
+
draftAndPublish: false
|
|
564
604
|
},
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
605
|
+
pluginOptions: {
|
|
606
|
+
'content-manager': {
|
|
607
|
+
visible: false
|
|
608
|
+
},
|
|
609
|
+
'content-type-builder': {
|
|
610
|
+
visible: false
|
|
611
|
+
}
|
|
569
612
|
},
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
613
|
+
attributes: {
|
|
614
|
+
name: {
|
|
615
|
+
type: 'string',
|
|
616
|
+
required: true
|
|
617
|
+
},
|
|
618
|
+
releasedAt: {
|
|
619
|
+
type: 'datetime'
|
|
620
|
+
},
|
|
621
|
+
scheduledAt: {
|
|
622
|
+
type: 'datetime'
|
|
623
|
+
},
|
|
624
|
+
timezone: {
|
|
625
|
+
type: 'string'
|
|
626
|
+
},
|
|
627
|
+
status: {
|
|
628
|
+
type: 'enumeration',
|
|
629
|
+
enum: [
|
|
630
|
+
'ready',
|
|
631
|
+
'blocked',
|
|
632
|
+
'failed',
|
|
633
|
+
'done',
|
|
634
|
+
'empty'
|
|
635
|
+
],
|
|
636
|
+
required: true
|
|
637
|
+
},
|
|
638
|
+
actions: {
|
|
639
|
+
type: 'relation',
|
|
640
|
+
relation: 'oneToMany',
|
|
641
|
+
target: RELEASE_ACTION_MODEL_UID,
|
|
642
|
+
mappedBy: 'release'
|
|
643
|
+
}
|
|
575
644
|
}
|
|
576
|
-
}
|
|
577
645
|
};
|
|
646
|
+
|
|
578
647
|
const release$1 = {
|
|
579
|
-
|
|
648
|
+
schema: schema$1
|
|
580
649
|
};
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
options: {
|
|
589
|
-
draftAndPublish: false
|
|
590
|
-
},
|
|
591
|
-
pluginOptions: {
|
|
592
|
-
"content-manager": {
|
|
593
|
-
visible: false
|
|
650
|
+
|
|
651
|
+
var schema = {
|
|
652
|
+
collectionName: 'strapi_release_actions',
|
|
653
|
+
info: {
|
|
654
|
+
singularName: 'release-action',
|
|
655
|
+
pluralName: 'release-actions',
|
|
656
|
+
displayName: 'Release Action'
|
|
594
657
|
},
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
}
|
|
598
|
-
},
|
|
599
|
-
attributes: {
|
|
600
|
-
type: {
|
|
601
|
-
type: "enumeration",
|
|
602
|
-
enum: ["publish", "unpublish"],
|
|
603
|
-
required: true
|
|
604
|
-
},
|
|
605
|
-
contentType: {
|
|
606
|
-
type: "string",
|
|
607
|
-
required: true
|
|
608
|
-
},
|
|
609
|
-
entryDocumentId: {
|
|
610
|
-
type: "string"
|
|
611
|
-
},
|
|
612
|
-
locale: {
|
|
613
|
-
type: "string"
|
|
658
|
+
options: {
|
|
659
|
+
draftAndPublish: false
|
|
614
660
|
},
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
661
|
+
pluginOptions: {
|
|
662
|
+
'content-manager': {
|
|
663
|
+
visible: false
|
|
664
|
+
},
|
|
665
|
+
'content-type-builder': {
|
|
666
|
+
visible: false
|
|
667
|
+
}
|
|
620
668
|
},
|
|
621
|
-
|
|
622
|
-
|
|
669
|
+
attributes: {
|
|
670
|
+
type: {
|
|
671
|
+
type: 'enumeration',
|
|
672
|
+
enum: [
|
|
673
|
+
'publish',
|
|
674
|
+
'unpublish'
|
|
675
|
+
],
|
|
676
|
+
required: true
|
|
677
|
+
},
|
|
678
|
+
contentType: {
|
|
679
|
+
type: 'string',
|
|
680
|
+
required: true
|
|
681
|
+
},
|
|
682
|
+
entryDocumentId: {
|
|
683
|
+
type: 'string'
|
|
684
|
+
},
|
|
685
|
+
locale: {
|
|
686
|
+
type: 'string'
|
|
687
|
+
},
|
|
688
|
+
release: {
|
|
689
|
+
type: 'relation',
|
|
690
|
+
relation: 'manyToOne',
|
|
691
|
+
target: RELEASE_MODEL_UID,
|
|
692
|
+
inversedBy: 'actions'
|
|
693
|
+
},
|
|
694
|
+
isEntryValid: {
|
|
695
|
+
type: 'boolean'
|
|
696
|
+
}
|
|
623
697
|
}
|
|
624
|
-
}
|
|
625
698
|
};
|
|
699
|
+
|
|
626
700
|
const releaseAction$1 = {
|
|
627
|
-
|
|
701
|
+
schema
|
|
628
702
|
};
|
|
703
|
+
|
|
629
704
|
const contentTypes = {
|
|
630
|
-
|
|
631
|
-
|
|
705
|
+
release: release$1,
|
|
706
|
+
'release-action': releaseAction$1
|
|
632
707
|
};
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
};
|
|
641
|
-
const getFormattedActions = async (releaseId) => {
|
|
642
|
-
const actions = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findMany({
|
|
643
|
-
where: {
|
|
644
|
-
release: {
|
|
645
|
-
id: releaseId
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
});
|
|
649
|
-
if (actions.length === 0) {
|
|
650
|
-
throw new utils.errors.ValidationError("No entries to publish");
|
|
651
|
-
}
|
|
652
|
-
const formattedActions = {};
|
|
653
|
-
for (const action of actions) {
|
|
654
|
-
const contentTypeUid = action.contentType;
|
|
655
|
-
if (!formattedActions[contentTypeUid]) {
|
|
656
|
-
formattedActions[contentTypeUid] = {
|
|
657
|
-
publish: [],
|
|
658
|
-
unpublish: []
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
formattedActions[contentTypeUid][action.type].push({
|
|
662
|
-
documentId: action.entryDocumentId,
|
|
663
|
-
locale: action.locale
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
return formattedActions;
|
|
667
|
-
};
|
|
668
|
-
return {
|
|
669
|
-
async create(releaseData, { user }) {
|
|
670
|
-
const releaseWithCreatorFields = await utils.setCreatorFields({ user })(releaseData);
|
|
671
|
-
const {
|
|
672
|
-
validatePendingReleasesLimit,
|
|
673
|
-
validateUniqueNameForPendingRelease,
|
|
674
|
-
validateScheduledAtIsLaterThanNow
|
|
675
|
-
} = getService("release-validation", { strapi: strapi2 });
|
|
676
|
-
await Promise.all([
|
|
677
|
-
validatePendingReleasesLimit(),
|
|
678
|
-
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
|
|
679
|
-
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
680
|
-
]);
|
|
681
|
-
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).create({
|
|
682
|
-
data: {
|
|
683
|
-
...releaseWithCreatorFields,
|
|
684
|
-
status: "empty"
|
|
685
|
-
}
|
|
686
|
-
});
|
|
687
|
-
if (releaseWithCreatorFields.scheduledAt) {
|
|
688
|
-
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
689
|
-
await schedulingService.set(release2.id, release2.scheduledAt);
|
|
690
|
-
}
|
|
691
|
-
strapi2.telemetry.send("didCreateContentRelease");
|
|
692
|
-
return release2;
|
|
693
|
-
},
|
|
694
|
-
async findOne(id, query = {}) {
|
|
695
|
-
const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query);
|
|
696
|
-
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
697
|
-
...dbQuery,
|
|
698
|
-
where: { id }
|
|
699
|
-
});
|
|
700
|
-
return release2;
|
|
701
|
-
},
|
|
702
|
-
findPage(query) {
|
|
703
|
-
const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
|
|
704
|
-
return strapi2.db.query(RELEASE_MODEL_UID).findPage({
|
|
705
|
-
...dbQuery,
|
|
706
|
-
populate: {
|
|
707
|
-
actions: {
|
|
708
|
-
count: true
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
});
|
|
712
|
-
},
|
|
713
|
-
findMany(query) {
|
|
714
|
-
const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
|
|
715
|
-
return strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
716
|
-
...dbQuery
|
|
717
|
-
});
|
|
718
|
-
},
|
|
719
|
-
async update(id, releaseData, { user }) {
|
|
720
|
-
const releaseWithCreatorFields = await utils.setCreatorFields({ user, isEdition: true })(
|
|
721
|
-
releaseData
|
|
722
|
-
);
|
|
723
|
-
const { validateUniqueNameForPendingRelease, validateScheduledAtIsLaterThanNow } = getService(
|
|
724
|
-
"release-validation",
|
|
725
|
-
{ strapi: strapi2 }
|
|
726
|
-
);
|
|
727
|
-
await Promise.all([
|
|
728
|
-
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name, id),
|
|
729
|
-
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
730
|
-
]);
|
|
731
|
-
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id } });
|
|
732
|
-
if (!release2) {
|
|
733
|
-
throw new utils.errors.NotFoundError(`No release found for id ${id}`);
|
|
734
|
-
}
|
|
735
|
-
if (release2.releasedAt) {
|
|
736
|
-
throw new utils.errors.ValidationError("Release already published");
|
|
737
|
-
}
|
|
738
|
-
const updatedRelease = await strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
739
|
-
where: { id },
|
|
740
|
-
data: releaseWithCreatorFields
|
|
741
|
-
});
|
|
742
|
-
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
743
|
-
if (releaseData.scheduledAt) {
|
|
744
|
-
await schedulingService.set(id, releaseData.scheduledAt);
|
|
745
|
-
} else if (release2.scheduledAt) {
|
|
746
|
-
schedulingService.cancel(id);
|
|
747
|
-
}
|
|
748
|
-
this.updateReleaseStatus(id);
|
|
749
|
-
strapi2.telemetry.send("didUpdateContentRelease");
|
|
750
|
-
return updatedRelease;
|
|
751
|
-
},
|
|
752
|
-
async getAllComponents() {
|
|
753
|
-
const contentManagerComponentsService = strapi2.plugin("content-manager").service("components");
|
|
754
|
-
const components = await contentManagerComponentsService.findAllComponents();
|
|
755
|
-
const componentsMap = components.reduce(
|
|
756
|
-
(acc, component) => {
|
|
757
|
-
acc[component.uid] = component;
|
|
758
|
-
return acc;
|
|
759
|
-
},
|
|
760
|
-
{}
|
|
761
|
-
);
|
|
762
|
-
return componentsMap;
|
|
763
|
-
},
|
|
764
|
-
async delete(releaseId) {
|
|
765
|
-
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
766
|
-
where: { id: releaseId },
|
|
767
|
-
populate: {
|
|
768
|
-
actions: {
|
|
769
|
-
select: ["id"]
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
});
|
|
773
|
-
if (!release2) {
|
|
774
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
775
|
-
}
|
|
776
|
-
if (release2.releasedAt) {
|
|
777
|
-
throw new utils.errors.ValidationError("Release already published");
|
|
778
|
-
}
|
|
779
|
-
await strapi2.db.transaction(async () => {
|
|
780
|
-
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
781
|
-
where: {
|
|
782
|
-
id: {
|
|
783
|
-
$in: release2.actions.map((action) => action.id)
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
});
|
|
787
|
-
await strapi2.db.query(RELEASE_MODEL_UID).delete({
|
|
788
|
-
where: {
|
|
789
|
-
id: releaseId
|
|
790
|
-
}
|
|
708
|
+
|
|
709
|
+
const createReleaseService = ({ strapi })=>{
|
|
710
|
+
const dispatchWebhook = (event, { isPublished, release, error })=>{
|
|
711
|
+
strapi.eventHub.emit(event, {
|
|
712
|
+
isPublished,
|
|
713
|
+
error,
|
|
714
|
+
release
|
|
791
715
|
});
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
return release2;
|
|
799
|
-
},
|
|
800
|
-
async publish(releaseId) {
|
|
801
|
-
const {
|
|
802
|
-
release: release2,
|
|
803
|
-
error
|
|
804
|
-
} = await strapi2.db.transaction(async ({ trx }) => {
|
|
805
|
-
const lockedRelease = await strapi2.db?.queryBuilder(RELEASE_MODEL_UID).where({ id: releaseId }).select(["id", "name", "releasedAt", "status"]).first().transacting(trx).forUpdate().execute();
|
|
806
|
-
if (!lockedRelease) {
|
|
807
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
808
|
-
}
|
|
809
|
-
if (lockedRelease.releasedAt) {
|
|
810
|
-
throw new utils.errors.ValidationError("Release already published");
|
|
811
|
-
}
|
|
812
|
-
if (lockedRelease.status === "failed") {
|
|
813
|
-
throw new utils.errors.ValidationError("Release failed to publish");
|
|
814
|
-
}
|
|
815
|
-
try {
|
|
816
|
-
strapi2.log.info(`[Content Releases] Starting to publish release ${lockedRelease.name}`);
|
|
817
|
-
const formattedActions = await getFormattedActions(releaseId);
|
|
818
|
-
await strapi2.db.transaction(
|
|
819
|
-
async () => Promise.all(
|
|
820
|
-
Object.keys(formattedActions).map(async (contentTypeUid) => {
|
|
821
|
-
const contentType = contentTypeUid;
|
|
822
|
-
const { publish, unpublish } = formattedActions[contentType];
|
|
823
|
-
return Promise.all([
|
|
824
|
-
...publish.map((params) => strapi2.documents(contentType).publish(params)),
|
|
825
|
-
...unpublish.map((params) => strapi2.documents(contentType).unpublish(params))
|
|
826
|
-
]);
|
|
827
|
-
})
|
|
828
|
-
)
|
|
829
|
-
);
|
|
830
|
-
const release22 = await strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
831
|
-
where: {
|
|
832
|
-
id: releaseId
|
|
833
|
-
},
|
|
834
|
-
data: {
|
|
835
|
-
status: "done",
|
|
836
|
-
releasedAt: /* @__PURE__ */ new Date()
|
|
837
|
-
}
|
|
838
|
-
});
|
|
839
|
-
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
840
|
-
isPublished: true,
|
|
841
|
-
release: release22
|
|
842
|
-
});
|
|
843
|
-
strapi2.telemetry.send("didPublishContentRelease");
|
|
844
|
-
return { release: release22, error: null };
|
|
845
|
-
} catch (error2) {
|
|
846
|
-
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
847
|
-
isPublished: false,
|
|
848
|
-
error: error2
|
|
849
|
-
});
|
|
850
|
-
await strapi2.db?.queryBuilder(RELEASE_MODEL_UID).where({ id: releaseId }).update({
|
|
851
|
-
status: "failed"
|
|
852
|
-
}).transacting(trx).execute();
|
|
853
|
-
return {
|
|
854
|
-
release: null,
|
|
855
|
-
error: error2
|
|
856
|
-
};
|
|
857
|
-
}
|
|
858
|
-
});
|
|
859
|
-
if (error instanceof Error) {
|
|
860
|
-
throw error;
|
|
861
|
-
}
|
|
862
|
-
return release2;
|
|
863
|
-
},
|
|
864
|
-
async updateReleaseStatus(releaseId) {
|
|
865
|
-
const releaseActionService = getService("release-action", { strapi: strapi2 });
|
|
866
|
-
const [totalActions, invalidActions] = await Promise.all([
|
|
867
|
-
releaseActionService.countActions({
|
|
868
|
-
filters: {
|
|
869
|
-
release: releaseId
|
|
870
|
-
}
|
|
871
|
-
}),
|
|
872
|
-
releaseActionService.countActions({
|
|
873
|
-
filters: {
|
|
874
|
-
release: releaseId,
|
|
875
|
-
isEntryValid: false
|
|
876
|
-
}
|
|
877
|
-
})
|
|
878
|
-
]);
|
|
879
|
-
if (totalActions > 0) {
|
|
880
|
-
if (invalidActions > 0) {
|
|
881
|
-
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
716
|
+
};
|
|
717
|
+
/**
|
|
718
|
+
* Given a release id, it returns the actions formatted ready to be used to publish them.
|
|
719
|
+
* We split them by contentType and type (publish/unpublish) and extract only the documentIds and locales.
|
|
720
|
+
*/ const getFormattedActions = async (releaseId)=>{
|
|
721
|
+
const actions = await strapi.db.query(RELEASE_ACTION_MODEL_UID).findMany({
|
|
882
722
|
where: {
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
status: "blocked"
|
|
723
|
+
release: {
|
|
724
|
+
id: releaseId
|
|
725
|
+
}
|
|
887
726
|
}
|
|
888
|
-
});
|
|
889
|
-
}
|
|
890
|
-
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
891
|
-
where: {
|
|
892
|
-
id: releaseId
|
|
893
|
-
},
|
|
894
|
-
data: {
|
|
895
|
-
status: "ready"
|
|
896
|
-
}
|
|
897
727
|
});
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
where: {
|
|
901
|
-
id: releaseId
|
|
902
|
-
},
|
|
903
|
-
data: {
|
|
904
|
-
status: "empty"
|
|
728
|
+
if (actions.length === 0) {
|
|
729
|
+
throw new utils.errors.ValidationError('No entries to publish');
|
|
905
730
|
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
const
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
};
|
|
922
|
-
const createReleaseActionService = ({ strapi: strapi2 }) => {
|
|
923
|
-
const getLocalesDataForActions = async () => {
|
|
924
|
-
if (!strapi2.plugin("i18n")) {
|
|
925
|
-
return {};
|
|
926
|
-
}
|
|
927
|
-
const allLocales = await strapi2.plugin("i18n").service("locales").find() || [];
|
|
928
|
-
return allLocales.reduce((acc, locale) => {
|
|
929
|
-
acc[locale.code] = { name: locale.name, code: locale.code };
|
|
930
|
-
return acc;
|
|
931
|
-
}, {});
|
|
932
|
-
};
|
|
933
|
-
const getContentTypesDataForActions = async (contentTypesUids) => {
|
|
934
|
-
const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
|
|
935
|
-
const contentTypesData = {};
|
|
936
|
-
for (const contentTypeUid of contentTypesUids) {
|
|
937
|
-
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
938
|
-
uid: contentTypeUid
|
|
939
|
-
});
|
|
940
|
-
contentTypesData[contentTypeUid] = {
|
|
941
|
-
mainField: contentTypeConfig.settings.mainField,
|
|
942
|
-
displayName: strapi2.getModel(contentTypeUid).info.displayName
|
|
943
|
-
};
|
|
944
|
-
}
|
|
945
|
-
return contentTypesData;
|
|
946
|
-
};
|
|
947
|
-
return {
|
|
948
|
-
async create(releaseId, action, { disableUpdateReleaseStatus = false } = {}) {
|
|
949
|
-
const { validateEntryData, validateUniqueEntry } = getService("release-validation", {
|
|
950
|
-
strapi: strapi2
|
|
951
|
-
});
|
|
952
|
-
await Promise.all([
|
|
953
|
-
validateEntryData(action.contentType, action.entryDocumentId),
|
|
954
|
-
validateUniqueEntry(releaseId, action)
|
|
955
|
-
]);
|
|
956
|
-
const model = strapi2.contentType(action.contentType);
|
|
957
|
-
if (model.kind === "singleType") {
|
|
958
|
-
const document = await strapi2.db.query(model.uid).findOne({ select: ["documentId"] });
|
|
959
|
-
if (!document) {
|
|
960
|
-
throw new utils.errors.NotFoundError(`No entry found for contentType ${action.contentType}`);
|
|
731
|
+
/**
|
|
732
|
+
* We separate publish and unpublish actions, grouping them by contentType and extracting only their documentIds and locales.
|
|
733
|
+
*/ const formattedActions = {};
|
|
734
|
+
for (const action of actions){
|
|
735
|
+
const contentTypeUid = action.contentType;
|
|
736
|
+
if (!formattedActions[contentTypeUid]) {
|
|
737
|
+
formattedActions[contentTypeUid] = {
|
|
738
|
+
publish: [],
|
|
739
|
+
unpublish: []
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
formattedActions[contentTypeUid][action.type].push({
|
|
743
|
+
documentId: action.entryDocumentId,
|
|
744
|
+
locale: action.locale
|
|
745
|
+
});
|
|
961
746
|
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
747
|
+
return formattedActions;
|
|
748
|
+
};
|
|
749
|
+
return {
|
|
750
|
+
async create (releaseData, { user }) {
|
|
751
|
+
const releaseWithCreatorFields = await utils.setCreatorFields({
|
|
752
|
+
user
|
|
753
|
+
})(releaseData);
|
|
754
|
+
const { validatePendingReleasesLimit, validateUniqueNameForPendingRelease, validateScheduledAtIsLaterThanNow } = getService('release-validation', {
|
|
755
|
+
strapi
|
|
756
|
+
});
|
|
757
|
+
await Promise.all([
|
|
758
|
+
validatePendingReleasesLimit(),
|
|
759
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
|
|
760
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
761
|
+
]);
|
|
762
|
+
const release = await strapi.db.query(RELEASE_MODEL_UID).create({
|
|
763
|
+
data: {
|
|
764
|
+
...releaseWithCreatorFields,
|
|
765
|
+
status: 'empty'
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
if (releaseWithCreatorFields.scheduledAt) {
|
|
769
|
+
const schedulingService = getService('scheduling', {
|
|
770
|
+
strapi
|
|
771
|
+
});
|
|
772
|
+
await schedulingService.set(release.id, release.scheduledAt);
|
|
773
|
+
}
|
|
774
|
+
strapi.telemetry.send('didCreateContentRelease');
|
|
775
|
+
return release;
|
|
976
776
|
},
|
|
977
|
-
{
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
777
|
+
async findOne (id, query = {}) {
|
|
778
|
+
const dbQuery = strapi.get('query-params').transform(RELEASE_MODEL_UID, query);
|
|
779
|
+
const release = await strapi.db.query(RELEASE_MODEL_UID).findOne({
|
|
780
|
+
...dbQuery,
|
|
781
|
+
where: {
|
|
782
|
+
id
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
return release;
|
|
986
786
|
},
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
787
|
+
findPage (query) {
|
|
788
|
+
const dbQuery = strapi.get('query-params').transform(RELEASE_MODEL_UID, query ?? {});
|
|
789
|
+
return strapi.db.query(RELEASE_MODEL_UID).findPage({
|
|
790
|
+
...dbQuery,
|
|
791
|
+
populate: {
|
|
792
|
+
actions: {
|
|
793
|
+
count: true
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
},
|
|
798
|
+
findMany (query) {
|
|
799
|
+
const dbQuery = strapi.get('query-params').transform(RELEASE_MODEL_UID, query ?? {});
|
|
800
|
+
return strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
801
|
+
...dbQuery
|
|
802
|
+
});
|
|
803
|
+
},
|
|
804
|
+
async update (id, releaseData, { user }) {
|
|
805
|
+
const releaseWithCreatorFields = await utils.setCreatorFields({
|
|
806
|
+
user,
|
|
807
|
+
isEdition: true
|
|
808
|
+
})(releaseData);
|
|
809
|
+
const { validateUniqueNameForPendingRelease, validateScheduledAtIsLaterThanNow } = getService('release-validation', {
|
|
810
|
+
strapi
|
|
811
|
+
});
|
|
812
|
+
await Promise.all([
|
|
813
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name, id),
|
|
814
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
815
|
+
]);
|
|
816
|
+
const release = await strapi.db.query(RELEASE_MODEL_UID).findOne({
|
|
817
|
+
where: {
|
|
818
|
+
id
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
if (!release) {
|
|
822
|
+
throw new utils.errors.NotFoundError(`No release found for id ${id}`);
|
|
823
|
+
}
|
|
824
|
+
if (release.releasedAt) {
|
|
825
|
+
throw new utils.errors.ValidationError('Release already published');
|
|
826
|
+
}
|
|
827
|
+
const updatedRelease = await strapi.db.query(RELEASE_MODEL_UID).update({
|
|
828
|
+
where: {
|
|
829
|
+
id
|
|
830
|
+
},
|
|
831
|
+
data: releaseWithCreatorFields
|
|
832
|
+
});
|
|
833
|
+
const schedulingService = getService('scheduling', {
|
|
834
|
+
strapi
|
|
835
|
+
});
|
|
836
|
+
if (releaseData.scheduledAt) {
|
|
837
|
+
// set function always cancel the previous job if it exists, so we can call it directly
|
|
838
|
+
await schedulingService.set(id, releaseData.scheduledAt);
|
|
839
|
+
} else if (release.scheduledAt) {
|
|
840
|
+
// When user don't send a scheduledAt and we have one on the release, means that user want to unschedule it
|
|
841
|
+
schedulingService.cancel(id);
|
|
842
|
+
}
|
|
843
|
+
this.updateReleaseStatus(id);
|
|
844
|
+
strapi.telemetry.send('didUpdateContentRelease');
|
|
845
|
+
return updatedRelease;
|
|
846
|
+
},
|
|
847
|
+
async getAllComponents () {
|
|
848
|
+
const contentManagerComponentsService = strapi.plugin('content-manager').service('components');
|
|
849
|
+
const components = await contentManagerComponentsService.findAllComponents();
|
|
850
|
+
const componentsMap = components.reduce((acc, component)=>{
|
|
851
|
+
acc[component.uid] = component;
|
|
852
|
+
return acc;
|
|
853
|
+
}, {});
|
|
854
|
+
return componentsMap;
|
|
855
|
+
},
|
|
856
|
+
async delete (releaseId) {
|
|
857
|
+
const release = await strapi.db.query(RELEASE_MODEL_UID).findOne({
|
|
858
|
+
where: {
|
|
859
|
+
id: releaseId
|
|
860
|
+
},
|
|
861
|
+
populate: {
|
|
862
|
+
actions: {
|
|
863
|
+
select: [
|
|
864
|
+
'id'
|
|
865
|
+
]
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
if (!release) {
|
|
870
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
871
|
+
}
|
|
872
|
+
if (release.releasedAt) {
|
|
873
|
+
throw new utils.errors.ValidationError('Release already published');
|
|
874
|
+
}
|
|
875
|
+
// Only delete the release and its actions is you in fact can delete all the actions and the release
|
|
876
|
+
// Otherwise, if the transaction fails it throws an error
|
|
877
|
+
await strapi.db.transaction(async ()=>{
|
|
878
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
879
|
+
where: {
|
|
880
|
+
id: {
|
|
881
|
+
$in: release.actions.map((action)=>action.id)
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
await strapi.db.query(RELEASE_MODEL_UID).delete({
|
|
886
|
+
where: {
|
|
887
|
+
id: releaseId
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
});
|
|
891
|
+
if (release.scheduledAt) {
|
|
892
|
+
const schedulingService = getService('scheduling', {
|
|
893
|
+
strapi
|
|
894
|
+
});
|
|
895
|
+
await schedulingService.cancel(release.id);
|
|
896
|
+
}
|
|
897
|
+
strapi.telemetry.send('didDeleteContentRelease');
|
|
898
|
+
return release;
|
|
899
|
+
},
|
|
900
|
+
async publish (releaseId) {
|
|
901
|
+
const { release, error } = await strapi.db.transaction(async ({ trx })=>{
|
|
902
|
+
/**
|
|
903
|
+
* We lock the release in this transaction, so any other process trying to publish it will wait until this transaction is finished
|
|
904
|
+
* In this transaction we don't care about rollback, becasue we want to persist the lock until the end and if it fails we want to change the release status to failed
|
|
905
|
+
*/ const lockedRelease = await strapi.db?.queryBuilder(RELEASE_MODEL_UID).where({
|
|
906
|
+
id: releaseId
|
|
907
|
+
}).select([
|
|
908
|
+
'id',
|
|
909
|
+
'name',
|
|
910
|
+
'releasedAt',
|
|
911
|
+
'status'
|
|
912
|
+
]).first().transacting(trx).forUpdate().execute();
|
|
913
|
+
if (!lockedRelease) {
|
|
914
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
915
|
+
}
|
|
916
|
+
if (lockedRelease.releasedAt) {
|
|
917
|
+
throw new utils.errors.ValidationError('Release already published');
|
|
918
|
+
}
|
|
919
|
+
if (lockedRelease.status === 'failed') {
|
|
920
|
+
throw new utils.errors.ValidationError('Release failed to publish');
|
|
921
|
+
}
|
|
922
|
+
try {
|
|
923
|
+
strapi.log.info(`[Content Releases] Starting to publish release ${lockedRelease.name}`);
|
|
924
|
+
const formattedActions = await getFormattedActions(releaseId);
|
|
925
|
+
await strapi.db.transaction(async ()=>Promise.all(Object.keys(formattedActions).map(async (contentTypeUid)=>{
|
|
926
|
+
const contentType = contentTypeUid;
|
|
927
|
+
const { publish, unpublish } = formattedActions[contentType];
|
|
928
|
+
return Promise.all([
|
|
929
|
+
...publish.map((params)=>strapi.documents(contentType).publish(params)),
|
|
930
|
+
...unpublish.map((params)=>strapi.documents(contentType).unpublish(params))
|
|
931
|
+
]);
|
|
932
|
+
})));
|
|
933
|
+
const release = await strapi.db.query(RELEASE_MODEL_UID).update({
|
|
934
|
+
where: {
|
|
935
|
+
id: releaseId
|
|
936
|
+
},
|
|
937
|
+
data: {
|
|
938
|
+
status: 'done',
|
|
939
|
+
releasedAt: new Date()
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
943
|
+
isPublished: true,
|
|
944
|
+
release
|
|
945
|
+
});
|
|
946
|
+
strapi.telemetry.send('didPublishContentRelease');
|
|
947
|
+
return {
|
|
948
|
+
release,
|
|
949
|
+
error: null
|
|
950
|
+
};
|
|
951
|
+
} catch (error) {
|
|
952
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
953
|
+
isPublished: false,
|
|
954
|
+
error
|
|
955
|
+
});
|
|
956
|
+
// We need to run the update in the same transaction because the release is locked
|
|
957
|
+
await strapi.db?.queryBuilder(RELEASE_MODEL_UID).where({
|
|
958
|
+
id: releaseId
|
|
959
|
+
}).update({
|
|
960
|
+
status: 'failed'
|
|
961
|
+
}).transacting(trx).execute();
|
|
962
|
+
// At this point, we don't want to throw the error because if that happen we rollback the change in the release status
|
|
963
|
+
// We want to throw the error after the transaction is finished, so we return the error
|
|
964
|
+
return {
|
|
965
|
+
release: null,
|
|
966
|
+
error
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
// Now the first transaction is commited, we can safely throw the error if it exists
|
|
971
|
+
if (error instanceof Error) {
|
|
972
|
+
throw error;
|
|
973
|
+
}
|
|
974
|
+
return release;
|
|
975
|
+
},
|
|
976
|
+
async updateReleaseStatus (releaseId) {
|
|
977
|
+
const releaseActionService = getService('release-action', {
|
|
978
|
+
strapi
|
|
979
|
+
});
|
|
980
|
+
const [totalActions, invalidActions] = await Promise.all([
|
|
981
|
+
releaseActionService.countActions({
|
|
982
|
+
filters: {
|
|
983
|
+
release: releaseId
|
|
984
|
+
}
|
|
985
|
+
}),
|
|
986
|
+
releaseActionService.countActions({
|
|
987
|
+
filters: {
|
|
988
|
+
release: releaseId,
|
|
989
|
+
isEntryValid: false
|
|
990
|
+
}
|
|
991
|
+
})
|
|
992
|
+
]);
|
|
993
|
+
if (totalActions > 0) {
|
|
994
|
+
if (invalidActions > 0) {
|
|
995
|
+
return strapi.db.query(RELEASE_MODEL_UID).update({
|
|
996
|
+
where: {
|
|
997
|
+
id: releaseId
|
|
998
|
+
},
|
|
999
|
+
data: {
|
|
1000
|
+
status: 'blocked'
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
return strapi.db.query(RELEASE_MODEL_UID).update({
|
|
1005
|
+
where: {
|
|
1006
|
+
id: releaseId
|
|
1007
|
+
},
|
|
1008
|
+
data: {
|
|
1009
|
+
status: 'ready'
|
|
1010
|
+
}
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
return strapi.db.query(RELEASE_MODEL_UID).update({
|
|
1014
|
+
where: {
|
|
1015
|
+
id: releaseId
|
|
1016
|
+
},
|
|
1017
|
+
data: {
|
|
1018
|
+
status: 'empty'
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1007
1021
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
contentType
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
});
|
|
1028
|
-
return {
|
|
1029
|
-
results: actionsWithEntry,
|
|
1030
|
-
pagination
|
|
1031
|
-
};
|
|
1032
|
-
},
|
|
1033
|
-
async groupActions(actions, groupBy) {
|
|
1034
|
-
const contentTypeUids = actions.reduce((acc, action) => {
|
|
1035
|
-
if (!acc.includes(action.contentType)) {
|
|
1036
|
-
acc.push(action.contentType);
|
|
1022
|
+
};
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
const getGroupName = (queryValue)=>{
|
|
1026
|
+
switch(queryValue){
|
|
1027
|
+
case 'contentType':
|
|
1028
|
+
return 'contentType.displayName';
|
|
1029
|
+
case 'type':
|
|
1030
|
+
return 'type';
|
|
1031
|
+
case 'locale':
|
|
1032
|
+
return _.getOr('No locale', 'locale.name');
|
|
1033
|
+
default:
|
|
1034
|
+
return 'contentType.displayName';
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
const createReleaseActionService = ({ strapi })=>{
|
|
1038
|
+
const getLocalesDataForActions = async ()=>{
|
|
1039
|
+
if (!strapi.plugin('i18n')) {
|
|
1040
|
+
return {};
|
|
1037
1041
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
const contentTypeUids = actions.reduce((acc, action) => {
|
|
1059
|
-
if (!acc.includes(action.contentType)) {
|
|
1060
|
-
acc.push(action.contentType);
|
|
1042
|
+
const allLocales = await strapi.plugin('i18n').service('locales').find() || [];
|
|
1043
|
+
return allLocales.reduce((acc, locale)=>{
|
|
1044
|
+
acc[locale.code] = {
|
|
1045
|
+
name: locale.name,
|
|
1046
|
+
code: locale.code
|
|
1047
|
+
};
|
|
1048
|
+
return acc;
|
|
1049
|
+
}, {});
|
|
1050
|
+
};
|
|
1051
|
+
const getContentTypesDataForActions = async (contentTypesUids)=>{
|
|
1052
|
+
const contentManagerContentTypeService = strapi.plugin('content-manager').service('content-types');
|
|
1053
|
+
const contentTypesData = {};
|
|
1054
|
+
for (const contentTypeUid of contentTypesUids){
|
|
1055
|
+
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
1056
|
+
uid: contentTypeUid
|
|
1057
|
+
});
|
|
1058
|
+
contentTypesData[contentTypeUid] = {
|
|
1059
|
+
mainField: contentTypeConfig.settings.mainField,
|
|
1060
|
+
displayName: strapi.getModel(contentTypeUid).info.displayName
|
|
1061
|
+
};
|
|
1061
1062
|
}
|
|
1062
|
-
return
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
return strapi2.db.query(RELEASE_ACTION_MODEL_UID).count(dbQuery);
|
|
1086
|
-
},
|
|
1087
|
-
async update(actionId, releaseId, update) {
|
|
1088
|
-
const action = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findOne({
|
|
1089
|
-
where: {
|
|
1090
|
-
id: actionId,
|
|
1091
|
-
release: {
|
|
1092
|
-
id: releaseId,
|
|
1093
|
-
releasedAt: {
|
|
1094
|
-
$null: true
|
|
1063
|
+
return contentTypesData;
|
|
1064
|
+
};
|
|
1065
|
+
return {
|
|
1066
|
+
async create (releaseId, action, { disableUpdateReleaseStatus = false } = {}) {
|
|
1067
|
+
const { validateEntryData, validateUniqueEntry } = getService('release-validation', {
|
|
1068
|
+
strapi
|
|
1069
|
+
});
|
|
1070
|
+
await Promise.all([
|
|
1071
|
+
validateEntryData(action.contentType, action.entryDocumentId),
|
|
1072
|
+
validateUniqueEntry(releaseId, action)
|
|
1073
|
+
]);
|
|
1074
|
+
// If we are adding a singleType, we need to append the documentId of that singleType
|
|
1075
|
+
const model = strapi.contentType(action.contentType);
|
|
1076
|
+
if (model.kind === 'singleType') {
|
|
1077
|
+
const document = await strapi.db.query(model.uid).findOne({
|
|
1078
|
+
select: [
|
|
1079
|
+
'documentId'
|
|
1080
|
+
]
|
|
1081
|
+
});
|
|
1082
|
+
if (!document) {
|
|
1083
|
+
throw new utils.errors.NotFoundError(`No entry found for contentType ${action.contentType}`);
|
|
1084
|
+
}
|
|
1085
|
+
action.entryDocumentId = document.documentId;
|
|
1095
1086
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1087
|
+
const release = await strapi.db.query(RELEASE_MODEL_UID).findOne({
|
|
1088
|
+
where: {
|
|
1089
|
+
id: releaseId
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1092
|
+
if (!release) {
|
|
1093
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
1094
|
+
}
|
|
1095
|
+
if (release.releasedAt) {
|
|
1096
|
+
throw new utils.errors.ValidationError('Release already published');
|
|
1097
|
+
}
|
|
1098
|
+
// If the action is a publish, check if the entry is valid
|
|
1099
|
+
// If the action is an unpublish, skip the validation
|
|
1100
|
+
const actionStatus = action.type === 'publish' ? await getDraftEntryValidStatus({
|
|
1101
|
+
contentType: action.contentType,
|
|
1102
|
+
documentId: action.entryDocumentId,
|
|
1103
|
+
locale: action.locale
|
|
1104
|
+
}, {
|
|
1105
|
+
strapi
|
|
1106
|
+
}) : true;
|
|
1107
|
+
const releaseAction = await strapi.db.query(RELEASE_ACTION_MODEL_UID).create({
|
|
1108
|
+
data: {
|
|
1109
|
+
...action,
|
|
1110
|
+
release: release.id,
|
|
1111
|
+
isEntryValid: actionStatus
|
|
1112
|
+
},
|
|
1113
|
+
populate: {
|
|
1114
|
+
release: {
|
|
1115
|
+
select: [
|
|
1116
|
+
'id'
|
|
1117
|
+
]
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
});
|
|
1121
|
+
if (!disableUpdateReleaseStatus) {
|
|
1122
|
+
getService('release', {
|
|
1123
|
+
strapi
|
|
1124
|
+
}).updateReleaseStatus(release.id);
|
|
1125
|
+
}
|
|
1126
|
+
return releaseAction;
|
|
1109
1127
|
},
|
|
1110
|
-
{
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1128
|
+
async findPage (releaseId, query) {
|
|
1129
|
+
const release = await strapi.db.query(RELEASE_MODEL_UID).findOne({
|
|
1130
|
+
where: {
|
|
1131
|
+
id: releaseId
|
|
1132
|
+
},
|
|
1133
|
+
select: [
|
|
1134
|
+
'id'
|
|
1135
|
+
]
|
|
1136
|
+
});
|
|
1137
|
+
if (!release) {
|
|
1138
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
1121
1139
|
}
|
|
1122
|
-
|
|
1140
|
+
const dbQuery = strapi.get('query-params').transform(RELEASE_ACTION_MODEL_UID, query ?? {});
|
|
1141
|
+
const { results: actions, pagination } = await strapi.db.query(RELEASE_ACTION_MODEL_UID).findPage({
|
|
1142
|
+
...dbQuery,
|
|
1143
|
+
where: {
|
|
1144
|
+
release: releaseId
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1147
|
+
// For each contentType on the release, we create a custom populate object for nested relations
|
|
1148
|
+
const populateBuilderService = strapi.plugin('content-manager').service('populate-builder');
|
|
1149
|
+
const actionsWithEntry = await utils.async.map(actions, async (action)=>{
|
|
1150
|
+
// @ts-expect-error - Core.Service type is not a function
|
|
1151
|
+
const populate = await populateBuilderService(action.contentType).populateDeep(Infinity).build();
|
|
1152
|
+
const entry = await getEntry({
|
|
1153
|
+
contentType: action.contentType,
|
|
1154
|
+
documentId: action.entryDocumentId,
|
|
1155
|
+
locale: action.locale,
|
|
1156
|
+
populate,
|
|
1157
|
+
status: action.type === 'publish' ? 'draft' : 'published'
|
|
1158
|
+
}, {
|
|
1159
|
+
strapi
|
|
1160
|
+
});
|
|
1161
|
+
return {
|
|
1162
|
+
...action,
|
|
1163
|
+
entry,
|
|
1164
|
+
status: entry ? await getEntryStatus(action.contentType, entry) : null
|
|
1165
|
+
};
|
|
1166
|
+
});
|
|
1167
|
+
return {
|
|
1168
|
+
results: actionsWithEntry,
|
|
1169
|
+
pagination
|
|
1170
|
+
};
|
|
1123
1171
|
},
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1172
|
+
async groupActions (actions, groupBy) {
|
|
1173
|
+
const contentTypeUids = actions.reduce((acc, action)=>{
|
|
1174
|
+
if (!acc.includes(action.contentType)) {
|
|
1175
|
+
acc.push(action.contentType);
|
|
1176
|
+
}
|
|
1177
|
+
return acc;
|
|
1178
|
+
}, []);
|
|
1179
|
+
const allReleaseContentTypesDictionary = await getContentTypesDataForActions(contentTypeUids);
|
|
1180
|
+
const allLocalesDictionary = await getLocalesDataForActions();
|
|
1181
|
+
const formattedData = actions.map((action)=>{
|
|
1182
|
+
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
1183
|
+
return {
|
|
1184
|
+
...action,
|
|
1185
|
+
locale: action.locale ? allLocalesDictionary[action.locale] : null,
|
|
1186
|
+
contentType: {
|
|
1187
|
+
displayName,
|
|
1188
|
+
mainFieldValue: action.entry[mainField],
|
|
1189
|
+
uid: action.contentType
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
});
|
|
1193
|
+
const groupName = getGroupName(groupBy);
|
|
1194
|
+
return _.groupBy(groupName)(formattedData);
|
|
1195
|
+
},
|
|
1196
|
+
async getContentTypeModelsFromActions (actions) {
|
|
1197
|
+
const contentTypeUids = actions.reduce((acc, action)=>{
|
|
1198
|
+
if (!acc.includes(action.contentType)) {
|
|
1199
|
+
acc.push(action.contentType);
|
|
1200
|
+
}
|
|
1201
|
+
return acc;
|
|
1202
|
+
}, []);
|
|
1203
|
+
const workflowsService = strapi.plugin('review-workflows').service('workflows');
|
|
1204
|
+
const contentTypeModelsMap = await utils.async.reduce(contentTypeUids)(async (accPromise, contentTypeUid)=>{
|
|
1205
|
+
const acc = await accPromise;
|
|
1206
|
+
const contentTypeModel = strapi.getModel(contentTypeUid);
|
|
1207
|
+
const workflow = await workflowsService.getAssignedWorkflow(contentTypeUid, {
|
|
1208
|
+
populate: 'stageRequiredToPublish'
|
|
1209
|
+
});
|
|
1210
|
+
acc[contentTypeUid] = {
|
|
1211
|
+
...contentTypeModel,
|
|
1212
|
+
hasReviewWorkflow: !!workflow,
|
|
1213
|
+
stageRequiredToPublish: workflow?.stageRequiredToPublish
|
|
1214
|
+
};
|
|
1215
|
+
return acc;
|
|
1216
|
+
}, {});
|
|
1217
|
+
return contentTypeModelsMap;
|
|
1218
|
+
},
|
|
1219
|
+
async countActions (query) {
|
|
1220
|
+
const dbQuery = strapi.get('query-params').transform(RELEASE_ACTION_MODEL_UID, query ?? {});
|
|
1221
|
+
return strapi.db.query(RELEASE_ACTION_MODEL_UID).count(dbQuery);
|
|
1222
|
+
},
|
|
1223
|
+
async update (actionId, releaseId, update) {
|
|
1224
|
+
const action = await strapi.db.query(RELEASE_ACTION_MODEL_UID).findOne({
|
|
1225
|
+
where: {
|
|
1226
|
+
id: actionId,
|
|
1227
|
+
release: {
|
|
1228
|
+
id: releaseId,
|
|
1229
|
+
releasedAt: {
|
|
1230
|
+
$null: true
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1235
|
+
if (!action) {
|
|
1236
|
+
throw new utils.errors.NotFoundError(`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`);
|
|
1140
1237
|
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1238
|
+
const actionStatus = update.type === 'publish' ? await getDraftEntryValidStatus({
|
|
1239
|
+
contentType: action.contentType,
|
|
1240
|
+
documentId: action.entryDocumentId,
|
|
1241
|
+
locale: action.locale
|
|
1242
|
+
}, {
|
|
1243
|
+
strapi
|
|
1244
|
+
}) : true;
|
|
1245
|
+
const updatedAction = await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
1246
|
+
where: {
|
|
1247
|
+
id: actionId,
|
|
1248
|
+
release: {
|
|
1249
|
+
id: releaseId,
|
|
1250
|
+
releasedAt: {
|
|
1251
|
+
$null: true
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
},
|
|
1255
|
+
data: {
|
|
1256
|
+
...update,
|
|
1257
|
+
isEntryValid: actionStatus
|
|
1258
|
+
}
|
|
1259
|
+
});
|
|
1260
|
+
getService('release', {
|
|
1261
|
+
strapi
|
|
1262
|
+
}).updateReleaseStatus(releaseId);
|
|
1263
|
+
return updatedAction;
|
|
1264
|
+
},
|
|
1265
|
+
async delete (actionId, releaseId) {
|
|
1266
|
+
const deletedAction = await strapi.db.query(RELEASE_ACTION_MODEL_UID).delete({
|
|
1267
|
+
where: {
|
|
1268
|
+
id: actionId,
|
|
1269
|
+
release: {
|
|
1270
|
+
id: releaseId,
|
|
1271
|
+
releasedAt: {
|
|
1272
|
+
$null: true
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
});
|
|
1277
|
+
if (!deletedAction) {
|
|
1278
|
+
throw new utils.errors.NotFoundError(`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`);
|
|
1163
1279
|
}
|
|
1164
|
-
|
|
1280
|
+
getService('release', {
|
|
1281
|
+
strapi
|
|
1282
|
+
}).updateReleaseStatus(releaseId);
|
|
1283
|
+
return deletedAction;
|
|
1165
1284
|
},
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1285
|
+
async validateActionsByContentTypes (contentTypeUids) {
|
|
1286
|
+
const actions = await strapi.db.query(RELEASE_ACTION_MODEL_UID).findMany({
|
|
1287
|
+
where: {
|
|
1288
|
+
contentType: {
|
|
1289
|
+
$in: contentTypeUids
|
|
1290
|
+
},
|
|
1291
|
+
// We only want to validate actions that are going to be published
|
|
1292
|
+
type: 'publish',
|
|
1293
|
+
release: {
|
|
1294
|
+
releasedAt: {
|
|
1295
|
+
$null: true
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
},
|
|
1299
|
+
populate: {
|
|
1300
|
+
release: true
|
|
1301
|
+
}
|
|
1302
|
+
});
|
|
1303
|
+
const releasesUpdated = [];
|
|
1304
|
+
await utils.async.map(actions, async (action)=>{
|
|
1305
|
+
const isValid = await getDraftEntryValidStatus({
|
|
1306
|
+
contentType: action.contentType,
|
|
1307
|
+
documentId: action.entryDocumentId,
|
|
1308
|
+
locale: action.locale
|
|
1309
|
+
}, {
|
|
1310
|
+
strapi
|
|
1311
|
+
});
|
|
1312
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
1313
|
+
where: {
|
|
1314
|
+
id: action.id
|
|
1315
|
+
},
|
|
1316
|
+
data: {
|
|
1317
|
+
isEntryValid: isValid
|
|
1318
|
+
}
|
|
1319
|
+
});
|
|
1320
|
+
if (!releasesUpdated.includes(action.release.id)) {
|
|
1321
|
+
releasesUpdated.push(action.release.id);
|
|
1322
|
+
}
|
|
1323
|
+
return {
|
|
1324
|
+
id: action.id,
|
|
1325
|
+
isEntryValid: isValid
|
|
1326
|
+
};
|
|
1327
|
+
});
|
|
1328
|
+
if (releasesUpdated.length > 0) {
|
|
1329
|
+
await utils.async.map(releasesUpdated, async (releaseId)=>{
|
|
1330
|
+
await getService('release', {
|
|
1331
|
+
strapi
|
|
1332
|
+
}).updateReleaseStatus(releaseId);
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1188
1335
|
}
|
|
1189
|
-
|
|
1190
|
-
id: action.id,
|
|
1191
|
-
isEntryValid: isValid
|
|
1192
|
-
};
|
|
1193
|
-
});
|
|
1194
|
-
if (releasesUpdated.length > 0) {
|
|
1195
|
-
await utils.async.map(releasesUpdated, async (releaseId) => {
|
|
1196
|
-
await getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
|
|
1197
|
-
});
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
};
|
|
1336
|
+
};
|
|
1201
1337
|
};
|
|
1338
|
+
|
|
1202
1339
|
class AlreadyOnReleaseError extends utils.errors.ApplicationError {
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
1209
|
-
async validateUniqueEntry(releaseId, releaseActionArgs) {
|
|
1210
|
-
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
1211
|
-
where: {
|
|
1212
|
-
id: releaseId
|
|
1213
|
-
},
|
|
1214
|
-
populate: {
|
|
1215
|
-
actions: true
|
|
1216
|
-
}
|
|
1217
|
-
});
|
|
1218
|
-
if (!release2) {
|
|
1219
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
1220
|
-
}
|
|
1221
|
-
const isEntryInRelease = release2.actions.some(
|
|
1222
|
-
(action) => action.entryDocumentId === releaseActionArgs.entryDocumentId && action.contentType === releaseActionArgs.contentType && (releaseActionArgs.locale ? action.locale === releaseActionArgs.locale : true)
|
|
1223
|
-
);
|
|
1224
|
-
if (isEntryInRelease) {
|
|
1225
|
-
throw new AlreadyOnReleaseError(
|
|
1226
|
-
`Entry with documentId ${releaseActionArgs.entryDocumentId}${releaseActionArgs.locale ? `( ${releaseActionArgs.locale})` : ""} and contentType ${releaseActionArgs.contentType} already exists in release with id ${releaseId}`
|
|
1227
|
-
);
|
|
1228
|
-
}
|
|
1229
|
-
},
|
|
1230
|
-
validateEntryData(contentTypeUid, entryDocumentId) {
|
|
1231
|
-
const contentType = strapi2.contentType(contentTypeUid);
|
|
1232
|
-
if (!contentType) {
|
|
1233
|
-
throw new utils.errors.NotFoundError(`No content type found for uid ${contentTypeUid}`);
|
|
1234
|
-
}
|
|
1235
|
-
if (!utils.contentTypes.hasDraftAndPublish(contentType)) {
|
|
1236
|
-
throw new utils.errors.ValidationError(
|
|
1237
|
-
`Content type with uid ${contentTypeUid} does not have draftAndPublish enabled`
|
|
1238
|
-
);
|
|
1239
|
-
}
|
|
1240
|
-
if (contentType.kind === "collectionType" && !entryDocumentId) {
|
|
1241
|
-
throw new utils.errors.ValidationError("Document id is required for collection type");
|
|
1242
|
-
}
|
|
1243
|
-
},
|
|
1244
|
-
async validatePendingReleasesLimit() {
|
|
1245
|
-
const featureCfg = strapi2.ee.features.get("cms-content-releases");
|
|
1246
|
-
const maximumPendingReleases = typeof featureCfg === "object" && featureCfg?.options?.maximumReleases || 3;
|
|
1247
|
-
const [, pendingReleasesCount] = await strapi2.db.query(RELEASE_MODEL_UID).findWithCount({
|
|
1248
|
-
filters: {
|
|
1249
|
-
releasedAt: {
|
|
1250
|
-
$null: true
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
});
|
|
1254
|
-
if (pendingReleasesCount >= maximumPendingReleases) {
|
|
1255
|
-
throw new utils.errors.ValidationError("You have reached the maximum number of pending releases");
|
|
1340
|
+
constructor(message){
|
|
1341
|
+
super(message);
|
|
1342
|
+
this.name = 'AlreadyOnReleaseError';
|
|
1256
1343
|
}
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1344
|
+
}
|
|
1345
|
+
const createReleaseValidationService = ({ strapi })=>({
|
|
1346
|
+
async validateUniqueEntry (releaseId, releaseActionArgs) {
|
|
1347
|
+
/**
|
|
1348
|
+
* Asserting the type, otherwise TS complains: 'release.actions' is of type 'unknown', even though the types come through for non-populated fields...
|
|
1349
|
+
* Possibly related to the comment on GetValues: https://github.com/strapi/strapi/blob/main/packages/core/types/src/modules/entity-service/result.ts
|
|
1350
|
+
*/ const release = await strapi.db.query(RELEASE_MODEL_UID).findOne({
|
|
1351
|
+
where: {
|
|
1352
|
+
id: releaseId
|
|
1353
|
+
},
|
|
1354
|
+
populate: {
|
|
1355
|
+
actions: true
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
if (!release) {
|
|
1359
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
1360
|
+
}
|
|
1361
|
+
const isEntryInRelease = release.actions.some((action)=>action.entryDocumentId === releaseActionArgs.entryDocumentId && action.contentType === releaseActionArgs.contentType && (releaseActionArgs.locale ? action.locale === releaseActionArgs.locale : true));
|
|
1362
|
+
if (isEntryInRelease) {
|
|
1363
|
+
throw new AlreadyOnReleaseError(`Entry with documentId ${releaseActionArgs.entryDocumentId}${releaseActionArgs.locale ? `( ${releaseActionArgs.locale})` : ''} and contentType ${releaseActionArgs.contentType} already exists in release with id ${releaseId}`);
|
|
1364
|
+
}
|
|
1263
1365
|
},
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
const
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1366
|
+
validateEntryData (contentTypeUid, entryDocumentId) {
|
|
1367
|
+
const contentType = strapi.contentType(contentTypeUid);
|
|
1368
|
+
if (!contentType) {
|
|
1369
|
+
throw new utils.errors.NotFoundError(`No content type found for uid ${contentTypeUid}`);
|
|
1370
|
+
}
|
|
1371
|
+
if (!utils.contentTypes.hasDraftAndPublish(contentType)) {
|
|
1372
|
+
throw new utils.errors.ValidationError(`Content type with uid ${contentTypeUid} does not have draftAndPublish enabled`);
|
|
1373
|
+
}
|
|
1374
|
+
if (contentType.kind === 'collectionType' && !entryDocumentId) {
|
|
1375
|
+
throw new utils.errors.ValidationError('Document id is required for collection type');
|
|
1376
|
+
}
|
|
1377
|
+
},
|
|
1378
|
+
async validatePendingReleasesLimit () {
|
|
1379
|
+
// Use the maximum releases option if it exists, otherwise default to 3
|
|
1380
|
+
const featureCfg = strapi.ee.features.get('cms-content-releases');
|
|
1381
|
+
const maximumPendingReleases = typeof featureCfg === 'object' && featureCfg?.options?.maximumReleases || 3;
|
|
1382
|
+
const [, pendingReleasesCount] = await strapi.db.query(RELEASE_MODEL_UID).findWithCount({
|
|
1383
|
+
filters: {
|
|
1384
|
+
releasedAt: {
|
|
1385
|
+
$null: true
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
});
|
|
1389
|
+
// Unlimited is a number that will never be reached like 9999
|
|
1390
|
+
if (pendingReleasesCount >= maximumPendingReleases) {
|
|
1391
|
+
throw new utils.errors.ValidationError('You have reached the maximum number of pending releases');
|
|
1392
|
+
}
|
|
1393
|
+
},
|
|
1394
|
+
async validateUniqueNameForPendingRelease (name, id) {
|
|
1395
|
+
const pendingReleases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
1396
|
+
where: {
|
|
1397
|
+
releasedAt: {
|
|
1398
|
+
$null: true
|
|
1399
|
+
},
|
|
1400
|
+
name,
|
|
1401
|
+
...id && {
|
|
1402
|
+
id: {
|
|
1403
|
+
$ne: id
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1408
|
+
const isNameUnique = pendingReleases.length === 0;
|
|
1409
|
+
if (!isNameUnique) {
|
|
1410
|
+
throw new utils.errors.ValidationError(`Release with name ${name} already exists`);
|
|
1411
|
+
}
|
|
1412
|
+
},
|
|
1413
|
+
async validateScheduledAtIsLaterThanNow (scheduledAt) {
|
|
1414
|
+
if (scheduledAt && new Date(scheduledAt) <= new Date()) {
|
|
1415
|
+
throw new utils.errors.ValidationError('Scheduled at must be later than now');
|
|
1416
|
+
}
|
|
1291
1417
|
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1418
|
+
});
|
|
1419
|
+
|
|
1420
|
+
const createSchedulingService = ({ strapi })=>{
|
|
1421
|
+
const scheduledJobs = new Map();
|
|
1422
|
+
return {
|
|
1423
|
+
async set (releaseId, scheduleDate) {
|
|
1424
|
+
const release = await strapi.db.query(RELEASE_MODEL_UID).findOne({
|
|
1425
|
+
where: {
|
|
1426
|
+
id: releaseId,
|
|
1427
|
+
releasedAt: null
|
|
1428
|
+
}
|
|
1429
|
+
});
|
|
1430
|
+
if (!release) {
|
|
1431
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
1432
|
+
}
|
|
1433
|
+
const job = nodeSchedule.scheduleJob(scheduleDate, async ()=>{
|
|
1434
|
+
try {
|
|
1435
|
+
await getService('release', {
|
|
1436
|
+
strapi
|
|
1437
|
+
}).publish(releaseId);
|
|
1438
|
+
// @TODO: Trigger webhook with success message
|
|
1439
|
+
} catch (error) {
|
|
1440
|
+
// @TODO: Trigger webhook with error message
|
|
1441
|
+
}
|
|
1442
|
+
this.cancel(releaseId);
|
|
1443
|
+
});
|
|
1444
|
+
if (scheduledJobs.has(releaseId)) {
|
|
1445
|
+
this.cancel(releaseId);
|
|
1446
|
+
}
|
|
1447
|
+
scheduledJobs.set(releaseId, job);
|
|
1448
|
+
return scheduledJobs;
|
|
1449
|
+
},
|
|
1450
|
+
cancel (releaseId) {
|
|
1451
|
+
if (scheduledJobs.has(releaseId)) {
|
|
1452
|
+
scheduledJobs.get(releaseId).cancel();
|
|
1453
|
+
scheduledJobs.delete(releaseId);
|
|
1454
|
+
}
|
|
1455
|
+
return scheduledJobs;
|
|
1456
|
+
},
|
|
1457
|
+
getAll () {
|
|
1458
|
+
return scheduledJobs;
|
|
1459
|
+
},
|
|
1460
|
+
/**
|
|
1311
1461
|
* On bootstrap, we can use this function to make sure to sync the scheduled jobs from the database that are not yet released
|
|
1312
1462
|
* This is useful in case the server was restarted and the scheduled jobs were lost
|
|
1313
1463
|
* This also could be used to sync different Strapi instances in case of a cluster
|
|
1314
|
-
*/
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1464
|
+
*/ async syncFromDatabase () {
|
|
1465
|
+
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
1466
|
+
where: {
|
|
1467
|
+
scheduledAt: {
|
|
1468
|
+
$gte: new Date()
|
|
1469
|
+
},
|
|
1470
|
+
releasedAt: null
|
|
1471
|
+
}
|
|
1472
|
+
});
|
|
1473
|
+
for (const release of releases){
|
|
1474
|
+
this.set(release.id, release.scheduledAt);
|
|
1475
|
+
}
|
|
1476
|
+
return scheduledJobs;
|
|
1322
1477
|
}
|
|
1323
|
-
|
|
1324
|
-
for (const release2 of releases) {
|
|
1325
|
-
this.set(release2.id, release2.scheduledAt);
|
|
1326
|
-
}
|
|
1327
|
-
return scheduledJobs;
|
|
1328
|
-
}
|
|
1329
|
-
};
|
|
1478
|
+
};
|
|
1330
1479
|
};
|
|
1480
|
+
|
|
1331
1481
|
const DEFAULT_SETTINGS = {
|
|
1332
|
-
|
|
1482
|
+
defaultTimezone: null
|
|
1333
1483
|
};
|
|
1334
|
-
const createSettingsService = ({ strapi
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1484
|
+
const createSettingsService = ({ strapi })=>{
|
|
1485
|
+
const getStore = async ()=>strapi.store({
|
|
1486
|
+
type: 'core',
|
|
1487
|
+
name: 'content-releases'
|
|
1488
|
+
});
|
|
1489
|
+
return {
|
|
1490
|
+
async update ({ settings }) {
|
|
1491
|
+
const store = await getStore();
|
|
1492
|
+
store.set({
|
|
1493
|
+
key: 'settings',
|
|
1494
|
+
value: settings
|
|
1495
|
+
});
|
|
1496
|
+
return settings;
|
|
1497
|
+
},
|
|
1498
|
+
async find () {
|
|
1499
|
+
const store = await getStore();
|
|
1500
|
+
const settings = await store.get({
|
|
1501
|
+
key: 'settings'
|
|
1502
|
+
});
|
|
1503
|
+
return {
|
|
1504
|
+
...DEFAULT_SETTINGS,
|
|
1505
|
+
...settings || {}
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1351
1509
|
};
|
|
1510
|
+
|
|
1352
1511
|
const services = {
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1512
|
+
release: createReleaseService,
|
|
1513
|
+
'release-action': createReleaseActionService,
|
|
1514
|
+
'release-validation': createReleaseValidationService,
|
|
1515
|
+
scheduling: createSchedulingService,
|
|
1516
|
+
settings: createSettingsService
|
|
1358
1517
|
};
|
|
1518
|
+
|
|
1359
1519
|
const RELEASE_SCHEMA = utils.yup.object().shape({
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1520
|
+
name: utils.yup.string().trim().required(),
|
|
1521
|
+
scheduledAt: utils.yup.string().nullable(),
|
|
1522
|
+
timezone: utils.yup.string().when('scheduledAt', {
|
|
1523
|
+
is: (value)=>value !== null && value !== undefined,
|
|
1524
|
+
then: utils.yup.string().required(),
|
|
1525
|
+
otherwise: utils.yup.string().nullable()
|
|
1526
|
+
})
|
|
1367
1527
|
}).required().noUnknown();
|
|
1368
1528
|
const FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA = utils.yup.object().shape({
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1529
|
+
contentType: utils.yup.string().required(),
|
|
1530
|
+
entryDocumentId: utils.yup.string().nullable(),
|
|
1531
|
+
hasEntryAttached: utils.yup.string().nullable(),
|
|
1532
|
+
locale: utils.yup.string().nullable()
|
|
1373
1533
|
}).required().noUnknown();
|
|
1374
1534
|
const validateRelease = utils.validateYupSchema(RELEASE_SCHEMA);
|
|
1375
|
-
const validatefindByDocumentAttachedParams = utils.validateYupSchema(
|
|
1376
|
-
|
|
1377
|
-
);
|
|
1535
|
+
const validatefindByDocumentAttachedParams = utils.validateYupSchema(FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA);
|
|
1536
|
+
|
|
1378
1537
|
const releaseController = {
|
|
1379
|
-
|
|
1538
|
+
/**
|
|
1380
1539
|
* Find releases based on documents attached or not to the release.
|
|
1381
1540
|
* If `hasEntryAttached` is true, it will return all releases that have the entry attached.
|
|
1382
1541
|
* If `hasEntryAttached` is false, it will return all releases that don't have the entry attached.
|
|
1383
|
-
*/
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
const releases = await releaseService.findMany({
|
|
1405
|
-
where: {
|
|
1406
|
-
releasedAt: null,
|
|
1407
|
-
actions: {
|
|
1408
|
-
contentType,
|
|
1409
|
-
entryDocumentId: entryDocumentId ?? null,
|
|
1410
|
-
locale: locale ?? null
|
|
1411
|
-
}
|
|
1412
|
-
},
|
|
1413
|
-
populate: {
|
|
1414
|
-
actions: {
|
|
1415
|
-
fields: ["type"],
|
|
1416
|
-
filters: {
|
|
1417
|
-
contentType,
|
|
1418
|
-
entryDocumentId: entryDocumentId ?? null,
|
|
1419
|
-
locale: locale ?? null
|
|
1542
|
+
*/ async findByDocumentAttached (ctx) {
|
|
1543
|
+
const permissionsManager = strapi.service('admin::permission').createPermissionsManager({
|
|
1544
|
+
ability: ctx.state.userAbility,
|
|
1545
|
+
model: RELEASE_MODEL_UID
|
|
1546
|
+
});
|
|
1547
|
+
await permissionsManager.validateQuery(ctx.query);
|
|
1548
|
+
const releaseService = getService('release', {
|
|
1549
|
+
strapi
|
|
1550
|
+
});
|
|
1551
|
+
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
1552
|
+
await validatefindByDocumentAttachedParams(query);
|
|
1553
|
+
// If entry is a singleType, we need to manually add the entryDocumentId to the query
|
|
1554
|
+
const model = strapi.getModel(query.contentType);
|
|
1555
|
+
if (model.kind && model.kind === 'singleType') {
|
|
1556
|
+
const document = await strapi.db.query(model.uid).findOne({
|
|
1557
|
+
select: [
|
|
1558
|
+
'documentId'
|
|
1559
|
+
]
|
|
1560
|
+
});
|
|
1561
|
+
if (!document) {
|
|
1562
|
+
throw new utils.errors.NotFoundError(`No entry found for contentType ${query.contentType}`);
|
|
1420
1563
|
}
|
|
1421
|
-
|
|
1564
|
+
query.entryDocumentId = document.documentId;
|
|
1422
1565
|
}
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1566
|
+
const { contentType, hasEntryAttached, entryDocumentId, locale } = query;
|
|
1567
|
+
const isEntryAttached = typeof hasEntryAttached === 'string' ? Boolean(JSON.parse(hasEntryAttached)) : false;
|
|
1568
|
+
if (isEntryAttached) {
|
|
1569
|
+
const releases = await releaseService.findMany({
|
|
1570
|
+
where: {
|
|
1571
|
+
releasedAt: null,
|
|
1572
|
+
actions: {
|
|
1573
|
+
contentType,
|
|
1574
|
+
entryDocumentId: entryDocumentId ?? null,
|
|
1575
|
+
locale: locale ?? null
|
|
1576
|
+
}
|
|
1577
|
+
},
|
|
1578
|
+
populate: {
|
|
1579
|
+
actions: {
|
|
1580
|
+
fields: [
|
|
1581
|
+
'type'
|
|
1582
|
+
],
|
|
1583
|
+
filters: {
|
|
1584
|
+
contentType,
|
|
1585
|
+
entryDocumentId: entryDocumentId ?? null,
|
|
1586
|
+
locale: locale ?? null
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
});
|
|
1591
|
+
ctx.body = {
|
|
1592
|
+
data: releases
|
|
1593
|
+
};
|
|
1594
|
+
} else {
|
|
1595
|
+
const relatedReleases = await releaseService.findMany({
|
|
1596
|
+
where: {
|
|
1597
|
+
releasedAt: null,
|
|
1598
|
+
actions: {
|
|
1599
|
+
contentType,
|
|
1600
|
+
entryDocumentId: entryDocumentId ?? null,
|
|
1601
|
+
locale: locale ?? null
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
});
|
|
1605
|
+
const releases = await releaseService.findMany({
|
|
1606
|
+
where: {
|
|
1607
|
+
$or: [
|
|
1608
|
+
{
|
|
1609
|
+
id: {
|
|
1610
|
+
$notIn: relatedReleases.map((release)=>release.id)
|
|
1611
|
+
}
|
|
1612
|
+
},
|
|
1613
|
+
{
|
|
1614
|
+
actions: null
|
|
1615
|
+
}
|
|
1616
|
+
],
|
|
1617
|
+
releasedAt: null
|
|
1618
|
+
}
|
|
1619
|
+
});
|
|
1620
|
+
ctx.body = {
|
|
1621
|
+
data: releases
|
|
1622
|
+
};
|
|
1434
1623
|
}
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1624
|
+
},
|
|
1625
|
+
async findPage (ctx) {
|
|
1626
|
+
const permissionsManager = strapi.service('admin::permission').createPermissionsManager({
|
|
1627
|
+
ability: ctx.state.userAbility,
|
|
1628
|
+
model: RELEASE_MODEL_UID
|
|
1629
|
+
});
|
|
1630
|
+
await permissionsManager.validateQuery(ctx.query);
|
|
1631
|
+
const releaseService = getService('release', {
|
|
1632
|
+
strapi
|
|
1633
|
+
});
|
|
1634
|
+
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
1635
|
+
const { results, pagination } = await releaseService.findPage(query);
|
|
1636
|
+
const data = results.map((release)=>{
|
|
1637
|
+
const { actions, ...releaseData } = release;
|
|
1638
|
+
return {
|
|
1639
|
+
...releaseData,
|
|
1640
|
+
actions: {
|
|
1641
|
+
meta: {
|
|
1642
|
+
count: actions.count
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
};
|
|
1646
|
+
});
|
|
1647
|
+
const pendingReleasesCount = await strapi.db.query(RELEASE_MODEL_UID).count({
|
|
1648
|
+
where: {
|
|
1649
|
+
releasedAt: null
|
|
1446
1650
|
}
|
|
1447
|
-
],
|
|
1448
|
-
releasedAt: null
|
|
1449
|
-
}
|
|
1450
|
-
});
|
|
1451
|
-
ctx.body = { data: releases };
|
|
1452
|
-
}
|
|
1453
|
-
},
|
|
1454
|
-
async findPage(ctx) {
|
|
1455
|
-
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
1456
|
-
ability: ctx.state.userAbility,
|
|
1457
|
-
model: RELEASE_MODEL_UID
|
|
1458
|
-
});
|
|
1459
|
-
await permissionsManager.validateQuery(ctx.query);
|
|
1460
|
-
const releaseService = getService("release", { strapi });
|
|
1461
|
-
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
1462
|
-
const { results, pagination } = await releaseService.findPage(query);
|
|
1463
|
-
const data = results.map((release2) => {
|
|
1464
|
-
const { actions, ...releaseData } = release2;
|
|
1465
|
-
return {
|
|
1466
|
-
...releaseData,
|
|
1467
|
-
actions: {
|
|
1468
|
-
meta: {
|
|
1469
|
-
count: actions.count
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
};
|
|
1473
|
-
});
|
|
1474
|
-
const pendingReleasesCount = await strapi.db.query(RELEASE_MODEL_UID).count({
|
|
1475
|
-
where: {
|
|
1476
|
-
releasedAt: null
|
|
1477
|
-
}
|
|
1478
|
-
});
|
|
1479
|
-
ctx.body = { data, meta: { pagination, pendingReleasesCount } };
|
|
1480
|
-
},
|
|
1481
|
-
async findOne(ctx) {
|
|
1482
|
-
const id = ctx.params.id;
|
|
1483
|
-
const releaseService = getService("release", { strapi });
|
|
1484
|
-
const releaseActionService = getService("release-action", { strapi });
|
|
1485
|
-
const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
|
|
1486
|
-
if (!release2) {
|
|
1487
|
-
throw new utils.errors.NotFoundError(`Release not found for id: ${id}`);
|
|
1488
|
-
}
|
|
1489
|
-
const count = await releaseActionService.countActions({
|
|
1490
|
-
filters: {
|
|
1491
|
-
release: id
|
|
1492
|
-
}
|
|
1493
|
-
});
|
|
1494
|
-
const sanitizedRelease = {
|
|
1495
|
-
...release2,
|
|
1496
|
-
createdBy: release2.createdBy ? strapi.service("admin::user").sanitizeUser(release2.createdBy) : null
|
|
1497
|
-
};
|
|
1498
|
-
const data = {
|
|
1499
|
-
...sanitizedRelease,
|
|
1500
|
-
actions: {
|
|
1501
|
-
meta: {
|
|
1502
|
-
count
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
};
|
|
1506
|
-
ctx.body = { data };
|
|
1507
|
-
},
|
|
1508
|
-
async mapEntriesToReleases(ctx) {
|
|
1509
|
-
const { contentTypeUid, documentIds, locale } = ctx.query;
|
|
1510
|
-
if (!contentTypeUid || !documentIds) {
|
|
1511
|
-
throw new utils.errors.ValidationError("Missing required query parameters");
|
|
1512
|
-
}
|
|
1513
|
-
const releaseService = getService("release", { strapi });
|
|
1514
|
-
const releasesWithActions = await releaseService.findMany({
|
|
1515
|
-
where: {
|
|
1516
|
-
releasedAt: null,
|
|
1517
|
-
actions: {
|
|
1518
|
-
contentType: contentTypeUid,
|
|
1519
|
-
entryDocumentId: {
|
|
1520
|
-
$in: documentIds
|
|
1521
|
-
},
|
|
1522
|
-
locale
|
|
1523
|
-
}
|
|
1524
|
-
},
|
|
1525
|
-
populate: {
|
|
1526
|
-
actions: true
|
|
1527
|
-
}
|
|
1528
|
-
});
|
|
1529
|
-
const mappedEntriesInReleases = releasesWithActions.reduce(
|
|
1530
|
-
(acc, release2) => {
|
|
1531
|
-
release2.actions.forEach((action) => {
|
|
1532
|
-
if (action.contentType !== contentTypeUid) {
|
|
1533
|
-
return;
|
|
1534
|
-
}
|
|
1535
|
-
if (locale && action.locale !== locale) {
|
|
1536
|
-
return;
|
|
1537
|
-
}
|
|
1538
|
-
if (!acc[action.entryDocumentId]) {
|
|
1539
|
-
acc[action.entryDocumentId] = [{ id: release2.id, name: release2.name }];
|
|
1540
|
-
} else {
|
|
1541
|
-
acc[action.entryDocumentId].push({ id: release2.id, name: release2.name });
|
|
1542
|
-
}
|
|
1543
1651
|
});
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
const user = ctx.state.user;
|
|
1568
|
-
const releaseArgs = ctx.request.body;
|
|
1569
|
-
const id = ctx.params.id;
|
|
1570
|
-
await validateRelease(releaseArgs);
|
|
1571
|
-
const releaseService = getService("release", { strapi });
|
|
1572
|
-
const release2 = await releaseService.update(id, releaseArgs, { user });
|
|
1573
|
-
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
1574
|
-
ability: ctx.state.userAbility,
|
|
1575
|
-
model: RELEASE_MODEL_UID
|
|
1576
|
-
});
|
|
1577
|
-
ctx.body = {
|
|
1578
|
-
data: await permissionsManager.sanitizeOutput(release2)
|
|
1579
|
-
};
|
|
1580
|
-
},
|
|
1581
|
-
async delete(ctx) {
|
|
1582
|
-
const id = ctx.params.id;
|
|
1583
|
-
const releaseService = getService("release", { strapi });
|
|
1584
|
-
const release2 = await releaseService.delete(id);
|
|
1585
|
-
ctx.body = {
|
|
1586
|
-
data: release2
|
|
1587
|
-
};
|
|
1588
|
-
},
|
|
1589
|
-
async publish(ctx) {
|
|
1590
|
-
const id = ctx.params.id;
|
|
1591
|
-
const releaseService = getService("release", { strapi });
|
|
1592
|
-
const releaseActionService = getService("release-action", { strapi });
|
|
1593
|
-
const release2 = await releaseService.publish(id);
|
|
1594
|
-
const [countPublishActions, countUnpublishActions] = await Promise.all([
|
|
1595
|
-
releaseActionService.countActions({
|
|
1596
|
-
filters: {
|
|
1597
|
-
release: id,
|
|
1598
|
-
type: "publish"
|
|
1652
|
+
ctx.body = {
|
|
1653
|
+
data,
|
|
1654
|
+
meta: {
|
|
1655
|
+
pagination,
|
|
1656
|
+
pendingReleasesCount
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
},
|
|
1660
|
+
async findOne (ctx) {
|
|
1661
|
+
const id = ctx.params.id;
|
|
1662
|
+
const releaseService = getService('release', {
|
|
1663
|
+
strapi
|
|
1664
|
+
});
|
|
1665
|
+
const releaseActionService = getService('release-action', {
|
|
1666
|
+
strapi
|
|
1667
|
+
});
|
|
1668
|
+
const release = await releaseService.findOne(id, {
|
|
1669
|
+
populate: [
|
|
1670
|
+
'createdBy'
|
|
1671
|
+
]
|
|
1672
|
+
});
|
|
1673
|
+
if (!release) {
|
|
1674
|
+
throw new utils.errors.NotFoundError(`Release not found for id: ${id}`);
|
|
1599
1675
|
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1676
|
+
const count = await releaseActionService.countActions({
|
|
1677
|
+
filters: {
|
|
1678
|
+
release: id
|
|
1679
|
+
}
|
|
1680
|
+
});
|
|
1681
|
+
const sanitizedRelease = {
|
|
1682
|
+
...release,
|
|
1683
|
+
createdBy: release.createdBy ? strapi.service('admin::user').sanitizeUser(release.createdBy) : null
|
|
1684
|
+
};
|
|
1685
|
+
// Format the data object
|
|
1686
|
+
const data = {
|
|
1687
|
+
...sanitizedRelease,
|
|
1688
|
+
actions: {
|
|
1689
|
+
meta: {
|
|
1690
|
+
count
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
};
|
|
1694
|
+
ctx.body = {
|
|
1695
|
+
data
|
|
1696
|
+
};
|
|
1697
|
+
},
|
|
1698
|
+
async mapEntriesToReleases (ctx) {
|
|
1699
|
+
const { contentTypeUid, documentIds, locale } = ctx.query;
|
|
1700
|
+
if (!contentTypeUid || !documentIds) {
|
|
1701
|
+
throw new utils.errors.ValidationError('Missing required query parameters');
|
|
1605
1702
|
}
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1703
|
+
const releaseService = getService('release', {
|
|
1704
|
+
strapi
|
|
1705
|
+
});
|
|
1706
|
+
const releasesWithActions = await releaseService.findMany({
|
|
1707
|
+
where: {
|
|
1708
|
+
releasedAt: null,
|
|
1709
|
+
actions: {
|
|
1710
|
+
contentType: contentTypeUid,
|
|
1711
|
+
entryDocumentId: {
|
|
1712
|
+
$in: documentIds
|
|
1713
|
+
},
|
|
1714
|
+
locale
|
|
1715
|
+
}
|
|
1716
|
+
},
|
|
1717
|
+
populate: {
|
|
1718
|
+
actions: true
|
|
1719
|
+
}
|
|
1720
|
+
});
|
|
1721
|
+
const mappedEntriesInReleases = releasesWithActions.reduce((acc, release)=>{
|
|
1722
|
+
release.actions.forEach((action)=>{
|
|
1723
|
+
if (action.contentType !== contentTypeUid) {
|
|
1724
|
+
return;
|
|
1725
|
+
}
|
|
1726
|
+
if (locale && action.locale !== locale) {
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1729
|
+
if (!acc[action.entryDocumentId]) {
|
|
1730
|
+
acc[action.entryDocumentId] = [
|
|
1731
|
+
{
|
|
1732
|
+
id: release.id,
|
|
1733
|
+
name: release.name
|
|
1734
|
+
}
|
|
1735
|
+
];
|
|
1736
|
+
} else {
|
|
1737
|
+
acc[action.entryDocumentId].push({
|
|
1738
|
+
id: release.id,
|
|
1739
|
+
name: release.name
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
});
|
|
1743
|
+
return acc;
|
|
1744
|
+
}, {});
|
|
1745
|
+
ctx.body = {
|
|
1746
|
+
data: mappedEntriesInReleases
|
|
1747
|
+
};
|
|
1748
|
+
},
|
|
1749
|
+
async create (ctx) {
|
|
1750
|
+
const user = ctx.state.user;
|
|
1751
|
+
const releaseArgs = ctx.request.body;
|
|
1752
|
+
await validateRelease(releaseArgs);
|
|
1753
|
+
const releaseService = getService('release', {
|
|
1754
|
+
strapi
|
|
1755
|
+
});
|
|
1756
|
+
const release = await releaseService.create(releaseArgs, {
|
|
1757
|
+
user
|
|
1758
|
+
});
|
|
1759
|
+
const permissionsManager = strapi.service('admin::permission').createPermissionsManager({
|
|
1760
|
+
ability: ctx.state.userAbility,
|
|
1761
|
+
model: RELEASE_MODEL_UID
|
|
1762
|
+
});
|
|
1763
|
+
ctx.created({
|
|
1764
|
+
data: await permissionsManager.sanitizeOutput(release)
|
|
1765
|
+
});
|
|
1766
|
+
},
|
|
1767
|
+
async update (ctx) {
|
|
1768
|
+
const user = ctx.state.user;
|
|
1769
|
+
const releaseArgs = ctx.request.body;
|
|
1770
|
+
const id = ctx.params.id;
|
|
1771
|
+
await validateRelease(releaseArgs);
|
|
1772
|
+
const releaseService = getService('release', {
|
|
1773
|
+
strapi
|
|
1774
|
+
});
|
|
1775
|
+
const release = await releaseService.update(id, releaseArgs, {
|
|
1776
|
+
user
|
|
1777
|
+
});
|
|
1778
|
+
const permissionsManager = strapi.service('admin::permission').createPermissionsManager({
|
|
1779
|
+
ability: ctx.state.userAbility,
|
|
1780
|
+
model: RELEASE_MODEL_UID
|
|
1781
|
+
});
|
|
1782
|
+
ctx.body = {
|
|
1783
|
+
data: await permissionsManager.sanitizeOutput(release)
|
|
1784
|
+
};
|
|
1785
|
+
},
|
|
1786
|
+
async delete (ctx) {
|
|
1787
|
+
const id = ctx.params.id;
|
|
1788
|
+
const releaseService = getService('release', {
|
|
1789
|
+
strapi
|
|
1790
|
+
});
|
|
1791
|
+
const release = await releaseService.delete(id);
|
|
1792
|
+
ctx.body = {
|
|
1793
|
+
data: release
|
|
1794
|
+
};
|
|
1795
|
+
},
|
|
1796
|
+
async publish (ctx) {
|
|
1797
|
+
const id = ctx.params.id;
|
|
1798
|
+
const releaseService = getService('release', {
|
|
1799
|
+
strapi
|
|
1800
|
+
});
|
|
1801
|
+
const releaseActionService = getService('release-action', {
|
|
1802
|
+
strapi
|
|
1803
|
+
});
|
|
1804
|
+
const release = await releaseService.publish(id);
|
|
1805
|
+
const [countPublishActions, countUnpublishActions] = await Promise.all([
|
|
1806
|
+
releaseActionService.countActions({
|
|
1807
|
+
filters: {
|
|
1808
|
+
release: id,
|
|
1809
|
+
type: 'publish'
|
|
1810
|
+
}
|
|
1811
|
+
}),
|
|
1812
|
+
releaseActionService.countActions({
|
|
1813
|
+
filters: {
|
|
1814
|
+
release: id,
|
|
1815
|
+
type: 'unpublish'
|
|
1816
|
+
}
|
|
1817
|
+
})
|
|
1818
|
+
]);
|
|
1819
|
+
ctx.body = {
|
|
1820
|
+
data: release,
|
|
1821
|
+
meta: {
|
|
1822
|
+
totalEntries: countPublishActions + countUnpublishActions,
|
|
1823
|
+
totalPublishedEntries: countPublishActions,
|
|
1824
|
+
totalUnpublishedEntries: countUnpublishActions
|
|
1825
|
+
}
|
|
1826
|
+
};
|
|
1827
|
+
}
|
|
1617
1828
|
};
|
|
1829
|
+
|
|
1618
1830
|
const RELEASE_ACTION_SCHEMA = utils.yup.object().shape({
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1831
|
+
contentType: utils.yup.string().required(),
|
|
1832
|
+
entryDocumentId: utils.yup.strapiID(),
|
|
1833
|
+
locale: utils.yup.string(),
|
|
1834
|
+
type: utils.yup.string().oneOf([
|
|
1835
|
+
'publish',
|
|
1836
|
+
'unpublish'
|
|
1837
|
+
]).required()
|
|
1623
1838
|
});
|
|
1624
1839
|
const RELEASE_ACTION_UPDATE_SCHEMA = utils.yup.object().shape({
|
|
1625
|
-
|
|
1840
|
+
type: utils.yup.string().oneOf([
|
|
1841
|
+
'publish',
|
|
1842
|
+
'unpublish'
|
|
1843
|
+
]).required()
|
|
1626
1844
|
});
|
|
1627
1845
|
const FIND_MANY_ACTIONS_PARAMS = utils.yup.object().shape({
|
|
1628
|
-
|
|
1846
|
+
groupBy: utils.yup.string().oneOf([
|
|
1847
|
+
'action',
|
|
1848
|
+
'contentType',
|
|
1849
|
+
'locale'
|
|
1850
|
+
])
|
|
1629
1851
|
});
|
|
1630
1852
|
const validateReleaseAction = utils.validateYupSchema(RELEASE_ACTION_SCHEMA);
|
|
1631
1853
|
const validateReleaseActionUpdateSchema = utils.validateYupSchema(RELEASE_ACTION_UPDATE_SCHEMA);
|
|
1632
1854
|
const validateFindManyActionsParams = utils.validateYupSchema(FIND_MANY_ACTIONS_PARAMS);
|
|
1855
|
+
|
|
1633
1856
|
const releaseActionController = {
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1857
|
+
async create (ctx) {
|
|
1858
|
+
const releaseId = ctx.params.releaseId;
|
|
1859
|
+
const releaseActionArgs = ctx.request.body;
|
|
1860
|
+
await validateReleaseAction(releaseActionArgs);
|
|
1861
|
+
const releaseActionService = getService('release-action', {
|
|
1862
|
+
strapi
|
|
1863
|
+
});
|
|
1864
|
+
const releaseAction = await releaseActionService.create(releaseId, releaseActionArgs);
|
|
1865
|
+
ctx.created({
|
|
1866
|
+
data: releaseAction
|
|
1867
|
+
});
|
|
1868
|
+
},
|
|
1869
|
+
async createMany (ctx) {
|
|
1870
|
+
const releaseId = ctx.params.releaseId;
|
|
1871
|
+
const releaseActionsArgs = ctx.request.body;
|
|
1872
|
+
await Promise.all(releaseActionsArgs.map((releaseActionArgs)=>validateReleaseAction(releaseActionArgs)));
|
|
1873
|
+
const releaseActionService = getService('release-action', {
|
|
1874
|
+
strapi
|
|
1875
|
+
});
|
|
1876
|
+
const releaseService = getService('release', {
|
|
1877
|
+
strapi
|
|
1878
|
+
});
|
|
1879
|
+
const releaseActions = await strapi.db.transaction(async ()=>{
|
|
1880
|
+
const releaseActions = await Promise.all(releaseActionsArgs.map(async (releaseActionArgs)=>{
|
|
1881
|
+
try {
|
|
1882
|
+
const action = await releaseActionService.create(releaseId, releaseActionArgs, {
|
|
1883
|
+
disableUpdateReleaseStatus: true
|
|
1884
|
+
});
|
|
1885
|
+
return action;
|
|
1886
|
+
} catch (error) {
|
|
1887
|
+
// If the entry is already in the release, we don't want to throw an error, so we catch and ignore it
|
|
1888
|
+
if (error instanceof AlreadyOnReleaseError) {
|
|
1889
|
+
return null;
|
|
1890
|
+
}
|
|
1891
|
+
throw error;
|
|
1892
|
+
}
|
|
1893
|
+
}));
|
|
1894
|
+
return releaseActions;
|
|
1895
|
+
});
|
|
1896
|
+
const newReleaseActions = releaseActions.filter((action)=>action !== null);
|
|
1897
|
+
if (newReleaseActions.length > 0) {
|
|
1898
|
+
releaseService.updateReleaseStatus(releaseId);
|
|
1899
|
+
}
|
|
1900
|
+
ctx.created({
|
|
1901
|
+
data: newReleaseActions,
|
|
1902
|
+
meta: {
|
|
1903
|
+
entriesAlreadyInRelease: releaseActions.length - newReleaseActions.length,
|
|
1904
|
+
totalEntries: releaseActions.length
|
|
1905
|
+
}
|
|
1906
|
+
});
|
|
1907
|
+
},
|
|
1908
|
+
async findMany (ctx) {
|
|
1909
|
+
const releaseId = ctx.params.releaseId;
|
|
1910
|
+
const permissionsManager = strapi.service('admin::permission').createPermissionsManager({
|
|
1911
|
+
ability: ctx.state.userAbility,
|
|
1912
|
+
model: RELEASE_ACTION_MODEL_UID
|
|
1913
|
+
});
|
|
1914
|
+
await validateFindManyActionsParams(ctx.query);
|
|
1915
|
+
if (ctx.query.groupBy) {
|
|
1916
|
+
if (![
|
|
1917
|
+
'action',
|
|
1918
|
+
'contentType',
|
|
1919
|
+
'locale'
|
|
1920
|
+
].includes(ctx.query.groupBy)) {
|
|
1921
|
+
ctx.badRequest('Invalid groupBy parameter');
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
ctx.query.sort = ctx.query.groupBy === 'action' ? 'type' : ctx.query.groupBy;
|
|
1925
|
+
delete ctx.query.groupBy;
|
|
1926
|
+
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
1927
|
+
const releaseActionService = getService('release-action', {
|
|
1928
|
+
strapi
|
|
1929
|
+
});
|
|
1930
|
+
const { results, pagination } = await releaseActionService.findPage(releaseId, {
|
|
1931
|
+
...query
|
|
1932
|
+
});
|
|
1933
|
+
/**
|
|
1934
|
+
* Release actions can be related to entries of different content types.
|
|
1935
|
+
* We need to sanitize the entry output according to that content type.
|
|
1936
|
+
* So, we group the sanitized output function by content type.
|
|
1937
|
+
*/ const contentTypeOutputSanitizers = results.reduce((acc, action)=>{
|
|
1938
|
+
if (acc[action.contentType]) {
|
|
1939
|
+
return acc;
|
|
1940
|
+
}
|
|
1941
|
+
const contentTypePermissionsManager = strapi.service('admin::permission').createPermissionsManager({
|
|
1942
|
+
ability: ctx.state.userAbility,
|
|
1943
|
+
model: action.contentType
|
|
1658
1944
|
});
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1945
|
+
acc[action.contentType] = contentTypePermissionsManager.sanitizeOutput;
|
|
1946
|
+
return acc;
|
|
1947
|
+
}, {});
|
|
1948
|
+
/**
|
|
1949
|
+
* sanitizeOutput doesn't work if you use it directly on the Release Action model, it doesn't sanitize the entries
|
|
1950
|
+
* So, we need to sanitize manually each entry inside a Release Action
|
|
1951
|
+
*/ const sanitizedResults = await utils.async.map(results, async (action)=>({
|
|
1952
|
+
...action,
|
|
1953
|
+
entry: action.entry ? await contentTypeOutputSanitizers[action.contentType](action.entry) : {}
|
|
1954
|
+
}));
|
|
1955
|
+
const groupedData = await releaseActionService.groupActions(sanitizedResults, query.sort);
|
|
1956
|
+
const contentTypes = await releaseActionService.getContentTypeModelsFromActions(results);
|
|
1957
|
+
const releaseService = getService('release', {
|
|
1958
|
+
strapi
|
|
1959
|
+
});
|
|
1960
|
+
const components = await releaseService.getAllComponents();
|
|
1961
|
+
ctx.body = {
|
|
1962
|
+
data: groupedData,
|
|
1963
|
+
meta: {
|
|
1964
|
+
pagination,
|
|
1965
|
+
contentTypes,
|
|
1966
|
+
components
|
|
1967
|
+
}
|
|
1968
|
+
};
|
|
1969
|
+
},
|
|
1970
|
+
async update (ctx) {
|
|
1971
|
+
const actionId = ctx.params.actionId;
|
|
1972
|
+
const releaseId = ctx.params.releaseId;
|
|
1973
|
+
const releaseActionUpdateArgs = ctx.request.body;
|
|
1974
|
+
await validateReleaseActionUpdateSchema(releaseActionUpdateArgs);
|
|
1975
|
+
const releaseActionService = getService('release-action', {
|
|
1976
|
+
strapi
|
|
1977
|
+
});
|
|
1978
|
+
const updatedAction = await releaseActionService.update(actionId, releaseId, releaseActionUpdateArgs);
|
|
1979
|
+
ctx.body = {
|
|
1980
|
+
data: updatedAction
|
|
1981
|
+
};
|
|
1982
|
+
},
|
|
1983
|
+
async delete (ctx) {
|
|
1984
|
+
const actionId = ctx.params.actionId;
|
|
1985
|
+
const releaseId = ctx.params.releaseId;
|
|
1986
|
+
const releaseActionService = getService('release-action', {
|
|
1987
|
+
strapi
|
|
1988
|
+
});
|
|
1989
|
+
const deletedReleaseAction = await releaseActionService.delete(actionId, releaseId);
|
|
1990
|
+
ctx.body = {
|
|
1991
|
+
data: deletedReleaseAction
|
|
1992
|
+
};
|
|
1693
1993
|
}
|
|
1694
|
-
ctx.query.sort = ctx.query.groupBy === "action" ? "type" : ctx.query.groupBy;
|
|
1695
|
-
delete ctx.query.groupBy;
|
|
1696
|
-
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
1697
|
-
const releaseActionService = getService("release-action", { strapi });
|
|
1698
|
-
const { results, pagination } = await releaseActionService.findPage(releaseId, {
|
|
1699
|
-
...query
|
|
1700
|
-
});
|
|
1701
|
-
const contentTypeOutputSanitizers = results.reduce((acc, action) => {
|
|
1702
|
-
if (acc[action.contentType]) {
|
|
1703
|
-
return acc;
|
|
1704
|
-
}
|
|
1705
|
-
const contentTypePermissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
1706
|
-
ability: ctx.state.userAbility,
|
|
1707
|
-
model: action.contentType
|
|
1708
|
-
});
|
|
1709
|
-
acc[action.contentType] = contentTypePermissionsManager.sanitizeOutput;
|
|
1710
|
-
return acc;
|
|
1711
|
-
}, {});
|
|
1712
|
-
const sanitizedResults = await utils.async.map(results, async (action) => ({
|
|
1713
|
-
...action,
|
|
1714
|
-
entry: action.entry ? await contentTypeOutputSanitizers[action.contentType](action.entry) : {}
|
|
1715
|
-
}));
|
|
1716
|
-
const groupedData = await releaseActionService.groupActions(sanitizedResults, query.sort);
|
|
1717
|
-
const contentTypes2 = await releaseActionService.getContentTypeModelsFromActions(results);
|
|
1718
|
-
const releaseService = getService("release", { strapi });
|
|
1719
|
-
const components = await releaseService.getAllComponents();
|
|
1720
|
-
ctx.body = {
|
|
1721
|
-
data: groupedData,
|
|
1722
|
-
meta: {
|
|
1723
|
-
pagination,
|
|
1724
|
-
contentTypes: contentTypes2,
|
|
1725
|
-
components
|
|
1726
|
-
}
|
|
1727
|
-
};
|
|
1728
|
-
},
|
|
1729
|
-
async update(ctx) {
|
|
1730
|
-
const actionId = ctx.params.actionId;
|
|
1731
|
-
const releaseId = ctx.params.releaseId;
|
|
1732
|
-
const releaseActionUpdateArgs = ctx.request.body;
|
|
1733
|
-
await validateReleaseActionUpdateSchema(releaseActionUpdateArgs);
|
|
1734
|
-
const releaseActionService = getService("release-action", { strapi });
|
|
1735
|
-
const updatedAction = await releaseActionService.update(
|
|
1736
|
-
actionId,
|
|
1737
|
-
releaseId,
|
|
1738
|
-
releaseActionUpdateArgs
|
|
1739
|
-
);
|
|
1740
|
-
ctx.body = {
|
|
1741
|
-
data: updatedAction
|
|
1742
|
-
};
|
|
1743
|
-
},
|
|
1744
|
-
async delete(ctx) {
|
|
1745
|
-
const actionId = ctx.params.actionId;
|
|
1746
|
-
const releaseId = ctx.params.releaseId;
|
|
1747
|
-
const releaseActionService = getService("release-action", { strapi });
|
|
1748
|
-
const deletedReleaseAction = await releaseActionService.delete(actionId, releaseId);
|
|
1749
|
-
ctx.body = {
|
|
1750
|
-
data: deletedReleaseAction
|
|
1751
|
-
};
|
|
1752
|
-
}
|
|
1753
1994
|
};
|
|
1995
|
+
|
|
1754
1996
|
const SETTINGS_SCHEMA = yup__namespace.object().shape({
|
|
1755
|
-
|
|
1997
|
+
defaultTimezone: yup__namespace.string().nullable().default(null)
|
|
1756
1998
|
}).required().noUnknown();
|
|
1757
1999
|
const validateSettings = utils.validateYupSchema(SETTINGS_SCHEMA);
|
|
2000
|
+
|
|
1758
2001
|
const settingsController = {
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
2002
|
+
async find (ctx) {
|
|
2003
|
+
// Get settings
|
|
2004
|
+
const settingsService = getService('settings', {
|
|
2005
|
+
strapi
|
|
2006
|
+
});
|
|
2007
|
+
const settings = await settingsService.find();
|
|
2008
|
+
// Response
|
|
2009
|
+
ctx.body = {
|
|
2010
|
+
data: settings
|
|
2011
|
+
};
|
|
2012
|
+
},
|
|
2013
|
+
async update (ctx) {
|
|
2014
|
+
// Data validation
|
|
2015
|
+
const settingsBody = ctx.request.body;
|
|
2016
|
+
const settings = await validateSettings(settingsBody);
|
|
2017
|
+
// Update
|
|
2018
|
+
const settingsService = getService('settings', {
|
|
2019
|
+
strapi
|
|
2020
|
+
});
|
|
2021
|
+
const updatedSettings = await settingsService.update({
|
|
2022
|
+
settings
|
|
2023
|
+
});
|
|
2024
|
+
// Response
|
|
2025
|
+
ctx.body = {
|
|
2026
|
+
data: updatedSettings
|
|
2027
|
+
};
|
|
2028
|
+
}
|
|
1771
2029
|
};
|
|
2030
|
+
|
|
1772
2031
|
const controllers = {
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
2032
|
+
release: releaseController,
|
|
2033
|
+
'release-action': releaseActionController,
|
|
2034
|
+
settings: settingsController
|
|
1776
2035
|
};
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
policies: [
|
|
1786
|
-
"admin::isAuthenticatedAdmin",
|
|
1787
|
-
{
|
|
1788
|
-
name: "admin::hasPermissions",
|
|
2036
|
+
|
|
2037
|
+
var release = {
|
|
2038
|
+
type: 'admin',
|
|
2039
|
+
routes: [
|
|
2040
|
+
{
|
|
2041
|
+
method: 'GET',
|
|
2042
|
+
path: '/mapEntriesToReleases',
|
|
2043
|
+
handler: 'release.mapEntriesToReleases',
|
|
1789
2044
|
config: {
|
|
1790
|
-
|
|
2045
|
+
policies: [
|
|
2046
|
+
'admin::isAuthenticatedAdmin',
|
|
2047
|
+
{
|
|
2048
|
+
name: 'admin::hasPermissions',
|
|
2049
|
+
config: {
|
|
2050
|
+
actions: [
|
|
2051
|
+
'plugin::content-releases.read'
|
|
2052
|
+
]
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
]
|
|
1791
2056
|
}
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
method: "GET",
|
|
1798
|
-
path: "/getByDocumentAttached",
|
|
1799
|
-
handler: "release.findByDocumentAttached",
|
|
1800
|
-
config: {
|
|
1801
|
-
policies: [
|
|
1802
|
-
"admin::isAuthenticatedAdmin",
|
|
1803
|
-
{
|
|
1804
|
-
name: "admin::hasPermissions",
|
|
2057
|
+
},
|
|
2058
|
+
{
|
|
2059
|
+
method: 'GET',
|
|
2060
|
+
path: '/getByDocumentAttached',
|
|
2061
|
+
handler: 'release.findByDocumentAttached',
|
|
1805
2062
|
config: {
|
|
1806
|
-
|
|
2063
|
+
policies: [
|
|
2064
|
+
'admin::isAuthenticatedAdmin',
|
|
2065
|
+
{
|
|
2066
|
+
name: 'admin::hasPermissions',
|
|
2067
|
+
config: {
|
|
2068
|
+
actions: [
|
|
2069
|
+
'plugin::content-releases.read'
|
|
2070
|
+
]
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
]
|
|
1807
2074
|
}
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
method: "POST",
|
|
1814
|
-
path: "/",
|
|
1815
|
-
handler: "release.create",
|
|
1816
|
-
config: {
|
|
1817
|
-
policies: [
|
|
1818
|
-
"admin::isAuthenticatedAdmin",
|
|
1819
|
-
{
|
|
1820
|
-
name: "admin::hasPermissions",
|
|
2075
|
+
},
|
|
2076
|
+
{
|
|
2077
|
+
method: 'POST',
|
|
2078
|
+
path: '/',
|
|
2079
|
+
handler: 'release.create',
|
|
1821
2080
|
config: {
|
|
1822
|
-
|
|
2081
|
+
policies: [
|
|
2082
|
+
'admin::isAuthenticatedAdmin',
|
|
2083
|
+
{
|
|
2084
|
+
name: 'admin::hasPermissions',
|
|
2085
|
+
config: {
|
|
2086
|
+
actions: [
|
|
2087
|
+
'plugin::content-releases.create'
|
|
2088
|
+
]
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
]
|
|
1823
2092
|
}
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
method: "GET",
|
|
1830
|
-
path: "/",
|
|
1831
|
-
handler: "release.findPage",
|
|
1832
|
-
config: {
|
|
1833
|
-
policies: [
|
|
1834
|
-
"admin::isAuthenticatedAdmin",
|
|
1835
|
-
{
|
|
1836
|
-
name: "admin::hasPermissions",
|
|
2093
|
+
},
|
|
2094
|
+
{
|
|
2095
|
+
method: 'GET',
|
|
2096
|
+
path: '/',
|
|
2097
|
+
handler: 'release.findPage',
|
|
1837
2098
|
config: {
|
|
1838
|
-
|
|
2099
|
+
policies: [
|
|
2100
|
+
'admin::isAuthenticatedAdmin',
|
|
2101
|
+
{
|
|
2102
|
+
name: 'admin::hasPermissions',
|
|
2103
|
+
config: {
|
|
2104
|
+
actions: [
|
|
2105
|
+
'plugin::content-releases.read'
|
|
2106
|
+
]
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
]
|
|
1839
2110
|
}
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
method: "GET",
|
|
1846
|
-
path: "/:id",
|
|
1847
|
-
handler: "release.findOne",
|
|
1848
|
-
config: {
|
|
1849
|
-
policies: [
|
|
1850
|
-
"admin::isAuthenticatedAdmin",
|
|
1851
|
-
{
|
|
1852
|
-
name: "admin::hasPermissions",
|
|
2111
|
+
},
|
|
2112
|
+
{
|
|
2113
|
+
method: 'GET',
|
|
2114
|
+
path: '/:id',
|
|
2115
|
+
handler: 'release.findOne',
|
|
1853
2116
|
config: {
|
|
1854
|
-
|
|
2117
|
+
policies: [
|
|
2118
|
+
'admin::isAuthenticatedAdmin',
|
|
2119
|
+
{
|
|
2120
|
+
name: 'admin::hasPermissions',
|
|
2121
|
+
config: {
|
|
2122
|
+
actions: [
|
|
2123
|
+
'plugin::content-releases.read'
|
|
2124
|
+
]
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
]
|
|
1855
2128
|
}
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
method: "PUT",
|
|
1862
|
-
path: "/:id",
|
|
1863
|
-
handler: "release.update",
|
|
1864
|
-
config: {
|
|
1865
|
-
policies: [
|
|
1866
|
-
"admin::isAuthenticatedAdmin",
|
|
1867
|
-
{
|
|
1868
|
-
name: "admin::hasPermissions",
|
|
2129
|
+
},
|
|
2130
|
+
{
|
|
2131
|
+
method: 'PUT',
|
|
2132
|
+
path: '/:id',
|
|
2133
|
+
handler: 'release.update',
|
|
1869
2134
|
config: {
|
|
1870
|
-
|
|
2135
|
+
policies: [
|
|
2136
|
+
'admin::isAuthenticatedAdmin',
|
|
2137
|
+
{
|
|
2138
|
+
name: 'admin::hasPermissions',
|
|
2139
|
+
config: {
|
|
2140
|
+
actions: [
|
|
2141
|
+
'plugin::content-releases.update'
|
|
2142
|
+
]
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
]
|
|
1871
2146
|
}
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
method: "DELETE",
|
|
1878
|
-
path: "/:id",
|
|
1879
|
-
handler: "release.delete",
|
|
1880
|
-
config: {
|
|
1881
|
-
policies: [
|
|
1882
|
-
"admin::isAuthenticatedAdmin",
|
|
1883
|
-
{
|
|
1884
|
-
name: "admin::hasPermissions",
|
|
2147
|
+
},
|
|
2148
|
+
{
|
|
2149
|
+
method: 'DELETE',
|
|
2150
|
+
path: '/:id',
|
|
2151
|
+
handler: 'release.delete',
|
|
1885
2152
|
config: {
|
|
1886
|
-
|
|
2153
|
+
policies: [
|
|
2154
|
+
'admin::isAuthenticatedAdmin',
|
|
2155
|
+
{
|
|
2156
|
+
name: 'admin::hasPermissions',
|
|
2157
|
+
config: {
|
|
2158
|
+
actions: [
|
|
2159
|
+
'plugin::content-releases.delete'
|
|
2160
|
+
]
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
]
|
|
1887
2164
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
method: "POST",
|
|
1894
|
-
path: "/:id/publish",
|
|
1895
|
-
handler: "release.publish",
|
|
1896
|
-
config: {
|
|
1897
|
-
policies: [
|
|
1898
|
-
"admin::isAuthenticatedAdmin",
|
|
1899
|
-
{
|
|
1900
|
-
name: "admin::hasPermissions",
|
|
2165
|
+
},
|
|
2166
|
+
{
|
|
2167
|
+
method: 'POST',
|
|
2168
|
+
path: '/:id/publish',
|
|
2169
|
+
handler: 'release.publish',
|
|
1901
2170
|
config: {
|
|
1902
|
-
|
|
2171
|
+
policies: [
|
|
2172
|
+
'admin::isAuthenticatedAdmin',
|
|
2173
|
+
{
|
|
2174
|
+
name: 'admin::hasPermissions',
|
|
2175
|
+
config: {
|
|
2176
|
+
actions: [
|
|
2177
|
+
'plugin::content-releases.publish'
|
|
2178
|
+
]
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
]
|
|
1903
2182
|
}
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
]
|
|
2183
|
+
}
|
|
2184
|
+
]
|
|
1909
2185
|
};
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
policies: [
|
|
1919
|
-
"admin::isAuthenticatedAdmin",
|
|
1920
|
-
{
|
|
1921
|
-
name: "admin::hasPermissions",
|
|
2186
|
+
|
|
2187
|
+
var releaseAction = {
|
|
2188
|
+
type: 'admin',
|
|
2189
|
+
routes: [
|
|
2190
|
+
{
|
|
2191
|
+
method: 'POST',
|
|
2192
|
+
path: '/:releaseId/actions',
|
|
2193
|
+
handler: 'release-action.create',
|
|
1922
2194
|
config: {
|
|
1923
|
-
|
|
2195
|
+
policies: [
|
|
2196
|
+
'admin::isAuthenticatedAdmin',
|
|
2197
|
+
{
|
|
2198
|
+
name: 'admin::hasPermissions',
|
|
2199
|
+
config: {
|
|
2200
|
+
actions: [
|
|
2201
|
+
'plugin::content-releases.create-action'
|
|
2202
|
+
]
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
]
|
|
1924
2206
|
}
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
method: "POST",
|
|
1931
|
-
path: "/:releaseId/actions/bulk",
|
|
1932
|
-
handler: "release-action.createMany",
|
|
1933
|
-
config: {
|
|
1934
|
-
policies: [
|
|
1935
|
-
"admin::isAuthenticatedAdmin",
|
|
1936
|
-
{
|
|
1937
|
-
name: "admin::hasPermissions",
|
|
2207
|
+
},
|
|
2208
|
+
{
|
|
2209
|
+
method: 'POST',
|
|
2210
|
+
path: '/:releaseId/actions/bulk',
|
|
2211
|
+
handler: 'release-action.createMany',
|
|
1938
2212
|
config: {
|
|
1939
|
-
|
|
2213
|
+
policies: [
|
|
2214
|
+
'admin::isAuthenticatedAdmin',
|
|
2215
|
+
{
|
|
2216
|
+
name: 'admin::hasPermissions',
|
|
2217
|
+
config: {
|
|
2218
|
+
actions: [
|
|
2219
|
+
'plugin::content-releases.create-action'
|
|
2220
|
+
]
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
]
|
|
1940
2224
|
}
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
method: "GET",
|
|
1947
|
-
path: "/:releaseId/actions",
|
|
1948
|
-
handler: "release-action.findMany",
|
|
1949
|
-
config: {
|
|
1950
|
-
policies: [
|
|
1951
|
-
"admin::isAuthenticatedAdmin",
|
|
1952
|
-
{
|
|
1953
|
-
name: "admin::hasPermissions",
|
|
2225
|
+
},
|
|
2226
|
+
{
|
|
2227
|
+
method: 'GET',
|
|
2228
|
+
path: '/:releaseId/actions',
|
|
2229
|
+
handler: 'release-action.findMany',
|
|
1954
2230
|
config: {
|
|
1955
|
-
|
|
2231
|
+
policies: [
|
|
2232
|
+
'admin::isAuthenticatedAdmin',
|
|
2233
|
+
{
|
|
2234
|
+
name: 'admin::hasPermissions',
|
|
2235
|
+
config: {
|
|
2236
|
+
actions: [
|
|
2237
|
+
'plugin::content-releases.read'
|
|
2238
|
+
]
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
]
|
|
1956
2242
|
}
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
method: "PUT",
|
|
1963
|
-
path: "/:releaseId/actions/:actionId",
|
|
1964
|
-
handler: "release-action.update",
|
|
1965
|
-
config: {
|
|
1966
|
-
policies: [
|
|
1967
|
-
"admin::isAuthenticatedAdmin",
|
|
1968
|
-
{
|
|
1969
|
-
name: "admin::hasPermissions",
|
|
2243
|
+
},
|
|
2244
|
+
{
|
|
2245
|
+
method: 'PUT',
|
|
2246
|
+
path: '/:releaseId/actions/:actionId',
|
|
2247
|
+
handler: 'release-action.update',
|
|
1970
2248
|
config: {
|
|
1971
|
-
|
|
2249
|
+
policies: [
|
|
2250
|
+
'admin::isAuthenticatedAdmin',
|
|
2251
|
+
{
|
|
2252
|
+
name: 'admin::hasPermissions',
|
|
2253
|
+
config: {
|
|
2254
|
+
actions: [
|
|
2255
|
+
'plugin::content-releases.update'
|
|
2256
|
+
]
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
]
|
|
1972
2260
|
}
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
method: "DELETE",
|
|
1979
|
-
path: "/:releaseId/actions/:actionId",
|
|
1980
|
-
handler: "release-action.delete",
|
|
1981
|
-
config: {
|
|
1982
|
-
policies: [
|
|
1983
|
-
"admin::isAuthenticatedAdmin",
|
|
1984
|
-
{
|
|
1985
|
-
name: "admin::hasPermissions",
|
|
2261
|
+
},
|
|
2262
|
+
{
|
|
2263
|
+
method: 'DELETE',
|
|
2264
|
+
path: '/:releaseId/actions/:actionId',
|
|
2265
|
+
handler: 'release-action.delete',
|
|
1986
2266
|
config: {
|
|
1987
|
-
|
|
2267
|
+
policies: [
|
|
2268
|
+
'admin::isAuthenticatedAdmin',
|
|
2269
|
+
{
|
|
2270
|
+
name: 'admin::hasPermissions',
|
|
2271
|
+
config: {
|
|
2272
|
+
actions: [
|
|
2273
|
+
'plugin::content-releases.delete-action'
|
|
2274
|
+
]
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
]
|
|
1988
2278
|
}
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
}
|
|
1992
|
-
}
|
|
1993
|
-
]
|
|
2279
|
+
}
|
|
2280
|
+
]
|
|
1994
2281
|
};
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
policies: [
|
|
2004
|
-
"admin::isAuthenticatedAdmin",
|
|
2005
|
-
{
|
|
2006
|
-
name: "admin::hasPermissions",
|
|
2282
|
+
|
|
2283
|
+
var settings = {
|
|
2284
|
+
type: 'admin',
|
|
2285
|
+
routes: [
|
|
2286
|
+
{
|
|
2287
|
+
method: 'GET',
|
|
2288
|
+
path: '/settings',
|
|
2289
|
+
handler: 'settings.find',
|
|
2007
2290
|
config: {
|
|
2008
|
-
|
|
2291
|
+
policies: [
|
|
2292
|
+
'admin::isAuthenticatedAdmin',
|
|
2293
|
+
{
|
|
2294
|
+
name: 'admin::hasPermissions',
|
|
2295
|
+
config: {
|
|
2296
|
+
actions: [
|
|
2297
|
+
'plugin::content-releases.settings.read'
|
|
2298
|
+
]
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
]
|
|
2009
2302
|
}
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
method: "PUT",
|
|
2016
|
-
path: "/settings",
|
|
2017
|
-
handler: "settings.update",
|
|
2018
|
-
config: {
|
|
2019
|
-
policies: [
|
|
2020
|
-
"admin::isAuthenticatedAdmin",
|
|
2021
|
-
{
|
|
2022
|
-
name: "admin::hasPermissions",
|
|
2303
|
+
},
|
|
2304
|
+
{
|
|
2305
|
+
method: 'PUT',
|
|
2306
|
+
path: '/settings',
|
|
2307
|
+
handler: 'settings.update',
|
|
2023
2308
|
config: {
|
|
2024
|
-
|
|
2309
|
+
policies: [
|
|
2310
|
+
'admin::isAuthenticatedAdmin',
|
|
2311
|
+
{
|
|
2312
|
+
name: 'admin::hasPermissions',
|
|
2313
|
+
config: {
|
|
2314
|
+
actions: [
|
|
2315
|
+
'plugin::content-releases.settings.update'
|
|
2316
|
+
]
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
]
|
|
2025
2320
|
}
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
}
|
|
2029
|
-
}
|
|
2030
|
-
]
|
|
2321
|
+
}
|
|
2322
|
+
]
|
|
2031
2323
|
};
|
|
2324
|
+
|
|
2032
2325
|
const routes = {
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2326
|
+
settings,
|
|
2327
|
+
release,
|
|
2328
|
+
'release-action': releaseAction
|
|
2036
2329
|
};
|
|
2037
|
-
|
|
2038
|
-
|
|
2330
|
+
|
|
2331
|
+
const getPlugin = ()=>{
|
|
2332
|
+
if (strapi.ee.features.isEnabled('cms-content-releases')) {
|
|
2333
|
+
return {
|
|
2334
|
+
register,
|
|
2335
|
+
bootstrap,
|
|
2336
|
+
destroy,
|
|
2337
|
+
contentTypes,
|
|
2338
|
+
services,
|
|
2339
|
+
controllers,
|
|
2340
|
+
routes
|
|
2341
|
+
};
|
|
2342
|
+
}
|
|
2039
2343
|
return {
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
services,
|
|
2045
|
-
controllers,
|
|
2046
|
-
routes
|
|
2344
|
+
// Always return register, it handles its own feature check
|
|
2345
|
+
register,
|
|
2346
|
+
// Always return contentTypes to avoid losing data when the feature is disabled
|
|
2347
|
+
contentTypes
|
|
2047
2348
|
};
|
|
2048
|
-
}
|
|
2049
|
-
return {
|
|
2050
|
-
// Always return register, it handles its own feature check
|
|
2051
|
-
register,
|
|
2052
|
-
// Always return contentTypes to avoid losing data when the feature is disabled
|
|
2053
|
-
contentTypes
|
|
2054
|
-
};
|
|
2055
2349
|
};
|
|
2056
|
-
|
|
2350
|
+
var index = getPlugin();
|
|
2351
|
+
|
|
2057
2352
|
module.exports = index;
|
|
2058
2353
|
//# sourceMappingURL=index.js.map
|