@webbio/strapi-plugin-page-builder 0.9.1-platform → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.9.1-platform",
3
+ "version": "0.9.2-platform",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -1,107 +1,138 @@
1
1
  import { Strapi } from '@strapi/strapi';
2
- import { PAGE_TYPE_UID, PLATFORM_UID } from '../../shared/utils/constants';
2
+ import { PLATFORM_UID } from '../../shared/utils/constants';
3
3
 
4
4
  export default async ({ strapi }: { strapi: Strapi }) => {
5
5
  try {
6
- const pageTypes = (await strapi.entityService?.findMany(PAGE_TYPE_UID, {
7
- limit: -1
8
- })) as Record<string, any>[];
9
-
10
6
  const platforms = (await strapi.entityService?.findMany(PLATFORM_UID, {
11
7
  limit: -1
12
8
  })) as Record<string, any>[];
13
9
 
14
10
  const platformPagePermissions = platforms.map((platform) => {
15
- return pageTypes.map((pageType) => {
16
- const name = `platform-is-${platform.title}-${pageType.uid}`;
17
- const displayName = `${platform.title}-${pageType.title}`;
11
+ const name = `platform-is-${platform.title}`;
12
+ const displayName = platform.title;
18
13
 
19
- return {
20
- plugin: 'page-builder',
21
- name,
22
- displayName,
23
- category: `${platform.title} Page roles`,
24
- handler: async () => {
14
+ return {
15
+ plugin: 'page-builder',
16
+ name,
17
+ displayName,
18
+ category: `Platform`,
19
+ handler: async (x) => {
20
+ if (x?.permission?.subject === 'api::platform.platform') {
25
21
  return {
26
- $and: [
27
- {
28
- 'platform.id': {
29
- $eq: platform.id
30
- }
31
- },
32
- {
33
- 'pageType.uid': {
34
- $eq: pageType.uid
35
- }
36
- },
37
- {
38
- uid: {
39
- $eq: pageType.uid
40
- }
41
- }
42
- ]
22
+ id: {
23
+ $eq: platform.id
24
+ }
43
25
  };
44
26
  }
45
- };
46
- });
47
- });
48
27
 
49
- const pageTypePermissions = pageTypes.map((pageType) => {
50
- const name = `pageType-permission-${pageType.uid}`;
51
- const displayName = `pageType ${pageType.title}`;
28
+ if (x?.permission?.subject === 'api::page.page') {
29
+ try {
30
+ const roles = (await strapi.entityService?.findMany('admin::role', {
31
+ limit: -1,
32
+ populate: '*'
33
+ })) as Record<string, any>[];
52
34
 
53
- return {
54
- plugin: 'page-builder',
55
- name,
56
- displayName,
57
- category: `Platform pageType roles`,
58
- handler: async () => {
59
- return {
60
- uid: {
61
- $eq: pageType.uid
62
- }
63
- };
64
- }
65
- };
66
- });
35
+ // checks which role the user has
36
+ const foundRole = roles.filter((role) => {
37
+ return x.roles.find((userRole) => userRole.name === role.name);
38
+ });
67
39
 
68
- const platformCollectiontypePermissions = platforms.map((platform) => {
69
- const name = `platform-is-${platform.title}`;
70
- const displayName = platform.title;
40
+ // get the right platform permissions, and filters out the platform
41
+ // this is neccesary because of multiple platforms. if you can see Vacancy from platform 1 and collegue from platform 2
42
+ // it will show both at page level, so this filters out the wrong page
43
+ const platformPermission = foundRole?.[0]?.permissions.map((permission) => {
44
+ return {
45
+ permission: permission.subject,
46
+ condition: permission.conditions.filter((condition) => condition.includes(platform.title))
47
+ };
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;
54
+ }
55
+ });
56
+
57
+ return {
58
+ $and: [
59
+ {
60
+ 'platform.id': {
61
+ $eq: platform.id
62
+ }
63
+ },
64
+ {
65
+ 'pageType.uid': {
66
+ $in: permissions
67
+ }
68
+ }
69
+ ]
70
+ };
71
+ } catch (error) {
72
+ console.log(error);
73
+ }
74
+ }
71
75
 
72
- return {
73
- plugin: 'page-builder',
74
- name,
75
- displayName,
76
- category: 'Platform CollectionType roles',
77
- handler: async () => {
78
76
  return {
79
- $or: [
77
+ $and: [
80
78
  {
81
79
  'platform.id': {
82
80
  $eq: platform.id
83
81
  }
84
- },
85
- {
86
- id: {
87
- $eq: platform.id
88
- }
89
82
  }
90
83
  ]
91
84
  };
92
85
  }
93
86
  };
87
+ // });
94
88
  });
95
89
 
96
- const allPermissions = [
97
- ...platformPagePermissions.flat(),
98
- ...pageTypePermissions.flat(),
99
- ...platformCollectiontypePermissions
100
- ];
90
+ const allPermissions = [...platformPagePermissions.flat()];
101
91
 
102
92
  // @ts-ignore shitty types
103
93
  await strapi.admin.services.permission.conditionProvider.registerMany(allPermissions);
104
- } catch {
94
+ } catch (error) {
105
95
  console.log('Cannot set page permissions');
106
96
  }
107
97
  };
98
+
99
+ // Leave this commented code here, This might be used in the future to change up the permissions IF needed
100
+
101
+ // const platformPagePermissions = platforms.map((platform) => {
102
+ // const platformPageTypes = pageTypes.filter((pageType) => pageType.platform.id === platform.id);
103
+ // return platformPageTypes.map((pageType) => {
104
+ // const name = `platform-is-${platform.title}-${pageType.uid}`;
105
+ // const displayName = pageType.title;
106
+
107
+ // return {
108
+ // plugin: 'page-builder',
109
+ // name,
110
+ // displayName,
111
+ // category: `${platform.title} pageTypes`,
112
+ // handler: async (x) => {
113
+ // if (x?.permission?.subject === 'api::platform.platform') {
114
+ // return {
115
+ // id: {
116
+ // $eq: platform.id
117
+ // }
118
+ // };
119
+ // }
120
+
121
+ // return {
122
+ // $and: [
123
+ // {
124
+ // 'platform.id': {
125
+ // $eq: platform.id
126
+ // }
127
+ // },
128
+ // {
129
+ // 'pageType.uid': {
130
+ // $eq: pageType.uid
131
+ // }
132
+ // }
133
+ // ]
134
+ // };
135
+ // }
136
+ // };
137
+ // });
138
+ // });