@webbio/strapi-plugin-page-builder 0.9.11-authentication → 0.9.13-authentication

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.11-authentication",
3
+ "version": "0.9.13-authentication",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -4,7 +4,7 @@ const routes = {
4
4
  prefix: undefined,
5
5
  routes: [
6
6
  {
7
- method: 'POST',
7
+ method: 'GET',
8
8
  path: '/activate/:token',
9
9
  handler: 'private-content.activateUser',
10
10
  config: { policies: [], auth: false }
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ACTIONS = exports.CONTENT_ENTITY_MANAGER = exports.USER_ROLE = exports.USER_CONTENT_MANAGER = exports.USER_MODEL = exports.CREATED_BY_ATTRIBUTE = exports.UPDATED_BY_ATTRIBUTE = void 0;
5
- const utils_1 = require("@strapi/utils");
6
- _a = utils_1.contentTypes.constants, exports.UPDATED_BY_ATTRIBUTE = _a.UPDATED_BY_ATTRIBUTE, exports.CREATED_BY_ATTRIBUTE = _a.CREATED_BY_ATTRIBUTE;
7
- exports.USER_MODEL = 'plugin::users-permissions.user';
8
- exports.USER_CONTENT_MANAGER = 'plugin::users-permissions.contentmanageruser';
9
- exports.USER_ROLE = 'plugin::users-permissions.role';
10
- exports.CONTENT_ENTITY_MANAGER = 'plugin::content-manager.entity-manager';
11
- exports.ACTIONS = {
12
- read: 'plugin::content-manager.explorer.read',
13
- create: 'plugin::content-manager.explorer.create',
14
- edit: 'plugin::content-manager.explorer.update',
15
- delete: 'plugin::content-manager.explorer.delete'
16
- };
@@ -1,161 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const pluginId_1 = __importDefault(require("../../admin/src/pluginId"));
7
- const toString_1 = __importDefault(require("lodash/toString"));
8
- const has_1 = __importDefault(require("lodash/has"));
9
- const omit_1 = __importDefault(require("lodash/omit"));
10
- const utils_1 = require("@strapi/utils");
11
- const customUserConstants_1 = require("./constants/customUserConstants");
12
- const { ApplicationError, ValidationError, NotFoundError, ForbiddenError } = utils_1.errors;
13
- exports.default = {
14
- async createCustomUsers() {
15
- const config = this.getConfig();
16
- const customNPOUser = config === null || config === void 0 ? void 0 : config.customNPOUser;
17
- if (customNPOUser) {
18
- await this.createNPOUsers();
19
- await this.customNPOUserControllers();
20
- }
21
- },
22
- async createNPOUsers() {
23
- const contentTypeName = await strapi.contentType(customUserConstants_1.USER_MODEL);
24
- contentTypeName.attributes = {
25
- // Spread previous defined attributes
26
- ...contentTypeName.attributes,
27
- // Add new, or override attributes
28
- platform: {
29
- type: 'relation',
30
- relation: 'oneToOne',
31
- target: 'api::platform.platform',
32
- required: true
33
- },
34
- firstName: {
35
- type: 'string'
36
- },
37
- lastName: {
38
- type: 'string'
39
- },
40
- company: {
41
- type: 'string'
42
- },
43
- jobTitle: {
44
- type: 'string'
45
- },
46
- address: {
47
- type: 'string'
48
- },
49
- postalCode: {
50
- type: 'string'
51
- },
52
- city: {
53
- type: 'string'
54
- },
55
- country: {
56
- type: 'string'
57
- },
58
- phone: {
59
- type: 'string'
60
- },
61
- categories: {
62
- type: 'relation',
63
- relation: 'oneToMany',
64
- target: 'api::category.category'
65
- }
66
- };
67
- delete contentTypeName.attributes.username;
68
- },
69
- async findEntityAndCheckPermissions(ability, action, model, id) {
70
- const entity = await strapi.query(customUserConstants_1.USER_MODEL).findOne({
71
- where: { id },
72
- populate: [`${customUserConstants_1.CREATED_BY_ATTRIBUTE}.roles`, 'platform']
73
- });
74
- if (!entity) {
75
- throw new NotFoundError();
76
- }
77
- const pm = strapi.admin.services.permission.createPermissionsManager({ ability, action, model });
78
- if (pm.ability.cannot(pm.action, pm.toSubject(entity))) {
79
- throw new ForbiddenError();
80
- }
81
- const entityWithoutCreatorRoles = (0, omit_1.default)(entity, `${customUserConstants_1.CREATED_BY_ATTRIBUTE}.roles`);
82
- return { pm, entity: entityWithoutCreatorRoles };
83
- },
84
- customNPOUserControllers() {
85
- const contentController = strapi.controller(customUserConstants_1.USER_CONTENT_MANAGER);
86
- contentController.create = async (ctx) => {
87
- var _a;
88
- const { body } = ctx.request;
89
- const { user: admin, userAbility } = ctx.state;
90
- const { email } = body;
91
- const platformId = body.platform.connect[0].id;
92
- const pm = (_a = strapi === null || strapi === void 0 ? void 0 : strapi.admin) === null || _a === void 0 ? void 0 : _a.services.permission.createPermissionsManager({
93
- ability: userAbility,
94
- action: customUserConstants_1.ACTIONS.create,
95
- model: customUserConstants_1.USER_MODEL
96
- });
97
- if (!pm.isAllowed) {
98
- return ctx.forbidden();
99
- }
100
- const sanitizedBody = await pm.pickPermittedFieldsOf(body, { subject: customUserConstants_1.USER_MODEL });
101
- const userWithSameEmail = await strapi.query(customUserConstants_1.USER_MODEL).findOne({
102
- where: { $and: [{ email: email.toLowerCase() }, { platform: { id: platformId } }] }
103
- });
104
- if (userWithSameEmail) {
105
- throw new ApplicationError('Email already taken');
106
- }
107
- const user = {
108
- ...sanitizedBody,
109
- provider: 'local',
110
- [customUserConstants_1.CREATED_BY_ATTRIBUTE]: admin.id,
111
- [customUserConstants_1.UPDATED_BY_ATTRIBUTE]: admin.id
112
- };
113
- user.email = user.email.toLowerCase();
114
- const advanced = await (strapi === null || strapi === void 0 ? void 0 : strapi.store({ type: 'plugin', name: 'users-permissions', key: 'advanced' }).get({}));
115
- if (user.role.connect.length === 0) {
116
- //@ts-ignore strapi types...
117
- const defaultRole = await strapi.query(customUserConstants_1.USER_ROLE).findOne({ where: { type: advanced.default_role } });
118
- user.role = defaultRole.id;
119
- }
120
- try {
121
- const data = await strapi.service(customUserConstants_1.CONTENT_ENTITY_MANAGER).create(user, customUserConstants_1.USER_MODEL);
122
- const sanitizedData = await pm.sanitizeOutput(data, { action: customUserConstants_1.ACTIONS.read });
123
- ctx.created(sanitizedData);
124
- }
125
- catch (error) {
126
- throw new ApplicationError(error.message);
127
- }
128
- };
129
- contentController.update = async (ctx) => {
130
- const { id } = ctx.params;
131
- const { body } = ctx.request;
132
- const { user: admin, userAbility } = ctx.state;
133
- const { email, password } = body;
134
- const { pm, entity } = await this.findEntityAndCheckPermissions(userAbility, customUserConstants_1.ACTIONS.edit, customUserConstants_1.USER_MODEL, id);
135
- const user = entity;
136
- const platformId = body.platform.connect.length > 0 ? body.platform.connect[0].id : entity.platform.id;
137
- if ((0, has_1.default)(body, 'password') && !password && user.provider === 'local') {
138
- throw new ValidationError('password.notNull');
139
- }
140
- //@ts-ignore
141
- if ((0, has_1.default)(body, 'email')) {
142
- const userWithSameEmail = await strapi
143
- .query(customUserConstants_1.USER_MODEL)
144
- .findOne({ where: { $and: [{ email: email.toLowerCase() }, { platform: { id: platformId } }] } });
145
- if (userWithSameEmail && (0, toString_1.default)(userWithSameEmail.id) !== (0, toString_1.default)(id)) {
146
- throw new ApplicationError('Email already taken');
147
- }
148
- body.email = body.email.toLowerCase();
149
- }
150
- const sanitizedData = await pm.pickPermittedFieldsOf(body, { subject: pm.toSubject(user) });
151
- const updateData = (0, omit_1.default)({ ...sanitizedData, updatedBy: admin.id }, 'createdBy');
152
- const data = await strapi
153
- .service('plugin::content-manager.entity-manager')
154
- .update({ id }, updateData, customUserConstants_1.USER_MODEL);
155
- ctx.body = await pm.sanitizeOutput(data, { action: customUserConstants_1.ACTIONS.read });
156
- };
157
- },
158
- getConfig() {
159
- return strapi.config.get(`plugin.${pluginId_1.default}`);
160
- }
161
- };
File without changes
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {};
@@ -1,128 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extendGraphQL = void 0;
4
- const utils_1 = require("@strapi/utils");
5
- const schemas_1 = require("./schemas");
6
- const constants_1 = require("./constants");
7
- const { ApplicationError } = utils_1.errors;
8
- const extendGraphQL = () => {
9
- const extensionService = strapi.plugin('graphql').service('extension');
10
- const extension = () => ({
11
- typeDefs: `
12
- input LoginInput {
13
- email: String!
14
- password: String!
15
- platformId: ID!
16
- }
17
-
18
- input RegisterInput {
19
- email: String!
20
- password: String!
21
- firstName: String
22
- lastName: String
23
- company: String
24
- jobTitle: String
25
- address: String
26
- postalCode: String
27
- city: String
28
- country: String
29
- phone: String
30
- subscribeToNewsletter: Boolean
31
- categories: [ID]
32
- platformId: ID!
33
- }
34
-
35
- type LoginResponse {
36
- jwt: String
37
- user: User
38
- }
39
-
40
- type RegisterResponse {
41
- user: User
42
- }
43
-
44
- type ForgotPasswordResponse {
45
- ok: Boolean!
46
- }
47
-
48
- type User {
49
- id: ID!
50
- email: String!
51
- confirmed: Boolean
52
- blocked: Boolean
53
- activated: Boolean
54
- platformId: ID!
55
- }
56
-
57
- type Mutation {
58
- platformLogin(input: LoginInput!): LoginResponse
59
- platformRegister(input: RegisterInput!): RegisterResponse
60
- platformForgotPassword(email: String!): ForgotPasswordResponse
61
- }
62
- `,
63
- resolversConfig: {
64
- 'Mutation.platformLogin': {
65
- auth: false
66
- },
67
- 'Mutation.platformRegister': {
68
- auth: false
69
- }
70
- },
71
- resolvers: {
72
- Mutation: {
73
- platformLogin: {
74
- resolve() {
75
- return null;
76
- }
77
- },
78
- platformRegister: {
79
- async resolve(parent, args, context) {
80
- const pluginStore = await strapi.store({ type: 'plugin', name: 'users-permissions' });
81
- const settings = await pluginStore.get({ key: 'advanced' });
82
- await (0, schemas_1.validateRegisterSchema)(args.input);
83
- const { email, platformId } = args.input;
84
- const role = await strapi
85
- .query('plugin::users-permissions.role')
86
- .findOne({ where: { type: settings.default_role } });
87
- if (!role) {
88
- throw new ApplicationError('Impossible to find the default role');
89
- }
90
- const conflictingUserCount = await strapi.query(constants_1.USER_MODEL).count({
91
- where: {
92
- email,
93
- platform: {
94
- id: platformId
95
- }
96
- }
97
- });
98
- if (conflictingUserCount > 0) {
99
- throw new ApplicationError('Email is already taken');
100
- }
101
- const userData = {
102
- ...args.input,
103
- role: role.id,
104
- categories: args.input.categories,
105
- platform: platformId,
106
- email: email.toLowerCase(),
107
- provider: 'local',
108
- confirmed: false,
109
- activateUser: false
110
- };
111
- const createdUser = await strapi.query(constants_1.USER_MODEL).create({
112
- data: userData
113
- });
114
- const userModel = strapi.getModel(constants_1.USER_MODEL);
115
- const sanitizedUser = utils_1.sanitize.contentAPI.output(createdUser, userModel, {
116
- auth: false
117
- });
118
- return {
119
- user: sanitizedUser
120
- };
121
- }
122
- }
123
- }
124
- }
125
- });
126
- extensionService.use(extension);
127
- };
128
- exports.extendGraphQL = extendGraphQL;
File without changes