@webbio/strapi-plugin-page-builder 0.12.1-platform → 0.12.2-platform
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/README.md +166 -166
- package/admin/src/api/collection-type.ts +111 -111
- package/admin/src/api/entity-relation.ts +42 -42
- package/admin/src/api/has-page-relation.ts +37 -37
- package/admin/src/api/has-platform-relation.ts +40 -40
- package/admin/src/api/page-type-relation.ts +41 -41
- package/admin/src/api/platform-page-types.ts +45 -45
- package/admin/src/api/platform-relation.ts +42 -42
- package/admin/src/api/platform.ts +35 -35
- package/admin/src/api/search-filtered-entity.ts +114 -114
- package/admin/src/api/template.ts +39 -39
- package/admin/src/components/Combobox/index.tsx +83 -83
- package/admin/src/components/Combobox/react-select-custom-styles.tsx +121 -121
- package/admin/src/components/Combobox/styles.ts +46 -46
- package/admin/src/components/ConfirmModal/index.tsx +90 -90
- package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +127 -127
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +149 -149
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/styles.ts +19 -19
- package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +82 -82
- package/admin/src/components/EditView/Details/index.tsx +48 -48
- package/admin/src/components/EditView/Details/styles.ts +51 -51
- package/admin/src/components/EditView/PageSettings/index.tsx +124 -124
- package/admin/src/components/EditView/Platform/platform-select.tsx +30 -30
- package/admin/src/components/EditView/Template/TemplateConfirmModal/index.tsx +36 -36
- package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +70 -70
- package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +41 -41
- package/admin/src/components/EditView/index.tsx +35 -35
- package/admin/src/components/EditView/page-type-select.tsx +32 -32
- package/admin/src/components/EditView/wrapper.tsx +41 -41
- package/admin/src/components/GlobalPlatformSelect/index.tsx +40 -40
- package/admin/src/components/GlobalPlatformSelect/styles.ts +27 -27
- package/admin/src/components/Initializer/index.tsx +24 -24
- package/admin/src/components/PageFilters/PageTypeFilter/index.tsx +39 -39
- package/admin/src/components/PageFilters/PlatformFilter/index.tsx +32 -32
- package/admin/src/components/PageFilters/filters.tsx +189 -189
- package/admin/src/components/PageFilters/index.tsx +35 -35
- package/admin/src/components/PageTypeEditView/TemplatePlatformSelect/index.tsx +76 -76
- package/admin/src/components/PageTypeEditView/index.tsx +53 -53
- package/admin/src/components/PlatformFilteredSelectField/InputIcon/index.tsx +23 -23
- package/admin/src/components/PlatformFilteredSelectField/Multi/index.tsx +210 -210
- package/admin/src/components/PlatformFilteredSelectField/Single/index.tsx +197 -197
- package/admin/src/components/PlatformFilteredSelectField/hooks/useRelationLoad.tsx +128 -128
- package/admin/src/components/PlatformFilteredSelectField/index.tsx +85 -85
- package/admin/src/components/PlatformFilteredSelectField/styles.tsx +77 -77
- package/admin/src/components/PlatformFilteredSelectField/utils/get-translations.ts +3 -3
- package/admin/src/components/PlatformFilteredSelectField/utils/relation-helper.ts +147 -147
- package/admin/src/components/PluginIcon/index.tsx +94 -94
- package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/RelationInput.tsx +689 -689
- package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/RelationInputDataManager.tsx +6 -6
- package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/useRelation.ts +170 -170
- package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/utils/getRelationLink.ts +5 -5
- package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/utils/normalizeRelations.ts +52 -52
- package/admin/src/components/StrapiCore/admin/admin/src/content-manager/constants/attributes.ts +3 -3
- package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/useDragAndDrop.ts +253 -253
- package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/useKeyboardDragAndDrop.ts +96 -96
- package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/usePrev.ts +11 -11
- package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/dragAndDrop.ts +8 -8
- package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/paths.ts +29 -29
- package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/refs.ts +19 -19
- package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/translations.ts +3 -3
- package/admin/src/components/StrapiCore/content-manager/shared/contracts/collection-types.ts +300 -300
- package/admin/src/components/StrapiCore/content-manager/shared/contracts/components.ts +72 -72
- package/admin/src/components/StrapiCore/content-manager/shared/contracts/content-types.ts +116 -116
- package/admin/src/components/StrapiCore/content-manager/shared/contracts/index.ts +8 -8
- package/admin/src/components/StrapiCore/content-manager/shared/contracts/init.ts +22 -22
- package/admin/src/components/StrapiCore/content-manager/shared/contracts/relations.ts +80 -80
- package/admin/src/components/StrapiCore/content-manager/shared/contracts/review-workflows.ts +88 -88
- package/admin/src/components/StrapiCore/content-manager/shared/contracts/single-types.ts +112 -112
- package/admin/src/components/StrapiCore/content-manager/shared/contracts/uid.ts +48 -48
- package/admin/src/components/StrapiCore/content-manager/shared/index.ts +1 -1
- package/admin/src/constants.ts +3 -3
- package/admin/src/index.tsx +101 -101
- package/admin/src/middlewares/index.tsx +37 -37
- package/admin/src/pages/app/index.tsx +14 -14
- package/admin/src/pluginId.ts +5 -5
- package/admin/src/translations/en.json +9 -9
- package/admin/src/translations/nl.json +9 -9
- package/admin/src/utils/findDomElement.ts +6 -6
- package/admin/src/utils/findElementParent.ts +20 -20
- package/admin/src/utils/getObjectFromFormName.ts +42 -42
- package/admin/src/utils/getRequestUrl.ts +11 -11
- package/admin/src/utils/getTrad.ts +5 -5
- package/admin/src/utils/hooks/useDebounce.ts +17 -17
- package/admin/src/utils/hooks/useDefaultPlatformFromLocalStorage.ts +61 -61
- package/admin/src/utils/hooks/useGetLocaleFromUrl.ts +9 -9
- package/admin/src/utils/hooks/useHideOverviewFilterTags.ts +34 -34
- package/admin/src/utils/hooks/usePlatformFormData.ts +64 -64
- package/admin/src/utils/hooks/usePrevious.ts +12 -12
- package/admin/src/utils/sanitizeModules.ts +93 -93
- package/custom.d.ts +6 -6
- package/dist/package.json +1 -1
- package/dist/server/bootstrap.js +1 -0
- package/dist/server/graphql/page-by-path.js +9 -9
- package/dist/server/graphql/page-by-slug.js +89 -0
- package/dist/server/graphql/pages-by-uid.js +5 -5
- package/dist/server/services/private-content/graphql/index.js +27 -27
- package/dist/server/services/private-content/graphql/types/index.js +74 -74
- package/dist/server/utils/graphql.js +100 -0
- package/dist/server/utils/paginationValidation.js +31 -0
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +78 -78
- package/server/bootstrap/collection-type-lifecycles.ts +47 -47
- package/server/bootstrap/permissions.ts +161 -161
- package/server/bootstrap.ts +261 -260
- package/server/config/index.ts +4 -4
- package/server/content-types/index.ts +7 -7
- package/server/content-types/user-category/schema.json +23 -23
- package/server/controllers/collection-types.ts +32 -32
- package/server/controllers/index.ts +19 -19
- package/server/controllers/page-type.ts +18 -18
- package/server/controllers/page.ts +9 -9
- package/server/controllers/platform.ts +21 -21
- package/server/controllers/private-content.ts +17 -17
- package/server/controllers/sitemap.ts +32 -32
- package/server/controllers/template.ts +16 -16
- package/server/controllers/user-category.ts +3 -3
- package/server/destroy.ts +5 -5
- package/server/graphql/index.ts +9 -9
- package/server/graphql/page-by-path.ts +132 -132
- package/server/graphql/page-type.ts +67 -67
- package/server/graphql/pages-by-uid.ts +89 -89
- package/server/index.ts +23 -23
- package/server/middlewares/index.ts +1 -1
- package/server/policies/index.ts +5 -5
- package/server/policies/isAuthorizedPage.ts +11 -11
- package/server/register.ts +22 -22
- package/server/routes/index.ts +115 -115
- package/server/routes/user-category.ts +3 -3
- package/server/schema/page-end.json +96 -96
- package/server/schema/page-start.json +87 -87
- package/server/schema/page-type-end.json +53 -53
- package/server/schema/page-type-start.json +38 -38
- package/server/schema/platform-start.json +21 -21
- package/server/schema/template-end.json +40 -40
- package/server/schema/template-start.json +35 -35
- package/server/services/builder.ts +232 -232
- package/server/services/collection-types.ts +95 -95
- package/server/services/email.ts +127 -127
- package/server/services/index.ts +23 -23
- package/server/services/page-type.ts +30 -30
- package/server/services/page.ts +24 -24
- package/server/services/platform.ts +30 -30
- package/server/services/private-content/components/admin-email.json +22 -22
- package/server/services/private-content/components/email.json +22 -22
- package/server/services/private-content/components/platform-email.json +30 -30
- package/server/services/private-content/constants/index.ts +13 -13
- package/server/services/private-content/graphql/index.ts +88 -88
- package/server/services/private-content/graphql/resolvers/findOnePage.ts +40 -40
- package/server/services/private-content/graphql/resolvers/findPage.ts +45 -45
- package/server/services/private-content/graphql/resolvers/forgot-password.ts +34 -34
- package/server/services/private-content/graphql/resolvers/login.ts +56 -56
- package/server/services/private-content/graphql/resolvers/register.ts +78 -78
- package/server/services/private-content/graphql/resolvers/reset-password.ts +44 -44
- package/server/services/private-content/graphql/types/index.ts +96 -96
- package/server/services/private-content/index.ts +95 -95
- package/server/services/private-content/mail-template/txtMail.email.template.text.ts +6 -6
- package/server/services/private-content/page.ts +20 -20
- package/server/services/private-content/platform.ts +19 -19
- package/server/services/private-content/schemas/index.ts +28 -28
- package/server/services/private-content/user.ts +197 -197
- package/server/services/sitemap.ts +83 -83
- package/server/services/template.ts +13 -13
- package/server/services/user-category.ts +3 -3
- package/server/utils/filter-underscore-arguments.ts +12 -12
- package/server/utils/reload-strapi-on-load.ts +13 -13
- package/server/utils/strapi.ts +50 -50
- package/shared/utils/constants.ts +8 -8
- package/shared/utils/sleep.ts +1 -1
- package/strapi-admin.js +3 -3
- package/strapi-server.js +3 -3
- package/tsconfig.json +20 -20
- package/tsconfig.server.json +25 -25
- package/dist/server/content-types/user-categories/schema.json +0 -18
package/server/bootstrap.ts
CHANGED
|
@@ -1,260 +1,261 @@
|
|
|
1
|
-
import { Common, Strapi } from '@strapi/strapi';
|
|
2
|
-
import { errors } from '@strapi/utils';
|
|
3
|
-
import {
|
|
4
|
-
PAGE_BUILDER_EMAIL_PLUGIN,
|
|
5
|
-
PAGE_TYPE_UID,
|
|
6
|
-
PAGE_UID,
|
|
7
|
-
PLATFORM_UID,
|
|
8
|
-
USER_PERMISSION_USER_PLUGIN
|
|
9
|
-
} from '../shared/utils/constants';
|
|
10
|
-
import permissions from './bootstrap/permissions';
|
|
11
|
-
import collectionTypeLifecycles from './bootstrap/collection-type-lifecycles';
|
|
12
|
-
|
|
13
|
-
export default async ({ strapi }: { strapi: Strapi }) => {
|
|
14
|
-
await permissions({ strapi });
|
|
15
|
-
await collectionTypeLifecycles({ strapi });
|
|
16
|
-
|
|
17
|
-
const updateCollectionTypeData = (data: any, collectionTypeId: number, uid: string) => {
|
|
18
|
-
data.collectionTypeData = {
|
|
19
|
-
id: collectionTypeId,
|
|
20
|
-
__type: uid,
|
|
21
|
-
__pivot: {
|
|
22
|
-
field: 'page'
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
return data;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const plugin = strapi.plugin('users-permissions');
|
|
30
|
-
|
|
31
|
-
plugin.services.user.fetchAuthenticatedUser = async (id: any) => {
|
|
32
|
-
return strapi.query('plugin::users-permissions.user').findOne({ where: { id }, populate: ['role', 'platform'] });
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
strapi.db?.lifecycles.subscribe({
|
|
36
|
-
models: [USER_PERMISSION_USER_PLUGIN],
|
|
37
|
-
async beforeUpdate(event) {
|
|
38
|
-
if (event.params.data.id) {
|
|
39
|
-
const userToUpdate = await strapi.entityService?.findOne(USER_PERMISSION_USER_PLUGIN, event.params.data.id, {
|
|
40
|
-
populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
|
|
41
|
-
});
|
|
42
|
-
if (userToUpdate) {
|
|
43
|
-
if (event.params.data.activateUser && event.params.data.confirmed && !userToUpdate.confirmMailSend) {
|
|
44
|
-
await strapi.service(PAGE_BUILDER_EMAIL_PLUGIN).sendMail({
|
|
45
|
-
// @ts-ignore strapi typings
|
|
46
|
-
from: userToUpdate.platform.platformEmails.accountAcceptedMail.fromEmail,
|
|
47
|
-
to: event.params.data.email,
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
subject: userToUpdate.platform.platformEmails.accountAcceptedMail.subject,
|
|
50
|
-
// @ts-ignore
|
|
51
|
-
text: userToUpdate.platform.platformEmails.accountAcceptedMail.message,
|
|
52
|
-
firstName: event.params.data.firstName,
|
|
53
|
-
lastName: event.params.data.lastName
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
strapi.db?.lifecycles.subscribe({
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
models: [PAGE_UID],
|
|
64
|
-
async beforeCreate(event) {
|
|
65
|
-
let { data } = event.params;
|
|
66
|
-
const collectionTypeId = data?.collectionTypeId;
|
|
67
|
-
const pageTypeId = data?.pageType.connect?.[0]?.id || data.initialPageType;
|
|
68
|
-
const platformId = data?.platform.connect?.[0]?.id;
|
|
69
|
-
|
|
70
|
-
if (collectionTypeId && pageTypeId) {
|
|
71
|
-
const pageType: Record<string, any> | undefined | null = await strapi.entityService?.findOne(
|
|
72
|
-
PAGE_TYPE_UID,
|
|
73
|
-
pageTypeId
|
|
74
|
-
);
|
|
75
|
-
const collectionToConnect = await strapi.entityService?.findOne(pageType?.uid, collectionTypeId, {
|
|
76
|
-
populate: { page: true }
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const page: Record<string, any>[] = collectionToConnect?.page as any;
|
|
80
|
-
|
|
81
|
-
const foundPlatforms: Record<string, any> | undefined | null = await strapi.entityService?.findMany(
|
|
82
|
-
PLATFORM_UID,
|
|
83
|
-
{
|
|
84
|
-
populate: '*',
|
|
85
|
-
filters: {
|
|
86
|
-
pagetype: {
|
|
87
|
-
uid: pageType?.uid
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
if (page && page.length > 0) {
|
|
94
|
-
throw new errors.ValidationError('You can only link one CollectionType to one page');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (platformId && !foundPlatforms?.some((platform) => platform.id === platformId)) {
|
|
98
|
-
throw new errors.ValidationError('Platform not found');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
data = updateCollectionTypeData(data, collectionTypeId, pageType?.uid);
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
async beforeUpdate(event) {
|
|
105
|
-
let { data, where } = event?.params;
|
|
106
|
-
|
|
107
|
-
const collectionTypeId = data?.collectionTypeId;
|
|
108
|
-
const pageTypeId = data?.pageType?.connect?.[0]?.id || data?.initialPageType;
|
|
109
|
-
const removedPageType = data?.pageType?.disconnect?.[0]?.id;
|
|
110
|
-
|
|
111
|
-
const originalEntity = await strapi.entityService?.findOne(
|
|
112
|
-
event.model.uid as Common.UID.CollectionType,
|
|
113
|
-
data.id || where.id,
|
|
114
|
-
{
|
|
115
|
-
populate: {
|
|
116
|
-
collectionTypeData: true
|
|
117
|
-
}
|
|
118
|
-
} as Record<string, any>
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
if (removedPageType || collectionTypeId === null) {
|
|
122
|
-
data.collectionTypeData = undefined;
|
|
123
|
-
|
|
124
|
-
if (originalEntity?.collectionTypeData?.[0]?.__type && originalEntity?.collectionTypeData?.[0]?.id) {
|
|
125
|
-
strapi.entityService?.update(
|
|
126
|
-
originalEntity.collectionTypeData[0].__type,
|
|
127
|
-
originalEntity.collectionTypeData[0].id,
|
|
128
|
-
{
|
|
129
|
-
data: {
|
|
130
|
-
id: originalEntity.collectionTypeData.id,
|
|
131
|
-
hasPage: false
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (collectionTypeId && pageTypeId && !removedPageType) {
|
|
139
|
-
const pageType: Record<string, any> | undefined | null = await strapi.entityService?.findOne(
|
|
140
|
-
PAGE_TYPE_UID,
|
|
141
|
-
pageTypeId
|
|
142
|
-
);
|
|
143
|
-
const collectionToConnect = await strapi.entityService?.findOne(pageType?.uid, collectionTypeId, {
|
|
144
|
-
populate: { page: true }
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
const page: Record<string, any>[] = collectionToConnect?.page as any;
|
|
148
|
-
|
|
149
|
-
if (page && page?.length > 0 && !page.some((p) => p.id === data.id)) {
|
|
150
|
-
throw new errors.ValidationError('You can only link one CollectionType to one page');
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
data = updateCollectionTypeData(data, collectionTypeId, pageType?.uid);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (
|
|
157
|
-
data.collectionTypeData &&
|
|
158
|
-
originalEntity?.collectionTypeData?.[0]?.__type &&
|
|
159
|
-
originalEntity?.collectionTypeData?.[0]?.id &&
|
|
160
|
-
Number(data.collectionTypeData.id) !== Number(originalEntity.collectionTypeData[0].id)
|
|
161
|
-
) {
|
|
162
|
-
await strapi.entityService?.update(
|
|
163
|
-
originalEntity.collectionTypeData[0].__type,
|
|
164
|
-
originalEntity.collectionTypeData[0].id,
|
|
165
|
-
{
|
|
166
|
-
data: {
|
|
167
|
-
id: originalEntity.collectionTypeData[0].id,
|
|
168
|
-
hasPage: false,
|
|
169
|
-
lifecycleState: {
|
|
170
|
-
exit: true
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
async afterUpdate(event) {
|
|
178
|
-
await afterUpdate(event?.['result']);
|
|
179
|
-
},
|
|
180
|
-
async afterUpdateMany(event) {
|
|
181
|
-
try {
|
|
182
|
-
const pagesToUpdate = event.params.where?.id?.['$in'];
|
|
183
|
-
const pages: Record<string, any>[] | undefined = (await strapi.entityService?.findMany(PAGE_UID, {
|
|
184
|
-
populate: {
|
|
185
|
-
collectionTypeData: true
|
|
186
|
-
},
|
|
187
|
-
filters: {
|
|
188
|
-
id: {
|
|
189
|
-
$in: pagesToUpdate
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
})) as any;
|
|
193
|
-
|
|
194
|
-
if (pages && pages.length > 0) {
|
|
195
|
-
await Promise.all(pages?.map((p) => afterUpdate(p)));
|
|
196
|
-
}
|
|
197
|
-
} catch (error) {
|
|
198
|
-
console.error('Failed to save hasPage many data', error);
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
|
-
async beforeDelete(event) {
|
|
202
|
-
await beforeDelete(event.params.where.id);
|
|
203
|
-
},
|
|
204
|
-
async beforeDeleteMany(event) {
|
|
205
|
-
const pagesToDisconnect = event.params.where?.['$and']?.[0]?.id?.['$in'];
|
|
206
|
-
|
|
207
|
-
for (const pageId of pagesToDisconnect) {
|
|
208
|
-
await beforeDelete(pageId);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
const beforeDelete = async (id: number) => {
|
|
215
|
-
const originalEntity = (await strapi.entityService?.findOne(PAGE_UID, id, {
|
|
216
|
-
populate: {
|
|
217
|
-
collectionTypeData: true
|
|
218
|
-
}
|
|
219
|
-
})) as Record<string, any> | undefined;
|
|
220
|
-
|
|
221
|
-
if (originalEntity?.collectionTypeData?.[0]?.__type && originalEntity?.collectionTypeData?.[0]?.id) {
|
|
222
|
-
await strapi.entityService?.update(
|
|
223
|
-
originalEntity.collectionTypeData[0].__type,
|
|
224
|
-
originalEntity.collectionTypeData[0].id,
|
|
225
|
-
{
|
|
226
|
-
data: {
|
|
227
|
-
id: originalEntity.collectionTypeData[0].id,
|
|
228
|
-
hasPage: false
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
const afterUpdate = async (result: Record<string, any>) => {
|
|
236
|
-
try {
|
|
237
|
-
const hasCollectionTypeRelation =
|
|
238
|
-
result &&
|
|
239
|
-
result?.collectionTypeData?.[0] &&
|
|
240
|
-
result?.collectionTypeData[0].__type &&
|
|
241
|
-
result?.collectionTypeData[0];
|
|
242
|
-
|
|
243
|
-
if (hasCollectionTypeRelation) {
|
|
244
|
-
const isPublished = result.publishedAt !== undefined;
|
|
245
|
-
const pageData = isPublished ? { hasPage: !!result.publishedAt } : {};
|
|
246
|
-
|
|
247
|
-
await strapi.entityService?.update(result.collectionTypeData[0].__type, result.collectionTypeData[0].id, {
|
|
248
|
-
data: {
|
|
249
|
-
...pageData,
|
|
250
|
-
id: result.collectionTypeData[0].id,
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
1
|
+
import { Common, Strapi } from '@strapi/strapi';
|
|
2
|
+
import { errors } from '@strapi/utils';
|
|
3
|
+
import {
|
|
4
|
+
PAGE_BUILDER_EMAIL_PLUGIN,
|
|
5
|
+
PAGE_TYPE_UID,
|
|
6
|
+
PAGE_UID,
|
|
7
|
+
PLATFORM_UID,
|
|
8
|
+
USER_PERMISSION_USER_PLUGIN
|
|
9
|
+
} from '../shared/utils/constants';
|
|
10
|
+
import permissions from './bootstrap/permissions';
|
|
11
|
+
import collectionTypeLifecycles from './bootstrap/collection-type-lifecycles';
|
|
12
|
+
|
|
13
|
+
export default async ({ strapi }: { strapi: Strapi }) => {
|
|
14
|
+
await permissions({ strapi });
|
|
15
|
+
await collectionTypeLifecycles({ strapi });
|
|
16
|
+
|
|
17
|
+
const updateCollectionTypeData = (data: any, collectionTypeId: number, uid: string) => {
|
|
18
|
+
data.collectionTypeData = {
|
|
19
|
+
id: collectionTypeId,
|
|
20
|
+
__type: uid,
|
|
21
|
+
__pivot: {
|
|
22
|
+
field: 'page'
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return data;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const plugin = strapi.plugin('users-permissions');
|
|
30
|
+
|
|
31
|
+
plugin.services.user.fetchAuthenticatedUser = async (id: any) => {
|
|
32
|
+
return strapi.query('plugin::users-permissions.user').findOne({ where: { id }, populate: ['role', 'platform'] });
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
strapi.db?.lifecycles.subscribe({
|
|
36
|
+
models: [USER_PERMISSION_USER_PLUGIN],
|
|
37
|
+
async beforeUpdate(event) {
|
|
38
|
+
if (event.params.data.id) {
|
|
39
|
+
const userToUpdate = await strapi.entityService?.findOne(USER_PERMISSION_USER_PLUGIN, event.params.data.id, {
|
|
40
|
+
populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
|
|
41
|
+
});
|
|
42
|
+
if (userToUpdate) {
|
|
43
|
+
if (event.params.data.activateUser && event.params.data.confirmed && !userToUpdate.confirmMailSend) {
|
|
44
|
+
await strapi.service(PAGE_BUILDER_EMAIL_PLUGIN).sendMail({
|
|
45
|
+
// @ts-ignore strapi typings
|
|
46
|
+
from: userToUpdate.platform.platformEmails.accountAcceptedMail.fromEmail,
|
|
47
|
+
to: event.params.data.email,
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
subject: userToUpdate.platform.platformEmails.accountAcceptedMail.subject,
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
text: userToUpdate.platform.platformEmails.accountAcceptedMail.message,
|
|
52
|
+
firstName: event.params.data.firstName,
|
|
53
|
+
lastName: event.params.data.lastName
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
strapi.db?.lifecycles.subscribe({
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
models: [PAGE_UID],
|
|
64
|
+
async beforeCreate(event) {
|
|
65
|
+
let { data } = event.params;
|
|
66
|
+
const collectionTypeId = data?.collectionTypeId;
|
|
67
|
+
const pageTypeId = data?.pageType.connect?.[0]?.id || data.initialPageType;
|
|
68
|
+
const platformId = data?.platform.connect?.[0]?.id;
|
|
69
|
+
|
|
70
|
+
if (collectionTypeId && pageTypeId) {
|
|
71
|
+
const pageType: Record<string, any> | undefined | null = await strapi.entityService?.findOne(
|
|
72
|
+
PAGE_TYPE_UID,
|
|
73
|
+
pageTypeId
|
|
74
|
+
);
|
|
75
|
+
const collectionToConnect = await strapi.entityService?.findOne(pageType?.uid, collectionTypeId, {
|
|
76
|
+
populate: { page: true }
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const page: Record<string, any>[] = collectionToConnect?.page as any;
|
|
80
|
+
|
|
81
|
+
const foundPlatforms: Record<string, any> | undefined | null = await strapi.entityService?.findMany(
|
|
82
|
+
PLATFORM_UID,
|
|
83
|
+
{
|
|
84
|
+
populate: '*',
|
|
85
|
+
filters: {
|
|
86
|
+
pagetype: {
|
|
87
|
+
uid: pageType?.uid
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
if (page && page.length > 0) {
|
|
94
|
+
throw new errors.ValidationError('You can only link one CollectionType to one page');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (platformId && !foundPlatforms?.some((platform) => platform.id === platformId)) {
|
|
98
|
+
throw new errors.ValidationError('Platform not found');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
data = updateCollectionTypeData(data, collectionTypeId, pageType?.uid);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
async beforeUpdate(event) {
|
|
105
|
+
let { data, where } = event?.params;
|
|
106
|
+
|
|
107
|
+
const collectionTypeId = data?.collectionTypeId;
|
|
108
|
+
const pageTypeId = data?.pageType?.connect?.[0]?.id || data?.initialPageType;
|
|
109
|
+
const removedPageType = data?.pageType?.disconnect?.[0]?.id;
|
|
110
|
+
|
|
111
|
+
const originalEntity = await strapi.entityService?.findOne(
|
|
112
|
+
event.model.uid as Common.UID.CollectionType,
|
|
113
|
+
data.id || where.id,
|
|
114
|
+
{
|
|
115
|
+
populate: {
|
|
116
|
+
collectionTypeData: true
|
|
117
|
+
}
|
|
118
|
+
} as Record<string, any>
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
if (removedPageType || collectionTypeId === null) {
|
|
122
|
+
data.collectionTypeData = undefined;
|
|
123
|
+
|
|
124
|
+
if (originalEntity?.collectionTypeData?.[0]?.__type && originalEntity?.collectionTypeData?.[0]?.id) {
|
|
125
|
+
strapi.entityService?.update(
|
|
126
|
+
originalEntity.collectionTypeData[0].__type,
|
|
127
|
+
originalEntity.collectionTypeData[0].id,
|
|
128
|
+
{
|
|
129
|
+
data: {
|
|
130
|
+
id: originalEntity.collectionTypeData.id,
|
|
131
|
+
hasPage: false
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (collectionTypeId && pageTypeId && !removedPageType) {
|
|
139
|
+
const pageType: Record<string, any> | undefined | null = await strapi.entityService?.findOne(
|
|
140
|
+
PAGE_TYPE_UID,
|
|
141
|
+
pageTypeId
|
|
142
|
+
);
|
|
143
|
+
const collectionToConnect = await strapi.entityService?.findOne(pageType?.uid, collectionTypeId, {
|
|
144
|
+
populate: { page: true }
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const page: Record<string, any>[] = collectionToConnect?.page as any;
|
|
148
|
+
|
|
149
|
+
if (page && page?.length > 0 && !page.some((p) => p.id === data.id)) {
|
|
150
|
+
throw new errors.ValidationError('You can only link one CollectionType to one page');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
data = updateCollectionTypeData(data, collectionTypeId, pageType?.uid);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (
|
|
157
|
+
data.collectionTypeData &&
|
|
158
|
+
originalEntity?.collectionTypeData?.[0]?.__type &&
|
|
159
|
+
originalEntity?.collectionTypeData?.[0]?.id &&
|
|
160
|
+
Number(data.collectionTypeData.id) !== Number(originalEntity.collectionTypeData[0].id)
|
|
161
|
+
) {
|
|
162
|
+
await strapi.entityService?.update(
|
|
163
|
+
originalEntity.collectionTypeData[0].__type,
|
|
164
|
+
originalEntity.collectionTypeData[0].id,
|
|
165
|
+
{
|
|
166
|
+
data: {
|
|
167
|
+
id: originalEntity.collectionTypeData[0].id,
|
|
168
|
+
hasPage: false,
|
|
169
|
+
lifecycleState: {
|
|
170
|
+
exit: true
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
async afterUpdate(event) {
|
|
178
|
+
await afterUpdate(event?.['result']);
|
|
179
|
+
},
|
|
180
|
+
async afterUpdateMany(event) {
|
|
181
|
+
try {
|
|
182
|
+
const pagesToUpdate = event.params.where?.id?.['$in'];
|
|
183
|
+
const pages: Record<string, any>[] | undefined = (await strapi.entityService?.findMany(PAGE_UID, {
|
|
184
|
+
populate: {
|
|
185
|
+
collectionTypeData: true
|
|
186
|
+
},
|
|
187
|
+
filters: {
|
|
188
|
+
id: {
|
|
189
|
+
$in: pagesToUpdate
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
})) as any;
|
|
193
|
+
|
|
194
|
+
if (pages && pages.length > 0) {
|
|
195
|
+
await Promise.all(pages?.map((p) => afterUpdate(p)));
|
|
196
|
+
}
|
|
197
|
+
} catch (error) {
|
|
198
|
+
console.error('Failed to save hasPage many data', error);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
async beforeDelete(event) {
|
|
202
|
+
await beforeDelete(event.params.where.id);
|
|
203
|
+
},
|
|
204
|
+
async beforeDeleteMany(event) {
|
|
205
|
+
const pagesToDisconnect = event.params.where?.['$and']?.[0]?.id?.['$in'];
|
|
206
|
+
|
|
207
|
+
for (const pageId of pagesToDisconnect) {
|
|
208
|
+
await beforeDelete(pageId);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const beforeDelete = async (id: number) => {
|
|
215
|
+
const originalEntity = (await strapi.entityService?.findOne(PAGE_UID, id, {
|
|
216
|
+
populate: {
|
|
217
|
+
collectionTypeData: true
|
|
218
|
+
}
|
|
219
|
+
})) as Record<string, any> | undefined;
|
|
220
|
+
|
|
221
|
+
if (originalEntity?.collectionTypeData?.[0]?.__type && originalEntity?.collectionTypeData?.[0]?.id) {
|
|
222
|
+
await strapi.entityService?.update(
|
|
223
|
+
originalEntity.collectionTypeData[0].__type,
|
|
224
|
+
originalEntity.collectionTypeData[0].id,
|
|
225
|
+
{
|
|
226
|
+
data: {
|
|
227
|
+
id: originalEntity.collectionTypeData[0].id,
|
|
228
|
+
hasPage: false
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const afterUpdate = async (result: Record<string, any>) => {
|
|
236
|
+
try {
|
|
237
|
+
const hasCollectionTypeRelation =
|
|
238
|
+
result &&
|
|
239
|
+
result?.collectionTypeData?.[0] &&
|
|
240
|
+
result?.collectionTypeData[0].__type &&
|
|
241
|
+
result?.collectionTypeData[0];
|
|
242
|
+
|
|
243
|
+
if (hasCollectionTypeRelation) {
|
|
244
|
+
const isPublished = result.publishedAt !== undefined;
|
|
245
|
+
const pageData = isPublished ? { hasPage: !!result.publishedAt } : {};
|
|
246
|
+
|
|
247
|
+
await strapi.entityService?.update(result.collectionTypeData[0].__type, result.collectionTypeData[0].id, {
|
|
248
|
+
data: {
|
|
249
|
+
...pageData,
|
|
250
|
+
id: result.collectionTypeData[0].id,
|
|
251
|
+
...result.customPublishedAt ? { publishedAt: result.customPublishedAt } : undefined,
|
|
252
|
+
lifecycleState: {
|
|
253
|
+
exit: true
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
} catch (error) {
|
|
259
|
+
console.error('Failed to save hasPage data', error);
|
|
260
|
+
}
|
|
261
|
+
};
|
package/server/config/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
default: {},
|
|
3
|
-
validator() {}
|
|
4
|
-
};
|
|
1
|
+
export default {
|
|
2
|
+
default: {},
|
|
3
|
+
validator() {}
|
|
4
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import userCategory from './user-category/schema.json';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
'user-category': {
|
|
5
|
-
schema: userCategory
|
|
6
|
-
}
|
|
7
|
-
};
|
|
1
|
+
import userCategory from './user-category/schema.json';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
'user-category': {
|
|
5
|
+
schema: userCategory
|
|
6
|
+
}
|
|
7
|
+
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"kind": "collectionType",
|
|
3
|
-
"collectionName": "user-categories",
|
|
4
|
-
"info": {
|
|
5
|
-
"singularName": "user-category",
|
|
6
|
-
"pluralName": "user-categories",
|
|
7
|
-
"displayName": "User Categories"
|
|
8
|
-
},
|
|
9
|
-
"options": {
|
|
10
|
-
"draftAndPublish": false,
|
|
11
|
-
"comment": ""
|
|
12
|
-
},
|
|
13
|
-
"attributes": {
|
|
14
|
-
"title": {
|
|
15
|
-
"type": "string"
|
|
16
|
-
},
|
|
17
|
-
"platform": {
|
|
18
|
-
"type": "relation",
|
|
19
|
-
"relation": "oneToOne",
|
|
20
|
-
"target": "api::platform.platform"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"kind": "collectionType",
|
|
3
|
+
"collectionName": "user-categories",
|
|
4
|
+
"info": {
|
|
5
|
+
"singularName": "user-category",
|
|
6
|
+
"pluralName": "user-categories",
|
|
7
|
+
"displayName": "User Categories"
|
|
8
|
+
},
|
|
9
|
+
"options": {
|
|
10
|
+
"draftAndPublish": false,
|
|
11
|
+
"comment": ""
|
|
12
|
+
},
|
|
13
|
+
"attributes": {
|
|
14
|
+
"title": {
|
|
15
|
+
"type": "string"
|
|
16
|
+
},
|
|
17
|
+
"platform": {
|
|
18
|
+
"type": "relation",
|
|
19
|
+
"relation": "oneToOne",
|
|
20
|
+
"target": "api::platform.platform"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { Strapi } from '@strapi/strapi';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
async hasPageRelation(ctx: any) {
|
|
5
|
-
const uid = ctx.params?.uid;
|
|
6
|
-
|
|
7
|
-
return (strapi as Strapi).service('plugin::page-builder.collection-types').hasPageRelation(uid);
|
|
8
|
-
},
|
|
9
|
-
async hasPlatformRelation(ctx: any) {
|
|
10
|
-
const uid = ctx.params?.uid;
|
|
11
|
-
|
|
12
|
-
return (strapi as Strapi).service('plugin::page-builder.collection-types').hasPlatformRelation(uid);
|
|
13
|
-
},
|
|
14
|
-
async getTranslationPageLinks(ctx: any): Promise<IGetTranslationPageLinks[] | undefined> {
|
|
15
|
-
const { uid, ids } = ctx.params || {};
|
|
16
|
-
const idsArr = (ids as string)
|
|
17
|
-
?.split(',')
|
|
18
|
-
.map(Number)
|
|
19
|
-
.filter((x) => !isNaN(x));
|
|
20
|
-
|
|
21
|
-
if (!uid || idsArr?.length === 0) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return (strapi as Strapi).service('plugin::page-builder.collection-types').getTranslationPageLinks(uid, idsArr);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export interface IGetTranslationPageLinks {
|
|
30
|
-
id: number;
|
|
31
|
-
locale: string;
|
|
32
|
-
}
|
|
1
|
+
import { Strapi } from '@strapi/strapi';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
async hasPageRelation(ctx: any) {
|
|
5
|
+
const uid = ctx.params?.uid;
|
|
6
|
+
|
|
7
|
+
return (strapi as Strapi).service('plugin::page-builder.collection-types').hasPageRelation(uid);
|
|
8
|
+
},
|
|
9
|
+
async hasPlatformRelation(ctx: any) {
|
|
10
|
+
const uid = ctx.params?.uid;
|
|
11
|
+
|
|
12
|
+
return (strapi as Strapi).service('plugin::page-builder.collection-types').hasPlatformRelation(uid);
|
|
13
|
+
},
|
|
14
|
+
async getTranslationPageLinks(ctx: any): Promise<IGetTranslationPageLinks[] | undefined> {
|
|
15
|
+
const { uid, ids } = ctx.params || {};
|
|
16
|
+
const idsArr = (ids as string)
|
|
17
|
+
?.split(',')
|
|
18
|
+
.map(Number)
|
|
19
|
+
.filter((x) => !isNaN(x));
|
|
20
|
+
|
|
21
|
+
if (!uid || idsArr?.length === 0) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return (strapi as Strapi).service('plugin::page-builder.collection-types').getTranslationPageLinks(uid, idsArr);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export interface IGetTranslationPageLinks {
|
|
30
|
+
id: number;
|
|
31
|
+
locale: string;
|
|
32
|
+
}
|