@strapi/content-releases 0.0.0-next.334c95408abdd9ecc0ece0e8c0fd5eb0024ad027 → 0.0.0-next.36632203b17974c18103c138ffbef53a82e448c3
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/LICENSE +17 -1
- package/dist/_chunks/App-BKB1esYS.js +1395 -0
- package/dist/_chunks/App-BKB1esYS.js.map +1 -0
- package/dist/_chunks/App-Cne--1Z8.mjs +1374 -0
- package/dist/_chunks/App-Cne--1Z8.mjs.map +1 -0
- package/dist/_chunks/PurchaseContentReleases-Be3acS2L.js +52 -0
- package/dist/_chunks/PurchaseContentReleases-Be3acS2L.js.map +1 -0
- package/dist/_chunks/PurchaseContentReleases-_MxP6-Dt.mjs +52 -0
- package/dist/_chunks/PurchaseContentReleases-_MxP6-Dt.mjs.map +1 -0
- package/dist/_chunks/ReleasesSettingsPage-C1WwGWIH.mjs +178 -0
- package/dist/_chunks/ReleasesSettingsPage-C1WwGWIH.mjs.map +1 -0
- package/dist/_chunks/ReleasesSettingsPage-kuXIwpWp.js +178 -0
- package/dist/_chunks/ReleasesSettingsPage-kuXIwpWp.js.map +1 -0
- package/dist/_chunks/{en-gYDqKYFd.js → en-CmYoEnA7.js} +37 -7
- package/dist/_chunks/en-CmYoEnA7.js.map +1 -0
- package/dist/_chunks/{en-MyLPoISH.mjs → en-D0yVZFqf.mjs} +37 -7
- package/dist/_chunks/en-D0yVZFqf.mjs.map +1 -0
- package/dist/_chunks/index-5Odi61vw.js +1381 -0
- package/dist/_chunks/index-5Odi61vw.js.map +1 -0
- package/dist/_chunks/index-Cy7qwpaU.mjs +1362 -0
- package/dist/_chunks/index-Cy7qwpaU.mjs.map +1 -0
- package/dist/_chunks/schemas-BE1LxE9J.js +62 -0
- package/dist/_chunks/schemas-BE1LxE9J.js.map +1 -0
- package/dist/_chunks/schemas-DdA2ic2U.mjs +44 -0
- package/dist/_chunks/schemas-DdA2ic2U.mjs.map +1 -0
- package/dist/admin/index.js +1 -15
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +2 -16
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/src/components/RelativeTime.d.ts +28 -0
- package/dist/admin/src/components/ReleaseAction.d.ts +3 -0
- package/dist/admin/src/components/ReleaseActionMenu.d.ts +26 -0
- package/dist/admin/src/components/ReleaseActionModal.d.ts +24 -0
- package/dist/admin/src/components/ReleaseActionOptions.d.ts +9 -0
- package/dist/admin/src/components/ReleaseListCell.d.ts +28 -0
- package/dist/admin/src/components/ReleaseModal.d.ts +17 -0
- package/dist/admin/src/components/ReleasesPanel.d.ts +3 -0
- package/dist/admin/src/constants.d.ts +76 -0
- package/dist/admin/src/index.d.ts +3 -0
- package/dist/admin/src/modules/hooks.d.ts +7 -0
- package/dist/admin/src/pages/App.d.ts +1 -0
- package/dist/admin/src/pages/PurchaseContentReleases.d.ts +2 -0
- package/dist/admin/src/pages/ReleaseDetailsPage.d.ts +2 -0
- package/dist/admin/src/pages/ReleasesPage.d.ts +8 -0
- package/dist/admin/src/pages/ReleasesSettingsPage.d.ts +1 -0
- package/dist/admin/src/pages/tests/mockReleaseDetailsPageData.d.ts +181 -0
- package/dist/admin/src/pages/tests/mockReleasesPageData.d.ts +39 -0
- package/dist/admin/src/pluginId.d.ts +1 -0
- package/dist/admin/src/services/release.d.ts +112 -0
- package/dist/admin/src/store/hooks.d.ts +7 -0
- package/dist/admin/src/utils/api.d.ts +6 -0
- package/dist/admin/src/utils/prefixPluginTranslations.d.ts +3 -0
- package/dist/admin/src/utils/time.d.ts +10 -0
- package/dist/admin/src/validation/schemas.d.ts +6 -0
- package/dist/server/index.js +1409 -458
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +1409 -458
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/bootstrap.d.ts +5 -0
- package/dist/server/src/bootstrap.d.ts.map +1 -0
- package/dist/server/src/constants.d.ts +21 -0
- package/dist/server/src/constants.d.ts.map +1 -0
- package/dist/server/src/content-types/index.d.ts +97 -0
- package/dist/server/src/content-types/index.d.ts.map +1 -0
- package/dist/server/src/content-types/release/index.d.ts +48 -0
- package/dist/server/src/content-types/release/index.d.ts.map +1 -0
- package/dist/server/src/content-types/release/schema.d.ts +47 -0
- package/dist/server/src/content-types/release/schema.d.ts.map +1 -0
- package/dist/server/src/content-types/release-action/index.d.ts +48 -0
- package/dist/server/src/content-types/release-action/index.d.ts.map +1 -0
- package/dist/server/src/content-types/release-action/schema.d.ts +47 -0
- package/dist/server/src/content-types/release-action/schema.d.ts.map +1 -0
- package/dist/server/src/controllers/index.d.ts +25 -0
- package/dist/server/src/controllers/index.d.ts.map +1 -0
- package/dist/server/src/controllers/release-action.d.ts +10 -0
- package/dist/server/src/controllers/release-action.d.ts.map +1 -0
- package/dist/server/src/controllers/release.d.ts +18 -0
- package/dist/server/src/controllers/release.d.ts.map +1 -0
- package/dist/server/src/controllers/settings.d.ts +11 -0
- package/dist/server/src/controllers/settings.d.ts.map +1 -0
- package/dist/server/src/controllers/validation/release-action.d.ts +14 -0
- package/dist/server/src/controllers/validation/release-action.d.ts.map +1 -0
- package/dist/server/src/controllers/validation/release.d.ts +4 -0
- package/dist/server/src/controllers/validation/release.d.ts.map +1 -0
- package/dist/server/src/controllers/validation/settings.d.ts +3 -0
- package/dist/server/src/controllers/validation/settings.d.ts.map +1 -0
- package/dist/server/src/destroy.d.ts +5 -0
- package/dist/server/src/destroy.d.ts.map +1 -0
- package/dist/server/src/index.d.ts +2115 -0
- package/dist/server/src/index.d.ts.map +1 -0
- package/dist/server/src/middlewares/documents.d.ts +6 -0
- package/dist/server/src/middlewares/documents.d.ts.map +1 -0
- package/dist/server/src/migrations/database/5.0.0-document-id-in-actions.d.ts +9 -0
- package/dist/server/src/migrations/database/5.0.0-document-id-in-actions.d.ts.map +1 -0
- package/dist/server/src/migrations/index.d.ts +13 -0
- package/dist/server/src/migrations/index.d.ts.map +1 -0
- package/dist/server/src/register.d.ts +5 -0
- package/dist/server/src/register.d.ts.map +1 -0
- package/dist/server/src/routes/index.d.ts +51 -0
- package/dist/server/src/routes/index.d.ts.map +1 -0
- package/dist/server/src/routes/release-action.d.ts +18 -0
- package/dist/server/src/routes/release-action.d.ts.map +1 -0
- package/dist/server/src/routes/release.d.ts +18 -0
- package/dist/server/src/routes/release.d.ts.map +1 -0
- package/dist/server/src/routes/settings.d.ts +18 -0
- package/dist/server/src/routes/settings.d.ts.map +1 -0
- package/dist/server/src/services/index.d.ts +1828 -0
- package/dist/server/src/services/index.d.ts.map +1 -0
- package/dist/server/src/services/release-action.d.ts +38 -0
- package/dist/server/src/services/release-action.d.ts.map +1 -0
- package/dist/server/src/services/release.d.ts +31 -0
- package/dist/server/src/services/release.d.ts.map +1 -0
- package/dist/server/src/services/scheduling.d.ts +18 -0
- package/dist/server/src/services/scheduling.d.ts.map +1 -0
- package/dist/server/src/services/settings.d.ts +13 -0
- package/dist/server/src/services/settings.d.ts.map +1 -0
- package/dist/server/src/services/validation.d.ts +18 -0
- package/dist/server/src/services/validation.d.ts.map +1 -0
- package/dist/server/src/utils/index.d.ts +35 -0
- package/dist/server/src/utils/index.d.ts.map +1 -0
- package/dist/shared/contracts/release-actions.d.ts +130 -0
- package/dist/shared/contracts/release-actions.d.ts.map +1 -0
- package/dist/shared/contracts/releases.d.ts +184 -0
- package/dist/shared/contracts/releases.d.ts.map +1 -0
- package/dist/shared/contracts/settings.d.ts +39 -0
- package/dist/shared/contracts/settings.d.ts.map +1 -0
- package/dist/shared/types.d.ts +24 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/package.json +35 -35
- package/dist/_chunks/App-AYV8n9jv.js +0 -989
- package/dist/_chunks/App-AYV8n9jv.js.map +0 -1
- package/dist/_chunks/App-KBaxZVmD.mjs +0 -967
- package/dist/_chunks/App-KBaxZVmD.mjs.map +0 -1
- package/dist/_chunks/en-MyLPoISH.mjs.map +0 -1
- package/dist/_chunks/en-gYDqKYFd.js.map +0 -1
- package/dist/_chunks/index-FYDbIuRi.js +0 -905
- package/dist/_chunks/index-FYDbIuRi.js.map +0 -1
- package/dist/_chunks/index-NFIckO1N.mjs +0 -884
- package/dist/_chunks/index-NFIckO1N.mjs.map +0 -1
- package/strapi-server.js +0 -3
package/dist/server/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { setCreatorFields, errors,
|
|
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";
|
|
2
4
|
import _ from "lodash/fp";
|
|
3
|
-
import
|
|
5
|
+
import { scheduleJob } from "node-schedule";
|
|
4
6
|
import * as yup from "yup";
|
|
5
7
|
const RELEASE_MODEL_UID = "plugin::content-releases.release";
|
|
6
8
|
const RELEASE_ACTION_MODEL_UID = "plugin::content-releases.release-action";
|
|
@@ -46,82 +48,455 @@ const ACTIONS = [
|
|
|
46
48
|
displayName: "Add an entry to a release",
|
|
47
49
|
uid: "create-action",
|
|
48
50
|
pluginName: "content-releases"
|
|
51
|
+
},
|
|
52
|
+
// Settings
|
|
53
|
+
{
|
|
54
|
+
uid: "settings.read",
|
|
55
|
+
section: "settings",
|
|
56
|
+
displayName: "Read",
|
|
57
|
+
category: "content releases",
|
|
58
|
+
subCategory: "options",
|
|
59
|
+
pluginName: "content-releases"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
uid: "settings.update",
|
|
63
|
+
section: "settings",
|
|
64
|
+
displayName: "Edit",
|
|
65
|
+
category: "content releases",
|
|
66
|
+
subCategory: "options",
|
|
67
|
+
pluginName: "content-releases"
|
|
49
68
|
}
|
|
50
69
|
];
|
|
51
|
-
const
|
|
70
|
+
const ALLOWED_WEBHOOK_EVENTS = {
|
|
71
|
+
RELEASES_PUBLISH: "releases.publish"
|
|
72
|
+
};
|
|
73
|
+
const getService = (name, { strapi: strapi2 }) => {
|
|
52
74
|
return strapi2.plugin("content-releases").service(name);
|
|
53
75
|
};
|
|
54
|
-
const {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
76
|
+
const getDraftEntryValidStatus = async ({ contentType, documentId, locale }, { strapi: strapi2 }) => {
|
|
77
|
+
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
78
|
+
const populate = await populateBuilderService(contentType).populateDeep(Infinity).build();
|
|
79
|
+
const entry = await getEntry({ contentType, documentId, locale, populate }, { strapi: strapi2 });
|
|
80
|
+
return isEntryValid(contentType, entry, { strapi: strapi2 });
|
|
81
|
+
};
|
|
82
|
+
const isEntryValid = async (contentTypeUid, entry, { strapi: strapi2 }) => {
|
|
83
|
+
try {
|
|
84
|
+
await strapi2.entityValidator.validateEntityCreation(
|
|
85
|
+
strapi2.getModel(contentTypeUid),
|
|
86
|
+
entry,
|
|
87
|
+
void 0,
|
|
88
|
+
// @ts-expect-error - FIXME: entity here is unnecessary
|
|
89
|
+
entry
|
|
90
|
+
);
|
|
91
|
+
return true;
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const getEntry = async ({
|
|
97
|
+
contentType,
|
|
98
|
+
documentId,
|
|
99
|
+
locale,
|
|
100
|
+
populate,
|
|
101
|
+
status = "draft"
|
|
102
|
+
}, { strapi: strapi2 }) => {
|
|
103
|
+
if (documentId) {
|
|
104
|
+
const entry = await strapi2.documents(contentType).findOne({ documentId, locale, populate, status });
|
|
105
|
+
if (status === "published" && !entry) {
|
|
106
|
+
return strapi2.documents(contentType).findOne({ documentId, locale, populate, status: "draft" });
|
|
107
|
+
}
|
|
108
|
+
return entry;
|
|
109
|
+
}
|
|
110
|
+
return strapi2.documents(contentType).findFirst({ locale, populate, status });
|
|
111
|
+
};
|
|
112
|
+
const getEntryStatus = async (contentType, entry) => {
|
|
113
|
+
if (entry.publishedAt) {
|
|
114
|
+
return "published";
|
|
115
|
+
}
|
|
116
|
+
const publishedEntry = await strapi.documents(contentType).findOne({
|
|
117
|
+
documentId: entry.documentId,
|
|
118
|
+
locale: entry.locale,
|
|
119
|
+
status: "published",
|
|
120
|
+
fields: ["updatedAt"]
|
|
121
|
+
});
|
|
122
|
+
if (!publishedEntry) {
|
|
123
|
+
return "draft";
|
|
124
|
+
}
|
|
125
|
+
const entryUpdatedAt = new Date(entry.updatedAt).getTime();
|
|
126
|
+
const publishedEntryUpdatedAt = new Date(publishedEntry.updatedAt).getTime();
|
|
127
|
+
if (entryUpdatedAt > publishedEntryUpdatedAt) {
|
|
128
|
+
return "modified";
|
|
129
|
+
}
|
|
130
|
+
return "published";
|
|
131
|
+
};
|
|
132
|
+
async function deleteActionsOnDisableDraftAndPublish({
|
|
133
|
+
oldContentTypes,
|
|
134
|
+
contentTypes: contentTypes2
|
|
135
|
+
}) {
|
|
136
|
+
if (!oldContentTypes) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
for (const uid in contentTypes2) {
|
|
140
|
+
if (!oldContentTypes[uid]) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const oldContentType = oldContentTypes[uid];
|
|
144
|
+
const contentType = contentTypes2[uid];
|
|
145
|
+
if (contentTypes$1.hasDraftAndPublish(oldContentType) && !contentTypes$1.hasDraftAndPublish(contentType)) {
|
|
146
|
+
await strapi.db?.queryBuilder(RELEASE_ACTION_MODEL_UID).delete().where({ contentType: uid }).execute();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async function deleteActionsOnDeleteContentType({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
151
|
+
const deletedContentTypes = difference(keys(oldContentTypes), keys(contentTypes2)) ?? [];
|
|
152
|
+
if (deletedContentTypes.length) {
|
|
153
|
+
await async.map(deletedContentTypes, async (deletedContentTypeUID) => {
|
|
154
|
+
return strapi.db?.queryBuilder(RELEASE_ACTION_MODEL_UID).delete().where({ contentType: deletedContentTypeUID }).execute();
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async function migrateIsValidAndStatusReleases() {
|
|
159
|
+
const releasesWithoutStatus = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
160
|
+
where: {
|
|
161
|
+
status: null,
|
|
162
|
+
releasedAt: null
|
|
163
|
+
},
|
|
164
|
+
populate: {
|
|
165
|
+
actions: {
|
|
166
|
+
populate: {
|
|
167
|
+
entry: true
|
|
65
168
|
}
|
|
66
169
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
async.map(releasesWithoutStatus, async (release2) => {
|
|
173
|
+
const actions = release2.actions;
|
|
174
|
+
const notValidatedActions = actions.filter((action) => action.isEntryValid === null);
|
|
175
|
+
for (const action of notValidatedActions) {
|
|
176
|
+
if (action.entry) {
|
|
177
|
+
const isEntryValid2 = getDraftEntryValidStatus(
|
|
178
|
+
{
|
|
179
|
+
contentType: action.contentType,
|
|
180
|
+
documentId: action.entryDocumentId,
|
|
181
|
+
locale: action.locale
|
|
182
|
+
},
|
|
183
|
+
{ strapi }
|
|
184
|
+
);
|
|
185
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
186
|
+
where: {
|
|
187
|
+
id: action.id
|
|
188
|
+
},
|
|
189
|
+
data: {
|
|
190
|
+
isEntryValid: isEntryValid2
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
196
|
+
});
|
|
197
|
+
const publishedReleases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
198
|
+
where: {
|
|
199
|
+
status: null,
|
|
200
|
+
releasedAt: {
|
|
201
|
+
$notNull: true
|
|
73
202
|
}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
async.map(publishedReleases, async (release2) => {
|
|
206
|
+
return strapi.db.query(RELEASE_MODEL_UID).update({
|
|
207
|
+
where: {
|
|
208
|
+
id: release2.id
|
|
209
|
+
},
|
|
210
|
+
data: {
|
|
211
|
+
status: "done"
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
async function revalidateChangedContentTypes({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
217
|
+
if (oldContentTypes !== void 0 && contentTypes2 !== void 0) {
|
|
218
|
+
const contentTypesWithDraftAndPublish = Object.keys(oldContentTypes).filter(
|
|
219
|
+
(uid) => oldContentTypes[uid]?.options?.draftAndPublish
|
|
74
220
|
);
|
|
75
|
-
|
|
221
|
+
const releasesAffected = /* @__PURE__ */ new Set();
|
|
222
|
+
async.map(contentTypesWithDraftAndPublish, async (contentTypeUID) => {
|
|
223
|
+
const oldContentType = oldContentTypes[contentTypeUID];
|
|
224
|
+
const contentType = contentTypes2[contentTypeUID];
|
|
225
|
+
if (!isEqual(oldContentType?.attributes, contentType?.attributes)) {
|
|
226
|
+
const actions = await strapi.db.query(RELEASE_ACTION_MODEL_UID).findMany({
|
|
227
|
+
where: {
|
|
228
|
+
contentType: contentTypeUID
|
|
229
|
+
},
|
|
230
|
+
populate: {
|
|
231
|
+
entry: true,
|
|
232
|
+
release: true
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
await async.map(actions, async (action) => {
|
|
236
|
+
if (action.entry && action.release && action.type === "publish") {
|
|
237
|
+
const isEntryValid2 = await getDraftEntryValidStatus(
|
|
238
|
+
{
|
|
239
|
+
contentType: contentTypeUID,
|
|
240
|
+
documentId: action.entryDocumentId,
|
|
241
|
+
locale: action.locale
|
|
242
|
+
},
|
|
243
|
+
{ strapi }
|
|
244
|
+
);
|
|
245
|
+
releasesAffected.add(action.release.id);
|
|
246
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
247
|
+
where: {
|
|
248
|
+
id: action.id
|
|
249
|
+
},
|
|
250
|
+
data: {
|
|
251
|
+
isEntryValid: isEntryValid2
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}).then(() => {
|
|
258
|
+
async.map(releasesAffected, async (releaseId) => {
|
|
259
|
+
return getService("release", { strapi }).updateReleaseStatus(releaseId);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async function disableContentTypeLocalized({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
265
|
+
if (!oldContentTypes) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const i18nPlugin = strapi.plugin("i18n");
|
|
269
|
+
if (!i18nPlugin) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
for (const uid in contentTypes2) {
|
|
273
|
+
if (!oldContentTypes[uid]) {
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
const oldContentType = oldContentTypes[uid];
|
|
277
|
+
const contentType = contentTypes2[uid];
|
|
278
|
+
const { isLocalizedContentType } = i18nPlugin.service("content-types");
|
|
279
|
+
if (isLocalizedContentType(oldContentType) && !isLocalizedContentType(contentType)) {
|
|
280
|
+
await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
|
|
281
|
+
locale: null
|
|
282
|
+
}).where({ contentType: uid }).execute();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async function enableContentTypeLocalized({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
287
|
+
if (!oldContentTypes) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const i18nPlugin = strapi.plugin("i18n");
|
|
291
|
+
if (!i18nPlugin) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
for (const uid in contentTypes2) {
|
|
295
|
+
if (!oldContentTypes[uid]) {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
const oldContentType = oldContentTypes[uid];
|
|
299
|
+
const contentType = contentTypes2[uid];
|
|
300
|
+
const { isLocalizedContentType } = i18nPlugin.service("content-types");
|
|
301
|
+
const { getDefaultLocale } = i18nPlugin.service("locales");
|
|
302
|
+
if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {
|
|
303
|
+
const defaultLocale = await getDefaultLocale();
|
|
304
|
+
await strapi.db.queryBuilder(RELEASE_ACTION_MODEL_UID).update({
|
|
305
|
+
locale: defaultLocale
|
|
306
|
+
}).where({ contentType: uid }).execute();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const addEntryDocumentToReleaseActions = {
|
|
311
|
+
name: "content-releases::5.0.0-add-entry-document-id-to-release-actions",
|
|
312
|
+
async up(trx, db) {
|
|
313
|
+
const hasTable = await trx.schema.hasTable("strapi_release_actions");
|
|
314
|
+
if (!hasTable) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const hasPolymorphicColumn = await trx.schema.hasColumn("strapi_release_actions", "target_id");
|
|
318
|
+
if (hasPolymorphicColumn) {
|
|
319
|
+
const hasEntryDocumentIdColumn = await trx.schema.hasColumn(
|
|
320
|
+
"strapi_release_actions",
|
|
321
|
+
"entry_document_id"
|
|
322
|
+
);
|
|
323
|
+
if (!hasEntryDocumentIdColumn) {
|
|
324
|
+
await trx.schema.alterTable("strapi_release_actions", (table) => {
|
|
325
|
+
table.string("entry_document_id");
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
const releaseActions = await trx.select("*").from("strapi_release_actions");
|
|
329
|
+
async.map(releaseActions, async (action) => {
|
|
330
|
+
const { target_type, target_id } = action;
|
|
331
|
+
const entry = await db.query(target_type).findOne({ where: { id: target_id } });
|
|
332
|
+
if (entry) {
|
|
333
|
+
await trx("strapi_release_actions").update({ entry_document_id: entry.documentId }).where("id", action.id);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
async down() {
|
|
339
|
+
throw new Error("not implemented");
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
const register = async ({ strapi: strapi2 }) => {
|
|
343
|
+
if (strapi2.ee.features.isEnabled("cms-content-releases")) {
|
|
344
|
+
await strapi2.service("admin::permission").actionProvider.registerMany(ACTIONS);
|
|
345
|
+
strapi2.db.migrations.providers.internal.register(addEntryDocumentToReleaseActions);
|
|
346
|
+
strapi2.hook("strapi::content-types.beforeSync").register(disableContentTypeLocalized).register(deleteActionsOnDisableDraftAndPublish);
|
|
347
|
+
strapi2.hook("strapi::content-types.afterSync").register(deleteActionsOnDeleteContentType).register(enableContentTypeLocalized).register(revalidateChangedContentTypes).register(migrateIsValidAndStatusReleases);
|
|
348
|
+
}
|
|
349
|
+
if (strapi2.plugin("graphql")) {
|
|
350
|
+
const graphqlExtensionService = strapi2.plugin("graphql").service("extension");
|
|
351
|
+
graphqlExtensionService.shadowCRUD(RELEASE_MODEL_UID).disable();
|
|
352
|
+
graphqlExtensionService.shadowCRUD(RELEASE_ACTION_MODEL_UID).disable();
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
const updateActionsStatusAndUpdateReleaseStatus = async (contentType, entry) => {
|
|
356
|
+
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
357
|
+
where: {
|
|
358
|
+
actions: {
|
|
359
|
+
contentType,
|
|
360
|
+
entryDocumentId: entry.documentId,
|
|
361
|
+
locale: entry.locale
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
const entryStatus = await isEntryValid(contentType, entry, { strapi });
|
|
366
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
367
|
+
where: {
|
|
368
|
+
contentType,
|
|
369
|
+
entryDocumentId: entry.documentId,
|
|
370
|
+
locale: entry.locale
|
|
371
|
+
},
|
|
372
|
+
data: {
|
|
373
|
+
isEntryValid: entryStatus
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
for (const release2 of releases) {
|
|
377
|
+
getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
const deleteActionsAndUpdateReleaseStatus = async (params) => {
|
|
381
|
+
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
382
|
+
where: {
|
|
383
|
+
actions: params
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
387
|
+
where: params
|
|
388
|
+
});
|
|
389
|
+
for (const release2 of releases) {
|
|
390
|
+
getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
const deleteActionsOnDelete = async (ctx, next) => {
|
|
394
|
+
if (ctx.action !== "delete") {
|
|
395
|
+
return next();
|
|
396
|
+
}
|
|
397
|
+
if (!contentTypes$1.hasDraftAndPublish(ctx.contentType)) {
|
|
398
|
+
return next();
|
|
399
|
+
}
|
|
400
|
+
const contentType = ctx.contentType.uid;
|
|
401
|
+
const { documentId, locale } = ctx.params;
|
|
402
|
+
const result = await next();
|
|
403
|
+
if (!result) {
|
|
404
|
+
return result;
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
deleteActionsAndUpdateReleaseStatus({
|
|
408
|
+
contentType,
|
|
409
|
+
entryDocumentId: documentId,
|
|
410
|
+
...locale !== "*" && { locale }
|
|
411
|
+
});
|
|
412
|
+
} catch (error) {
|
|
413
|
+
strapi.log.error("Error while deleting release actions after delete", {
|
|
414
|
+
error
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
return result;
|
|
418
|
+
};
|
|
419
|
+
const updateActionsOnUpdate = async (ctx, next) => {
|
|
420
|
+
if (ctx.action !== "update") {
|
|
421
|
+
return next();
|
|
422
|
+
}
|
|
423
|
+
if (!contentTypes$1.hasDraftAndPublish(ctx.contentType)) {
|
|
424
|
+
return next();
|
|
425
|
+
}
|
|
426
|
+
const contentType = ctx.contentType.uid;
|
|
427
|
+
const result = await next();
|
|
428
|
+
if (!result) {
|
|
429
|
+
return result;
|
|
430
|
+
}
|
|
431
|
+
try {
|
|
432
|
+
updateActionsStatusAndUpdateReleaseStatus(contentType, result);
|
|
433
|
+
} catch (error) {
|
|
434
|
+
strapi.log.error("Error while updating release actions after update", {
|
|
435
|
+
error
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
return result;
|
|
439
|
+
};
|
|
440
|
+
const deleteReleasesActionsAndUpdateReleaseStatus = async (params) => {
|
|
441
|
+
const releases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
442
|
+
where: {
|
|
443
|
+
actions: params
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
447
|
+
where: params
|
|
448
|
+
});
|
|
449
|
+
for (const release2 of releases) {
|
|
450
|
+
getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
76
451
|
}
|
|
77
452
|
};
|
|
78
|
-
const { features: features$1 } = require("@strapi/strapi/dist/utils/ee");
|
|
79
453
|
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
80
|
-
if (features
|
|
454
|
+
if (strapi2.ee.features.isEnabled("cms-content-releases")) {
|
|
455
|
+
const contentTypesWithDraftAndPublish = Object.keys(strapi2.contentTypes).filter(
|
|
456
|
+
(uid) => strapi2.contentTypes[uid]?.options?.draftAndPublish
|
|
457
|
+
);
|
|
81
458
|
strapi2.db.lifecycles.subscribe({
|
|
82
|
-
|
|
83
|
-
const { model, result } = event;
|
|
84
|
-
if (model.kind === "collectionType" && model.options.draftAndPublish) {
|
|
85
|
-
const { id } = result;
|
|
86
|
-
strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
87
|
-
where: {
|
|
88
|
-
target_type: model.uid,
|
|
89
|
-
target_id: id
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
},
|
|
459
|
+
models: contentTypesWithDraftAndPublish,
|
|
94
460
|
/**
|
|
95
|
-
* deleteMany
|
|
96
|
-
* so we need to fetch them before deleting the entries to save the ids on our state
|
|
97
|
-
*/
|
|
98
|
-
async beforeDeleteMany(event) {
|
|
99
|
-
const { model, params } = event;
|
|
100
|
-
if (model.kind === "collectionType" && model.options.draftAndPublish) {
|
|
101
|
-
const { where } = params;
|
|
102
|
-
const entriesToDelete = await strapi2.db.query(model.uid).findMany({ select: ["id"], where });
|
|
103
|
-
event.state.entriesToDelete = entriesToDelete;
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
/**
|
|
107
|
-
* We delete the release actions related to deleted entries
|
|
108
|
-
* We make this only after deleteMany is succesfully executed to avoid errors
|
|
461
|
+
* deleteMany is still used outside documents service, for example when deleting a locale
|
|
109
462
|
*/
|
|
110
463
|
async afterDeleteMany(event) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
464
|
+
try {
|
|
465
|
+
const model = strapi2.getModel(event.model.uid);
|
|
466
|
+
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
467
|
+
const { where } = event.params;
|
|
468
|
+
deleteReleasesActionsAndUpdateReleaseStatus({
|
|
469
|
+
contentType: model.uid,
|
|
470
|
+
locale: where?.locale ?? null,
|
|
471
|
+
...where?.documentId && { entryDocumentId: where.documentId }
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
} catch (error) {
|
|
475
|
+
strapi2.log.error("Error while deleting release actions after entry deleteMany", {
|
|
476
|
+
error
|
|
121
477
|
});
|
|
122
478
|
}
|
|
123
479
|
}
|
|
124
480
|
});
|
|
481
|
+
strapi2.documents.use(deleteActionsOnDelete);
|
|
482
|
+
strapi2.documents.use(updateActionsOnUpdate);
|
|
483
|
+
getService("scheduling", { strapi: strapi2 }).syncFromDatabase().catch((err) => {
|
|
484
|
+
strapi2.log.error(
|
|
485
|
+
"Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling."
|
|
486
|
+
);
|
|
487
|
+
throw err;
|
|
488
|
+
});
|
|
489
|
+
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
|
490
|
+
strapi2.get("webhookStore").addAllowedEvent(key, value);
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
const destroy = async ({ strapi: strapi2 }) => {
|
|
495
|
+
const scheduledJobs = getService("scheduling", {
|
|
496
|
+
strapi: strapi2
|
|
497
|
+
}).getAll();
|
|
498
|
+
for (const [, job] of scheduledJobs) {
|
|
499
|
+
job.cancel();
|
|
125
500
|
}
|
|
126
501
|
};
|
|
127
502
|
const schema$1 = {
|
|
@@ -150,6 +525,17 @@ const schema$1 = {
|
|
|
150
525
|
releasedAt: {
|
|
151
526
|
type: "datetime"
|
|
152
527
|
},
|
|
528
|
+
scheduledAt: {
|
|
529
|
+
type: "datetime"
|
|
530
|
+
},
|
|
531
|
+
timezone: {
|
|
532
|
+
type: "string"
|
|
533
|
+
},
|
|
534
|
+
status: {
|
|
535
|
+
type: "enumeration",
|
|
536
|
+
enum: ["ready", "blocked", "failed", "done", "empty"],
|
|
537
|
+
required: true
|
|
538
|
+
},
|
|
153
539
|
actions: {
|
|
154
540
|
type: "relation",
|
|
155
541
|
relation: "oneToMany",
|
|
@@ -185,15 +571,13 @@ const schema = {
|
|
|
185
571
|
enum: ["publish", "unpublish"],
|
|
186
572
|
required: true
|
|
187
573
|
},
|
|
188
|
-
entry: {
|
|
189
|
-
type: "relation",
|
|
190
|
-
relation: "morphToOne",
|
|
191
|
-
configurable: false
|
|
192
|
-
},
|
|
193
574
|
contentType: {
|
|
194
575
|
type: "string",
|
|
195
576
|
required: true
|
|
196
577
|
},
|
|
578
|
+
entryDocumentId: {
|
|
579
|
+
type: "string"
|
|
580
|
+
},
|
|
197
581
|
locale: {
|
|
198
582
|
type: "string"
|
|
199
583
|
},
|
|
@@ -202,6 +586,9 @@ const schema = {
|
|
|
202
586
|
relation: "manyToOne",
|
|
203
587
|
target: RELEASE_MODEL_UID,
|
|
204
588
|
inversedBy: "actions"
|
|
589
|
+
},
|
|
590
|
+
isEntryValid: {
|
|
591
|
+
type: "boolean"
|
|
205
592
|
}
|
|
206
593
|
}
|
|
207
594
|
};
|
|
@@ -212,211 +599,297 @@ const contentTypes = {
|
|
|
212
599
|
release: release$1,
|
|
213
600
|
"release-action": releaseAction$1
|
|
214
601
|
};
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
const getGroupName = (queryValue) => {
|
|
225
|
-
switch (queryValue) {
|
|
226
|
-
case "contentType":
|
|
227
|
-
return "entry.contentType.displayName";
|
|
228
|
-
case "action":
|
|
229
|
-
return "type";
|
|
230
|
-
case "locale":
|
|
231
|
-
return _.getOr("No locale", "entry.locale.name");
|
|
232
|
-
default:
|
|
233
|
-
return "entry.contentType.displayName";
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
const createReleaseService = ({ strapi: strapi2 }) => ({
|
|
237
|
-
async create(releaseData, { user }) {
|
|
238
|
-
const releaseWithCreatorFields = await setCreatorFields({ user })(releaseData);
|
|
239
|
-
await getService("release-validation", { strapi: strapi2 }).validatePendingReleasesLimit();
|
|
240
|
-
return strapi2.entityService.create(RELEASE_MODEL_UID, {
|
|
241
|
-
data: releaseWithCreatorFields
|
|
242
|
-
});
|
|
243
|
-
},
|
|
244
|
-
async findOne(id, query = {}) {
|
|
245
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id, {
|
|
246
|
-
...query
|
|
602
|
+
const createReleaseService = ({ strapi: strapi2 }) => {
|
|
603
|
+
const dispatchWebhook = (event, { isPublished, release: release2, error }) => {
|
|
604
|
+
strapi2.eventHub.emit(event, {
|
|
605
|
+
isPublished,
|
|
606
|
+
error,
|
|
607
|
+
release: release2
|
|
247
608
|
});
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
actions: {
|
|
255
|
-
// @ts-expect-error Ignore missing properties
|
|
256
|
-
count: true
|
|
609
|
+
};
|
|
610
|
+
const getFormattedActions = async (releaseId) => {
|
|
611
|
+
const actions = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findMany({
|
|
612
|
+
where: {
|
|
613
|
+
release: {
|
|
614
|
+
id: releaseId
|
|
257
615
|
}
|
|
258
616
|
}
|
|
259
617
|
});
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
618
|
+
if (actions.length === 0) {
|
|
619
|
+
throw new errors.ValidationError("No entries to publish");
|
|
620
|
+
}
|
|
621
|
+
const formattedActions = {};
|
|
622
|
+
for (const action of actions) {
|
|
623
|
+
const contentTypeUid = action.contentType;
|
|
624
|
+
if (!formattedActions[contentTypeUid]) {
|
|
625
|
+
formattedActions[contentTypeUid] = {
|
|
626
|
+
publish: [],
|
|
627
|
+
unpublish: []
|
|
628
|
+
};
|
|
271
629
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
630
|
+
formattedActions[contentTypeUid][action.type].push({
|
|
631
|
+
documentId: action.entryDocumentId,
|
|
632
|
+
locale: action.locale
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
return formattedActions;
|
|
636
|
+
};
|
|
637
|
+
return {
|
|
638
|
+
async create(releaseData, { user }) {
|
|
639
|
+
const releaseWithCreatorFields = await setCreatorFields({ user })(releaseData);
|
|
640
|
+
const {
|
|
641
|
+
validatePendingReleasesLimit,
|
|
642
|
+
validateUniqueNameForPendingRelease,
|
|
643
|
+
validateScheduledAtIsLaterThanNow
|
|
644
|
+
} = getService("release-validation", { strapi: strapi2 });
|
|
645
|
+
await Promise.all([
|
|
646
|
+
validatePendingReleasesLimit(),
|
|
647
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
|
|
648
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
649
|
+
]);
|
|
650
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).create({
|
|
651
|
+
data: {
|
|
652
|
+
...releaseWithCreatorFields,
|
|
653
|
+
status: "empty"
|
|
294
654
|
}
|
|
655
|
+
});
|
|
656
|
+
if (releaseWithCreatorFields.scheduledAt) {
|
|
657
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
658
|
+
await schedulingService.set(release2.id, release2.scheduledAt);
|
|
295
659
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
660
|
+
strapi2.telemetry.send("didCreateContentRelease");
|
|
661
|
+
return release2;
|
|
662
|
+
},
|
|
663
|
+
async findOne(id, query = {}) {
|
|
664
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query);
|
|
665
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
666
|
+
...dbQuery,
|
|
667
|
+
where: { id }
|
|
668
|
+
});
|
|
669
|
+
return release2;
|
|
670
|
+
},
|
|
671
|
+
findPage(query) {
|
|
672
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
|
|
673
|
+
return strapi2.db.query(RELEASE_MODEL_UID).findPage({
|
|
674
|
+
...dbQuery,
|
|
675
|
+
populate: {
|
|
676
|
+
actions: {
|
|
677
|
+
count: true
|
|
678
|
+
}
|
|
302
679
|
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
680
|
+
});
|
|
681
|
+
},
|
|
682
|
+
findMany(query) {
|
|
683
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_MODEL_UID, query ?? {});
|
|
684
|
+
return strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
685
|
+
...dbQuery
|
|
686
|
+
});
|
|
687
|
+
},
|
|
688
|
+
async update(id, releaseData, { user }) {
|
|
689
|
+
const releaseWithCreatorFields = await setCreatorFields({ user, isEdition: true })(
|
|
690
|
+
releaseData
|
|
691
|
+
);
|
|
692
|
+
const { validateUniqueNameForPendingRelease, validateScheduledAtIsLaterThanNow } = getService(
|
|
693
|
+
"release-validation",
|
|
694
|
+
{ strapi: strapi2 }
|
|
695
|
+
);
|
|
696
|
+
await Promise.all([
|
|
697
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name, id),
|
|
698
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
699
|
+
]);
|
|
700
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id } });
|
|
701
|
+
if (!release2) {
|
|
702
|
+
throw new errors.NotFoundError(`No release found for id ${id}`);
|
|
306
703
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if (release2.actions?.length) {
|
|
310
|
-
const [actionForEntry] = release2.actions;
|
|
311
|
-
delete release2.actions;
|
|
312
|
-
return {
|
|
313
|
-
...release2,
|
|
314
|
-
action: actionForEntry
|
|
315
|
-
};
|
|
704
|
+
if (release2.releasedAt) {
|
|
705
|
+
throw new errors.ValidationError("Release already published");
|
|
316
706
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
},
|
|
339
|
-
async createAction(releaseId, action) {
|
|
340
|
-
const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
|
|
341
|
-
strapi: strapi2
|
|
342
|
-
});
|
|
343
|
-
await Promise.all([
|
|
344
|
-
validateEntryContentType(action.entry.contentType),
|
|
345
|
-
validateUniqueEntry(releaseId, action)
|
|
346
|
-
]);
|
|
347
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
|
|
348
|
-
if (!release2) {
|
|
349
|
-
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
350
|
-
}
|
|
351
|
-
if (release2.releasedAt) {
|
|
352
|
-
throw new errors.ValidationError("Release already published");
|
|
353
|
-
}
|
|
354
|
-
const { entry, type } = action;
|
|
355
|
-
return strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
|
|
356
|
-
data: {
|
|
357
|
-
type,
|
|
358
|
-
contentType: entry.contentType,
|
|
359
|
-
locale: entry.locale,
|
|
360
|
-
entry: {
|
|
361
|
-
id: entry.id,
|
|
362
|
-
__type: entry.contentType,
|
|
363
|
-
__pivot: { field: "entry" }
|
|
707
|
+
const updatedRelease = await strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
708
|
+
where: { id },
|
|
709
|
+
data: releaseWithCreatorFields
|
|
710
|
+
});
|
|
711
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
712
|
+
if (releaseData.scheduledAt) {
|
|
713
|
+
await schedulingService.set(id, releaseData.scheduledAt);
|
|
714
|
+
} else if (release2.scheduledAt) {
|
|
715
|
+
schedulingService.cancel(id);
|
|
716
|
+
}
|
|
717
|
+
this.updateReleaseStatus(id);
|
|
718
|
+
strapi2.telemetry.send("didUpdateContentRelease");
|
|
719
|
+
return updatedRelease;
|
|
720
|
+
},
|
|
721
|
+
async getAllComponents() {
|
|
722
|
+
const contentManagerComponentsService = strapi2.plugin("content-manager").service("components");
|
|
723
|
+
const components = await contentManagerComponentsService.findAllComponents();
|
|
724
|
+
const componentsMap = components.reduce(
|
|
725
|
+
(acc, component) => {
|
|
726
|
+
acc[component.uid] = component;
|
|
727
|
+
return acc;
|
|
364
728
|
},
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
entry: true
|
|
381
|
-
},
|
|
382
|
-
filters: {
|
|
383
|
-
release: releaseId
|
|
729
|
+
{}
|
|
730
|
+
);
|
|
731
|
+
return componentsMap;
|
|
732
|
+
},
|
|
733
|
+
async delete(releaseId) {
|
|
734
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
735
|
+
where: { id: releaseId },
|
|
736
|
+
populate: {
|
|
737
|
+
actions: {
|
|
738
|
+
select: ["id"]
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
if (!release2) {
|
|
743
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
384
744
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
async countActions(query) {
|
|
388
|
-
return strapi2.entityService.count(RELEASE_ACTION_MODEL_UID, query);
|
|
389
|
-
},
|
|
390
|
-
async groupActions(actions, groupBy) {
|
|
391
|
-
const contentTypeUids = actions.reduce((acc, action) => {
|
|
392
|
-
if (!acc.includes(action.contentType)) {
|
|
393
|
-
acc.push(action.contentType);
|
|
745
|
+
if (release2.releasedAt) {
|
|
746
|
+
throw new errors.ValidationError("Release already published");
|
|
394
747
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
748
|
+
await strapi2.db.transaction(async () => {
|
|
749
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
750
|
+
where: {
|
|
751
|
+
id: {
|
|
752
|
+
$in: release2.actions.map((action) => action.id)
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
await strapi2.db.query(RELEASE_MODEL_UID).delete({
|
|
757
|
+
where: {
|
|
758
|
+
id: releaseId
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
});
|
|
762
|
+
if (release2.scheduledAt) {
|
|
763
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
764
|
+
await schedulingService.cancel(release2.id);
|
|
765
|
+
}
|
|
766
|
+
strapi2.telemetry.send("didDeleteContentRelease");
|
|
767
|
+
return release2;
|
|
768
|
+
},
|
|
769
|
+
async publish(releaseId) {
|
|
770
|
+
const {
|
|
771
|
+
release: release2,
|
|
772
|
+
error
|
|
773
|
+
} = await strapi2.db.transaction(async ({ trx }) => {
|
|
774
|
+
const lockedRelease = await strapi2.db?.queryBuilder(RELEASE_MODEL_UID).where({ id: releaseId }).select(["id", "name", "releasedAt", "status"]).first().transacting(trx).forUpdate().execute();
|
|
775
|
+
if (!lockedRelease) {
|
|
776
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
777
|
+
}
|
|
778
|
+
if (lockedRelease.releasedAt) {
|
|
779
|
+
throw new errors.ValidationError("Release already published");
|
|
780
|
+
}
|
|
781
|
+
if (lockedRelease.status === "failed") {
|
|
782
|
+
throw new errors.ValidationError("Release failed to publish");
|
|
783
|
+
}
|
|
784
|
+
try {
|
|
785
|
+
strapi2.log.info(`[Content Releases] Starting to publish release ${lockedRelease.name}`);
|
|
786
|
+
const formattedActions = await getFormattedActions(releaseId);
|
|
787
|
+
await strapi2.db.transaction(
|
|
788
|
+
async () => Promise.all(
|
|
789
|
+
Object.keys(formattedActions).map(async (contentTypeUid) => {
|
|
790
|
+
const contentType = contentTypeUid;
|
|
791
|
+
const { publish, unpublish } = formattedActions[contentType];
|
|
792
|
+
return Promise.all([
|
|
793
|
+
...publish.map((params) => strapi2.documents(contentType).publish(params)),
|
|
794
|
+
...unpublish.map((params) => strapi2.documents(contentType).unpublish(params))
|
|
795
|
+
]);
|
|
796
|
+
})
|
|
797
|
+
)
|
|
798
|
+
);
|
|
799
|
+
const release22 = await strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
800
|
+
where: {
|
|
801
|
+
id: releaseId
|
|
802
|
+
},
|
|
803
|
+
data: {
|
|
804
|
+
status: "done",
|
|
805
|
+
releasedAt: /* @__PURE__ */ new Date()
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
809
|
+
isPublished: true,
|
|
810
|
+
release: release22
|
|
811
|
+
});
|
|
812
|
+
strapi2.telemetry.send("didPublishContentRelease");
|
|
813
|
+
return { release: release22, error: null };
|
|
814
|
+
} catch (error2) {
|
|
815
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
816
|
+
isPublished: false,
|
|
817
|
+
error: error2
|
|
818
|
+
});
|
|
819
|
+
await strapi2.db?.queryBuilder(RELEASE_MODEL_UID).where({ id: releaseId }).update({
|
|
820
|
+
status: "failed"
|
|
821
|
+
}).transacting(trx).execute();
|
|
822
|
+
return {
|
|
823
|
+
release: null,
|
|
824
|
+
error: error2
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
if (error instanceof Error) {
|
|
829
|
+
throw error;
|
|
830
|
+
}
|
|
831
|
+
return release2;
|
|
832
|
+
},
|
|
833
|
+
async updateReleaseStatus(releaseId) {
|
|
834
|
+
const releaseActionService = getService("release-action", { strapi: strapi2 });
|
|
835
|
+
const [totalActions, invalidActions] = await Promise.all([
|
|
836
|
+
releaseActionService.countActions({
|
|
837
|
+
filters: {
|
|
838
|
+
release: releaseId
|
|
839
|
+
}
|
|
840
|
+
}),
|
|
841
|
+
releaseActionService.countActions({
|
|
842
|
+
filters: {
|
|
843
|
+
release: releaseId,
|
|
844
|
+
isEntryValid: false
|
|
845
|
+
}
|
|
846
|
+
})
|
|
847
|
+
]);
|
|
848
|
+
if (totalActions > 0) {
|
|
849
|
+
if (invalidActions > 0) {
|
|
850
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
851
|
+
where: {
|
|
852
|
+
id: releaseId
|
|
853
|
+
},
|
|
854
|
+
data: {
|
|
855
|
+
status: "blocked"
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
860
|
+
where: {
|
|
861
|
+
id: releaseId
|
|
410
862
|
},
|
|
411
|
-
|
|
412
|
-
|
|
863
|
+
data: {
|
|
864
|
+
status: "ready"
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
869
|
+
where: {
|
|
870
|
+
id: releaseId
|
|
871
|
+
},
|
|
872
|
+
data: {
|
|
873
|
+
status: "empty"
|
|
413
874
|
}
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
};
|
|
879
|
+
const getGroupName = (queryValue) => {
|
|
880
|
+
switch (queryValue) {
|
|
881
|
+
case "contentType":
|
|
882
|
+
return "contentType.displayName";
|
|
883
|
+
case "type":
|
|
884
|
+
return "type";
|
|
885
|
+
case "locale":
|
|
886
|
+
return _.getOr("No locale", "locale.name");
|
|
887
|
+
default:
|
|
888
|
+
return "contentType.displayName";
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
const createReleaseActionService = ({ strapi: strapi2 }) => {
|
|
892
|
+
const getLocalesDataForActions = async () => {
|
|
420
893
|
if (!strapi2.plugin("i18n")) {
|
|
421
894
|
return {};
|
|
422
895
|
}
|
|
@@ -425,8 +898,8 @@ const createReleaseService = ({ strapi: strapi2 }) => ({
|
|
|
425
898
|
acc[locale.code] = { name: locale.name, code: locale.code };
|
|
426
899
|
return acc;
|
|
427
900
|
}, {});
|
|
428
|
-
}
|
|
429
|
-
async
|
|
901
|
+
};
|
|
902
|
+
const getContentTypesDataForActions = async (contentTypesUids) => {
|
|
430
903
|
const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
|
|
431
904
|
const contentTypesData = {};
|
|
432
905
|
for (const contentTypeUid of contentTypesUids) {
|
|
@@ -439,167 +912,249 @@ const createReleaseService = ({ strapi: strapi2 }) => ({
|
|
|
439
912
|
};
|
|
440
913
|
}
|
|
441
914
|
return contentTypesData;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
915
|
+
};
|
|
916
|
+
return {
|
|
917
|
+
async create(releaseId, action, { disableUpdateReleaseStatus = false } = {}) {
|
|
918
|
+
const { validateEntryData, validateUniqueEntry } = getService("release-validation", {
|
|
919
|
+
strapi: strapi2
|
|
920
|
+
});
|
|
921
|
+
await Promise.all([
|
|
922
|
+
validateEntryData(action.contentType, action.entryDocumentId),
|
|
923
|
+
validateUniqueEntry(releaseId, action)
|
|
924
|
+
]);
|
|
925
|
+
const model = strapi2.contentType(action.contentType);
|
|
926
|
+
if (model.kind === "singleType") {
|
|
927
|
+
const document = await strapi2.db.query(model.uid).findOne({ select: ["documentId"] });
|
|
928
|
+
if (!document) {
|
|
929
|
+
throw new errors.NotFoundError(`No entry found for contentType ${action.contentType}`);
|
|
448
930
|
}
|
|
931
|
+
action.entryDocumentId = document.documentId;
|
|
449
932
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
933
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id: releaseId } });
|
|
934
|
+
if (!release2) {
|
|
935
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
936
|
+
}
|
|
937
|
+
if (release2.releasedAt) {
|
|
938
|
+
throw new errors.ValidationError("Release already published");
|
|
939
|
+
}
|
|
940
|
+
const actionStatus = action.type === "publish" ? await getDraftEntryValidStatus(
|
|
941
|
+
{
|
|
942
|
+
contentType: action.contentType,
|
|
943
|
+
documentId: action.entryDocumentId,
|
|
944
|
+
locale: action.locale
|
|
945
|
+
},
|
|
946
|
+
{
|
|
947
|
+
strapi: strapi2
|
|
948
|
+
}
|
|
949
|
+
) : true;
|
|
950
|
+
const releaseAction2 = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).create({
|
|
951
|
+
data: {
|
|
952
|
+
...action,
|
|
953
|
+
release: release2.id,
|
|
954
|
+
isEntryValid: actionStatus
|
|
955
|
+
},
|
|
956
|
+
populate: { release: { select: ["id"] } }
|
|
957
|
+
});
|
|
958
|
+
if (!disableUpdateReleaseStatus) {
|
|
959
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
|
|
960
|
+
}
|
|
961
|
+
return releaseAction2;
|
|
962
|
+
},
|
|
963
|
+
async findPage(releaseId, query) {
|
|
964
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
965
|
+
where: { id: releaseId },
|
|
966
|
+
select: ["id"]
|
|
967
|
+
});
|
|
968
|
+
if (!release2) {
|
|
969
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
970
|
+
}
|
|
971
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
|
|
972
|
+
const { results: actions, pagination } = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findPage({
|
|
973
|
+
...dbQuery,
|
|
459
974
|
where: {
|
|
460
|
-
|
|
461
|
-
$in: release2.actions.map((action) => action.id)
|
|
462
|
-
}
|
|
975
|
+
release: releaseId
|
|
463
976
|
}
|
|
464
977
|
});
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
978
|
+
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
979
|
+
const actionsWithEntry = await async.map(actions, async (action) => {
|
|
980
|
+
const populate = await populateBuilderService(action.contentType).populateDeep(Infinity).build();
|
|
981
|
+
const entry = await getEntry(
|
|
982
|
+
{
|
|
983
|
+
contentType: action.contentType,
|
|
984
|
+
documentId: action.entryDocumentId,
|
|
985
|
+
locale: action.locale,
|
|
986
|
+
populate,
|
|
987
|
+
status: action.type === "publish" ? "draft" : "published"
|
|
988
|
+
},
|
|
989
|
+
{ strapi: strapi2 }
|
|
990
|
+
);
|
|
991
|
+
return {
|
|
992
|
+
...action,
|
|
993
|
+
entry,
|
|
994
|
+
status: entry ? await getEntryStatus(action.contentType, entry) : null
|
|
995
|
+
};
|
|
996
|
+
});
|
|
997
|
+
return {
|
|
998
|
+
results: actionsWithEntry,
|
|
999
|
+
pagination
|
|
1000
|
+
};
|
|
1001
|
+
},
|
|
1002
|
+
async groupActions(actions, groupBy) {
|
|
1003
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
1004
|
+
if (!acc.includes(action.contentType)) {
|
|
1005
|
+
acc.push(action.contentType);
|
|
480
1006
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
if (!actions[contentTypeUid]) {
|
|
496
|
-
actions[contentTypeUid] = {
|
|
497
|
-
publish: [],
|
|
498
|
-
unpublish: []
|
|
1007
|
+
return acc;
|
|
1008
|
+
}, []);
|
|
1009
|
+
const allReleaseContentTypesDictionary = await getContentTypesDataForActions(contentTypeUids);
|
|
1010
|
+
const allLocalesDictionary = await getLocalesDataForActions();
|
|
1011
|
+
const formattedData = actions.map((action) => {
|
|
1012
|
+
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
1013
|
+
return {
|
|
1014
|
+
...action,
|
|
1015
|
+
locale: action.locale ? allLocalesDictionary[action.locale] : null,
|
|
1016
|
+
contentType: {
|
|
1017
|
+
displayName,
|
|
1018
|
+
mainFieldValue: action.entry[mainField],
|
|
1019
|
+
uid: action.contentType
|
|
1020
|
+
}
|
|
499
1021
|
};
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
await strapi2.db.transaction(async () => {
|
|
509
|
-
for (const contentTypeUid of Object.keys(actions)) {
|
|
510
|
-
const { publish, unpublish } = actions[contentTypeUid];
|
|
511
|
-
if (publish.length > 0) {
|
|
512
|
-
await entityManagerService.publishMany(publish, contentTypeUid);
|
|
1022
|
+
});
|
|
1023
|
+
const groupName = getGroupName(groupBy);
|
|
1024
|
+
return _.groupBy(groupName)(formattedData);
|
|
1025
|
+
},
|
|
1026
|
+
getContentTypeModelsFromActions(actions) {
|
|
1027
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
1028
|
+
if (!acc.includes(action.contentType)) {
|
|
1029
|
+
acc.push(action.contentType);
|
|
513
1030
|
}
|
|
514
|
-
|
|
515
|
-
|
|
1031
|
+
return acc;
|
|
1032
|
+
}, []);
|
|
1033
|
+
const contentTypeModelsMap = contentTypeUids.reduce(
|
|
1034
|
+
(acc, contentTypeUid) => {
|
|
1035
|
+
acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
|
|
1036
|
+
return acc;
|
|
1037
|
+
},
|
|
1038
|
+
{}
|
|
1039
|
+
);
|
|
1040
|
+
return contentTypeModelsMap;
|
|
1041
|
+
},
|
|
1042
|
+
async countActions(query) {
|
|
1043
|
+
const dbQuery = strapi2.get("query-params").transform(RELEASE_ACTION_MODEL_UID, query ?? {});
|
|
1044
|
+
return strapi2.db.query(RELEASE_ACTION_MODEL_UID).count(dbQuery);
|
|
1045
|
+
},
|
|
1046
|
+
async update(actionId, releaseId, update) {
|
|
1047
|
+
const action = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).findOne({
|
|
1048
|
+
where: {
|
|
1049
|
+
id: actionId,
|
|
1050
|
+
release: {
|
|
1051
|
+
id: releaseId,
|
|
1052
|
+
releasedAt: {
|
|
1053
|
+
$null: true
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
516
1056
|
}
|
|
1057
|
+
});
|
|
1058
|
+
if (!action) {
|
|
1059
|
+
throw new errors.NotFoundError(
|
|
1060
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
1061
|
+
);
|
|
517
1062
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
releasedAt: {
|
|
537
|
-
$null: true
|
|
1063
|
+
const actionStatus = update.type === "publish" ? await getDraftEntryValidStatus(
|
|
1064
|
+
{
|
|
1065
|
+
contentType: action.contentType,
|
|
1066
|
+
documentId: action.entryDocumentId,
|
|
1067
|
+
locale: action.locale
|
|
1068
|
+
},
|
|
1069
|
+
{
|
|
1070
|
+
strapi: strapi2
|
|
1071
|
+
}
|
|
1072
|
+
) : true;
|
|
1073
|
+
const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
1074
|
+
where: {
|
|
1075
|
+
id: actionId,
|
|
1076
|
+
release: {
|
|
1077
|
+
id: releaseId,
|
|
1078
|
+
releasedAt: {
|
|
1079
|
+
$null: true
|
|
1080
|
+
}
|
|
538
1081
|
}
|
|
1082
|
+
},
|
|
1083
|
+
data: {
|
|
1084
|
+
...update,
|
|
1085
|
+
isEntryValid: actionStatus
|
|
539
1086
|
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
id: actionId,
|
|
554
|
-
release: {
|
|
555
|
-
id: releaseId,
|
|
556
|
-
releasedAt: {
|
|
557
|
-
$null: true
|
|
1087
|
+
});
|
|
1088
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
|
|
1089
|
+
return updatedAction;
|
|
1090
|
+
},
|
|
1091
|
+
async delete(actionId, releaseId) {
|
|
1092
|
+
const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
|
|
1093
|
+
where: {
|
|
1094
|
+
id: actionId,
|
|
1095
|
+
release: {
|
|
1096
|
+
id: releaseId,
|
|
1097
|
+
releasedAt: {
|
|
1098
|
+
$null: true
|
|
1099
|
+
}
|
|
558
1100
|
}
|
|
559
1101
|
}
|
|
1102
|
+
});
|
|
1103
|
+
if (!deletedAction) {
|
|
1104
|
+
throw new errors.NotFoundError(
|
|
1105
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
1106
|
+
);
|
|
560
1107
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
throw new errors.NotFoundError(
|
|
564
|
-
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
565
|
-
);
|
|
1108
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(releaseId);
|
|
1109
|
+
return deletedAction;
|
|
566
1110
|
}
|
|
567
|
-
|
|
1111
|
+
};
|
|
1112
|
+
};
|
|
1113
|
+
class AlreadyOnReleaseError extends errors.ApplicationError {
|
|
1114
|
+
constructor(message) {
|
|
1115
|
+
super(message);
|
|
1116
|
+
this.name = "AlreadyOnReleaseError";
|
|
568
1117
|
}
|
|
569
|
-
}
|
|
1118
|
+
}
|
|
570
1119
|
const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
571
1120
|
async validateUniqueEntry(releaseId, releaseActionArgs) {
|
|
572
|
-
const release2 = await strapi2.
|
|
573
|
-
|
|
1121
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({
|
|
1122
|
+
where: {
|
|
1123
|
+
id: releaseId
|
|
1124
|
+
},
|
|
1125
|
+
populate: {
|
|
1126
|
+
actions: true
|
|
1127
|
+
}
|
|
574
1128
|
});
|
|
575
1129
|
if (!release2) {
|
|
576
1130
|
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
577
1131
|
}
|
|
578
1132
|
const isEntryInRelease = release2.actions.some(
|
|
579
|
-
(action) =>
|
|
1133
|
+
(action) => action.entryDocumentId === releaseActionArgs.entryDocumentId && action.contentType === releaseActionArgs.contentType && (releaseActionArgs.locale ? action.locale === releaseActionArgs.locale : true)
|
|
580
1134
|
);
|
|
581
1135
|
if (isEntryInRelease) {
|
|
582
|
-
throw new
|
|
583
|
-
`Entry with
|
|
1136
|
+
throw new AlreadyOnReleaseError(
|
|
1137
|
+
`Entry with documentId ${releaseActionArgs.entryDocumentId}${releaseActionArgs.locale ? `( ${releaseActionArgs.locale})` : ""} and contentType ${releaseActionArgs.contentType} already exists in release with id ${releaseId}`
|
|
584
1138
|
);
|
|
585
1139
|
}
|
|
586
1140
|
},
|
|
587
|
-
|
|
1141
|
+
validateEntryData(contentTypeUid, entryDocumentId) {
|
|
588
1142
|
const contentType = strapi2.contentType(contentTypeUid);
|
|
589
1143
|
if (!contentType) {
|
|
590
1144
|
throw new errors.NotFoundError(`No content type found for uid ${contentTypeUid}`);
|
|
591
1145
|
}
|
|
592
|
-
if (!contentType
|
|
1146
|
+
if (!contentTypes$1.hasDraftAndPublish(contentType)) {
|
|
593
1147
|
throw new errors.ValidationError(
|
|
594
1148
|
`Content type with uid ${contentTypeUid} does not have draftAndPublish enabled`
|
|
595
1149
|
);
|
|
596
1150
|
}
|
|
1151
|
+
if (contentType.kind === "collectionType" && !entryDocumentId) {
|
|
1152
|
+
throw new errors.ValidationError("Document id is required for collection type");
|
|
1153
|
+
}
|
|
597
1154
|
},
|
|
598
1155
|
async validatePendingReleasesLimit() {
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
EE.features.get("cms-content-releases")?.options?.maximumReleases || 3
|
|
602
|
-
);
|
|
1156
|
+
const featureCfg = strapi2.ee.features.get("cms-content-releases");
|
|
1157
|
+
const maximumPendingReleases = typeof featureCfg === "object" && featureCfg?.options?.maximumReleases || 3;
|
|
603
1158
|
const [, pendingReleasesCount] = await strapi2.db.query(RELEASE_MODEL_UID).findWithCount({
|
|
604
1159
|
filters: {
|
|
605
1160
|
releasedAt: {
|
|
@@ -610,23 +1165,98 @@ const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
|
610
1165
|
if (pendingReleasesCount >= maximumPendingReleases) {
|
|
611
1166
|
throw new errors.ValidationError("You have reached the maximum number of pending releases");
|
|
612
1167
|
}
|
|
1168
|
+
},
|
|
1169
|
+
async validateUniqueNameForPendingRelease(name, id) {
|
|
1170
|
+
const pendingReleases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
1171
|
+
where: {
|
|
1172
|
+
releasedAt: {
|
|
1173
|
+
$null: true
|
|
1174
|
+
},
|
|
1175
|
+
name,
|
|
1176
|
+
...id && { id: { $ne: id } }
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
const isNameUnique = pendingReleases.length === 0;
|
|
1180
|
+
if (!isNameUnique) {
|
|
1181
|
+
throw new errors.ValidationError(`Release with name ${name} already exists`);
|
|
1182
|
+
}
|
|
1183
|
+
},
|
|
1184
|
+
async validateScheduledAtIsLaterThanNow(scheduledAt) {
|
|
1185
|
+
if (scheduledAt && new Date(scheduledAt) <= /* @__PURE__ */ new Date()) {
|
|
1186
|
+
throw new errors.ValidationError("Scheduled at must be later than now");
|
|
1187
|
+
}
|
|
613
1188
|
}
|
|
614
1189
|
});
|
|
615
|
-
const
|
|
616
|
-
const
|
|
617
|
-
destroyListenerCallbacks: []
|
|
618
|
-
};
|
|
1190
|
+
const createSchedulingService = ({ strapi: strapi2 }) => {
|
|
1191
|
+
const scheduledJobs = /* @__PURE__ */ new Map();
|
|
619
1192
|
return {
|
|
620
|
-
|
|
621
|
-
|
|
1193
|
+
async set(releaseId, scheduleDate) {
|
|
1194
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id: releaseId, releasedAt: null } });
|
|
1195
|
+
if (!release2) {
|
|
1196
|
+
throw new errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
1197
|
+
}
|
|
1198
|
+
const job = scheduleJob(scheduleDate, async () => {
|
|
1199
|
+
try {
|
|
1200
|
+
await getService("release", { strapi: strapi2 }).publish(releaseId);
|
|
1201
|
+
} catch (error) {
|
|
1202
|
+
}
|
|
1203
|
+
this.cancel(releaseId);
|
|
1204
|
+
});
|
|
1205
|
+
if (scheduledJobs.has(releaseId)) {
|
|
1206
|
+
this.cancel(releaseId);
|
|
1207
|
+
}
|
|
1208
|
+
scheduledJobs.set(releaseId, job);
|
|
1209
|
+
return scheduledJobs;
|
|
622
1210
|
},
|
|
623
|
-
|
|
624
|
-
if (
|
|
625
|
-
|
|
1211
|
+
cancel(releaseId) {
|
|
1212
|
+
if (scheduledJobs.has(releaseId)) {
|
|
1213
|
+
scheduledJobs.get(releaseId).cancel();
|
|
1214
|
+
scheduledJobs.delete(releaseId);
|
|
626
1215
|
}
|
|
627
|
-
|
|
628
|
-
|
|
1216
|
+
return scheduledJobs;
|
|
1217
|
+
},
|
|
1218
|
+
getAll() {
|
|
1219
|
+
return scheduledJobs;
|
|
1220
|
+
},
|
|
1221
|
+
/**
|
|
1222
|
+
* On bootstrap, we can use this function to make sure to sync the scheduled jobs from the database that are not yet released
|
|
1223
|
+
* This is useful in case the server was restarted and the scheduled jobs were lost
|
|
1224
|
+
* This also could be used to sync different Strapi instances in case of a cluster
|
|
1225
|
+
*/
|
|
1226
|
+
async syncFromDatabase() {
|
|
1227
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
1228
|
+
where: {
|
|
1229
|
+
scheduledAt: {
|
|
1230
|
+
$gte: /* @__PURE__ */ new Date()
|
|
1231
|
+
},
|
|
1232
|
+
releasedAt: null
|
|
1233
|
+
}
|
|
629
1234
|
});
|
|
1235
|
+
for (const release2 of releases) {
|
|
1236
|
+
this.set(release2.id, release2.scheduledAt);
|
|
1237
|
+
}
|
|
1238
|
+
return scheduledJobs;
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
};
|
|
1242
|
+
const DEFAULT_SETTINGS = {
|
|
1243
|
+
defaultTimezone: null
|
|
1244
|
+
};
|
|
1245
|
+
const createSettingsService = ({ strapi: strapi2 }) => {
|
|
1246
|
+
const getStore = async () => strapi2.store({ type: "core", name: "content-releases" });
|
|
1247
|
+
return {
|
|
1248
|
+
async update({ settings: settings2 }) {
|
|
1249
|
+
const store = await getStore();
|
|
1250
|
+
store.set({ key: "settings", value: settings2 });
|
|
1251
|
+
return settings2;
|
|
1252
|
+
},
|
|
1253
|
+
async find() {
|
|
1254
|
+
const store = await getStore();
|
|
1255
|
+
const settings2 = await store.get({ key: "settings" });
|
|
1256
|
+
return {
|
|
1257
|
+
...DEFAULT_SETTINGS,
|
|
1258
|
+
...settings2 || {}
|
|
1259
|
+
};
|
|
630
1260
|
}
|
|
631
1261
|
};
|
|
632
1262
|
};
|
|
@@ -634,64 +1264,148 @@ const services = {
|
|
|
634
1264
|
release: createReleaseService,
|
|
635
1265
|
"release-action": createReleaseActionService,
|
|
636
1266
|
"release-validation": createReleaseValidationService,
|
|
637
|
-
|
|
1267
|
+
scheduling: createSchedulingService,
|
|
1268
|
+
settings: createSettingsService
|
|
638
1269
|
};
|
|
639
|
-
const RELEASE_SCHEMA = yup.object().shape({
|
|
640
|
-
name: yup.string().trim().required()
|
|
1270
|
+
const RELEASE_SCHEMA = yup$1.object().shape({
|
|
1271
|
+
name: yup$1.string().trim().required(),
|
|
1272
|
+
scheduledAt: yup$1.string().nullable(),
|
|
1273
|
+
timezone: yup$1.string().when("scheduledAt", {
|
|
1274
|
+
is: (value) => value !== null && value !== void 0,
|
|
1275
|
+
then: yup$1.string().required(),
|
|
1276
|
+
otherwise: yup$1.string().nullable()
|
|
1277
|
+
})
|
|
1278
|
+
}).required().noUnknown();
|
|
1279
|
+
const FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA = yup$1.object().shape({
|
|
1280
|
+
contentType: yup$1.string().required(),
|
|
1281
|
+
entryDocumentId: yup$1.string().nullable(),
|
|
1282
|
+
hasEntryAttached: yup$1.string().nullable(),
|
|
1283
|
+
locale: yup$1.string().nullable()
|
|
641
1284
|
}).required().noUnknown();
|
|
642
1285
|
const validateRelease = validateYupSchema(RELEASE_SCHEMA);
|
|
1286
|
+
const validatefindByDocumentAttachedParams = validateYupSchema(
|
|
1287
|
+
FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA
|
|
1288
|
+
);
|
|
643
1289
|
const releaseController = {
|
|
644
|
-
|
|
645
|
-
|
|
1290
|
+
/**
|
|
1291
|
+
* Find releases based on documents attached or not to the release.
|
|
1292
|
+
* If `hasEntryAttached` is true, it will return all releases that have the entry attached.
|
|
1293
|
+
* If `hasEntryAttached` is false, it will return all releases that don't have the entry attached.
|
|
1294
|
+
*/
|
|
1295
|
+
async findByDocumentAttached(ctx) {
|
|
1296
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
646
1297
|
ability: ctx.state.userAbility,
|
|
647
1298
|
model: RELEASE_MODEL_UID
|
|
648
1299
|
});
|
|
649
1300
|
await permissionsManager.validateQuery(ctx.query);
|
|
650
1301
|
const releaseService = getService("release", { strapi });
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
1302
|
+
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
1303
|
+
await validatefindByDocumentAttachedParams(query);
|
|
1304
|
+
const model = strapi.getModel(query.contentType);
|
|
1305
|
+
if (model.kind && model.kind === "singleType") {
|
|
1306
|
+
const document = await strapi.db.query(model.uid).findOne({ select: ["documentId"] });
|
|
1307
|
+
if (!document) {
|
|
1308
|
+
throw new errors.NotFoundError(`No entry found for contentType ${query.contentType}`);
|
|
1309
|
+
}
|
|
1310
|
+
query.entryDocumentId = document.documentId;
|
|
1311
|
+
}
|
|
1312
|
+
const { contentType, hasEntryAttached, entryDocumentId, locale } = query;
|
|
1313
|
+
const isEntryAttached = typeof hasEntryAttached === "string" ? Boolean(JSON.parse(hasEntryAttached)) : false;
|
|
1314
|
+
if (isEntryAttached) {
|
|
1315
|
+
const releases = await releaseService.findMany({
|
|
1316
|
+
where: {
|
|
1317
|
+
releasedAt: null,
|
|
1318
|
+
actions: {
|
|
1319
|
+
contentType,
|
|
1320
|
+
entryDocumentId: entryDocumentId ?? null,
|
|
1321
|
+
locale: locale ?? null
|
|
1322
|
+
}
|
|
1323
|
+
},
|
|
1324
|
+
populate: {
|
|
1325
|
+
actions: {
|
|
1326
|
+
fields: ["type"],
|
|
1327
|
+
filters: {
|
|
1328
|
+
contentType,
|
|
1329
|
+
entryDocumentId: entryDocumentId ?? null,
|
|
1330
|
+
locale: locale ?? null
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
659
1334
|
});
|
|
660
|
-
ctx.body = { data };
|
|
1335
|
+
ctx.body = { data: releases };
|
|
661
1336
|
} else {
|
|
662
|
-
const
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
const { actions, ...releaseData } = release2;
|
|
666
|
-
return {
|
|
667
|
-
...releaseData,
|
|
1337
|
+
const relatedReleases = await releaseService.findMany({
|
|
1338
|
+
where: {
|
|
1339
|
+
releasedAt: null,
|
|
668
1340
|
actions: {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
1341
|
+
contentType,
|
|
1342
|
+
entryDocumentId: entryDocumentId ?? null,
|
|
1343
|
+
locale: locale ?? null
|
|
672
1344
|
}
|
|
673
|
-
}
|
|
1345
|
+
}
|
|
1346
|
+
});
|
|
1347
|
+
const releases = await releaseService.findMany({
|
|
1348
|
+
where: {
|
|
1349
|
+
$or: [
|
|
1350
|
+
{
|
|
1351
|
+
id: {
|
|
1352
|
+
$notIn: relatedReleases.map((release2) => release2.id)
|
|
1353
|
+
}
|
|
1354
|
+
},
|
|
1355
|
+
{
|
|
1356
|
+
actions: null
|
|
1357
|
+
}
|
|
1358
|
+
],
|
|
1359
|
+
releasedAt: null
|
|
1360
|
+
}
|
|
674
1361
|
});
|
|
675
|
-
ctx.body = { data
|
|
1362
|
+
ctx.body = { data: releases };
|
|
676
1363
|
}
|
|
677
1364
|
},
|
|
678
|
-
async
|
|
679
|
-
const
|
|
680
|
-
const releaseService = getService("release", { strapi });
|
|
681
|
-
const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
|
|
682
|
-
const permissionsManager = strapi.admin.services.permission.createPermissionsManager({
|
|
1365
|
+
async findPage(ctx) {
|
|
1366
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
683
1367
|
ability: ctx.state.userAbility,
|
|
684
1368
|
model: RELEASE_MODEL_UID
|
|
685
1369
|
});
|
|
686
|
-
|
|
687
|
-
const
|
|
688
|
-
|
|
689
|
-
|
|
1370
|
+
await permissionsManager.validateQuery(ctx.query);
|
|
1371
|
+
const releaseService = getService("release", { strapi });
|
|
1372
|
+
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
1373
|
+
const { results, pagination } = await releaseService.findPage(query);
|
|
1374
|
+
const data = results.map((release2) => {
|
|
1375
|
+
const { actions, ...releaseData } = release2;
|
|
1376
|
+
return {
|
|
1377
|
+
...releaseData,
|
|
1378
|
+
actions: {
|
|
1379
|
+
meta: {
|
|
1380
|
+
count: actions.count
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
});
|
|
1385
|
+
const pendingReleasesCount = await strapi.db.query(RELEASE_MODEL_UID).count({
|
|
1386
|
+
where: {
|
|
1387
|
+
releasedAt: null
|
|
690
1388
|
}
|
|
691
1389
|
});
|
|
1390
|
+
ctx.body = { data, meta: { pagination, pendingReleasesCount } };
|
|
1391
|
+
},
|
|
1392
|
+
async findOne(ctx) {
|
|
1393
|
+
const id = ctx.params.id;
|
|
1394
|
+
const releaseService = getService("release", { strapi });
|
|
1395
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1396
|
+
const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
|
|
692
1397
|
if (!release2) {
|
|
693
1398
|
throw new errors.NotFoundError(`Release not found for id: ${id}`);
|
|
694
1399
|
}
|
|
1400
|
+
const count = await releaseActionService.countActions({
|
|
1401
|
+
filters: {
|
|
1402
|
+
release: id
|
|
1403
|
+
}
|
|
1404
|
+
});
|
|
1405
|
+
const sanitizedRelease = {
|
|
1406
|
+
...release2,
|
|
1407
|
+
createdBy: release2.createdBy ? strapi.service("admin::user").sanitizeUser(release2.createdBy) : null
|
|
1408
|
+
};
|
|
695
1409
|
const data = {
|
|
696
1410
|
...sanitizedRelease,
|
|
697
1411
|
actions: {
|
|
@@ -702,19 +1416,63 @@ const releaseController = {
|
|
|
702
1416
|
};
|
|
703
1417
|
ctx.body = { data };
|
|
704
1418
|
},
|
|
1419
|
+
async mapEntriesToReleases(ctx) {
|
|
1420
|
+
const { contentTypeUid, documentIds, locale } = ctx.query;
|
|
1421
|
+
if (!contentTypeUid || !documentIds) {
|
|
1422
|
+
throw new errors.ValidationError("Missing required query parameters");
|
|
1423
|
+
}
|
|
1424
|
+
const releaseService = getService("release", { strapi });
|
|
1425
|
+
const releasesWithActions = await releaseService.findMany({
|
|
1426
|
+
where: {
|
|
1427
|
+
releasedAt: null,
|
|
1428
|
+
actions: {
|
|
1429
|
+
contentType: contentTypeUid,
|
|
1430
|
+
entryDocumentId: {
|
|
1431
|
+
$in: documentIds
|
|
1432
|
+
},
|
|
1433
|
+
locale
|
|
1434
|
+
}
|
|
1435
|
+
},
|
|
1436
|
+
populate: {
|
|
1437
|
+
actions: true
|
|
1438
|
+
}
|
|
1439
|
+
});
|
|
1440
|
+
const mappedEntriesInReleases = releasesWithActions.reduce(
|
|
1441
|
+
(acc, release2) => {
|
|
1442
|
+
release2.actions.forEach((action) => {
|
|
1443
|
+
if (action.contentType !== contentTypeUid) {
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
if (locale && action.locale !== locale) {
|
|
1447
|
+
return;
|
|
1448
|
+
}
|
|
1449
|
+
if (!acc[action.entryDocumentId]) {
|
|
1450
|
+
acc[action.entryDocumentId] = [{ id: release2.id, name: release2.name }];
|
|
1451
|
+
} else {
|
|
1452
|
+
acc[action.entryDocumentId].push({ id: release2.id, name: release2.name });
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1455
|
+
return acc;
|
|
1456
|
+
},
|
|
1457
|
+
{}
|
|
1458
|
+
);
|
|
1459
|
+
ctx.body = {
|
|
1460
|
+
data: mappedEntriesInReleases
|
|
1461
|
+
};
|
|
1462
|
+
},
|
|
705
1463
|
async create(ctx) {
|
|
706
1464
|
const user = ctx.state.user;
|
|
707
1465
|
const releaseArgs = ctx.request.body;
|
|
708
1466
|
await validateRelease(releaseArgs);
|
|
709
1467
|
const releaseService = getService("release", { strapi });
|
|
710
1468
|
const release2 = await releaseService.create(releaseArgs, { user });
|
|
711
|
-
const permissionsManager = strapi.admin
|
|
1469
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
712
1470
|
ability: ctx.state.userAbility,
|
|
713
1471
|
model: RELEASE_MODEL_UID
|
|
714
1472
|
});
|
|
715
|
-
ctx.
|
|
1473
|
+
ctx.created({
|
|
716
1474
|
data: await permissionsManager.sanitizeOutput(release2)
|
|
717
|
-
};
|
|
1475
|
+
});
|
|
718
1476
|
},
|
|
719
1477
|
async update(ctx) {
|
|
720
1478
|
const user = ctx.state.user;
|
|
@@ -723,7 +1481,7 @@ const releaseController = {
|
|
|
723
1481
|
await validateRelease(releaseArgs);
|
|
724
1482
|
const releaseService = getService("release", { strapi });
|
|
725
1483
|
const release2 = await releaseService.update(id, releaseArgs, { user });
|
|
726
|
-
const permissionsManager = strapi.admin
|
|
1484
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
727
1485
|
ability: ctx.state.userAbility,
|
|
728
1486
|
model: RELEASE_MODEL_UID
|
|
729
1487
|
});
|
|
@@ -740,55 +1498,142 @@ const releaseController = {
|
|
|
740
1498
|
};
|
|
741
1499
|
},
|
|
742
1500
|
async publish(ctx) {
|
|
743
|
-
const user = ctx.state.user;
|
|
744
1501
|
const id = ctx.params.id;
|
|
745
1502
|
const releaseService = getService("release", { strapi });
|
|
746
|
-
const
|
|
1503
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1504
|
+
const release2 = await releaseService.publish(id);
|
|
1505
|
+
const [countPublishActions, countUnpublishActions] = await Promise.all([
|
|
1506
|
+
releaseActionService.countActions({
|
|
1507
|
+
filters: {
|
|
1508
|
+
release: id,
|
|
1509
|
+
type: "publish"
|
|
1510
|
+
}
|
|
1511
|
+
}),
|
|
1512
|
+
releaseActionService.countActions({
|
|
1513
|
+
filters: {
|
|
1514
|
+
release: id,
|
|
1515
|
+
type: "unpublish"
|
|
1516
|
+
}
|
|
1517
|
+
})
|
|
1518
|
+
]);
|
|
747
1519
|
ctx.body = {
|
|
748
|
-
data: release2
|
|
1520
|
+
data: release2,
|
|
1521
|
+
meta: {
|
|
1522
|
+
totalEntries: countPublishActions + countUnpublishActions,
|
|
1523
|
+
totalPublishedEntries: countPublishActions,
|
|
1524
|
+
totalUnpublishedEntries: countUnpublishActions
|
|
1525
|
+
}
|
|
749
1526
|
};
|
|
750
1527
|
}
|
|
751
1528
|
};
|
|
752
1529
|
const RELEASE_ACTION_SCHEMA = yup$1.object().shape({
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
}).required(),
|
|
1530
|
+
contentType: yup$1.string().required(),
|
|
1531
|
+
entryDocumentId: yup$1.strapiID(),
|
|
1532
|
+
locale: yup$1.string(),
|
|
757
1533
|
type: yup$1.string().oneOf(["publish", "unpublish"]).required()
|
|
758
1534
|
});
|
|
759
1535
|
const RELEASE_ACTION_UPDATE_SCHEMA = yup$1.object().shape({
|
|
760
1536
|
type: yup$1.string().oneOf(["publish", "unpublish"]).required()
|
|
761
1537
|
});
|
|
1538
|
+
const FIND_MANY_ACTIONS_PARAMS = yup$1.object().shape({
|
|
1539
|
+
groupBy: yup$1.string().oneOf(["action", "contentType", "locale"])
|
|
1540
|
+
});
|
|
762
1541
|
const validateReleaseAction = validateYupSchema(RELEASE_ACTION_SCHEMA);
|
|
763
1542
|
const validateReleaseActionUpdateSchema = validateYupSchema(RELEASE_ACTION_UPDATE_SCHEMA);
|
|
1543
|
+
const validateFindManyActionsParams = validateYupSchema(FIND_MANY_ACTIONS_PARAMS);
|
|
764
1544
|
const releaseActionController = {
|
|
765
1545
|
async create(ctx) {
|
|
766
1546
|
const releaseId = ctx.params.releaseId;
|
|
767
1547
|
const releaseActionArgs = ctx.request.body;
|
|
768
1548
|
await validateReleaseAction(releaseActionArgs);
|
|
769
|
-
const
|
|
770
|
-
const releaseAction2 = await
|
|
771
|
-
ctx.
|
|
1549
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1550
|
+
const releaseAction2 = await releaseActionService.create(releaseId, releaseActionArgs);
|
|
1551
|
+
ctx.created({
|
|
772
1552
|
data: releaseAction2
|
|
773
|
-
};
|
|
1553
|
+
});
|
|
1554
|
+
},
|
|
1555
|
+
async createMany(ctx) {
|
|
1556
|
+
const releaseId = ctx.params.releaseId;
|
|
1557
|
+
const releaseActionsArgs = ctx.request.body;
|
|
1558
|
+
await Promise.all(
|
|
1559
|
+
releaseActionsArgs.map((releaseActionArgs) => validateReleaseAction(releaseActionArgs))
|
|
1560
|
+
);
|
|
1561
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1562
|
+
const releaseService = getService("release", { strapi });
|
|
1563
|
+
const releaseActions = await strapi.db.transaction(async () => {
|
|
1564
|
+
const releaseActions2 = await Promise.all(
|
|
1565
|
+
releaseActionsArgs.map(async (releaseActionArgs) => {
|
|
1566
|
+
try {
|
|
1567
|
+
const action = await releaseActionService.create(releaseId, releaseActionArgs, {
|
|
1568
|
+
disableUpdateReleaseStatus: true
|
|
1569
|
+
});
|
|
1570
|
+
return action;
|
|
1571
|
+
} catch (error) {
|
|
1572
|
+
if (error instanceof AlreadyOnReleaseError) {
|
|
1573
|
+
return null;
|
|
1574
|
+
}
|
|
1575
|
+
throw error;
|
|
1576
|
+
}
|
|
1577
|
+
})
|
|
1578
|
+
);
|
|
1579
|
+
return releaseActions2;
|
|
1580
|
+
});
|
|
1581
|
+
const newReleaseActions = releaseActions.filter((action) => action !== null);
|
|
1582
|
+
if (newReleaseActions.length > 0) {
|
|
1583
|
+
releaseService.updateReleaseStatus(releaseId);
|
|
1584
|
+
}
|
|
1585
|
+
ctx.created({
|
|
1586
|
+
data: newReleaseActions,
|
|
1587
|
+
meta: {
|
|
1588
|
+
entriesAlreadyInRelease: releaseActions.length - newReleaseActions.length,
|
|
1589
|
+
totalEntries: releaseActions.length
|
|
1590
|
+
}
|
|
1591
|
+
});
|
|
774
1592
|
},
|
|
775
1593
|
async findMany(ctx) {
|
|
776
1594
|
const releaseId = ctx.params.releaseId;
|
|
777
|
-
const permissionsManager = strapi.admin
|
|
1595
|
+
const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
778
1596
|
ability: ctx.state.userAbility,
|
|
779
1597
|
model: RELEASE_ACTION_MODEL_UID
|
|
780
1598
|
});
|
|
1599
|
+
await validateFindManyActionsParams(ctx.query);
|
|
1600
|
+
if (ctx.query.groupBy) {
|
|
1601
|
+
if (!["action", "contentType", "locale"].includes(ctx.query.groupBy)) {
|
|
1602
|
+
ctx.badRequest("Invalid groupBy parameter");
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
ctx.query.sort = ctx.query.groupBy === "action" ? "type" : ctx.query.groupBy;
|
|
1606
|
+
delete ctx.query.groupBy;
|
|
781
1607
|
const query = await permissionsManager.sanitizeQuery(ctx.query);
|
|
782
|
-
const
|
|
783
|
-
const { results, pagination } = await
|
|
784
|
-
sort: query.groupBy === "action" ? "type" : query.groupBy,
|
|
1608
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1609
|
+
const { results, pagination } = await releaseActionService.findPage(releaseId, {
|
|
785
1610
|
...query
|
|
786
1611
|
});
|
|
787
|
-
const
|
|
1612
|
+
const contentTypeOutputSanitizers = results.reduce((acc, action) => {
|
|
1613
|
+
if (acc[action.contentType]) {
|
|
1614
|
+
return acc;
|
|
1615
|
+
}
|
|
1616
|
+
const contentTypePermissionsManager = strapi.service("admin::permission").createPermissionsManager({
|
|
1617
|
+
ability: ctx.state.userAbility,
|
|
1618
|
+
model: action.contentType
|
|
1619
|
+
});
|
|
1620
|
+
acc[action.contentType] = contentTypePermissionsManager.sanitizeOutput;
|
|
1621
|
+
return acc;
|
|
1622
|
+
}, {});
|
|
1623
|
+
const sanitizedResults = await async.map(results, async (action) => ({
|
|
1624
|
+
...action,
|
|
1625
|
+
entry: action.entry ? await contentTypeOutputSanitizers[action.contentType](action.entry) : {}
|
|
1626
|
+
}));
|
|
1627
|
+
const groupedData = await releaseActionService.groupActions(sanitizedResults, query.sort);
|
|
1628
|
+
const contentTypes2 = releaseActionService.getContentTypeModelsFromActions(results);
|
|
1629
|
+
const releaseService = getService("release", { strapi });
|
|
1630
|
+
const components = await releaseService.getAllComponents();
|
|
788
1631
|
ctx.body = {
|
|
789
1632
|
data: groupedData,
|
|
790
1633
|
meta: {
|
|
791
|
-
pagination
|
|
1634
|
+
pagination,
|
|
1635
|
+
contentTypes: contentTypes2,
|
|
1636
|
+
components
|
|
792
1637
|
}
|
|
793
1638
|
};
|
|
794
1639
|
},
|
|
@@ -797,8 +1642,8 @@ const releaseActionController = {
|
|
|
797
1642
|
const releaseId = ctx.params.releaseId;
|
|
798
1643
|
const releaseActionUpdateArgs = ctx.request.body;
|
|
799
1644
|
await validateReleaseActionUpdateSchema(releaseActionUpdateArgs);
|
|
800
|
-
const
|
|
801
|
-
const updatedAction = await
|
|
1645
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1646
|
+
const updatedAction = await releaseActionService.update(
|
|
802
1647
|
actionId,
|
|
803
1648
|
releaseId,
|
|
804
1649
|
releaseActionUpdateArgs
|
|
@@ -810,17 +1655,71 @@ const releaseActionController = {
|
|
|
810
1655
|
async delete(ctx) {
|
|
811
1656
|
const actionId = ctx.params.actionId;
|
|
812
1657
|
const releaseId = ctx.params.releaseId;
|
|
813
|
-
const
|
|
814
|
-
const deletedReleaseAction = await
|
|
1658
|
+
const releaseActionService = getService("release-action", { strapi });
|
|
1659
|
+
const deletedReleaseAction = await releaseActionService.delete(actionId, releaseId);
|
|
815
1660
|
ctx.body = {
|
|
816
1661
|
data: deletedReleaseAction
|
|
817
1662
|
};
|
|
818
1663
|
}
|
|
819
1664
|
};
|
|
820
|
-
const
|
|
1665
|
+
const SETTINGS_SCHEMA = yup.object().shape({
|
|
1666
|
+
defaultTimezone: yup.string().nullable().default(null)
|
|
1667
|
+
}).required().noUnknown();
|
|
1668
|
+
const validateSettings = validateYupSchema(SETTINGS_SCHEMA);
|
|
1669
|
+
const settingsController = {
|
|
1670
|
+
async find(ctx) {
|
|
1671
|
+
const settingsService = getService("settings", { strapi });
|
|
1672
|
+
const settings2 = await settingsService.find();
|
|
1673
|
+
ctx.body = { data: settings2 };
|
|
1674
|
+
},
|
|
1675
|
+
async update(ctx) {
|
|
1676
|
+
const settingsBody = ctx.request.body;
|
|
1677
|
+
const settings2 = await validateSettings(settingsBody);
|
|
1678
|
+
const settingsService = getService("settings", { strapi });
|
|
1679
|
+
const updatedSettings = await settingsService.update({ settings: settings2 });
|
|
1680
|
+
ctx.body = { data: updatedSettings };
|
|
1681
|
+
}
|
|
1682
|
+
};
|
|
1683
|
+
const controllers = {
|
|
1684
|
+
release: releaseController,
|
|
1685
|
+
"release-action": releaseActionController,
|
|
1686
|
+
settings: settingsController
|
|
1687
|
+
};
|
|
821
1688
|
const release = {
|
|
822
1689
|
type: "admin",
|
|
823
1690
|
routes: [
|
|
1691
|
+
{
|
|
1692
|
+
method: "GET",
|
|
1693
|
+
path: "/mapEntriesToReleases",
|
|
1694
|
+
handler: "release.mapEntriesToReleases",
|
|
1695
|
+
config: {
|
|
1696
|
+
policies: [
|
|
1697
|
+
"admin::isAuthenticatedAdmin",
|
|
1698
|
+
{
|
|
1699
|
+
name: "admin::hasPermissions",
|
|
1700
|
+
config: {
|
|
1701
|
+
actions: ["plugin::content-releases.read"]
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
]
|
|
1705
|
+
}
|
|
1706
|
+
},
|
|
1707
|
+
{
|
|
1708
|
+
method: "GET",
|
|
1709
|
+
path: "/getByDocumentAttached",
|
|
1710
|
+
handler: "release.findByDocumentAttached",
|
|
1711
|
+
config: {
|
|
1712
|
+
policies: [
|
|
1713
|
+
"admin::isAuthenticatedAdmin",
|
|
1714
|
+
{
|
|
1715
|
+
name: "admin::hasPermissions",
|
|
1716
|
+
config: {
|
|
1717
|
+
actions: ["plugin::content-releases.read"]
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
]
|
|
1721
|
+
}
|
|
1722
|
+
},
|
|
824
1723
|
{
|
|
825
1724
|
method: "POST",
|
|
826
1725
|
path: "/",
|
|
@@ -840,7 +1739,7 @@ const release = {
|
|
|
840
1739
|
{
|
|
841
1740
|
method: "GET",
|
|
842
1741
|
path: "/",
|
|
843
|
-
handler: "release.
|
|
1742
|
+
handler: "release.findPage",
|
|
844
1743
|
config: {
|
|
845
1744
|
policies: [
|
|
846
1745
|
"admin::isAuthenticatedAdmin",
|
|
@@ -938,6 +1837,22 @@ const releaseAction = {
|
|
|
938
1837
|
]
|
|
939
1838
|
}
|
|
940
1839
|
},
|
|
1840
|
+
{
|
|
1841
|
+
method: "POST",
|
|
1842
|
+
path: "/:releaseId/actions/bulk",
|
|
1843
|
+
handler: "release-action.createMany",
|
|
1844
|
+
config: {
|
|
1845
|
+
policies: [
|
|
1846
|
+
"admin::isAuthenticatedAdmin",
|
|
1847
|
+
{
|
|
1848
|
+
name: "admin::hasPermissions",
|
|
1849
|
+
config: {
|
|
1850
|
+
actions: ["plugin::content-releases.create-action"]
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
]
|
|
1854
|
+
}
|
|
1855
|
+
},
|
|
941
1856
|
{
|
|
942
1857
|
method: "GET",
|
|
943
1858
|
path: "/:releaseId/actions",
|
|
@@ -988,28 +1903,64 @@ const releaseAction = {
|
|
|
988
1903
|
}
|
|
989
1904
|
]
|
|
990
1905
|
};
|
|
1906
|
+
const settings = {
|
|
1907
|
+
type: "admin",
|
|
1908
|
+
routes: [
|
|
1909
|
+
{
|
|
1910
|
+
method: "GET",
|
|
1911
|
+
path: "/settings",
|
|
1912
|
+
handler: "settings.find",
|
|
1913
|
+
config: {
|
|
1914
|
+
policies: [
|
|
1915
|
+
"admin::isAuthenticatedAdmin",
|
|
1916
|
+
{
|
|
1917
|
+
name: "admin::hasPermissions",
|
|
1918
|
+
config: {
|
|
1919
|
+
actions: ["plugin::content-releases.settings.read"]
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
]
|
|
1923
|
+
}
|
|
1924
|
+
},
|
|
1925
|
+
{
|
|
1926
|
+
method: "PUT",
|
|
1927
|
+
path: "/settings",
|
|
1928
|
+
handler: "settings.update",
|
|
1929
|
+
config: {
|
|
1930
|
+
policies: [
|
|
1931
|
+
"admin::isAuthenticatedAdmin",
|
|
1932
|
+
{
|
|
1933
|
+
name: "admin::hasPermissions",
|
|
1934
|
+
config: {
|
|
1935
|
+
actions: ["plugin::content-releases.settings.update"]
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
]
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
]
|
|
1942
|
+
};
|
|
991
1943
|
const routes = {
|
|
1944
|
+
settings,
|
|
992
1945
|
release,
|
|
993
1946
|
"release-action": releaseAction
|
|
994
1947
|
};
|
|
995
|
-
const { features } = require("@strapi/strapi/dist/utils/ee");
|
|
996
1948
|
const getPlugin = () => {
|
|
997
|
-
if (features.isEnabled("cms-content-releases")
|
|
1949
|
+
if (strapi.ee.features.isEnabled("cms-content-releases")) {
|
|
998
1950
|
return {
|
|
999
1951
|
register,
|
|
1000
1952
|
bootstrap,
|
|
1953
|
+
destroy,
|
|
1001
1954
|
contentTypes,
|
|
1002
1955
|
services,
|
|
1003
1956
|
controllers,
|
|
1004
|
-
routes
|
|
1005
|
-
destroy() {
|
|
1006
|
-
if (features.isEnabled("cms-content-releases") && strapi.features.future.isEnabled("contentReleases")) {
|
|
1007
|
-
getService("event-manager").destroyAllListeners();
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1957
|
+
routes
|
|
1010
1958
|
};
|
|
1011
1959
|
}
|
|
1012
1960
|
return {
|
|
1961
|
+
// Always return register, it handles its own feature check
|
|
1962
|
+
register,
|
|
1963
|
+
// Always return contentTypes to avoid losing data when the feature is disabled
|
|
1013
1964
|
contentTypes
|
|
1014
1965
|
};
|
|
1015
1966
|
};
|