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