@webbio/strapi-plugin-page-builder 0.9.10-authentication → 0.9.12-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/dist/package.json +1 -1
- package/dist/server/bootstrap.js +4 -4
- package/dist/server/graphql/page-by-path.js +3 -0
- package/dist/server/policies/index.js +7 -1
- package/dist/server/policies/isAuthorizedPage.js +11 -0
- package/dist/server/services/email.js +14 -12
- package/dist/server/services/private-content/graphql/resolvers/forgot-password.js +1 -1
- package/dist/server/services/private-content/graphql/resolvers/register.js +3 -0
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/server/bootstrap.ts +4 -4
- package/server/content-types/category/schema.json +17 -17
- package/server/graphql/page-by-path.ts +4 -0
- package/server/policies/index.ts +5 -1
- package/server/policies/isAuthorizedPage.ts +11 -0
- package/server/schema/page-end.json +8 -8
- package/server/services/email.ts +14 -12
- package/server/services/private-content/components/admin-email.json +20 -21
- package/server/services/private-content/components/email.json +20 -21
- package/server/services/private-content/components/platform-email.json +28 -28
- package/server/services/private-content/graphql/resolvers/forgot-password.ts +1 -1
- package/server/services/private-content/graphql/resolvers/register.ts +4 -0
- package/dist/server/services/constants/customUserConstants.js +0 -16
- package/dist/server/services/custom-user.js +0 -161
- package/dist/server/services/private-content/auth.js +0 -0
- package/dist/server/services/private-content/email.js +0 -3
- package/dist/server/services/private-content/graphql.js +0 -128
- package/dist/server/services/private-content/hash.js +0 -0
package/package.json
CHANGED
package/server/bootstrap.ts
CHANGED
|
@@ -37,18 +37,18 @@ export default async ({ strapi }: { strapi: Strapi }) => {
|
|
|
37
37
|
async beforeUpdate(event) {
|
|
38
38
|
if (event.params.data.id) {
|
|
39
39
|
const userToUpdate = await strapi.entityService?.findOne(USER_PERMISSION_USER_PLUGIN, event.params.data.id, {
|
|
40
|
-
populate: { platform: { populate: {
|
|
40
|
+
populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
|
|
41
41
|
});
|
|
42
42
|
if (userToUpdate) {
|
|
43
43
|
if (event.params.data.activateUser && event.params.data.confirmed && !userToUpdate.confirmMailSend) {
|
|
44
44
|
await strapi.service(PAGE_BUILDER_EMAIL_PLUGIN).sendMail({
|
|
45
45
|
// @ts-ignore strapi typings
|
|
46
|
-
from: userToUpdate.platform.
|
|
46
|
+
from: userToUpdate.platform.platformEmails.accountAcceptedMail.fromEmail,
|
|
47
47
|
to: event.params.data.email,
|
|
48
48
|
// @ts-ignore
|
|
49
|
-
subject: userToUpdate.platform.
|
|
49
|
+
subject: userToUpdate.platform.platformEmails.accountAcceptedMail.subject,
|
|
50
50
|
// @ts-ignore
|
|
51
|
-
text: userToUpdate.platform.
|
|
51
|
+
text: userToUpdate.platform.platformEmails.accountAcceptedMail.message,
|
|
52
52
|
firstName: event.params.data.firstName,
|
|
53
53
|
lastName: event.params.data.lastName
|
|
54
54
|
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
2
|
+
"kind": "collectionType",
|
|
3
|
+
"collectionName": "categories",
|
|
4
|
+
"info": {
|
|
5
|
+
"singularName": "category",
|
|
6
|
+
"pluralName": "categories",
|
|
7
|
+
"displayName": "category"
|
|
8
|
+
},
|
|
9
|
+
"options": {
|
|
10
|
+
"draftAndPublish": false,
|
|
11
|
+
"comment": ""
|
|
12
|
+
},
|
|
13
|
+
"attributes": {
|
|
14
|
+
"title": {
|
|
15
|
+
"type": "string"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -3,6 +3,7 @@ import { Strapi } from '@strapi/strapi';
|
|
|
3
3
|
import { PAGE_UID } from '../../shared/utils/constants';
|
|
4
4
|
|
|
5
5
|
import { ForbiddenError as ApolloForbiddenError } from 'apollo-server-koa';
|
|
6
|
+
import { getConfig } from '../utils/strapi';
|
|
6
7
|
|
|
7
8
|
const getPageByPath = (strapi: Strapi) => {
|
|
8
9
|
const typeDefs = () => {
|
|
@@ -112,8 +113,11 @@ const getPageByPath = (strapi: Strapi) => {
|
|
|
112
113
|
};
|
|
113
114
|
};
|
|
114
115
|
|
|
116
|
+
const pageBuilderConfig = getConfig();
|
|
117
|
+
|
|
115
118
|
const resolversConfig = {
|
|
116
119
|
'Query.getPageByPath': {
|
|
120
|
+
policies: pageBuilderConfig?.privateContent === true ? ['plugin::page-builder.isAuthorizedForPage'] : [],
|
|
117
121
|
auth: false
|
|
118
122
|
}
|
|
119
123
|
};
|
package/server/policies/index.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const isAuthorizedForPage = (policyContext, _config, { strapi }) => {
|
|
2
|
+
const pageToken = policyContext.http.request.headers['x-strapi-page-secret'];
|
|
3
|
+
const pageEnvToken = process.env.STRAPI_PAGE_SECRET;
|
|
4
|
+
|
|
5
|
+
if (pageToken && pageEnvToken && pageToken === pageEnvToken) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default isAuthorizedForPage;
|
|
@@ -92,13 +92,13 @@
|
|
|
92
92
|
"relation": "oneToOne",
|
|
93
93
|
"target": "api::platform.platform"
|
|
94
94
|
},
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
95
|
+
"isPrivate": {
|
|
96
|
+
"pluginOptions": {
|
|
97
|
+
"i18n": {
|
|
98
|
+
"localized": true
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"type": "boolean"
|
|
102
|
+
}
|
|
103
103
|
}
|
|
104
104
|
}
|
package/server/services/email.ts
CHANGED
|
@@ -43,25 +43,27 @@ export default {
|
|
|
43
43
|
},
|
|
44
44
|
async sendAdminMail(user) {
|
|
45
45
|
const foundUser = await strapi.entityService.findOne(USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
46
|
-
populate: { platform: { populate: {
|
|
46
|
+
populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
|
|
47
47
|
});
|
|
48
48
|
await this.sendMail({
|
|
49
49
|
// @ts-ignore we all love strapi typings
|
|
50
|
-
from: foundUser.platform.
|
|
50
|
+
from: foundUser.platform.platformEmails.adminEmail.fromEmail,
|
|
51
51
|
// @ts-ignore
|
|
52
|
-
to: foundUser.platform.
|
|
52
|
+
to: foundUser.platform.platformEmails.adminEmail.toMail,
|
|
53
53
|
// @ts-ignore
|
|
54
|
-
subject: foundUser.platform.
|
|
54
|
+
subject: foundUser.platform.platformEmails.adminEmail.subject,
|
|
55
55
|
// @ts-ignore
|
|
56
|
-
text: foundUser.platform.
|
|
56
|
+
text: foundUser.platform.platformEmails.adminEmail.message,
|
|
57
57
|
firstName: user.firstName,
|
|
58
58
|
lastName: user.lastName
|
|
59
59
|
});
|
|
60
60
|
},
|
|
61
61
|
async sendConfirmationEmail(user) {
|
|
62
|
+
console.log('HALLO');
|
|
62
63
|
const foundUser = await strapi.entityService.findOne(USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
63
|
-
populate: { platform: { populate: {
|
|
64
|
+
populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
|
|
64
65
|
});
|
|
66
|
+
console.log({ foundUser });
|
|
65
67
|
if (foundUser && foundUser.platform) {
|
|
66
68
|
const jwtService = strapi.plugin('users-permissions').service('jwt');
|
|
67
69
|
const confirmationToken = await jwtService.issue(
|
|
@@ -78,12 +80,12 @@ export default {
|
|
|
78
80
|
|
|
79
81
|
await this.sendMail({
|
|
80
82
|
// @ts-ignore
|
|
81
|
-
from: foundUser.platform.
|
|
83
|
+
from: foundUser.platform.platformEmails.accountCreatedMail.fromEmail,
|
|
82
84
|
to: user.email,
|
|
83
85
|
// @ts-ignore
|
|
84
|
-
subject: foundUser.platform.
|
|
86
|
+
subject: foundUser.platform.platformEmails.accountCreatedMail.subject,
|
|
85
87
|
// @ts-ignore
|
|
86
|
-
text: foundUser.platform.
|
|
88
|
+
text: foundUser.platform.platformEmails.accountCreatedMail.message,
|
|
87
89
|
firstName: user.firstName,
|
|
88
90
|
lastName: user.lastName,
|
|
89
91
|
confirmationUrl: activateUrl
|
|
@@ -107,12 +109,12 @@ export default {
|
|
|
107
109
|
|
|
108
110
|
await this.sendMail({
|
|
109
111
|
// @ts-ignore
|
|
110
|
-
from: user.platform.
|
|
112
|
+
from: user.platform.platformEmails.resetPasswordMail.fromEmail,
|
|
111
113
|
to: user.email,
|
|
112
114
|
// @ts-ignore
|
|
113
|
-
subject: user.platform.
|
|
115
|
+
subject: user.platform.platformEmails.resetPasswordMail.subject,
|
|
114
116
|
// @ts-ignore
|
|
115
|
-
text: user.platform.
|
|
117
|
+
text: user.platform.platformEmails.resetPasswordMail.message,
|
|
116
118
|
firstName: user.firstName,
|
|
117
119
|
lastName: user.lastName,
|
|
118
120
|
confirmationUrl: activateUrl
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
"collectionName": "components_internal_admin_emails",
|
|
3
|
+
"info": {
|
|
4
|
+
"displayName": "AdminEmail",
|
|
5
|
+
"description": ""
|
|
6
|
+
},
|
|
7
|
+
"options": {},
|
|
8
|
+
"attributes": {
|
|
9
|
+
"toMail": {
|
|
10
|
+
"type": "string"
|
|
11
|
+
},
|
|
12
|
+
"fromEmail": {
|
|
13
|
+
"type": "string"
|
|
14
|
+
},
|
|
15
|
+
"subject": {
|
|
16
|
+
"type": "string"
|
|
17
|
+
},
|
|
18
|
+
"message": {
|
|
19
|
+
"type": "text"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
22
|
}
|
|
23
|
-
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
"collectionName": "components_internal_emails",
|
|
3
|
+
"info": {
|
|
4
|
+
"displayName": "email",
|
|
5
|
+
"description": ""
|
|
6
|
+
},
|
|
7
|
+
"options": {},
|
|
8
|
+
"attributes": {
|
|
9
|
+
"nameSender": {
|
|
10
|
+
"type": "string"
|
|
11
|
+
},
|
|
12
|
+
"fromEmail": {
|
|
13
|
+
"type": "string"
|
|
14
|
+
},
|
|
15
|
+
"subject": {
|
|
16
|
+
"type": "string"
|
|
17
|
+
},
|
|
18
|
+
"message": {
|
|
19
|
+
"type": "text"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
22
|
}
|
|
23
|
-
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
2
|
+
"collectionName": "components_internal_platform_emails",
|
|
3
|
+
"info": {
|
|
4
|
+
"displayName": "PlatformEmail"
|
|
5
|
+
},
|
|
6
|
+
"options": {},
|
|
7
|
+
"attributes": {
|
|
8
|
+
"resetPasswordMail": {
|
|
9
|
+
"type": "component",
|
|
10
|
+
"repeatable": false,
|
|
11
|
+
"component": "internal.email"
|
|
12
|
+
},
|
|
13
|
+
"accountCreatedMail": {
|
|
14
|
+
"type": "component",
|
|
15
|
+
"repeatable": false,
|
|
16
|
+
"component": "internal.email"
|
|
17
|
+
},
|
|
18
|
+
"accountAcceptedMail": {
|
|
19
|
+
"type": "component",
|
|
20
|
+
"repeatable": false,
|
|
21
|
+
"component": "internal.email"
|
|
22
|
+
},
|
|
23
|
+
"adminEmail": {
|
|
24
|
+
"displayName": "AdminEmail",
|
|
25
|
+
"type": "component",
|
|
26
|
+
"repeatable": false,
|
|
27
|
+
"component": "internal.admin-email"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
30
|
}
|
|
@@ -10,7 +10,7 @@ export const platformForgotPassword = {
|
|
|
10
10
|
const { email, platformId } = args.input;
|
|
11
11
|
|
|
12
12
|
const user = await strapi.query(USER_MODEL).findOne({
|
|
13
|
-
populate: { platform: { populate: {
|
|
13
|
+
populate: { platform: { populate: { platformEmails: { populate: true } } } },
|
|
14
14
|
where: {
|
|
15
15
|
email: email.toLowerCase(),
|
|
16
16
|
platform: {
|
|
@@ -6,6 +6,7 @@ const { ApplicationError } = errors;
|
|
|
6
6
|
|
|
7
7
|
export const platformRegister = {
|
|
8
8
|
async resolve(parent, args, context) {
|
|
9
|
+
console.log('WAAROM LOG JIJ NIKS');
|
|
9
10
|
const pluginStore = await strapi.store({ type: 'plugin', name: 'users-permissions' });
|
|
10
11
|
const settings: any = await pluginStore.get({ key: 'advanced' });
|
|
11
12
|
|
|
@@ -17,6 +18,8 @@ export const platformRegister = {
|
|
|
17
18
|
.query('plugin::users-permissions.role')
|
|
18
19
|
.findOne({ where: { type: settings.default_role } });
|
|
19
20
|
|
|
21
|
+
console.log('dsfjsdds');
|
|
22
|
+
|
|
20
23
|
if (!role) {
|
|
21
24
|
throw new ApplicationError('Impossible to find the default role');
|
|
22
25
|
}
|
|
@@ -59,6 +62,7 @@ export const platformRegister = {
|
|
|
59
62
|
auth: false
|
|
60
63
|
});
|
|
61
64
|
|
|
65
|
+
console.log('HALLO MADDERFACKKER');
|
|
62
66
|
await strapi.service('plugin::page-builder.email').sendConfirmationEmail(createdUser);
|
|
63
67
|
|
|
64
68
|
return {
|
|
@@ -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
|