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