@webbio/strapi-plugin-page-builder 0.12.2-platform → 0.12.3-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.
Files changed (172) hide show
  1. package/README.md +166 -166
  2. package/admin/src/api/collection-type.ts +111 -111
  3. package/admin/src/api/entity-relation.ts +42 -42
  4. package/admin/src/api/has-page-relation.ts +37 -37
  5. package/admin/src/api/has-platform-relation.ts +40 -40
  6. package/admin/src/api/page-type-relation.ts +41 -41
  7. package/admin/src/api/platform-page-types.ts +45 -45
  8. package/admin/src/api/platform-relation.ts +42 -42
  9. package/admin/src/api/platform.ts +35 -35
  10. package/admin/src/api/search-filtered-entity.ts +114 -114
  11. package/admin/src/api/template.ts +39 -39
  12. package/admin/src/components/Combobox/index.tsx +83 -83
  13. package/admin/src/components/Combobox/react-select-custom-styles.tsx +121 -121
  14. package/admin/src/components/Combobox/styles.ts +46 -46
  15. package/admin/src/components/ConfirmModal/index.tsx +90 -90
  16. package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +127 -127
  17. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +149 -149
  18. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/styles.ts +19 -19
  19. package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +82 -82
  20. package/admin/src/components/EditView/Details/index.tsx +48 -48
  21. package/admin/src/components/EditView/Details/styles.ts +51 -51
  22. package/admin/src/components/EditView/PageSettings/index.tsx +124 -124
  23. package/admin/src/components/EditView/Platform/platform-select.tsx +30 -30
  24. package/admin/src/components/EditView/Template/TemplateConfirmModal/index.tsx +36 -36
  25. package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +70 -70
  26. package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +41 -41
  27. package/admin/src/components/EditView/index.tsx +35 -35
  28. package/admin/src/components/EditView/page-type-select.tsx +32 -32
  29. package/admin/src/components/EditView/wrapper.tsx +41 -41
  30. package/admin/src/components/GlobalPlatformSelect/index.tsx +40 -40
  31. package/admin/src/components/GlobalPlatformSelect/styles.ts +27 -27
  32. package/admin/src/components/Initializer/index.tsx +24 -24
  33. package/admin/src/components/PageFilters/PageTypeFilter/index.tsx +39 -39
  34. package/admin/src/components/PageFilters/PlatformFilter/index.tsx +32 -32
  35. package/admin/src/components/PageFilters/filters.tsx +189 -189
  36. package/admin/src/components/PageFilters/index.tsx +35 -35
  37. package/admin/src/components/PageTypeEditView/TemplatePlatformSelect/index.tsx +76 -76
  38. package/admin/src/components/PageTypeEditView/index.tsx +53 -53
  39. package/admin/src/components/PlatformFilteredSelectField/InputIcon/index.tsx +23 -23
  40. package/admin/src/components/PlatformFilteredSelectField/Multi/index.tsx +210 -210
  41. package/admin/src/components/PlatformFilteredSelectField/Single/index.tsx +197 -197
  42. package/admin/src/components/PlatformFilteredSelectField/hooks/useRelationLoad.tsx +128 -128
  43. package/admin/src/components/PlatformFilteredSelectField/index.tsx +85 -85
  44. package/admin/src/components/PlatformFilteredSelectField/styles.tsx +77 -77
  45. package/admin/src/components/PlatformFilteredSelectField/utils/get-translations.ts +3 -3
  46. package/admin/src/components/PlatformFilteredSelectField/utils/relation-helper.ts +147 -147
  47. package/admin/src/components/PluginIcon/index.tsx +94 -94
  48. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/RelationInput.tsx +689 -689
  49. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/RelationInputDataManager.tsx +6 -6
  50. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/useRelation.ts +170 -170
  51. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/utils/getRelationLink.ts +5 -5
  52. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/utils/normalizeRelations.ts +52 -52
  53. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/constants/attributes.ts +3 -3
  54. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/useDragAndDrop.ts +253 -253
  55. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/useKeyboardDragAndDrop.ts +96 -96
  56. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/usePrev.ts +11 -11
  57. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/dragAndDrop.ts +8 -8
  58. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/paths.ts +29 -29
  59. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/refs.ts +19 -19
  60. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/translations.ts +3 -3
  61. package/admin/src/components/StrapiCore/content-manager/shared/contracts/collection-types.ts +300 -300
  62. package/admin/src/components/StrapiCore/content-manager/shared/contracts/components.ts +72 -72
  63. package/admin/src/components/StrapiCore/content-manager/shared/contracts/content-types.ts +116 -116
  64. package/admin/src/components/StrapiCore/content-manager/shared/contracts/index.ts +8 -8
  65. package/admin/src/components/StrapiCore/content-manager/shared/contracts/init.ts +22 -22
  66. package/admin/src/components/StrapiCore/content-manager/shared/contracts/relations.ts +80 -80
  67. package/admin/src/components/StrapiCore/content-manager/shared/contracts/review-workflows.ts +88 -88
  68. package/admin/src/components/StrapiCore/content-manager/shared/contracts/single-types.ts +112 -112
  69. package/admin/src/components/StrapiCore/content-manager/shared/contracts/uid.ts +48 -48
  70. package/admin/src/components/StrapiCore/content-manager/shared/index.ts +1 -1
  71. package/admin/src/constants.ts +3 -3
  72. package/admin/src/index.tsx +101 -101
  73. package/admin/src/middlewares/index.tsx +37 -37
  74. package/admin/src/pages/app/index.tsx +14 -14
  75. package/admin/src/pluginId.ts +5 -5
  76. package/admin/src/translations/en.json +9 -9
  77. package/admin/src/translations/nl.json +9 -9
  78. package/admin/src/utils/findDomElement.ts +6 -6
  79. package/admin/src/utils/findElementParent.ts +20 -20
  80. package/admin/src/utils/getObjectFromFormName.ts +42 -42
  81. package/admin/src/utils/getRequestUrl.ts +11 -11
  82. package/admin/src/utils/getTrad.ts +5 -5
  83. package/admin/src/utils/hooks/useDebounce.ts +17 -17
  84. package/admin/src/utils/hooks/useDefaultPlatformFromLocalStorage.ts +61 -61
  85. package/admin/src/utils/hooks/useGetLocaleFromUrl.ts +9 -9
  86. package/admin/src/utils/hooks/useHideOverviewFilterTags.ts +34 -34
  87. package/admin/src/utils/hooks/usePlatformFormData.ts +64 -64
  88. package/admin/src/utils/hooks/usePrevious.ts +12 -12
  89. package/admin/src/utils/sanitizeModules.ts +93 -93
  90. package/custom.d.ts +6 -6
  91. package/dist/package.json +1 -1
  92. package/dist/server/bootstrap.js +1 -1
  93. package/dist/server/graphql/page-by-path.js +20 -17
  94. package/dist/server/graphql/pages-by-uid.js +5 -5
  95. package/dist/server/services/private-content/graphql/index.js +27 -27
  96. package/dist/server/services/private-content/graphql/types/index.js +74 -74
  97. package/dist/tsconfig.server.tsbuildinfo +1 -1
  98. package/package.json +78 -78
  99. package/server/bootstrap/collection-type-lifecycles.ts +47 -47
  100. package/server/bootstrap/permissions.ts +161 -161
  101. package/server/bootstrap.ts +261 -261
  102. package/server/config/index.ts +4 -4
  103. package/server/content-types/index.ts +7 -7
  104. package/server/content-types/user-category/schema.json +23 -23
  105. package/server/controllers/collection-types.ts +32 -32
  106. package/server/controllers/index.ts +19 -19
  107. package/server/controllers/page-type.ts +18 -18
  108. package/server/controllers/page.ts +9 -9
  109. package/server/controllers/platform.ts +21 -21
  110. package/server/controllers/private-content.ts +17 -17
  111. package/server/controllers/sitemap.ts +32 -32
  112. package/server/controllers/template.ts +16 -16
  113. package/server/controllers/user-category.ts +3 -3
  114. package/server/destroy.ts +5 -5
  115. package/server/graphql/index.ts +9 -9
  116. package/server/graphql/page-by-path.ts +135 -132
  117. package/server/graphql/page-type.ts +67 -67
  118. package/server/graphql/pages-by-uid.ts +89 -89
  119. package/server/index.ts +23 -23
  120. package/server/middlewares/index.ts +1 -1
  121. package/server/policies/index.ts +5 -5
  122. package/server/policies/isAuthorizedPage.ts +11 -11
  123. package/server/register.ts +22 -22
  124. package/server/routes/index.ts +115 -115
  125. package/server/routes/user-category.ts +3 -3
  126. package/server/schema/page-end.json +96 -96
  127. package/server/schema/page-start.json +87 -87
  128. package/server/schema/page-type-end.json +53 -53
  129. package/server/schema/page-type-start.json +38 -38
  130. package/server/schema/platform-start.json +21 -21
  131. package/server/schema/template-end.json +40 -40
  132. package/server/schema/template-start.json +35 -35
  133. package/server/services/builder.ts +232 -232
  134. package/server/services/collection-types.ts +95 -95
  135. package/server/services/email.ts +127 -127
  136. package/server/services/index.ts +23 -23
  137. package/server/services/page-type.ts +30 -30
  138. package/server/services/page.ts +24 -24
  139. package/server/services/platform.ts +30 -30
  140. package/server/services/private-content/components/admin-email.json +22 -22
  141. package/server/services/private-content/components/email.json +22 -22
  142. package/server/services/private-content/components/platform-email.json +30 -30
  143. package/server/services/private-content/constants/index.ts +13 -13
  144. package/server/services/private-content/graphql/index.ts +88 -88
  145. package/server/services/private-content/graphql/resolvers/findOnePage.ts +40 -40
  146. package/server/services/private-content/graphql/resolvers/findPage.ts +45 -45
  147. package/server/services/private-content/graphql/resolvers/forgot-password.ts +34 -34
  148. package/server/services/private-content/graphql/resolvers/login.ts +56 -56
  149. package/server/services/private-content/graphql/resolvers/register.ts +78 -78
  150. package/server/services/private-content/graphql/resolvers/reset-password.ts +44 -44
  151. package/server/services/private-content/graphql/types/index.ts +96 -96
  152. package/server/services/private-content/index.ts +95 -95
  153. package/server/services/private-content/mail-template/txtMail.email.template.text.ts +6 -6
  154. package/server/services/private-content/page.ts +20 -20
  155. package/server/services/private-content/platform.ts +19 -19
  156. package/server/services/private-content/schemas/index.ts +28 -28
  157. package/server/services/private-content/user.ts +197 -197
  158. package/server/services/sitemap.ts +83 -83
  159. package/server/services/template.ts +13 -13
  160. package/server/services/user-category.ts +3 -3
  161. package/server/utils/filter-underscore-arguments.ts +12 -12
  162. package/server/utils/reload-strapi-on-load.ts +13 -13
  163. package/server/utils/strapi.ts +50 -50
  164. package/shared/utils/constants.ts +8 -8
  165. package/shared/utils/sleep.ts +1 -1
  166. package/strapi-admin.js +3 -3
  167. package/strapi-server.js +3 -3
  168. package/tsconfig.json +20 -20
  169. package/tsconfig.server.json +25 -25
  170. package/dist/server/graphql/page-by-slug.js +0 -89
  171. package/dist/server/utils/graphql.js +0 -100
  172. package/dist/server/utils/paginationValidation.js +0 -31
@@ -1,197 +1,197 @@
1
- import toString from 'lodash/toString';
2
- import has from 'lodash/has';
3
- import omit from 'lodash/omit';
4
- import { errors } from '@strapi/utils';
5
- import {
6
- ACTIONS,
7
- CONTENT_ENTITY_MANAGER,
8
- CREATED_BY_ATTRIBUTE,
9
- UPDATED_BY_ATTRIBUTE,
10
- USER_CONTENT_MANAGER,
11
- USER_MODEL,
12
- USER_ROLE
13
- } from './constants';
14
-
15
- const { ApplicationError, ValidationError, NotFoundError, ForbiddenError } = errors;
16
-
17
- export const extendUser = () => {
18
- const userContentType = strapi.contentType(USER_MODEL);
19
- userContentType.attributes = {
20
- // Spread previous defined attributes
21
- ...userContentType.attributes,
22
- // Add new, or override attributes
23
- platform: {
24
- type: 'relation',
25
- relation: 'oneToOne',
26
- target: 'api::platform.platform',
27
- required: true
28
- },
29
- firstName: {
30
- type: 'string'
31
- },
32
- lastName: {
33
- type: 'string'
34
- },
35
- company: {
36
- type: 'string'
37
- },
38
- jobTitle: {
39
- type: 'string'
40
- },
41
- address: {
42
- type: 'string'
43
- },
44
- postalCode: {
45
- type: 'string'
46
- },
47
- city: {
48
- type: 'string'
49
- },
50
- country: {
51
- type: 'string'
52
- },
53
- phone: {
54
- type: 'string'
55
- },
56
- activateUser: {
57
- type: 'boolean',
58
- default: false
59
- },
60
- categories: {
61
- type: 'relation',
62
- relation: 'oneToMany',
63
- target: 'plugin::page-builder.user-category'
64
- },
65
- filteredCategories: {
66
- pluginOptions: {
67
- filteredSelect: {
68
- targetField: 'categories'
69
- }
70
- },
71
- // @ts-expect-error
72
- type: 'customField',
73
- customField: 'plugin::page-builder.filtered-select'
74
- },
75
- confirmMailSend: {
76
- type: 'boolean',
77
- private: true,
78
- writable: false,
79
- visible: false,
80
- default: false
81
- }
82
- };
83
- delete userContentType.attributes.username;
84
- };
85
-
86
- export const extendControllers = () => {
87
- const contentController = strapi.controller(USER_CONTENT_MANAGER);
88
- contentController.create = async (ctx: any) => {
89
- const { body } = ctx.request;
90
- const { user: admin, userAbility } = ctx.state;
91
-
92
- const { email } = body;
93
- const platformId = body.platform.connect[0].id;
94
-
95
- const pm = strapi?.admin?.services.permission.createPermissionsManager({
96
- ability: userAbility,
97
- action: ACTIONS.create,
98
- model: USER_MODEL
99
- });
100
-
101
- if (!pm.isAllowed) {
102
- return ctx.forbidden();
103
- }
104
-
105
- const sanitizedBody = await pm.pickPermittedFieldsOf(body, { subject: USER_MODEL });
106
-
107
- const userWithSameEmail = await strapi.query(USER_MODEL).findOne({
108
- where: { $and: [{ email: email.toLowerCase() }, { platform: { id: platformId } }] }
109
- });
110
-
111
- if (userWithSameEmail) {
112
- throw new ApplicationError('Email already taken');
113
- }
114
-
115
- const user = {
116
- ...sanitizedBody,
117
- provider: 'local',
118
- [CREATED_BY_ATTRIBUTE]: admin.id,
119
- [UPDATED_BY_ATTRIBUTE]: admin.id
120
- };
121
-
122
- user.email = user.email.toLowerCase();
123
-
124
- const advanced = await strapi?.store({ type: 'plugin', name: 'users-permissions', key: 'advanced' }).get({});
125
-
126
- if (user.role.connect.length === 0) {
127
- //@ts-ignore strapi types...
128
- const defaultRole = await strapi.query(USER_ROLE).findOne({ where: { type: advanced.default_role } });
129
- user.role = defaultRole.id;
130
- }
131
-
132
- try {
133
- const data = await strapi.service(CONTENT_ENTITY_MANAGER).create(user, USER_MODEL);
134
- const sanitizedData = await pm.sanitizeOutput(data, { action: ACTIONS.read });
135
-
136
- ctx.created(sanitizedData);
137
- } catch (error) {
138
- throw new ApplicationError(error.message);
139
- }
140
- };
141
- contentController.update = async (ctx: any) => {
142
- const { id } = ctx.params;
143
- const { body } = ctx.request;
144
- const { user: admin, userAbility } = ctx.state;
145
-
146
- const { email, password } = body;
147
-
148
- const { pm, entity } = await findEntityAndCheckPermissions(userAbility, ACTIONS.edit, USER_MODEL, id);
149
- const user = entity;
150
-
151
- const platformId = body.platform.connect.length > 0 ? body.platform.connect[0].id : entity.platform.id;
152
-
153
- if (has(body, 'password') && !password && user.provider === 'local') {
154
- throw new ValidationError('password.notNull');
155
- }
156
-
157
- //@ts-ignore
158
- if (has(body, 'email')) {
159
- const userWithSameEmail = await strapi
160
- .query(USER_MODEL)
161
- .findOne({ where: { $and: [{ email: email.toLowerCase() }, { platform: { id: platformId } }] } });
162
-
163
- if (userWithSameEmail && toString(userWithSameEmail.id) !== toString(id)) {
164
- throw new ApplicationError('Email already taken');
165
- }
166
- body.email = body.email.toLowerCase();
167
- }
168
-
169
- const sanitizedData = await pm.pickPermittedFieldsOf(body, { subject: pm.toSubject(user) });
170
- const updateData = omit({ ...sanitizedData, updatedBy: admin.id }, 'createdBy');
171
-
172
- const data = await strapi.service('plugin::content-manager.entity-manager').update({ id }, updateData, USER_MODEL);
173
-
174
- ctx.body = await pm.sanitizeOutput(data, { action: ACTIONS.read });
175
- };
176
- };
177
-
178
- const findEntityAndCheckPermissions = async (ability, action, model, id) => {
179
- const entity = await strapi.query(USER_MODEL).findOne({
180
- where: { id },
181
- populate: [`${CREATED_BY_ATTRIBUTE}.roles`, 'platform']
182
- });
183
-
184
- if (!entity) {
185
- throw new NotFoundError();
186
- }
187
-
188
- const pm = strapi.admin.services.permission.createPermissionsManager({ ability, action, model });
189
-
190
- if (pm.ability.cannot(pm.action, pm.toSubject(entity))) {
191
- throw new ForbiddenError();
192
- }
193
-
194
- const entityWithoutCreatorRoles = omit(entity, `${CREATED_BY_ATTRIBUTE}.roles`);
195
-
196
- return { pm, entity: entityWithoutCreatorRoles };
197
- };
1
+ import toString from 'lodash/toString';
2
+ import has from 'lodash/has';
3
+ import omit from 'lodash/omit';
4
+ import { errors } from '@strapi/utils';
5
+ import {
6
+ ACTIONS,
7
+ CONTENT_ENTITY_MANAGER,
8
+ CREATED_BY_ATTRIBUTE,
9
+ UPDATED_BY_ATTRIBUTE,
10
+ USER_CONTENT_MANAGER,
11
+ USER_MODEL,
12
+ USER_ROLE
13
+ } from './constants';
14
+
15
+ const { ApplicationError, ValidationError, NotFoundError, ForbiddenError } = errors;
16
+
17
+ export const extendUser = () => {
18
+ const userContentType = strapi.contentType(USER_MODEL);
19
+ userContentType.attributes = {
20
+ // Spread previous defined attributes
21
+ ...userContentType.attributes,
22
+ // Add new, or override attributes
23
+ platform: {
24
+ type: 'relation',
25
+ relation: 'oneToOne',
26
+ target: 'api::platform.platform',
27
+ required: true
28
+ },
29
+ firstName: {
30
+ type: 'string'
31
+ },
32
+ lastName: {
33
+ type: 'string'
34
+ },
35
+ company: {
36
+ type: 'string'
37
+ },
38
+ jobTitle: {
39
+ type: 'string'
40
+ },
41
+ address: {
42
+ type: 'string'
43
+ },
44
+ postalCode: {
45
+ type: 'string'
46
+ },
47
+ city: {
48
+ type: 'string'
49
+ },
50
+ country: {
51
+ type: 'string'
52
+ },
53
+ phone: {
54
+ type: 'string'
55
+ },
56
+ activateUser: {
57
+ type: 'boolean',
58
+ default: false
59
+ },
60
+ categories: {
61
+ type: 'relation',
62
+ relation: 'oneToMany',
63
+ target: 'plugin::page-builder.user-category'
64
+ },
65
+ filteredCategories: {
66
+ pluginOptions: {
67
+ filteredSelect: {
68
+ targetField: 'categories'
69
+ }
70
+ },
71
+ // @ts-expect-error
72
+ type: 'customField',
73
+ customField: 'plugin::page-builder.filtered-select'
74
+ },
75
+ confirmMailSend: {
76
+ type: 'boolean',
77
+ private: true,
78
+ writable: false,
79
+ visible: false,
80
+ default: false
81
+ }
82
+ };
83
+ delete userContentType.attributes.username;
84
+ };
85
+
86
+ export const extendControllers = () => {
87
+ const contentController = strapi.controller(USER_CONTENT_MANAGER);
88
+ contentController.create = async (ctx: any) => {
89
+ const { body } = ctx.request;
90
+ const { user: admin, userAbility } = ctx.state;
91
+
92
+ const { email } = body;
93
+ const platformId = body.platform.connect[0].id;
94
+
95
+ const pm = strapi?.admin?.services.permission.createPermissionsManager({
96
+ ability: userAbility,
97
+ action: ACTIONS.create,
98
+ model: USER_MODEL
99
+ });
100
+
101
+ if (!pm.isAllowed) {
102
+ return ctx.forbidden();
103
+ }
104
+
105
+ const sanitizedBody = await pm.pickPermittedFieldsOf(body, { subject: USER_MODEL });
106
+
107
+ const userWithSameEmail = await strapi.query(USER_MODEL).findOne({
108
+ where: { $and: [{ email: email.toLowerCase() }, { platform: { id: platformId } }] }
109
+ });
110
+
111
+ if (userWithSameEmail) {
112
+ throw new ApplicationError('Email already taken');
113
+ }
114
+
115
+ const user = {
116
+ ...sanitizedBody,
117
+ provider: 'local',
118
+ [CREATED_BY_ATTRIBUTE]: admin.id,
119
+ [UPDATED_BY_ATTRIBUTE]: admin.id
120
+ };
121
+
122
+ user.email = user.email.toLowerCase();
123
+
124
+ const advanced = await strapi?.store({ type: 'plugin', name: 'users-permissions', key: 'advanced' }).get({});
125
+
126
+ if (user.role.connect.length === 0) {
127
+ //@ts-ignore strapi types...
128
+ const defaultRole = await strapi.query(USER_ROLE).findOne({ where: { type: advanced.default_role } });
129
+ user.role = defaultRole.id;
130
+ }
131
+
132
+ try {
133
+ const data = await strapi.service(CONTENT_ENTITY_MANAGER).create(user, USER_MODEL);
134
+ const sanitizedData = await pm.sanitizeOutput(data, { action: ACTIONS.read });
135
+
136
+ ctx.created(sanitizedData);
137
+ } catch (error) {
138
+ throw new ApplicationError(error.message);
139
+ }
140
+ };
141
+ contentController.update = async (ctx: any) => {
142
+ const { id } = ctx.params;
143
+ const { body } = ctx.request;
144
+ const { user: admin, userAbility } = ctx.state;
145
+
146
+ const { email, password } = body;
147
+
148
+ const { pm, entity } = await findEntityAndCheckPermissions(userAbility, ACTIONS.edit, USER_MODEL, id);
149
+ const user = entity;
150
+
151
+ const platformId = body.platform.connect.length > 0 ? body.platform.connect[0].id : entity.platform.id;
152
+
153
+ if (has(body, 'password') && !password && user.provider === 'local') {
154
+ throw new ValidationError('password.notNull');
155
+ }
156
+
157
+ //@ts-ignore
158
+ if (has(body, 'email')) {
159
+ const userWithSameEmail = await strapi
160
+ .query(USER_MODEL)
161
+ .findOne({ where: { $and: [{ email: email.toLowerCase() }, { platform: { id: platformId } }] } });
162
+
163
+ if (userWithSameEmail && toString(userWithSameEmail.id) !== toString(id)) {
164
+ throw new ApplicationError('Email already taken');
165
+ }
166
+ body.email = body.email.toLowerCase();
167
+ }
168
+
169
+ const sanitizedData = await pm.pickPermittedFieldsOf(body, { subject: pm.toSubject(user) });
170
+ const updateData = omit({ ...sanitizedData, updatedBy: admin.id }, 'createdBy');
171
+
172
+ const data = await strapi.service('plugin::content-manager.entity-manager').update({ id }, updateData, USER_MODEL);
173
+
174
+ ctx.body = await pm.sanitizeOutput(data, { action: ACTIONS.read });
175
+ };
176
+ };
177
+
178
+ const findEntityAndCheckPermissions = async (ability, action, model, id) => {
179
+ const entity = await strapi.query(USER_MODEL).findOne({
180
+ where: { id },
181
+ populate: [`${CREATED_BY_ATTRIBUTE}.roles`, 'platform']
182
+ });
183
+
184
+ if (!entity) {
185
+ throw new NotFoundError();
186
+ }
187
+
188
+ const pm = strapi.admin.services.permission.createPermissionsManager({ ability, action, model });
189
+
190
+ if (pm.ability.cannot(pm.action, pm.toSubject(entity))) {
191
+ throw new ForbiddenError();
192
+ }
193
+
194
+ const entityWithoutCreatorRoles = omit(entity, `${CREATED_BY_ATTRIBUTE}.roles`);
195
+
196
+ return { pm, entity: entityWithoutCreatorRoles };
197
+ };
@@ -1,83 +1,83 @@
1
- import { SitemapStream, streamToPromise } from 'sitemap';
2
- import { PAGE_UID } from '../../shared/utils/constants';
3
-
4
- export default {
5
- async generateSitemap(domain: string): Promise<string> {
6
- try {
7
- const entities: Array<{ path: string; updatedAt: string }> = await this.fetchPages(domain);
8
-
9
- if (entities.length === 0) {
10
- throw new Error('Cannot generate a sitemap with 0 pages');
11
- }
12
-
13
- const sitemapStream = new SitemapStream();
14
-
15
- for (const entity of entities) {
16
- const { path, updatedAt } = entity;
17
- const url = path === '/' ? domain : `${domain}/${path}`;
18
- sitemapStream.write({
19
- url,
20
- changefreq: 'always',
21
- lastmod: updatedAt,
22
- priority: 1
23
- });
24
- }
25
-
26
- sitemapStream.end();
27
-
28
- const sitemapPromise = await streamToPromise(sitemapStream);
29
- const sitemap = sitemapPromise.toString();
30
-
31
- return sitemap;
32
- } catch (error) {
33
- console.error(error);
34
- throw new Error(`Error generating sitemap for domain ${domain}`);
35
- }
36
- },
37
- async fetchPages(domain: string): Promise<Array<{ path: string; updatedAt: string }>> {
38
- const entities: Array<{ path: string; updatedAt: string }> = await strapi.query(PAGE_UID).findMany({
39
- select: ['path', 'updatedAt'],
40
- where: {
41
- $and: [
42
- {
43
- platform: {
44
- domain: {
45
- $eq: domain
46
- }
47
- }
48
- },
49
- {
50
- path: {
51
- $notNull: true
52
- }
53
- },
54
- {
55
- publishedAt: {
56
- $notNull: true
57
- }
58
- },
59
- {
60
- $or: [
61
- {
62
- seo: {
63
- metaRobots: {
64
- $notContainsi: 'noindex'
65
- }
66
- }
67
- },
68
- {
69
- seo: {
70
- metaRobots: {
71
- $null: true
72
- }
73
- }
74
- }
75
- ]
76
- }
77
- ]
78
- }
79
- });
80
-
81
- return entities;
82
- }
83
- };
1
+ import { SitemapStream, streamToPromise } from 'sitemap';
2
+ import { PAGE_UID } from '../../shared/utils/constants';
3
+
4
+ export default {
5
+ async generateSitemap(domain: string): Promise<string> {
6
+ try {
7
+ const entities: Array<{ path: string; updatedAt: string }> = await this.fetchPages(domain);
8
+
9
+ if (entities.length === 0) {
10
+ throw new Error('Cannot generate a sitemap with 0 pages');
11
+ }
12
+
13
+ const sitemapStream = new SitemapStream();
14
+
15
+ for (const entity of entities) {
16
+ const { path, updatedAt } = entity;
17
+ const url = path === '/' ? domain : `${domain}/${path}`;
18
+ sitemapStream.write({
19
+ url,
20
+ changefreq: 'always',
21
+ lastmod: updatedAt,
22
+ priority: 1
23
+ });
24
+ }
25
+
26
+ sitemapStream.end();
27
+
28
+ const sitemapPromise = await streamToPromise(sitemapStream);
29
+ const sitemap = sitemapPromise.toString();
30
+
31
+ return sitemap;
32
+ } catch (error) {
33
+ console.error(error);
34
+ throw new Error(`Error generating sitemap for domain ${domain}`);
35
+ }
36
+ },
37
+ async fetchPages(domain: string): Promise<Array<{ path: string; updatedAt: string }>> {
38
+ const entities: Array<{ path: string; updatedAt: string }> = await strapi.query(PAGE_UID).findMany({
39
+ select: ['path', 'updatedAt'],
40
+ where: {
41
+ $and: [
42
+ {
43
+ platform: {
44
+ domain: {
45
+ $eq: domain
46
+ }
47
+ }
48
+ },
49
+ {
50
+ path: {
51
+ $notNull: true
52
+ }
53
+ },
54
+ {
55
+ publishedAt: {
56
+ $notNull: true
57
+ }
58
+ },
59
+ {
60
+ $or: [
61
+ {
62
+ seo: {
63
+ metaRobots: {
64
+ $notContainsi: 'noindex'
65
+ }
66
+ }
67
+ },
68
+ {
69
+ seo: {
70
+ metaRobots: {
71
+ $null: true
72
+ }
73
+ }
74
+ }
75
+ ]
76
+ }
77
+ ]
78
+ }
79
+ });
80
+
81
+ return entities;
82
+ }
83
+ };
@@ -1,13 +1,13 @@
1
- import { getPopulatedEntity } from '../utils/strapi';
2
- import { TEMPLATE_UID } from '../../shared/utils/constants';
3
-
4
- export default {
5
- async findAll() {
6
- const foundTemplates = await strapi.entityService.findMany(TEMPLATE_UID);
7
-
8
- return foundTemplates;
9
- },
10
- async findOne(id: number) {
11
- return await getPopulatedEntity(TEMPLATE_UID, id);
12
- }
13
- };
1
+ import { getPopulatedEntity } from '../utils/strapi';
2
+ import { TEMPLATE_UID } from '../../shared/utils/constants';
3
+
4
+ export default {
5
+ async findAll() {
6
+ const foundTemplates = await strapi.entityService.findMany(TEMPLATE_UID);
7
+
8
+ return foundTemplates;
9
+ },
10
+ async findOne(id: number) {
11
+ return await getPopulatedEntity(TEMPLATE_UID, id);
12
+ }
13
+ };
@@ -1,3 +1,3 @@
1
- import { factories } from '@strapi/strapi';
2
-
3
- export default factories.createCoreService('plugin::page-builder.user-category');
1
+ import { factories } from '@strapi/strapi';
2
+
3
+ export default factories.createCoreService('plugin::page-builder.user-category');
@@ -1,12 +1,12 @@
1
- export const filterUnderscoreArguments = (args: Record<string, any>) => {
2
- const newArgs = {};
3
- const objectArray = Object.keys(args);
4
-
5
- objectArray.forEach((key) => {
6
- if (!key.startsWith('_')) {
7
- newArgs[key] = args[key];
8
- }
9
- });
10
-
11
- return newArgs;
12
- };
1
+ export const filterUnderscoreArguments = (args: Record<string, any>) => {
2
+ const newArgs = {};
3
+ const objectArray = Object.keys(args);
4
+
5
+ objectArray.forEach((key) => {
6
+ if (!key.startsWith('_')) {
7
+ newArgs[key] = args[key];
8
+ }
9
+ });
10
+
11
+ return newArgs;
12
+ };
@@ -1,13 +1,13 @@
1
- const reloadStrapiOnLoad = () => {
2
- console.log('[Plugin Page Builder]: Checking if strapi is loaded', strapi.isLoaded);
3
-
4
- if (strapi.isLoaded) {
5
- strapi.reload();
6
-
7
- return;
8
- }
9
-
10
- setTimeout(reloadStrapiOnLoad, 1000);
11
- };
12
-
13
- export { reloadStrapiOnLoad };
1
+ const reloadStrapiOnLoad = () => {
2
+ console.log('[Plugin Page Builder]: Checking if strapi is loaded', strapi.isLoaded);
3
+
4
+ if (strapi.isLoaded) {
5
+ strapi.reload();
6
+
7
+ return;
8
+ }
9
+
10
+ setTimeout(reloadStrapiOnLoad, 1000);
11
+ };
12
+
13
+ export { reloadStrapiOnLoad };