@webbio/strapi-plugin-page-builder 0.3.2 → 0.3.4-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.3.2",
3
+ "version": "0.3.4-platform",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -1,5 +1,5 @@
1
1
  import { Strapi } from '@strapi/strapi';
2
- import { PAGE_TYPE_UID } from '../../shared/utils/constants';
2
+ import { PAGE_TYPE_UID, PLATFORM_UID } from '../../shared/utils/constants';
3
3
 
4
4
  export default async ({ strapi }: { strapi: Strapi }) => {
5
5
  try {
@@ -7,26 +7,84 @@ export default async ({ strapi }: { strapi: Strapi }) => {
7
7
  limit: -1
8
8
  })) as Record<string, any>[];
9
9
 
10
- const pagePermissions = pageTypes.map((pageType) => {
11
- const name = `page-type-is-${pageType.uid}`;
12
- const displayName = pageType.title;
10
+ const platforms = (await strapi.entityService?.findMany(PLATFORM_UID, {
11
+ limit: -1
12
+ })) as Record<string, any>[];
13
+
14
+ 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}`;
18
+
19
+ return {
20
+ plugin: 'page-builder',
21
+ name,
22
+ displayName,
23
+ category: `${platform.title} Page roles`,
24
+ handler: async () => {
25
+ 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
+ ]
43
+ };
44
+ }
45
+ };
46
+ });
47
+ });
48
+
49
+ const pageTypePermissions = pageTypes.map((pageType) => {
50
+ const name = `pageType-permission-${pageType.uid}`;
51
+ const displayName = `pageType ${pageType.title}`;
13
52
 
14
53
  return {
15
54
  plugin: 'page-builder',
16
55
  name,
17
56
  displayName,
18
- category: 'Page type',
57
+ category: `Platform pageType roles`,
58
+ handler: async () => {
59
+ return {
60
+ uid: {
61
+ $eq: pageType.uid
62
+ }
63
+ };
64
+ }
65
+ };
66
+ });
67
+
68
+ const platformCollectiontypePermissions = platforms.map((platform) => {
69
+ const name = `platform-is-${platform.title}`;
70
+ const displayName = platform.title;
71
+
72
+ return {
73
+ plugin: 'page-builder',
74
+ name,
75
+ displayName,
76
+ category: 'Platform CollectionType roles',
19
77
  handler: async () => {
20
78
  return {
21
79
  $or: [
22
80
  {
23
- 'pageType.uid': {
24
- $eq: pageType.uid
81
+ 'platform.id': {
82
+ $eq: platform.id
25
83
  }
26
84
  },
27
85
  {
28
- uid: {
29
- $eq: pageType.uid
86
+ id: {
87
+ $eq: platform.id
30
88
  }
31
89
  }
32
90
  ]
@@ -34,8 +92,15 @@ export default async ({ strapi }: { strapi: Strapi }) => {
34
92
  }
35
93
  };
36
94
  });
95
+
96
+ const allPermissions = [
97
+ ...platformPagePermissions.flat(),
98
+ ...pageTypePermissions.flat(),
99
+ ...platformCollectiontypePermissions
100
+ ];
101
+
37
102
  // @ts-ignore shitty types
38
- await strapi.admin.services.permission.conditionProvider.registerMany(pagePermissions);
103
+ await strapi.admin.services.permission.conditionProvider.registerMany(allPermissions);
39
104
  } catch {
40
105
  console.log('Cannot set page permissions');
41
106
  }
@@ -11,7 +11,7 @@ const getPageBySlug = (strapi: Strapi) => {
11
11
  }
12
12
 
13
13
  type Query {
14
- getPageBySlug(path: String, _locale: String, _publicationState: PublicationState): PageEntity
14
+ getPageBySlug(path: String, _domain: String, _locale: String, _publicationState: PublicationState): PageEntity
15
15
  }
16
16
 
17
17
  `;
@@ -24,56 +24,63 @@ const getPageBySlug = (strapi: Strapi) => {
24
24
  Query: {
25
25
  getPageBySlug: {
26
26
  resolve: async (_parent: any, args: Record<string, any>, ctx: any) => {
27
- const filteredArgs = {
28
- ...filterUnderscoreArguments(args)
29
- };
30
-
31
- const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
32
-
33
- const getPage = async () => {
34
- const transformedArgs = transformArgs(filteredArgs, {
35
- contentType: strapi.contentTypes[PAGE_UID],
36
- usePagination: false
37
- });
38
-
39
- const results = await strapi.entityService?.findMany(PAGE_UID, {
40
- filters: transformedArgs,
41
- locale: args._locale,
42
- publicationState: args._publicationState,
43
- populate: '*'
44
- });
45
-
46
- const entityResponse = toEntityResponse(results?.[0] || {}, {
47
- args: transformedArgs,
48
- resourceUID: PAGE_UID
49
- });
50
-
51
- if (!entityResponse?.value || Object.keys(entityResponse.value).length === 0) {
52
- throw new Error(ctx.koaContext.response.message);
53
- }
27
+ try {
28
+ const filteredArgs = {
29
+ ...filterUnderscoreArguments(args),
30
+ platform: { domain: args._domain }
31
+ };
54
32
 
55
- const collectionTypeDataFilter = entityResponse?.value?.collectionTypeData?.filter(Boolean);
33
+ const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
56
34
 
57
- const collectionType: Record<string, any> | null =
58
- collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter?.[0] : null;
35
+ const getPage = async () => {
36
+ const transformedArgs = transformArgs(filteredArgs, {
37
+ contentType: strapi.contentTypes[PAGE_UID],
38
+ usePagination: false
39
+ });
59
40
 
60
- const addedAttributes = {
61
- collectionType: collectionType
62
- };
41
+ const results = await strapi.entityService?.findMany(PAGE_UID, {
42
+ filters: filteredArgs,
43
+ locale: args._locale,
44
+ publicationState: args._publicationState,
45
+ populate: '*'
46
+ });
47
+
48
+ const entityResponse = toEntityResponse(results?.[0] || {}, {
49
+ args: transformedArgs,
50
+ resourceUID: PAGE_UID
51
+ });
52
+
53
+ if (!entityResponse?.value || Object.keys(entityResponse.value).length === 0) {
54
+ throw new Error(ctx.koaContext.response.message);
55
+ }
63
56
 
64
- const result = {
65
- ...entityResponse.value,
66
- ...addedAttributes
57
+ const collectionTypeDataFilter = entityResponse?.value?.collectionTypeData?.filter(Boolean);
58
+
59
+ const collectionType: Record<string, any> | null =
60
+ collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter?.[0] : null;
61
+
62
+ const addedAttributes = {
63
+ collectionType: collectionType
64
+ };
65
+
66
+ const result = {
67
+ ...entityResponse.value,
68
+ ...addedAttributes
69
+ };
70
+
71
+ return result;
67
72
  };
68
73
 
69
- return result;
70
- };
74
+ const results: Record<string, any> = await getPage();
71
75
 
72
- const results: Record<string, any> = await getPage();
76
+ if (Object.values(results)?.filter(Boolean).length > 0) {
77
+ return results;
78
+ } else {
79
+ throw new Error(ctx.koaContext.response.message);
80
+ }
81
+ } catch (error) {
82
+ console.log('Error in getPageBySlug:', error);
73
83
 
74
- if (Object.values(results)?.filter(Boolean).length > 0) {
75
- return results;
76
- } else {
77
84
  throw new Error(ctx.koaContext.response.message);
78
85
  }
79
86
  }