@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.
package/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",
@@ -33,27 +33,31 @@ export default async ({ strapi }: { strapi: Strapi }) => {
33
33
  populate: '*'
34
34
  })) as Record<string, any>[];
35
35
 
36
- // checks which role the user has
37
- const foundRole = roles.filter((role) => {
38
- return x.roles.find((userRole) => userRole.name === role.name);
39
- });
36
+ // checks which roles the user has
37
+ const foundRoles = roles.filter((role) => x.roles.find((userRole) => userRole.name === role.name));
38
+
39
+ // Get all permissions from the roles the user has
40
+ const allPermissions = [foundRoles?.[0]]
41
+ .map((role) => role?.permissions)
42
+ .flat()
43
+ .filter(Boolean);
40
44
 
41
45
  // get the right platform permissions, and filters out the platform
42
46
  // this is neccesary because of multiple platforms. if you can see Vacancy from platform 1 and collegue from platform 2
43
47
  // it will show both at page level, so this filters out the wrong page
44
- const platformPermission = foundRole?.[0]?.permissions.map((permission) => {
45
- return {
46
- permission: permission.subject,
47
- condition: permission.conditions.filter((condition) => condition.includes(platform.title))
48
- };
49
- });
50
-
51
- // get the right permission for platform
52
- const permissions = platformPermission.map((permission) => {
53
- if (permission.condition.length > 0) {
54
- return permission.permission;
55
- }
56
- });
48
+ const platformPermission = allPermissions.map((permission) => ({
49
+ subject: permission.subject,
50
+ conditions: permission?.conditions.filter((condition) => condition.includes(platform.title))
51
+ }));
52
+
53
+ // Get the right permission for platform
54
+ const permissions = platformPermission
55
+ .map((permission) => {
56
+ if (permission.conditions.length > 0) {
57
+ return permission.subject;
58
+ }
59
+ })
60
+ .filter(Boolean);
57
61
 
58
62
  const uniquePermissions = uniq(permissions);
59
63
 
@@ -36,23 +36,32 @@ export default async ({ strapi }: { strapi: Strapi }) => {
36
36
  models: [USER_PERMISSION_USER_PLUGIN],
37
37
  async beforeUpdate(event) {
38
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
- });
39
+ const originalUserObject = await strapi.entityService?.findOne(
40
+ USER_PERMISSION_USER_PLUGIN,
41
+ event.params.data.id,
42
+ {
43
+ populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
55
44
  }
45
+ );
46
+
47
+ if (
48
+ originalUserObject &&
49
+ event.params.data.activateUser &&
50
+ event.params.data.confirmed &&
51
+ !originalUserObject.confirmMailSend
52
+ ) {
53
+ await strapi.service(PAGE_BUILDER_EMAIL_PLUGIN).sendMail({
54
+ // @ts-ignore strapi typings
55
+ from: originalUserObject.platform.platformEmails.accountAcceptedMail.fromEmail,
56
+ to: event.params.data.email,
57
+ // @ts-ignore
58
+ subject: originalUserObject.platform.platformEmails.accountAcceptedMail.subject,
59
+ // @ts-ignore
60
+ text: originalUserObject.platform.platformEmails.accountAcceptedMail.message,
61
+ firstName: event.params.data.firstName,
62
+ lastName: event.params.data.lastName
63
+ });
64
+ event.params.data.confirmMailSend = true;
56
65
  }
57
66
  }
58
67
  }
@@ -7,7 +7,7 @@ export default {
7
7
  const callbackUrl = `${user.platform.domain}/inloggen`;
8
8
  return ctx.redirect(callbackUrl);
9
9
  } catch (error) {
10
- console.log(ctx);
10
+ console.log('Activate User Error', error, ctx);
11
11
  return ctx.unauthorized('User is already confirmed or token is invalid');
12
12
  }
13
13
  },
@@ -1,6 +1,7 @@
1
1
  import * as AWS from '@aws-sdk/client-ses';
2
2
  import { txtEmail } from './private-content/mail-template/txtMail.email.template.text';
3
3
  import { USER_PERMISSION_USER_PLUGIN } from '../../shared/utils/constants';
4
+ import { errors } from '@strapi/utils';
4
5
 
5
6
  interface SendOptions {
6
7
  from: string;
@@ -32,6 +33,7 @@ export default {
32
33
  });
33
34
  } catch (error) {
34
35
  console.error(error);
36
+ throw new errors.ApplicationError('Failed to send email', error);
35
37
  }
36
38
  },
37
39
  async sendAdminMail(user) {