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