@webbio/strapi-plugin-page-builder 0.12.7-platform → 0.13.0-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.
@@ -0,0 +1,52 @@
1
+ import { parse, stringify } from 'qs';
2
+ import { useMemo, useCallback } from 'react';
3
+ import { useLocation, useHistory } from 'react-router-dom';
4
+
5
+ interface IUseQueryParamsObj {
6
+ query: Record<string, any>;
7
+ rawQuery: string;
8
+ }
9
+
10
+ type ISetQuery = (nextParams: Record<string, any>, method?: string, routerMethod?: string) => void;
11
+
12
+ // We created this as a copy of the useQueryParams hook from the Strapi plugin
13
+ // This one however supports the replace and push methods from the useHistory hook
14
+ const useQueryParams = (initialParams?: Record<string, any>): [IUseQueryParamsObj, ISetQuery] => {
15
+ const { search } = useLocation();
16
+ const { replace, push } = useHistory();
17
+
18
+ const query = useMemo(() => {
19
+ const searchQuery = search.substring(1);
20
+ if (!search) {
21
+ return initialParams || {};
22
+ }
23
+ return parse(searchQuery);
24
+ }, [search, initialParams]);
25
+
26
+ const setQuery = useCallback(
27
+ (nextParams: Record<string, any>, method = 'push', routerMethod = 'push') => {
28
+ let nextQuery = { ...query };
29
+ if (method === 'remove') {
30
+ Object.keys(nextParams).forEach((key) => {
31
+ if (Object.prototype.hasOwnProperty.call(nextQuery, key)) {
32
+ delete nextQuery[key];
33
+ }
34
+ });
35
+ } else {
36
+ nextQuery = { ...query, ...nextParams };
37
+ }
38
+ const props = { search: stringify(nextQuery, { encode: false }) };
39
+
40
+ if (routerMethod === 'replace') {
41
+ replace(props);
42
+ } else {
43
+ push(props);
44
+ }
45
+ },
46
+ [push, replace, query]
47
+ );
48
+
49
+ return [{ query, rawQuery: search }, setQuery];
50
+ };
51
+
52
+ export { useQueryParams };
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.12.7-platform",
3
+ "version": "0.13.0-platform",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -20,7 +20,7 @@ exports.default = async ({ strapi }) => {
20
20
  displayName,
21
21
  category: 'Platform',
22
22
  handler: async (x) => {
23
- var _a, _b, _c, _d;
23
+ var _a, _b, _c;
24
24
  if (((_a = x === null || x === void 0 ? void 0 : x.permission) === null || _a === void 0 ? void 0 : _a.subject) === 'api::platform.platform') {
25
25
  return {
26
26
  id: {
@@ -34,25 +34,28 @@ exports.default = async ({ strapi }) => {
34
34
  limit: -1,
35
35
  populate: '*'
36
36
  })));
37
- // checks which role the user has
38
- const foundRole = roles.filter((role) => {
39
- return x.roles.find((userRole) => userRole.name === role.name);
40
- });
37
+ // checks which roles the user has
38
+ const foundRoles = roles.filter((role) => x.roles.find((userRole) => userRole.name === role.name));
39
+ // Get all permissions from the roles the user has
40
+ const allPermissions = [foundRoles === null || foundRoles === void 0 ? void 0 : foundRoles[0]]
41
+ .map((role) => role === null || role === void 0 ? void 0 : role.permissions)
42
+ .flat()
43
+ .filter(Boolean);
41
44
  // get the right platform permissions, and filters out the platform
42
45
  // this is neccesary because of multiple platforms. if you can see Vacancy from platform 1 and collegue from platform 2
43
46
  // it will show both at page level, so this filters out the wrong page
44
- const platformPermission = (_d = foundRole === null || foundRole === void 0 ? void 0 : foundRole[0]) === null || _d === void 0 ? void 0 : _d.permissions.map((permission) => {
45
- return {
46
- permission: permission.subject,
47
- condition: permission.conditions.filter((condition) => condition.includes(platform.title))
48
- };
49
- });
50
- // get the right permission for platform
51
- const permissions = platformPermission.map((permission) => {
52
- if (permission.condition.length > 0) {
53
- return permission.permission;
47
+ const platformPermission = allPermissions.map((permission) => ({
48
+ subject: permission.subject,
49
+ conditions: permission === null || permission === void 0 ? void 0 : permission.conditions.filter((condition) => condition.includes(platform.title))
50
+ }));
51
+ // Get the right permission for platform
52
+ const permissions = platformPermission
53
+ .map((permission) => {
54
+ if (permission.conditions.length > 0) {
55
+ return permission.subject;
54
56
  }
55
- });
57
+ })
58
+ .filter(Boolean);
56
59
  const uniquePermissions = (0, uniq_1.default)(permissions);
57
60
  return {
58
61
  $and: [
@@ -30,23 +30,25 @@ exports.default = async ({ strapi }) => {
30
30
  async beforeUpdate(event) {
31
31
  var _a;
32
32
  if (event.params.data.id) {
33
- const userToUpdate = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findOne(constants_1.USER_PERMISSION_USER_PLUGIN, event.params.data.id, {
33
+ const originalUserObject = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findOne(constants_1.USER_PERMISSION_USER_PLUGIN, event.params.data.id, {
34
34
  populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
35
35
  }));
36
- if (userToUpdate) {
37
- if (event.params.data.activateUser && event.params.data.confirmed && !userToUpdate.confirmMailSend) {
38
- await strapi.service(constants_1.PAGE_BUILDER_EMAIL_PLUGIN).sendMail({
39
- // @ts-ignore strapi typings
40
- from: userToUpdate.platform.platformEmails.accountAcceptedMail.fromEmail,
41
- to: event.params.data.email,
42
- // @ts-ignore
43
- subject: userToUpdate.platform.platformEmails.accountAcceptedMail.subject,
44
- // @ts-ignore
45
- text: userToUpdate.platform.platformEmails.accountAcceptedMail.message,
46
- firstName: event.params.data.firstName,
47
- lastName: event.params.data.lastName
48
- });
49
- }
36
+ if (originalUserObject &&
37
+ event.params.data.activateUser &&
38
+ event.params.data.confirmed &&
39
+ !originalUserObject.confirmMailSend) {
40
+ await strapi.service(constants_1.PAGE_BUILDER_EMAIL_PLUGIN).sendMail({
41
+ // @ts-ignore strapi typings
42
+ from: originalUserObject.platform.platformEmails.accountAcceptedMail.fromEmail,
43
+ to: event.params.data.email,
44
+ // @ts-ignore
45
+ subject: originalUserObject.platform.platformEmails.accountAcceptedMail.subject,
46
+ // @ts-ignore
47
+ text: originalUserObject.platform.platformEmails.accountAcceptedMail.message,
48
+ firstName: event.params.data.firstName,
49
+ lastName: event.params.data.lastName
50
+ });
51
+ event.params.data.confirmMailSend = true;
50
52
  }
51
53
  }
52
54
  }
@@ -0,0 +1,18 @@
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
+ }
18
+ }
@@ -8,7 +8,7 @@ exports.default = {
8
8
  return ctx.redirect(callbackUrl);
9
9
  }
10
10
  catch (error) {
11
- console.log(ctx);
11
+ console.log('Activate User Error', error, ctx);
12
12
  return ctx.unauthorized('User is already confirmed or token is invalid');
13
13
  }
14
14
  },
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const AWS = __importStar(require("@aws-sdk/client-ses"));
27
27
  const txtMail_email_template_text_1 = require("./private-content/mail-template/txtMail.email.template.text");
28
28
  const constants_1 = require("../../shared/utils/constants");
29
+ const utils_1 = require("@strapi/utils");
29
30
  exports.default = {
30
31
  async sendMail(options) {
31
32
  const { from, to, subject, text, variables } = options;
@@ -47,6 +48,7 @@ exports.default = {
47
48
  }
48
49
  catch (error) {
49
50
  console.error(error);
51
+ throw new utils_1.errors.ApplicationError('Failed to send email', error);
50
52
  }
51
53
  },
52
54
  async sendAdminMail(user) {