@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/dist/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",
@@ -2,99 +2,127 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const constants_1 = require("../../shared/utils/constants");
4
4
  exports.default = async ({ strapi }) => {
5
- var _a, _b;
5
+ var _a;
6
6
  try {
7
- const pageTypes = (await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_TYPE_UID, {
8
- limit: -1
9
- })));
10
- const platforms = (await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.findMany(constants_1.PLATFORM_UID, {
7
+ const platforms = (await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PLATFORM_UID, {
11
8
  limit: -1
12
9
  })));
13
10
  const platformPagePermissions = platforms.map((platform) => {
14
- return pageTypes.map((pageType) => {
15
- const name = `platform-is-${platform.title}-${pageType.uid}`;
16
- const displayName = `${platform.title}-${pageType.title}`;
17
- return {
18
- plugin: 'page-builder',
19
- name,
20
- displayName,
21
- category: `${platform.title} Page roles`,
22
- handler: async () => {
23
- return {
24
- $and: [
25
- {
26
- 'platform.id': {
27
- $eq: platform.id
28
- }
29
- },
30
- {
31
- 'pageType.uid': {
32
- $eq: pageType.uid
33
- }
34
- },
35
- {
36
- uid: {
37
- $eq: pageType.uid
38
- }
39
- }
40
- ]
41
- };
42
- }
43
- };
44
- });
45
- });
46
- const pageTypePermissions = pageTypes.map((pageType) => {
47
- const name = `pageType-permission-${pageType.uid}`;
48
- const displayName = `pageType ${pageType.title}`;
49
- return {
50
- plugin: 'page-builder',
51
- name,
52
- displayName,
53
- category: `Platform pageType roles`,
54
- handler: async () => {
55
- return {
56
- uid: {
57
- $eq: pageType.uid
58
- }
59
- };
60
- }
61
- };
62
- });
63
- const platformCollectiontypePermissions = platforms.map((platform) => {
64
11
  const name = `platform-is-${platform.title}`;
65
12
  const displayName = platform.title;
66
13
  return {
67
14
  plugin: 'page-builder',
68
15
  name,
69
16
  displayName,
70
- category: 'Platform CollectionType roles',
71
- handler: async () => {
17
+ category: `Platform`,
18
+ handler: async (x) => {
19
+ var _a, _b, _c, _d;
20
+ if (((_a = x === null || x === void 0 ? void 0 : x.permission) === null || _a === void 0 ? void 0 : _a.subject) === 'api::platform.platform') {
21
+ return {
22
+ id: {
23
+ $eq: platform.id
24
+ }
25
+ };
26
+ }
27
+ if (((_b = x === null || x === void 0 ? void 0 : x.permission) === null || _b === void 0 ? void 0 : _b.subject) === 'api::page.page') {
28
+ try {
29
+ const roles = (await ((_c = strapi.entityService) === null || _c === void 0 ? void 0 : _c.findMany('admin::role', {
30
+ limit: -1,
31
+ populate: '*'
32
+ })));
33
+ // checks which role the user has
34
+ const foundRole = roles.filter((role) => {
35
+ return x.roles.find((userRole) => userRole.name === role.name);
36
+ });
37
+ // get the right platform permissions, and filters out the platform
38
+ // this is neccesary because of multiple platforms. if you can see Vacancy from platform 1 and collegue from platform 2
39
+ // it will show both at page level, so this filters out the wrong page
40
+ const platformPermission = (_d = foundRole === null || foundRole === void 0 ? void 0 : foundRole[0]) === null || _d === void 0 ? void 0 : _d.permissions.map((permission) => {
41
+ return {
42
+ permission: permission.subject,
43
+ condition: permission.conditions.filter((condition) => condition.includes(platform.title))
44
+ };
45
+ });
46
+ // get the right permission for platform
47
+ const permissions = platformPermission.map((permission) => {
48
+ if (permission.condition.length > 0) {
49
+ return permission.permission;
50
+ }
51
+ });
52
+ return {
53
+ $and: [
54
+ {
55
+ 'platform.id': {
56
+ $eq: platform.id
57
+ }
58
+ },
59
+ {
60
+ 'pageType.uid': {
61
+ $in: permissions
62
+ }
63
+ }
64
+ ]
65
+ };
66
+ }
67
+ catch (error) {
68
+ console.log(error);
69
+ }
70
+ }
72
71
  return {
73
- $or: [
72
+ $and: [
74
73
  {
75
74
  'platform.id': {
76
75
  $eq: platform.id
77
76
  }
78
- },
79
- {
80
- id: {
81
- $eq: platform.id
82
- }
83
77
  }
84
78
  ]
85
79
  };
86
80
  }
87
81
  };
82
+ // });
88
83
  });
89
- const allPermissions = [
90
- ...platformPagePermissions.flat(),
91
- ...pageTypePermissions.flat(),
92
- ...platformCollectiontypePermissions
93
- ];
84
+ const allPermissions = [...platformPagePermissions.flat()];
94
85
  // @ts-ignore shitty types
95
86
  await strapi.admin.services.permission.conditionProvider.registerMany(allPermissions);
96
87
  }
97
- catch {
88
+ catch (error) {
98
89
  console.log('Cannot set page permissions');
99
90
  }
100
91
  };
92
+ // Leave this commented code here, This might be used in the future to change up the permissions IF needed
93
+ // const platformPagePermissions = platforms.map((platform) => {
94
+ // const platformPageTypes = pageTypes.filter((pageType) => pageType.platform.id === platform.id);
95
+ // return platformPageTypes.map((pageType) => {
96
+ // const name = `platform-is-${platform.title}-${pageType.uid}`;
97
+ // const displayName = pageType.title;
98
+ // return {
99
+ // plugin: 'page-builder',
100
+ // name,
101
+ // displayName,
102
+ // category: `${platform.title} pageTypes`,
103
+ // handler: async (x) => {
104
+ // if (x?.permission?.subject === 'api::platform.platform') {
105
+ // return {
106
+ // id: {
107
+ // $eq: platform.id
108
+ // }
109
+ // };
110
+ // }
111
+ // return {
112
+ // $and: [
113
+ // {
114
+ // 'platform.id': {
115
+ // $eq: platform.id
116
+ // }
117
+ // },
118
+ // {
119
+ // 'pageType.uid': {
120
+ // $eq: pageType.uid
121
+ // }
122
+ // }
123
+ // ]
124
+ // };
125
+ // }
126
+ // };
127
+ // });
128
+ // });
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // @ts-ignore
4
+ exports.default = (strapi) => {
5
+ return async (ctx, next) => {
6
+ console.log(ctx);
7
+ await next();
8
+ // // then logs info
9
+ // console.log('REQUEST:')
10
+ // console.log(ctx.request.body.query);
11
+ // console.log('RESPONSE:')
12
+ // console.log(ctx.body);
13
+ // const result = JSON.parse(ctx.response.body);
14
+ // console.log('result');
15
+ // if (result && result.data.getPageByPath) {
16
+ // console.log(result.data.getPageByPath.attributes);
17
+ // }
18
+ // console.log("middleware state")
19
+ // console.log(context.request.header.host)
20
+ // if(context.request.header.host == "localhost:1337") {
21
+ // return context.badRequest('name is missing', { foo: 'bar' })
22
+ // }
23
+ // try {
24
+ // if (
25
+ // (context.state.user.platform && context.args.domain === context.state.user.platform.domain) ||
26
+ // (context.state.user.roles && context.state.user.roles[0].name !== 'Public')
27
+ // ) {
28
+ // return true;
29
+ // }
30
+ // } catch (error) {
31
+ // console.log(error);
32
+ // }
33
+ // return false;
34
+ };
35
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = (ctx) => {
4
+ // console.log('user state');
5
+ // console.log(ctx.state.user);
6
+ // console.log('End User State');
7
+ // || ctx.state.user.roles && ctx.state.user.roles[0].name !== "Public"
8
+ try {
9
+ if ((ctx.state.user.platform && ctx.args.domain === ctx.state.user.platform.domain) ||
10
+ (ctx.state.user.roles && ctx.state.user.roles[0].name !== 'Public')) {
11
+ return true;
12
+ }
13
+ }
14
+ catch (error) {
15
+ console.log(error);
16
+ }
17
+ return false;
18
+ };
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerGraphQLResolvers = void 0;
4
+ const constants_1 = require("../../shared/utils/constants");
5
+ const findPageByPath = (strapi) => {
6
+ const typeDefs = `
7
+ type Query {
8
+ findPageByPath(path: String, locale: I18NLocaleCode): PageEntityResponse
9
+ }
10
+ `;
11
+ const resolvers = (strapi) => {
12
+ const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
13
+ const { toEntityResponse, toEntityResponseCollection } = strapi.plugin('graphql').service('format').returnTypes;
14
+ return {
15
+ Query: {
16
+ findPageByPath: {
17
+ resolve: async (parent, args, ctx) => {
18
+ const contentType = strapi.getModel(constants_1.PAGE_UID);
19
+ const transformedArgs = transformArgs(args, { contentType });
20
+ const queryResult = await strapi.entityService.findMany(contentType.uid, {
21
+ filters: {
22
+ path: {
23
+ $eq: transformedArgs.path
24
+ }
25
+ },
26
+ locale: transformedArgs.locale
27
+ });
28
+ const result = queryResult === null || queryResult === void 0 ? void 0 : queryResult[0];
29
+ return toEntityResponse(result, {
30
+ args: transformedArgs,
31
+ resourceUID: contentType.uid
32
+ });
33
+ }
34
+ }
35
+ }
36
+ };
37
+ };
38
+ const resolversConfig = {
39
+ 'Query.findPageByPath': {
40
+ auth: false
41
+ }
42
+ };
43
+ return {
44
+ typeDefs,
45
+ resolvers: resolvers(strapi),
46
+ resolversConfig
47
+ };
48
+ };
49
+ const findPagePaths = (strapi) => {
50
+ const typeDefs = `
51
+ type PageByPath {
52
+ id: Int!
53
+ path: String!
54
+ title: String!
55
+ locale: String!
56
+ pageType: ENUM_PAGE_PAGETYPE
57
+ updatedAt: DateTime!
58
+ publishedAt: DateTime!
59
+ }
60
+
61
+ type Query {
62
+ findPagePaths(locale: String, pageType: String = "all"): [PageByPath]
63
+ }
64
+ `;
65
+ const resolvers = (strapi) => {
66
+ const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
67
+ return {
68
+ Query: {
69
+ findPagePaths: {
70
+ resolve: async (parent, args, ctx) => {
71
+ const contentType = strapi.getModel(constants_1.PAGE_UID);
72
+ const transformedArgs = transformArgs(args, { contentType });
73
+ const queryResult = await strapi.entityService.findMany(contentType.uid, {
74
+ populate: '*',
75
+ locale: transformedArgs.locale
76
+ });
77
+ const result = queryResult.filter((page) => page === null || page === void 0 ? void 0 : page.path);
78
+ return result;
79
+ }
80
+ }
81
+ }
82
+ };
83
+ };
84
+ const resolversConfig = {
85
+ 'Query.findPagePaths': {
86
+ auth: false
87
+ }
88
+ };
89
+ return {
90
+ typeDefs,
91
+ resolvers: resolvers(strapi),
92
+ resolversConfig
93
+ };
94
+ };
95
+ const registerGraphQLResolvers = (strapi) => {
96
+ const extensionService = strapi.plugin('graphql').service('extension');
97
+ extensionService.use(findPageByPath(strapi));
98
+ extensionService.use(findPagePaths(strapi));
99
+ };
100
+ exports.registerGraphQLResolvers = registerGraphQLResolvers;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pagination = void 0;
4
+ class Pagination {
5
+ static checkPagination(page, pageSize) {
6
+ const startPage = page === 1 ? 0 : page - 1;
7
+ const start = startPage * pageSize;
8
+ const limit = (startPage + 1) * pageSize;
9
+ return { start, limit };
10
+ }
11
+ static async getPaginationInfo(transformedpageArgs, transformArgs, start, pageSize, entityResponse, uid) {
12
+ var _a;
13
+ const total = await ((_a = strapi === null || strapi === void 0 ? void 0 : strapi.entityService) === null || _a === void 0 ? void 0 : _a.count(uid, {
14
+ filters: {
15
+ ...transformArgs.filters,
16
+ hasPage: { $eq: true },
17
+ page: { ...transformedpageArgs.filters }
18
+ }
19
+ }));
20
+ const pageCount = Math.ceil(total / pageSize);
21
+ const page = Math.floor(start / pageSize) + 1;
22
+ entityResponse.metaInfo = {
23
+ total,
24
+ pageCount,
25
+ page,
26
+ pageSize
27
+ };
28
+ return entityResponse;
29
+ }
30
+ }
31
+ exports.Pagination = Pagination;