@strapi/plugin-users-permissions 4.1.8 → 4.1.10

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.
@@ -1,4 +1,15 @@
1
1
  import React, { useState, useRef } from 'react';
2
+ import { Formik } from 'formik';
3
+ import { useIntl } from 'react-intl';
4
+ import { useRouteMatch } from 'react-router-dom';
5
+ import {
6
+ useOverlayBlocker,
7
+ SettingsPageTitle,
8
+ LoadingIndicatorPage,
9
+ Form,
10
+ useNotification,
11
+ Link,
12
+ } from '@strapi/helper-plugin';
2
13
  import { ContentLayout, HeaderLayout } from '@strapi/design-system/Layout';
3
14
  import { Main } from '@strapi/design-system/Main';
4
15
  import { Button } from '@strapi/design-system/Button';
@@ -9,18 +20,7 @@ import { Textarea } from '@strapi/design-system/Textarea';
9
20
  import { Typography } from '@strapi/design-system/Typography';
10
21
  import ArrowLeft from '@strapi/icons/ArrowLeft';
11
22
  import Check from '@strapi/icons/Check';
12
- import { Link } from '@strapi/design-system/Link';
13
23
  import { GridItem, Grid } from '@strapi/design-system/Grid';
14
- import { Formik } from 'formik';
15
- import { useIntl } from 'react-intl';
16
- import { useRouteMatch } from 'react-router-dom';
17
- import {
18
- useOverlayBlocker,
19
- SettingsPageTitle,
20
- LoadingIndicatorPage,
21
- Form,
22
- useNotification,
23
- } from '@strapi/helper-plugin';
24
24
  import UsersPermissions from '../../../components/UsersPermissions';
25
25
  import getTrad from '../../../utils/getTrad';
26
26
  import pluginId from '../../../pluginId';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/plugin-users-permissions",
3
- "version": "4.1.8",
3
+ "version": "4.1.10",
4
4
  "description": "Protect your API with a full-authentication process based on JWT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,8 +27,8 @@
27
27
  "test:front:watch:ce": "cross-env IS_EE=false jest --config ./jest.config.front.js --watchAll"
28
28
  },
29
29
  "dependencies": {
30
- "@strapi/helper-plugin": "4.1.8",
31
- "@strapi/utils": "4.1.8",
30
+ "@strapi/helper-plugin": "4.1.10",
31
+ "@strapi/utils": "4.1.10",
32
32
  "bcryptjs": "2.4.3",
33
33
  "grant-koa": "5.4.8",
34
34
  "jsonwebtoken": "^8.1.0",
@@ -59,5 +59,5 @@
59
59
  "required": true,
60
60
  "kind": "plugin"
61
61
  },
62
- "gitHead": "3f204a0a48d4e1f6dca21683eb6c63041b2f6626"
62
+ "gitHead": "06abcda86ab96fc560b3ff5e3d72c4d5c1c5d42c"
63
63
  }
@@ -21,10 +21,10 @@ module.exports = {
21
21
  ctx.send({ ok: true });
22
22
  },
23
23
 
24
- async getRole(ctx) {
24
+ async findOne(ctx) {
25
25
  const { id } = ctx.params;
26
26
 
27
- const role = await getService('role').getRole(id);
27
+ const role = await getService('role').findOne(id);
28
28
 
29
29
  if (!role) {
30
30
  return ctx.notFound();
@@ -33,8 +33,8 @@ module.exports = {
33
33
  ctx.send({ role });
34
34
  },
35
35
 
36
- async getRoles(ctx) {
37
- const roles = await getService('role').getRoles();
36
+ async find(ctx) {
37
+ const roles = await getService('role').find();
38
38
 
39
39
  ctx.send({ roles });
40
40
  },
@@ -37,7 +37,7 @@ module.exports = {
37
37
  .store({ type: 'plugin', name: 'users-permissions', key: 'advanced' })
38
38
  .get();
39
39
 
40
- const roles = await getService('role').getRoles();
40
+ const roles = await getService('role').find();
41
41
 
42
42
  ctx.send({ settings, roles });
43
43
  },
@@ -90,7 +90,7 @@ module.exports = {
90
90
  const { id } = ctx.params;
91
91
  const { email, username, password } = ctx.request.body;
92
92
 
93
- const user = await getService('user').fetch({ id });
93
+ const user = await getService('user').fetch(id);
94
94
 
95
95
  await validateUpdateUserBody(ctx.request.body);
96
96
 
@@ -133,8 +133,8 @@ module.exports = {
133
133
  * Retrieve user records.
134
134
  * @return {Object|Array}
135
135
  */
136
- async find(ctx, next, { populate } = {}) {
137
- const users = await getService('user').fetchAll(ctx.query.filters, populate);
136
+ async find(ctx) {
137
+ const users = await getService('user').fetchAll(ctx.query);
138
138
 
139
139
  ctx.body = await Promise.all(users.map(user => sanitizeOutput(user, ctx)));
140
140
  },
@@ -145,7 +145,9 @@ module.exports = {
145
145
  */
146
146
  async findOne(ctx) {
147
147
  const { id } = ctx.params;
148
- let data = await getService('user').fetch({ id });
148
+ const { query } = ctx;
149
+
150
+ let data = await getService('user').fetch(id, query);
149
151
 
150
152
  if (data) {
151
153
  data = await sanitizeOutput(data, ctx);
@@ -1,9 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  const authStrategy = require('./strategies/users-permissions');
4
+ const sanitizers = require('./utils/sanitize/sanitizers');
4
5
 
5
6
  module.exports = ({ strapi }) => {
6
7
  strapi.container.get('auth').register('content-api', authStrategy);
8
+ strapi.sanitizers.add('content-api.output', sanitizers.defaultSanitizeOutput);
7
9
 
8
10
  if (strapi.plugin('graphql')) {
9
11
  require('./graphql')({ strapi });
@@ -4,7 +4,7 @@ module.exports = [
4
4
  {
5
5
  method: 'GET',
6
6
  path: '/roles/:id',
7
- handler: 'role.getRole',
7
+ handler: 'role.findOne',
8
8
  config: {
9
9
  policies: [
10
10
  {
@@ -19,7 +19,7 @@ module.exports = [
19
19
  {
20
20
  method: 'GET',
21
21
  path: '/roles',
22
- handler: 'role.getRoles',
22
+ handler: 'role.find',
23
23
  config: {
24
24
  policies: [
25
25
  {
@@ -4,12 +4,12 @@ module.exports = [
4
4
  {
5
5
  method: 'GET',
6
6
  path: '/roles/:id',
7
- handler: 'role.getRole',
7
+ handler: 'role.findOne',
8
8
  },
9
9
  {
10
10
  method: 'GET',
11
11
  path: '/roles',
12
- handler: 'role.getRoles',
12
+ handler: 'role.find',
13
13
  },
14
14
  {
15
15
  method: 'POST',
@@ -41,7 +41,7 @@ module.exports = ({ strapi }) => ({
41
41
  await Promise.all(createPromises);
42
42
  },
43
43
 
44
- async getRole(roleID) {
44
+ async findOne(roleID) {
45
45
  const role = await strapi
46
46
  .query('plugin::users-permissions.role')
47
47
  .findOne({ where: { id: roleID }, populate: ['permissions'] });
@@ -68,7 +68,7 @@ module.exports = ({ strapi }) => ({
68
68
  };
69
69
  },
70
70
 
71
- async getRoles() {
71
+ async find() {
72
72
  const roles = await strapi.query('plugin::users-permissions.role').findMany({ sort: ['name'] });
73
73
 
74
74
  for (const role of roles) {
@@ -58,8 +58,8 @@ module.exports = ({ strapi }) => ({
58
58
  * Promise to fetch a/an user.
59
59
  * @return {Promise}
60
60
  */
61
- fetch(params, populate) {
62
- return strapi.query('plugin::users-permissions.user').findOne({ where: params, populate });
61
+ fetch(id, params) {
62
+ return strapi.entityService.findOne('plugin::users-permissions.user', id, params);
63
63
  },
64
64
 
65
65
  /**
@@ -76,8 +76,8 @@ module.exports = ({ strapi }) => ({
76
76
  * Promise to fetch all users.
77
77
  * @return {Promise}
78
78
  */
79
- fetchAll(params, populate) {
80
- return strapi.query('plugin::users-permissions.user').findMany({ where: params, populate });
79
+ fetchAll(params) {
80
+ return strapi.entityService.findMany('plugin::users-permissions.user', params);
81
81
  },
82
82
 
83
83
  /**
@@ -1,9 +1,12 @@
1
1
  'use strict';
2
2
 
3
+ const sanitize = require('./sanitize');
4
+
3
5
  const getService = name => {
4
6
  return strapi.plugin('users-permissions').service(name);
5
7
  };
6
8
 
7
9
  module.exports = {
8
10
  getService,
11
+ sanitize,
9
12
  };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const visitors = require('./visitors');
4
+ const sanitizers = require('./sanitizers');
5
+
6
+ module.exports = {
7
+ sanitizers,
8
+ visitors,
9
+ };
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ const { curry } = require('lodash/fp');
4
+ const { traverseEntity, pipeAsync } = require('@strapi/utils');
5
+
6
+ const { removeUserRelationFromRoleEntities } = require('./visitors');
7
+
8
+ const sanitizeUserRelationFromRoleEntities = curry((schema, entity) => {
9
+ return traverseEntity(removeUserRelationFromRoleEntities, { schema }, entity);
10
+ });
11
+
12
+ const defaultSanitizeOutput = curry((schema, entity) => {
13
+ return pipeAsync(sanitizeUserRelationFromRoleEntities(schema))(entity);
14
+ });
15
+
16
+ module.exports = {
17
+ sanitizeUserRelationFromRoleEntities,
18
+ defaultSanitizeOutput,
19
+ };
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ removeUserRelationFromRoleEntities: require('./remove-user-relation-from-role-entities'),
5
+ };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ module.exports = ({ schema, key, attribute }, { remove }) => {
4
+ if (
5
+ attribute.type === 'relation' &&
6
+ attribute.target === 'plugin::users-permissions.user' &&
7
+ schema.uid === 'plugin::users-permissions.role'
8
+ ) {
9
+ remove(key);
10
+ }
11
+ };