@strapi/plugin-users-permissions 4.20.5 → 5.0.0-alpha.1

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.
Files changed (112) hide show
  1. package/admin/src/components/FormModal/index.jsx +1 -2
  2. package/admin/src/components/Permissions/reducer.js +1 -1
  3. package/admin/src/components/UsersPermissions/reducer.js +1 -1
  4. package/admin/src/index.js +15 -32
  5. package/admin/src/pages/AdvancedSettings/index.jsx +72 -112
  6. package/admin/src/pages/AdvancedSettings/utils/layout.js +20 -35
  7. package/admin/src/pages/AdvancedSettings/utils/schema.js +5 -2
  8. package/admin/src/pages/EmailTemplates/components/EmailForm.jsx +47 -74
  9. package/admin/src/pages/EmailTemplates/components/EmailTable.jsx +4 -5
  10. package/admin/src/pages/EmailTemplates/index.jsx +25 -55
  11. package/admin/src/pages/EmailTemplates/utils/schema.js +18 -6
  12. package/admin/src/pages/Providers/index.jsx +91 -108
  13. package/admin/src/pages/Providers/utils/forms.js +11 -11
  14. package/admin/src/pages/Roles/constants.js +3 -3
  15. package/admin/src/pages/Roles/hooks/usePlugins.js +4 -4
  16. package/admin/src/pages/Roles/index.jsx +9 -18
  17. package/admin/src/pages/Roles/pages/CreatePage.jsx +20 -28
  18. package/admin/src/pages/Roles/pages/EditPage.jsx +25 -37
  19. package/admin/src/pages/Roles/pages/ListPage/components/TableBody.jsx +23 -28
  20. package/admin/src/pages/Roles/pages/ListPage/index.jsx +73 -42
  21. package/admin/src/translations/en.json +1 -1
  22. package/admin/src/utils/prefixPluginTranslations.js +13 -0
  23. package/dist/_chunks/EditViewPage-kgrZ8rEg-6k5dfk_x.js +84412 -0
  24. package/dist/_chunks/EditViewPage-kgrZ8rEg-6k5dfk_x.js.map +1 -0
  25. package/dist/_chunks/EditViewPage-kgrZ8rEg-GlayP0Uq.mjs +84382 -0
  26. package/dist/_chunks/EditViewPage-kgrZ8rEg-GlayP0Uq.mjs.map +1 -0
  27. package/dist/_chunks/Helmet-d9JljxUo.js +1010 -0
  28. package/dist/_chunks/Helmet-d9JljxUo.js.map +1 -0
  29. package/dist/_chunks/Helmet-kyJ1Zklj.mjs +1008 -0
  30. package/dist/_chunks/Helmet-kyJ1Zklj.mjs.map +1 -0
  31. package/dist/_chunks/ListViewPage-BNB0ptO7-TUQO_9Hj.js +1617 -0
  32. package/dist/_chunks/ListViewPage-BNB0ptO7-TUQO_9Hj.js.map +1 -0
  33. package/dist/_chunks/ListViewPage-BNB0ptO7-t1ra9JlI.mjs +1594 -0
  34. package/dist/_chunks/ListViewPage-BNB0ptO7-t1ra9JlI.mjs.map +1 -0
  35. package/dist/_chunks/ReviewWorkflowsColumn-56Z6l-FH-3Dq1lGu9.js +33 -0
  36. package/dist/_chunks/ReviewWorkflowsColumn-56Z6l-FH-3Dq1lGu9.js.map +1 -0
  37. package/dist/_chunks/ReviewWorkflowsColumn-56Z6l-FH-mpkuW-HV.mjs +33 -0
  38. package/dist/_chunks/ReviewWorkflowsColumn-56Z6l-FH-mpkuW-HV.mjs.map +1 -0
  39. package/dist/_chunks/constants-evLWZCaJ-0QLv9QPI.mjs +190 -0
  40. package/dist/_chunks/constants-evLWZCaJ-0QLv9QPI.mjs.map +1 -0
  41. package/dist/_chunks/constants-evLWZCaJ-dGs71EWl.js +209 -0
  42. package/dist/_chunks/constants-evLWZCaJ-dGs71EWl.js.map +1 -0
  43. package/dist/_chunks/{en-m608rMZx.js → en-TaNIVnDO.js} +2 -2
  44. package/dist/_chunks/en-TaNIVnDO.js.map +1 -0
  45. package/dist/_chunks/{en-CE3wEy_c.mjs → en-jvJ-d-Qq.mjs} +2 -2
  46. package/dist/_chunks/en-jvJ-d-Qq.mjs.map +1 -0
  47. package/dist/_chunks/{index-XqdaO5WZ.js → index-6E51D69B.js} +149 -149
  48. package/dist/_chunks/index-6E51D69B.js.map +1 -0
  49. package/dist/_chunks/index-BGIcvvEB.mjs +260 -0
  50. package/dist/_chunks/index-BGIcvvEB.mjs.map +1 -0
  51. package/dist/_chunks/{index-6Kdo3KXv.js → index-Bg2Rf_5y.js} +112 -154
  52. package/dist/_chunks/index-Bg2Rf_5y.js.map +1 -0
  53. package/dist/_chunks/index-LpFmy25n.js +279 -0
  54. package/dist/_chunks/index-LpFmy25n.js.map +1 -0
  55. package/dist/_chunks/{index-a9oKDd3C.mjs → index-R05CeNXG.mjs} +106 -148
  56. package/dist/_chunks/index-R05CeNXG.mjs.map +1 -0
  57. package/dist/_chunks/index-YFPS5vYF-ZGkR3L1g.js +16558 -0
  58. package/dist/_chunks/index-YFPS5vYF-ZGkR3L1g.js.map +1 -0
  59. package/dist/_chunks/index-YFPS5vYF-cugkJcLS.mjs +16533 -0
  60. package/dist/_chunks/index-YFPS5vYF-cugkJcLS.mjs.map +1 -0
  61. package/dist/_chunks/{index-ethhTEkj.mjs → index-aEKi1Qb9.mjs} +39 -36
  62. package/dist/_chunks/index-aEKi1Qb9.mjs.map +1 -0
  63. package/dist/_chunks/{index-rryiT0-Z.mjs → index-hG66XSuA.mjs} +131 -130
  64. package/dist/_chunks/index-hG66XSuA.mjs.map +1 -0
  65. package/dist/_chunks/{index-iNtwnT3f.mjs → index-xt3l4qU9.mjs} +35 -35
  66. package/dist/_chunks/index-xt3l4qU9.mjs.map +1 -0
  67. package/dist/_chunks/{index-O9AAUvyy.js → index-yKMi8hKt.js} +36 -36
  68. package/dist/_chunks/index-yKMi8hKt.js.map +1 -0
  69. package/dist/_chunks/{index-1uupZmu0.js → index-ylhaoJtw.js} +43 -40
  70. package/dist/_chunks/index-ylhaoJtw.js.map +1 -0
  71. package/dist/_chunks/useSyncRbac-83vFRiaG-YY4KQcAU.js +57 -0
  72. package/dist/_chunks/useSyncRbac-83vFRiaG-YY4KQcAU.js.map +1 -0
  73. package/dist/_chunks/useSyncRbac-83vFRiaG-ov11t-T1.mjs +39 -0
  74. package/dist/_chunks/useSyncRbac-83vFRiaG-ov11t-T1.mjs.map +1 -0
  75. package/dist/admin/index.js +1 -2
  76. package/dist/admin/index.js.map +1 -1
  77. package/dist/admin/index.mjs +1 -2
  78. package/dist/admin/index.mjs.map +1 -1
  79. package/dist/style.css +84 -0
  80. package/package.json +13 -13
  81. package/server/bootstrap/grant-config.js +9 -0
  82. package/server/bootstrap/index.js +2 -39
  83. package/server/content-types/user/index.js +0 -1
  84. package/server/controllers/auth.js +24 -53
  85. package/server/controllers/content-manager-user.js +24 -28
  86. package/server/controllers/role.js +1 -1
  87. package/server/controllers/user.js +5 -5
  88. package/server/middlewares/rateLimit.js +1 -1
  89. package/server/register.js +1 -1
  90. package/server/services/jwt.js +3 -3
  91. package/server/services/permission.js +3 -7
  92. package/server/services/providers-registry.js +15 -0
  93. package/server/services/providers.js +10 -5
  94. package/server/services/role.js +15 -13
  95. package/server/services/user.js +28 -14
  96. package/server/services/users-permissions.js +12 -10
  97. package/server/utils/sanitize/sanitizers.js +2 -2
  98. package/admin/src/pages/Roles/pages/ListPage/utils/api.js +0 -30
  99. package/dist/_chunks/en-CE3wEy_c.mjs.map +0 -1
  100. package/dist/_chunks/en-m608rMZx.js.map +0 -1
  101. package/dist/_chunks/index-1uupZmu0.js.map +0 -1
  102. package/dist/_chunks/index-6Kdo3KXv.js.map +0 -1
  103. package/dist/_chunks/index-O9AAUvyy.js.map +0 -1
  104. package/dist/_chunks/index-Un-J-cxQ.js +0 -320
  105. package/dist/_chunks/index-Un-J-cxQ.js.map +0 -1
  106. package/dist/_chunks/index-X0yw_GgN.mjs +0 -301
  107. package/dist/_chunks/index-X0yw_GgN.mjs.map +0 -1
  108. package/dist/_chunks/index-XqdaO5WZ.js.map +0 -1
  109. package/dist/_chunks/index-a9oKDd3C.mjs.map +0 -1
  110. package/dist/_chunks/index-ethhTEkj.mjs.map +0 -1
  111. package/dist/_chunks/index-iNtwnT3f.mjs.map +0 -1
  112. package/dist/_chunks/index-rryiT0-Z.mjs.map +0 -1
@@ -10,12 +10,9 @@
10
10
  const crypto = require('crypto');
11
11
  const _ = require('lodash');
12
12
  const urljoin = require('url-join');
13
- const { isArray } = require('lodash/fp');
14
13
  const { getService } = require('../utils');
15
14
  const getGrantConfig = require('./grant-config');
16
-
17
15
  const usersPermissionsActions = require('./users-permissions-actions');
18
- const userSchema = require('../content-types/user');
19
16
 
20
17
  const initGrant = async (pluginStore) => {
21
18
  const apiPrefix = strapi.config.get('api.rest.prefix');
@@ -99,27 +96,6 @@ const initAdvancedOptions = async (pluginStore) => {
99
96
  }
100
97
  };
101
98
 
102
- const userSchemaAdditions = () => {
103
- const defaultSchema = Object.keys(userSchema.attributes);
104
- const currentSchema = Object.keys(
105
- strapi.contentTypes['plugin::users-permissions.user'].attributes
106
- );
107
-
108
- // Some dynamic fields may not have been initialized yet, so we need to ignore them
109
- // TODO: we should have a global method for finding these
110
- const ignoreDiffs = [
111
- 'createdBy',
112
- 'createdAt',
113
- 'updatedBy',
114
- 'updatedAt',
115
- 'publishedAt',
116
- 'strapi_stage',
117
- 'strapi_assignee',
118
- ];
119
-
120
- return currentSchema.filter((key) => !(ignoreDiffs.includes(key) || defaultSchema.includes(key)));
121
- };
122
-
123
99
  module.exports = async ({ strapi }) => {
124
100
  const pluginStore = strapi.store({ type: 'plugin', name: 'users-permissions' });
125
101
 
@@ -133,7 +109,7 @@ module.exports = async ({ strapi }) => {
133
109
 
134
110
  await getService('users-permissions').initialize();
135
111
 
136
- if (!strapi.config.get('plugin.users-permissions.jwtSecret')) {
112
+ if (!strapi.config.get('plugin::users-permissions.jwtSecret')) {
137
113
  if (process.env.NODE_ENV !== 'development') {
138
114
  throw new Error(
139
115
  `Missing jwtSecret. Please, set configuration variable "jwtSecret" for the users-permissions plugin in config/plugins.js (ex: you can generate one using Node with \`crypto.randomBytes(16).toString('base64')\`).
@@ -143,7 +119,7 @@ For security reasons, prefer storing the secret in an environment variable and r
143
119
 
144
120
  const jwtSecret = crypto.randomBytes(16).toString('base64');
145
121
 
146
- strapi.config.set('plugin.users-permissions.jwtSecret', jwtSecret);
122
+ strapi.config.set('plugin::users-permissions.jwtSecret', jwtSecret);
147
123
 
148
124
  if (!process.env.JWT_SECRET) {
149
125
  const envPath = process.env.ENV_PATH || '.env';
@@ -153,17 +129,4 @@ For security reasons, prefer storing the secret in an environment variable and r
153
129
  );
154
130
  }
155
131
  }
156
-
157
- // TODO v5: Remove this block of code and default allowedFields to empty array
158
- if (!isArray(strapi.config.get('plugin.users-permissions.register.allowedFields'))) {
159
- const modifications = userSchemaAdditions();
160
- if (modifications.length > 0) {
161
- // if there is a potential vulnerability, show a warning
162
- strapi.log.warn(
163
- `Users-permissions registration has defaulted to accepting the following additional user fields during registration: ${modifications.join(
164
- ','
165
- )}`
166
- );
167
- }
168
- }
169
132
  };
@@ -12,7 +12,6 @@ module.exports = {
12
12
  displayName: 'User',
13
13
  },
14
14
  options: {
15
- draftAndPublish: false,
16
15
  timestamps: true,
17
16
  },
18
17
  attributes: {
@@ -11,9 +11,6 @@ const crypto = require('crypto');
11
11
  const _ = require('lodash');
12
12
  const { concat, compact, isArray } = require('lodash/fp');
13
13
  const utils = require('@strapi/utils');
14
- const {
15
- contentTypes: { getNonWritableAttributes },
16
- } = require('@strapi/utils');
17
14
  const { getService } = require('../utils');
18
15
  const {
19
16
  validateCallbackBody,
@@ -25,7 +22,7 @@ const {
25
22
  validateChangePasswordBody,
26
23
  } = require('./validation/auth');
27
24
 
28
- const { getAbsoluteAdminUrl, getAbsoluteServerUrl, sanitize } = utils;
25
+ const { sanitize } = utils;
29
26
  const { ApplicationError, ValidationError, ForbiddenError } = utils.errors;
30
27
 
31
28
  const sanitizeUser = (user, ctx) => {
@@ -55,7 +52,7 @@ module.exports = {
55
52
  const { identifier } = params;
56
53
 
57
54
  // Check if the user exists.
58
- const user = await strapi.query('plugin::users-permissions.user').findOne({
55
+ const user = await strapi.db.query('plugin::users-permissions.user').findOne({
59
56
  where: {
60
57
  provider,
61
58
  $or: [{ email: identifier.toLowerCase() }, { username: identifier }],
@@ -120,10 +117,9 @@ module.exports = {
120
117
 
121
118
  const { currentPassword, password } = await validateChangePasswordBody(ctx.request.body);
122
119
 
123
- const user = await strapi.entityService.findOne(
124
- 'plugin::users-permissions.user',
125
- ctx.state.user.id
126
- );
120
+ const user = await strapi.db
121
+ .query('plugin::users-permissions.user')
122
+ .findOne({ where: { id: ctx.state.user.id } });
127
123
 
128
124
  const validPassword = await getService('user').validatePassword(currentPassword, user.password);
129
125
 
@@ -152,7 +148,7 @@ module.exports = {
152
148
  throw new ValidationError('Passwords do not match');
153
149
  }
154
150
 
155
- const user = await strapi
151
+ const user = await strapi.db
156
152
  .query('plugin::users-permissions.user')
157
153
  .findOne({ where: { resetPasswordToken: code } });
158
154
 
@@ -219,7 +215,7 @@ module.exports = {
219
215
  const advancedSettings = await pluginStore.get({ key: 'advanced' });
220
216
 
221
217
  // Find the user by email.
222
- const user = await strapi
218
+ const user = await strapi.db
223
219
  .query('plugin::users-permissions.user')
224
220
  .findOne({ where: { email: email.toLowerCase() } });
225
221
 
@@ -237,8 +233,8 @@ module.exports = {
237
233
  resetPasswordSettings.message,
238
234
  {
239
235
  URL: advancedSettings.email_reset_password,
240
- SERVER_URL: getAbsoluteServerUrl(strapi.config),
241
- ADMIN_URL: getAbsoluteAdminUrl(strapi.config),
236
+ SERVER_URL: strapi.config.get('server.absoluteUrl'),
237
+ ADMIN_URL: strapi.config.get('admin.absoluteUrl'),
242
238
  USER: userInfo,
243
239
  TOKEN: resetPasswordToken,
244
240
  }
@@ -281,47 +277,22 @@ module.exports = {
281
277
  throw new ApplicationError('Register action is currently disabled');
282
278
  }
283
279
 
284
- const { register } = strapi.config.get('plugin.users-permissions');
280
+ const { register } = strapi.config.get('plugin::users-permissions');
285
281
  const alwaysAllowedKeys = ['username', 'password', 'email'];
286
- const userModel = strapi.contentTypes['plugin::users-permissions.user'];
287
- const { attributes } = userModel;
288
-
289
- const nonWritable = getNonWritableAttributes(userModel);
290
282
 
283
+ // Note that we intentionally do not filter allowedFields to allow a project to explicitly accept private or other Strapi field on registration
291
284
  const allowedKeys = compact(
292
- concat(
293
- alwaysAllowedKeys,
294
- isArray(register?.allowedFields)
295
- ? // Note that we do not filter allowedFields in case a user explicitly chooses to allow a private or otherwise omitted field on registration
296
- register.allowedFields // if null or undefined, compact will remove it
297
- : // to prevent breaking changes, if allowedFields is not set in config, we only remove private and known dangerous user schema fields
298
- // TODO V5: allowedFields defaults to [] when undefined and remove this case
299
- Object.keys(attributes).filter(
300
- (key) =>
301
- !nonWritable.includes(key) &&
302
- !attributes[key].private &&
303
- ![
304
- // many of these are included in nonWritable, but we'll list them again to be safe and since we're removing this code in v5 anyway
305
- // Strapi user schema fields
306
- 'confirmed',
307
- 'blocked',
308
- 'confirmationToken',
309
- 'resetPasswordToken',
310
- 'provider',
311
- 'id',
312
- 'role',
313
- // other Strapi fields that might be added
314
- 'createdAt',
315
- 'updatedAt',
316
- 'createdBy',
317
- 'updatedBy',
318
- 'publishedAt', // d&p
319
- 'strapi_reviewWorkflows_stage', // review workflows
320
- ].includes(key)
321
- )
322
- )
285
+ concat(alwaysAllowedKeys, isArray(register?.allowedFields) ? register.allowedFields : [])
323
286
  );
324
287
 
288
+ // Check if there are any keys in requestBody that are not in allowedKeys
289
+ const invalidKeys = Object.keys(ctx.request.body).filter((key) => !allowedKeys.includes(key));
290
+
291
+ if (invalidKeys.length > 0) {
292
+ // If there are invalid keys, throw an error
293
+ throw new ValidationError(`Invalid parameters: ${invalidKeys.join(', ')}`);
294
+ }
295
+
325
296
  const params = {
326
297
  ..._.pick(ctx.request.body, allowedKeys),
327
298
  provider: 'local',
@@ -329,7 +300,7 @@ module.exports = {
329
300
 
330
301
  await validateRegisterBody(params);
331
302
 
332
- const role = await strapi
303
+ const role = await strapi.db
333
304
  .query('plugin::users-permissions.role')
334
305
  .findOne({ where: { type: settings.default_role } });
335
306
 
@@ -348,7 +319,7 @@ module.exports = {
348
319
  ],
349
320
  };
350
321
 
351
- const conflictingUserCount = await strapi.query('plugin::users-permissions.user').count({
322
+ const conflictingUserCount = await strapi.db.query('plugin::users-permissions.user').count({
352
323
  where: { ...identifierFilter, provider },
353
324
  });
354
325
 
@@ -357,7 +328,7 @@ module.exports = {
357
328
  }
358
329
 
359
330
  if (settings.unique_email) {
360
- const conflictingUserCount = await strapi.query('plugin::users-permissions.user').count({
331
+ const conflictingUserCount = await strapi.db.query('plugin::users-permissions.user').count({
361
332
  where: { ...identifierFilter },
362
333
  });
363
334
 
@@ -427,7 +398,7 @@ module.exports = {
427
398
  async sendEmailConfirmation(ctx) {
428
399
  const { email } = await validateSendEmailConfirmationBody(ctx.request.body);
429
400
 
430
- const user = await strapi.query('plugin::users-permissions.user').findOne({
401
+ const user = await strapi.db.query('plugin::users-permissions.user').findOne({
431
402
  where: { email: email.toLowerCase() },
432
403
  });
433
404
 
@@ -17,24 +17,23 @@ const ACTIONS = {
17
17
  };
18
18
 
19
19
  const findEntityAndCheckPermissions = async (ability, action, model, id) => {
20
- const entity = await strapi.query(userModel).findOne({
21
- where: { id },
20
+ const doc = await strapi.service('plugin::content-manager.document-manager').findOne(id, model, {
22
21
  populate: [`${CREATED_BY_ATTRIBUTE}.roles`],
23
22
  });
24
23
 
25
- if (_.isNil(entity)) {
24
+ if (_.isNil(doc)) {
26
25
  throw new NotFoundError();
27
26
  }
28
27
 
29
28
  const pm = strapi.admin.services.permission.createPermissionsManager({ ability, action, model });
30
29
 
31
- if (pm.ability.cannot(pm.action, pm.toSubject(entity))) {
30
+ if (pm.ability.cannot(pm.action, pm.toSubject(doc))) {
32
31
  throw new ForbiddenError();
33
32
  }
34
33
 
35
- const entityWithoutCreatorRoles = _.omit(entity, `${CREATED_BY_ATTRIBUTE}.roles`);
34
+ const docWithoutCreatorRoles = _.omit(doc, `${CREATED_BY_ATTRIBUTE}.roles`);
36
35
 
37
- return { pm, entity: entityWithoutCreatorRoles };
36
+ return { pm, doc: docWithoutCreatorRoles };
38
37
  };
39
38
 
40
39
  module.exports = {
@@ -66,7 +65,7 @@ module.exports = {
66
65
 
67
66
  await validateCreateUserBody(ctx.request.body);
68
67
 
69
- const userWithSameUsername = await strapi
68
+ const userWithSameUsername = await strapi.db
70
69
  .query('plugin::users-permissions.user')
71
70
  .findOne({ where: { username } });
72
71
 
@@ -75,7 +74,7 @@ module.exports = {
75
74
  }
76
75
 
77
76
  if (advanced.unique_email) {
78
- const userWithSameEmail = await strapi
77
+ const userWithSameEmail = await strapi.db
79
78
  .query('plugin::users-permissions.user')
80
79
  .findOne({ where: { email: email.toLowerCase() } });
81
80
 
@@ -93,18 +92,11 @@ module.exports = {
93
92
 
94
93
  user.email = _.toLower(user.email);
95
94
 
96
- if (!user.role) {
97
- const defaultRole = await strapi
98
- .query('plugin::users-permissions.role')
99
- .findOne({ where: { type: advanced.default_role } });
100
-
101
- user.role = defaultRole.id;
102
- }
103
-
104
95
  try {
105
96
  const data = await strapi
106
- .service('plugin::content-manager.entity-manager')
107
- .create(user, userModel);
97
+ .service('plugin::content-manager.document-manager')
98
+ .create(userModel, { data: user });
99
+
108
100
  const sanitizedData = await pm.sanitizeOutput(data, { action: ACTIONS.read });
109
101
 
110
102
  ctx.created(sanitizedData);
@@ -118,7 +110,7 @@ module.exports = {
118
110
  */
119
111
 
120
112
  async update(ctx) {
121
- const { id } = ctx.params;
113
+ const { id: documentId } = ctx.params;
122
114
  const { body } = ctx.request;
123
115
  const { user: admin, userAbility } = ctx.state;
124
116
 
@@ -128,13 +120,14 @@ module.exports = {
128
120
 
129
121
  const { email, username, password } = body;
130
122
 
131
- const { pm, entity } = await findEntityAndCheckPermissions(
123
+ const { pm, doc } = await findEntityAndCheckPermissions(
132
124
  userAbility,
133
125
  ACTIONS.edit,
134
126
  userModel,
135
- id
127
+ documentId
136
128
  );
137
- const user = entity;
129
+
130
+ const user = doc;
138
131
 
139
132
  await validateUpdateUserBody(ctx.request.body);
140
133
 
@@ -143,23 +136,24 @@ module.exports = {
143
136
  }
144
137
 
145
138
  if (_.has(body, 'username')) {
146
- const userWithSameUsername = await strapi
139
+ const userWithSameUsername = await strapi.db
147
140
  .query('plugin::users-permissions.user')
148
141
  .findOne({ where: { username } });
149
142
 
150
- if (userWithSameUsername && _.toString(userWithSameUsername.id) !== _.toString(id)) {
143
+ if (userWithSameUsername && _.toString(userWithSameUsername.id) !== _.toString(user.id)) {
151
144
  throw new ApplicationError('Username already taken');
152
145
  }
153
146
  }
154
147
 
155
148
  if (_.has(body, 'email') && advancedConfigs.unique_email) {
156
- const userWithSameEmail = await strapi
149
+ const userWithSameEmail = await strapi.db
157
150
  .query('plugin::users-permissions.user')
158
151
  .findOne({ where: { email: _.toLower(email) } });
159
152
 
160
- if (userWithSameEmail && _.toString(userWithSameEmail.id) !== _.toString(id)) {
153
+ if (userWithSameEmail && _.toString(userWithSameEmail.id) !== _.toString(user.id)) {
161
154
  throw new ApplicationError('Email already taken');
162
155
  }
156
+
163
157
  body.email = _.toLower(body.email);
164
158
  }
165
159
 
@@ -167,8 +161,10 @@ module.exports = {
167
161
  const updateData = _.omit({ ...sanitizedData, updatedBy: admin.id }, 'createdBy');
168
162
 
169
163
  const data = await strapi
170
- .service('plugin::content-manager.entity-manager')
171
- .update({ id }, updateData, userModel);
164
+ .service('plugin::content-manager.document-manager')
165
+ .update(documentId, userModel, {
166
+ data: updateData,
167
+ });
172
168
 
173
169
  ctx.body = await pm.sanitizeOutput(data, { action: ACTIONS.read });
174
170
  },
@@ -59,7 +59,7 @@ module.exports = {
59
59
  }
60
60
 
61
61
  // Fetch public role.
62
- const publicRole = await strapi
62
+ const publicRole = await strapi.db
63
63
  .query('plugin::users-permissions.role')
64
64
  .findOne({ where: { type: 'public' } });
65
65
 
@@ -49,7 +49,7 @@ module.exports = {
49
49
 
50
50
  const { email, username, role } = ctx.request.body;
51
51
 
52
- const userWithSameUsername = await strapi
52
+ const userWithSameUsername = await strapi.db
53
53
  .query('plugin::users-permissions.user')
54
54
  .findOne({ where: { username } });
55
55
 
@@ -58,7 +58,7 @@ module.exports = {
58
58
  }
59
59
 
60
60
  if (advanced.unique_email) {
61
- const userWithSameEmail = await strapi
61
+ const userWithSameEmail = await strapi.db
62
62
  .query('plugin::users-permissions.user')
63
63
  .findOne({ where: { email: email.toLowerCase() } });
64
64
 
@@ -74,7 +74,7 @@ module.exports = {
74
74
  };
75
75
 
76
76
  if (!role) {
77
- const defaultRole = await strapi
77
+ const defaultRole = await strapi.db
78
78
  .query('plugin::users-permissions.role')
79
79
  .findOne({ where: { type: advanced.default_role } });
80
80
 
@@ -115,7 +115,7 @@ module.exports = {
115
115
  }
116
116
 
117
117
  if (_.has(ctx.request.body, 'username')) {
118
- const userWithSameUsername = await strapi
118
+ const userWithSameUsername = await strapi.db
119
119
  .query('plugin::users-permissions.user')
120
120
  .findOne({ where: { username } });
121
121
 
@@ -125,7 +125,7 @@ module.exports = {
125
125
  }
126
126
 
127
127
  if (_.has(ctx.request.body, 'email') && advancedConfigs.unique_email) {
128
- const userWithSameEmail = await strapi
128
+ const userWithSameEmail = await strapi.db
129
129
  .query('plugin::users-permissions.user')
130
130
  .findOne({ where: { email: email.toLowerCase() } });
131
131
 
@@ -9,7 +9,7 @@ const { RateLimitError } = utils.errors;
9
9
  module.exports =
10
10
  (config, { strapi }) =>
11
11
  async (ctx, next) => {
12
- let rateLimitConfig = strapi.config.get('plugin.users-permissions.ratelimit');
12
+ let rateLimitConfig = strapi.config.get('plugin::users-permissions.ratelimit');
13
13
 
14
14
  if (!rateLimitConfig) {
15
15
  rateLimitConfig = {
@@ -7,7 +7,7 @@ const authStrategy = require('./strategies/users-permissions');
7
7
  const sanitizers = require('./utils/sanitize/sanitizers');
8
8
 
9
9
  module.exports = ({ strapi }) => {
10
- strapi.container.get('auth').register('content-api', authStrategy);
10
+ strapi.get('auth').register('content-api', authStrategy);
11
11
  strapi.sanitizers.add('content-api.output', sanitizers.defaultSanitizeOutput);
12
12
 
13
13
  if (strapi.plugin('graphql')) {
@@ -29,10 +29,10 @@ module.exports = ({ strapi }) => ({
29
29
  },
30
30
 
31
31
  issue(payload, jwtOptions = {}) {
32
- _.defaults(jwtOptions, strapi.config.get('plugin.users-permissions.jwt'));
32
+ _.defaults(jwtOptions, strapi.config.get('plugin::users-permissions.jwt'));
33
33
  return jwt.sign(
34
34
  _.clone(payload.toJSON ? payload.toJSON() : payload),
35
- strapi.config.get('plugin.users-permissions.jwtSecret'),
35
+ strapi.config.get('plugin::users-permissions.jwtSecret'),
36
36
  jwtOptions
37
37
  );
38
38
  },
@@ -41,7 +41,7 @@ module.exports = ({ strapi }) => ({
41
41
  return new Promise((resolve, reject) => {
42
42
  jwt.verify(
43
43
  token,
44
- strapi.config.get('plugin.users-permissions.jwtSecret'),
44
+ strapi.config.get('plugin::users-permissions.jwtSecret'),
45
45
  {},
46
46
  (err, tokenPayload = {}) => {
47
47
  if (err) {
@@ -11,11 +11,7 @@ module.exports = ({ strapi }) => ({
11
11
  * @return {object[]}
12
12
  */
13
13
  async findRolePermissions(roleID) {
14
- return strapi.entityService.load(
15
- 'plugin::users-permissions.role',
16
- { id: roleID },
17
- 'permissions'
18
- );
14
+ return strapi.db.query('plugin::users-permissions.role').load({ id: roleID }, 'permissions');
19
15
  },
20
16
 
21
17
  /**
@@ -24,8 +20,8 @@ module.exports = ({ strapi }) => ({
24
20
  * @return {object[]}
25
21
  */
26
22
  async findPublicPermissions() {
27
- return strapi.entityService.findMany('plugin::users-permissions.permission', {
28
- filters: PUBLIC_ROLE_FILTER,
23
+ return strapi.db.query('plugin::users-permissions.permission').findMany({
24
+ where: PUBLIC_ROLE_FILTER,
29
25
  });
30
26
  },
31
27
 
@@ -331,6 +331,21 @@ const getInitialProviders = ({ purest }) => ({
331
331
  };
332
332
  });
333
333
  },
334
+ async keycloak({ accessToken, providers }) {
335
+ const keycloak = purest({ provider: 'keycloak' });
336
+
337
+ return keycloak
338
+ .subdomain(providers.keycloak.subdomain)
339
+ .get('protocol/openid-connect/userinfo')
340
+ .auth(accessToken)
341
+ .request()
342
+ .then(({ body }) => {
343
+ return {
344
+ username: body.preferred_username,
345
+ email: body.email,
346
+ };
347
+ });
348
+ },
334
349
  });
335
350
 
336
351
  module.exports = () => {
@@ -8,7 +8,6 @@
8
8
  const _ = require('lodash');
9
9
  const urlJoin = require('url-join');
10
10
 
11
- const { getAbsoluteServerUrl } = require('@strapi/utils');
12
11
  const { getService } = require('../utils');
13
12
 
14
13
  module.exports = ({ strapi }) => {
@@ -60,7 +59,7 @@ module.exports = ({ strapi }) => {
60
59
  throw new Error('Email was not available.');
61
60
  }
62
61
 
63
- const users = await strapi.query('plugin::users-permissions.user').findMany({
62
+ const users = await strapi.db.query('plugin::users-permissions.user').findMany({
64
63
  where: { email },
65
64
  });
66
65
 
@@ -83,7 +82,7 @@ module.exports = ({ strapi }) => {
83
82
  }
84
83
 
85
84
  // Retrieve default role.
86
- const defaultRole = await strapi
85
+ const defaultRole = await strapi.db
87
86
  .query('plugin::users-permissions.role')
88
87
  .findOne({ where: { type: advancedSettings.default_role } });
89
88
 
@@ -96,7 +95,7 @@ module.exports = ({ strapi }) => {
96
95
  confirmed: true,
97
96
  };
98
97
 
99
- const createdUser = await strapi
98
+ const createdUser = await strapi.db
100
99
  .query('plugin::users-permissions.user')
101
100
  .create({ data: newUser });
102
101
 
@@ -105,7 +104,13 @@ module.exports = ({ strapi }) => {
105
104
 
106
105
  const buildRedirectUri = (provider = '') => {
107
106
  const apiPrefix = strapi.config.get('api.rest.prefix');
108
- return urlJoin(getAbsoluteServerUrl(strapi.config), apiPrefix, 'connect', provider, 'callback');
107
+ return urlJoin(
108
+ strapi.config.get('server.absoluteUrl'),
109
+ apiPrefix,
110
+ 'connect',
111
+ provider,
112
+ 'callback'
113
+ );
109
114
  };
110
115
 
111
116
  return {