@strapi/plugin-users-permissions 0.0.0-next.f7babb775ed9a7e18d8351cb7f74c63e016323c4 → 0.0.0-next.f8af92b375dc730ba47ed2117f25df893aae696c
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/.eslintignore +1 -2
- package/.eslintrc +17 -0
- package/admin/src/components/Permissions/{index.js → index.jsx} +2 -4
- package/admin/src/index.js +12 -23
- package/admin/src/pages/AdvancedSettings/{index.js → index.jsx} +41 -24
- package/admin/src/pages/EmailTemplates/{index.js → index.jsx} +62 -47
- package/admin/src/pages/Providers/{index.js → index.jsx} +64 -58
- package/admin/src/{hooks → pages/Roles/hooks}/usePlugins.js +15 -8
- package/admin/src/pages/Roles/{index.js → index.jsx} +10 -7
- package/admin/src/pages/Roles/pages/CreatePage.jsx +199 -0
- package/admin/src/pages/Roles/pages/EditPage.jsx +220 -0
- package/admin/src/pages/Roles/{ListPage/components/TableBody.js → pages/ListPage/components/TableBody.jsx} +44 -14
- package/admin/src/pages/Roles/{ListPage/index.js → pages/ListPage/index.jsx} +19 -15
- package/admin/src/translations/zh-Hans.json +80 -80
- package/dist/_chunks/ar-MvD8Ghac.mjs +44 -0
- package/dist/_chunks/ar-MvD8Ghac.mjs.map +1 -0
- package/dist/_chunks/ar-t5qTFaAD.js +44 -0
- package/dist/_chunks/ar-t5qTFaAD.js.map +1 -0
- package/dist/_chunks/cs-BMuXwxA1.mjs +50 -0
- package/dist/_chunks/cs-BMuXwxA1.mjs.map +1 -0
- package/dist/_chunks/cs-I8N4u-Sd.js +50 -0
- package/dist/_chunks/cs-I8N4u-Sd.js.map +1 -0
- package/dist/_chunks/de-YTjtq89K.js +62 -0
- package/dist/_chunks/de-YTjtq89K.js.map +1 -0
- package/dist/_chunks/de-zs2qqc0W.mjs +62 -0
- package/dist/_chunks/de-zs2qqc0W.mjs.map +1 -0
- package/dist/_chunks/dk-HctVBMsG.mjs +86 -0
- package/dist/_chunks/dk-HctVBMsG.mjs.map +1 -0
- package/dist/_chunks/dk-TF-dWjzl.js +86 -0
- package/dist/_chunks/dk-TF-dWjzl.js.map +1 -0
- package/dist/_chunks/en-CE3wEy_c.mjs +86 -0
- package/dist/_chunks/en-CE3wEy_c.mjs.map +1 -0
- package/dist/_chunks/en-m608rMZx.js +86 -0
- package/dist/_chunks/en-m608rMZx.js.map +1 -0
- package/dist/_chunks/es-9381tih_.mjs +86 -0
- package/dist/_chunks/es-9381tih_.mjs.map +1 -0
- package/dist/_chunks/es-XBQsB8_9.js +86 -0
- package/dist/_chunks/es-XBQsB8_9.js.map +1 -0
- package/dist/_chunks/fr-6cz3U-IF.js +50 -0
- package/dist/_chunks/fr-6cz3U-IF.js.map +1 -0
- package/dist/_chunks/fr-CMSc77If.mjs +50 -0
- package/dist/_chunks/fr-CMSc77If.mjs.map +1 -0
- package/dist/_chunks/id-RJ934rq-.js +62 -0
- package/dist/_chunks/id-RJ934rq-.js.map +1 -0
- package/dist/_chunks/id-SDuyIkZa.mjs +62 -0
- package/dist/_chunks/id-SDuyIkZa.mjs.map +1 -0
- package/dist/_chunks/index-9gWaMWEm.js +407 -0
- package/dist/_chunks/index-9gWaMWEm.js.map +1 -0
- package/dist/_chunks/index-GrQm7Vzp.mjs +385 -0
- package/dist/_chunks/index-GrQm7Vzp.mjs.map +1 -0
- package/dist/_chunks/index-IrxIszoz.mjs +250 -0
- package/dist/_chunks/index-IrxIszoz.mjs.map +1 -0
- package/dist/_chunks/index-OAhEloLu.mjs +615 -0
- package/dist/_chunks/index-OAhEloLu.mjs.map +1 -0
- package/dist/_chunks/index-Pd_ARJrq.js +1191 -0
- package/dist/_chunks/index-Pd_ARJrq.js.map +1 -0
- package/dist/_chunks/index-VwrATkHQ.js +320 -0
- package/dist/_chunks/index-VwrATkHQ.js.map +1 -0
- package/dist/_chunks/index-jmZgp6D6.mjs +1159 -0
- package/dist/_chunks/index-jmZgp6D6.mjs.map +1 -0
- package/dist/_chunks/index-oskitS-P.js +249 -0
- package/dist/_chunks/index-oskitS-P.js.map +1 -0
- package/dist/_chunks/index-uaeObIW1.js +638 -0
- package/dist/_chunks/index-uaeObIW1.js.map +1 -0
- package/dist/_chunks/index-x0N2TQLH.mjs +301 -0
- package/dist/_chunks/index-x0N2TQLH.mjs.map +1 -0
- package/dist/_chunks/it-YhZOlM2X.js +62 -0
- package/dist/_chunks/it-YhZOlM2X.js.map +1 -0
- package/dist/_chunks/it-bvH7DgQo.mjs +62 -0
- package/dist/_chunks/it-bvH7DgQo.mjs.map +1 -0
- package/dist/_chunks/ja-o_-JPvQv.mjs +48 -0
- package/dist/_chunks/ja-o_-JPvQv.mjs.map +1 -0
- package/dist/_chunks/ja-xssHUXFv.js +48 -0
- package/dist/_chunks/ja-xssHUXFv.js.map +1 -0
- package/dist/_chunks/ko-C3mHUSJa.js +86 -0
- package/dist/_chunks/ko-C3mHUSJa.js.map +1 -0
- package/dist/_chunks/ko-XJbPSez_.mjs +86 -0
- package/dist/_chunks/ko-XJbPSez_.mjs.map +1 -0
- package/dist/_chunks/ms-II5Ea73J.mjs +49 -0
- package/dist/_chunks/ms-II5Ea73J.mjs.map +1 -0
- package/dist/_chunks/ms-d0hfg65Z.js +49 -0
- package/dist/_chunks/ms-d0hfg65Z.js.map +1 -0
- package/dist/_chunks/nl-TA7TfK_5.js +48 -0
- package/dist/_chunks/nl-TA7TfK_5.js.map +1 -0
- package/dist/_chunks/nl-vEy6TN0K.mjs +48 -0
- package/dist/_chunks/nl-vEy6TN0K.mjs.map +1 -0
- package/dist/_chunks/pl-0pUL9hdA.js +86 -0
- package/dist/_chunks/pl-0pUL9hdA.js.map +1 -0
- package/dist/_chunks/pl-2VowaFGt.mjs +86 -0
- package/dist/_chunks/pl-2VowaFGt.mjs.map +1 -0
- package/dist/_chunks/pt-BR-WNOhafR4.js +44 -0
- package/dist/_chunks/pt-BR-WNOhafR4.js.map +1 -0
- package/dist/_chunks/pt-BR-sS1Xp3Jt.mjs +44 -0
- package/dist/_chunks/pt-BR-sS1Xp3Jt.mjs.map +1 -0
- package/dist/_chunks/pt-Rf9W51IO.mjs +48 -0
- package/dist/_chunks/pt-Rf9W51IO.mjs.map +1 -0
- package/dist/_chunks/pt-guNR9Gax.js +48 -0
- package/dist/_chunks/pt-guNR9Gax.js.map +1 -0
- package/dist/_chunks/ru-X3BMXDds.js +86 -0
- package/dist/_chunks/ru-X3BMXDds.js.map +1 -0
- package/dist/_chunks/ru-qKHnd5or.mjs +86 -0
- package/dist/_chunks/ru-qKHnd5or.mjs.map +1 -0
- package/dist/_chunks/sk-NWPw1oTN.js +50 -0
- package/dist/_chunks/sk-NWPw1oTN.js.map +1 -0
- package/dist/_chunks/sk-_Ryr-eTT.mjs +50 -0
- package/dist/_chunks/sk-_Ryr-eTT.mjs.map +1 -0
- package/dist/_chunks/sv-76NnbB__.js +86 -0
- package/dist/_chunks/sv-76NnbB__.js.map +1 -0
- package/dist/_chunks/sv-BqzScFXS.mjs +86 -0
- package/dist/_chunks/sv-BqzScFXS.mjs.map +1 -0
- package/dist/_chunks/th-WsknMEpq.mjs +60 -0
- package/dist/_chunks/th-WsknMEpq.mjs.map +1 -0
- package/dist/_chunks/th-cbppX21D.js +60 -0
- package/dist/_chunks/th-cbppX21D.js.map +1 -0
- package/dist/_chunks/tr-6mm_Fmz7.js +85 -0
- package/dist/_chunks/tr-6mm_Fmz7.js.map +1 -0
- package/dist/_chunks/tr-_DB1F1GW.mjs +85 -0
- package/dist/_chunks/tr-_DB1F1GW.mjs.map +1 -0
- package/dist/_chunks/uk-sI2I1ogF.js +49 -0
- package/dist/_chunks/uk-sI2I1ogF.js.map +1 -0
- package/dist/_chunks/uk-yxMSQAwI.mjs +49 -0
- package/dist/_chunks/uk-yxMSQAwI.mjs.map +1 -0
- package/dist/_chunks/vi-A3zJxaiI.js +50 -0
- package/dist/_chunks/vi-A3zJxaiI.js.map +1 -0
- package/dist/_chunks/vi-xY0zCW3d.mjs +50 -0
- package/dist/_chunks/vi-xY0zCW3d.mjs.map +1 -0
- package/dist/_chunks/zh-72SpmFXa.js +86 -0
- package/dist/_chunks/zh-72SpmFXa.js.map +1 -0
- package/dist/_chunks/zh-Hans-ArWWtyP4.js +86 -0
- package/dist/_chunks/zh-Hans-ArWWtyP4.js.map +1 -0
- package/dist/_chunks/zh-Hans-E84cu4kP.mjs +86 -0
- package/dist/_chunks/zh-Hans-E84cu4kP.mjs.map +1 -0
- package/dist/_chunks/zh-OFeldzbX.mjs +86 -0
- package/dist/_chunks/zh-OFeldzbX.mjs.map +1 -0
- package/dist/admin/index.js +5 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/index.mjs +6 -0
- package/dist/admin/index.mjs.map +1 -0
- package/documentation/content-api.yaml +1 -1
- package/jest.config.front.js +1 -1
- package/package.json +34 -14
- package/packup.config.ts +22 -0
- package/server/bootstrap/index.js +36 -0
- package/server/controllers/auth.js +51 -14
- package/server/controllers/user.js +12 -1
- package/server/middlewares/rateLimit.js +1 -1
- package/.eslintrc.js +0 -14
- package/admin/src/hooks/index.js +0 -5
- package/admin/src/hooks/useFetchRole/index.js +0 -67
- package/admin/src/hooks/useFetchRole/reducer.js +0 -31
- package/admin/src/hooks/useForm/index.js +0 -68
- package/admin/src/hooks/useForm/reducer.js +0 -40
- package/admin/src/hooks/useRolesList/index.js +0 -65
- package/admin/src/hooks/useRolesList/init.js +0 -5
- package/admin/src/hooks/useRolesList/reducer.js +0 -31
- package/admin/src/pages/AdvancedSettings/utils/api.js +0 -16
- package/admin/src/pages/EmailTemplates/utils/api.js +0 -16
- package/admin/src/pages/Providers/reducer.js +0 -54
- package/admin/src/pages/Providers/utils/api.js +0 -24
- package/admin/src/pages/Providers/utils/createProvidersArray.js +0 -21
- package/admin/src/pages/Roles/CreatePage.js +0 -185
- package/admin/src/pages/Roles/EditPage.js +0 -197
- package/admin/src/pages/Roles/ProtectedCreatePage.js +0 -15
- package/admin/src/pages/Roles/ProtectedEditPage.js +0 -15
- package/admin/src/pages/Roles/ProtectedListPage.js +0 -17
- package/strapi-admin.js +0 -3
- /package/admin/src/components/BoundRoute/{index.js → index.jsx} +0 -0
- /package/admin/src/components/FormModal/Input/{index.js → index.jsx} +0 -0
- /package/admin/src/components/FormModal/{index.js → index.jsx} +0 -0
- /package/admin/src/components/Permissions/PermissionRow/{CheckboxWrapper.js → CheckboxWrapper.jsx} +0 -0
- /package/admin/src/components/Permissions/PermissionRow/{SubCategory.js → SubCategory.jsx} +0 -0
- /package/admin/src/components/Permissions/PermissionRow/{index.js → index.jsx} +0 -0
- /package/admin/src/components/Policies/{index.js → index.jsx} +0 -0
- /package/admin/src/components/UsersPermissions/{index.js → index.jsx} +0 -0
- /package/admin/src/contexts/UsersPermissionsContext/{index.js → index.jsx} +0 -0
- /package/admin/src/pages/EmailTemplates/components/{EmailForm.js → EmailForm.jsx} +0 -0
- /package/admin/src/pages/EmailTemplates/components/{EmailTable.js → EmailTable.jsx} +0 -0
- /package/admin/src/pages/Roles/{ListPage → pages/ListPage}/utils/api.js +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/plugin-users-permissions",
|
|
3
|
-
"version": "0.0.0-next.
|
|
3
|
+
"version": "0.0.0-next.f8af92b375dc730ba47ed2117f25df893aae696c",
|
|
4
4
|
"description": "Protect your API with a full-authentication process based on JWT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,20 +19,37 @@
|
|
|
19
19
|
"url": "https://strapi.io"
|
|
20
20
|
}
|
|
21
21
|
],
|
|
22
|
+
"exports": {
|
|
23
|
+
"./strapi-admin": {
|
|
24
|
+
"source": "./admin/src/index.js",
|
|
25
|
+
"import": "./dist/admin/index.mjs",
|
|
26
|
+
"require": "./dist/admin/index.js",
|
|
27
|
+
"default": "./dist/admin/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./strapi-server": {
|
|
30
|
+
"source": "./strapi-server.js",
|
|
31
|
+
"require": "./strapi-server.js",
|
|
32
|
+
"default": "./strapi-server.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
22
36
|
"scripts": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
37
|
+
"build": "pack-up build",
|
|
38
|
+
"clean": "run -T rimraf dist",
|
|
39
|
+
"lint": "run -T eslint .",
|
|
25
40
|
"test:front": "run -T cross-env IS_EE=true jest --config ./jest.config.front.js",
|
|
26
|
-
"test:front:watch": "run -T cross-env IS_EE=true jest --config ./jest.config.front.js --watchAll",
|
|
27
41
|
"test:front:ce": "run -T cross-env IS_EE=false jest --config ./jest.config.front.js",
|
|
42
|
+
"test:front:watch": "run -T cross-env IS_EE=true jest --config ./jest.config.front.js --watchAll",
|
|
28
43
|
"test:front:watch:ce": "run -T cross-env IS_EE=false jest --config ./jest.config.front.js --watchAll",
|
|
29
|
-
"
|
|
44
|
+
"test:unit": "run -T jest",
|
|
45
|
+
"test:unit:watch": "run -T jest --watch",
|
|
46
|
+
"watch": "pack-up watch"
|
|
30
47
|
},
|
|
31
48
|
"dependencies": {
|
|
32
|
-
"@strapi/design-system": "1.
|
|
33
|
-
"@strapi/helper-plugin": "0.0.0-next.
|
|
34
|
-
"@strapi/icons": "1.
|
|
35
|
-
"@strapi/utils": "0.0.0-next.
|
|
49
|
+
"@strapi/design-system": "1.14.1",
|
|
50
|
+
"@strapi/helper-plugin": "0.0.0-next.f8af92b375dc730ba47ed2117f25df893aae696c",
|
|
51
|
+
"@strapi/icons": "1.14.1",
|
|
52
|
+
"@strapi/utils": "0.0.0-next.f8af92b375dc730ba47ed2117f25df893aae696c",
|
|
36
53
|
"bcryptjs": "2.4.3",
|
|
37
54
|
"formik": "2.4.0",
|
|
38
55
|
"grant-koa": "5.4.8",
|
|
@@ -51,23 +68,26 @@
|
|
|
51
68
|
"yup": "0.32.9"
|
|
52
69
|
},
|
|
53
70
|
"devDependencies": {
|
|
71
|
+
"@strapi/pack-up": "0.0.0-next.f8af92b375dc730ba47ed2117f25df893aae696c",
|
|
72
|
+
"@strapi/strapi": "0.0.0-next.f8af92b375dc730ba47ed2117f25df893aae696c",
|
|
54
73
|
"@testing-library/dom": "9.2.0",
|
|
55
74
|
"@testing-library/react": "14.0.0",
|
|
56
75
|
"@testing-library/user-event": "14.4.3",
|
|
57
|
-
"msw": "1.
|
|
76
|
+
"msw": "1.3.0",
|
|
58
77
|
"react": "^18.2.0",
|
|
59
78
|
"react-dom": "^18.2.0",
|
|
60
79
|
"react-router-dom": "5.3.4",
|
|
61
80
|
"styled-components": "5.3.3"
|
|
62
81
|
},
|
|
63
82
|
"peerDependencies": {
|
|
83
|
+
"@strapi/strapi": "^4.0.0",
|
|
64
84
|
"react": "^17.0.0 || ^18.0.0",
|
|
65
85
|
"react-dom": "^17.0.0 || ^18.0.0",
|
|
66
|
-
"react-router-dom": "5.
|
|
67
|
-
"styled-components": "5.
|
|
86
|
+
"react-router-dom": "^5.2.0",
|
|
87
|
+
"styled-components": "^5.2.1"
|
|
68
88
|
},
|
|
69
89
|
"engines": {
|
|
70
|
-
"node": ">=
|
|
90
|
+
"node": ">=18.0.0 <=20.x.x",
|
|
71
91
|
"npm": ">=6.0.0"
|
|
72
92
|
},
|
|
73
93
|
"strapi": {
|
|
@@ -77,5 +97,5 @@
|
|
|
77
97
|
"required": true,
|
|
78
98
|
"kind": "plugin"
|
|
79
99
|
},
|
|
80
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "f8af92b375dc730ba47ed2117f25df893aae696c"
|
|
81
101
|
}
|
package/packup.config.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Config, defineConfig } from '@strapi/pack-up';
|
|
2
|
+
import { transformWithEsbuild } from 'vite';
|
|
3
|
+
|
|
4
|
+
const config: Config = defineConfig({
|
|
5
|
+
bundles: [
|
|
6
|
+
{
|
|
7
|
+
source: './admin/src/index.js',
|
|
8
|
+
import: './dist/admin/index.mjs',
|
|
9
|
+
require: './dist/admin/index.js',
|
|
10
|
+
runtime: 'web',
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
dist: './dist',
|
|
14
|
+
/**
|
|
15
|
+
* Because we're exporting a server & client package
|
|
16
|
+
* which have different runtimes we want to ignore
|
|
17
|
+
* what they look like in the package.json
|
|
18
|
+
*/
|
|
19
|
+
exports: {},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export default config;
|
|
@@ -10,10 +10,12 @@
|
|
|
10
10
|
const crypto = require('crypto');
|
|
11
11
|
const _ = require('lodash');
|
|
12
12
|
const urljoin = require('url-join');
|
|
13
|
+
const { isArray } = require('lodash/fp');
|
|
13
14
|
const { getService } = require('../utils');
|
|
14
15
|
const getGrantConfig = require('./grant-config');
|
|
15
16
|
|
|
16
17
|
const usersPermissionsActions = require('./users-permissions-actions');
|
|
18
|
+
const userSchema = require('../content-types/user');
|
|
17
19
|
|
|
18
20
|
const initGrant = async (pluginStore) => {
|
|
19
21
|
const apiPrefix = strapi.config.get('api.rest.prefix');
|
|
@@ -97,6 +99,27 @@ const initAdvancedOptions = async (pluginStore) => {
|
|
|
97
99
|
}
|
|
98
100
|
};
|
|
99
101
|
|
|
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
|
+
|
|
100
123
|
module.exports = async ({ strapi }) => {
|
|
101
124
|
const pluginStore = strapi.store({ type: 'plugin', name: 'users-permissions' });
|
|
102
125
|
|
|
@@ -130,4 +153,17 @@ For security reasons, prefer storing the secret in an environment variable and r
|
|
|
130
153
|
);
|
|
131
154
|
}
|
|
132
155
|
}
|
|
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
|
+
}
|
|
133
169
|
};
|
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
/* eslint-disable no-useless-escape */
|
|
10
10
|
const crypto = require('crypto');
|
|
11
11
|
const _ = require('lodash');
|
|
12
|
+
const { concat, compact, isArray } = require('lodash/fp');
|
|
12
13
|
const utils = require('@strapi/utils');
|
|
14
|
+
const {
|
|
15
|
+
contentTypes: { getNonWritableAttributes },
|
|
16
|
+
} = require('@strapi/utils');
|
|
13
17
|
const { getService } = require('../utils');
|
|
14
18
|
const {
|
|
15
19
|
validateCallbackBody,
|
|
@@ -22,7 +26,7 @@ const {
|
|
|
22
26
|
} = require('./validation/auth');
|
|
23
27
|
|
|
24
28
|
const { getAbsoluteAdminUrl, getAbsoluteServerUrl, sanitize } = utils;
|
|
25
|
-
const { ApplicationError, ValidationError } = utils.errors;
|
|
29
|
+
const { ApplicationError, ValidationError, ForbiddenError } = utils.errors;
|
|
26
30
|
|
|
27
31
|
const sanitizeUser = (user, ctx) => {
|
|
28
32
|
const { auth } = ctx.state;
|
|
@@ -96,6 +100,10 @@ module.exports = {
|
|
|
96
100
|
try {
|
|
97
101
|
const user = await getService('providers').connect(provider, ctx.query);
|
|
98
102
|
|
|
103
|
+
if (user.blocked) {
|
|
104
|
+
throw new ForbiddenError('Your account has been blocked by an administrator');
|
|
105
|
+
}
|
|
106
|
+
|
|
99
107
|
return ctx.send({
|
|
100
108
|
jwt: getService('jwt').issue({ id: user.id }),
|
|
101
109
|
user: await sanitizeUser(user, ctx),
|
|
@@ -273,20 +281,49 @@ module.exports = {
|
|
|
273
281
|
throw new ApplicationError('Register action is currently disabled');
|
|
274
282
|
}
|
|
275
283
|
|
|
284
|
+
const { register } = strapi.config.get('plugin.users-permissions');
|
|
285
|
+
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
|
+
|
|
291
|
+
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
|
+
)
|
|
323
|
+
);
|
|
324
|
+
|
|
276
325
|
const params = {
|
|
277
|
-
..._.
|
|
278
|
-
'confirmed',
|
|
279
|
-
'blocked',
|
|
280
|
-
'confirmationToken',
|
|
281
|
-
'resetPasswordToken',
|
|
282
|
-
'provider',
|
|
283
|
-
'id',
|
|
284
|
-
'createdAt',
|
|
285
|
-
'updatedAt',
|
|
286
|
-
'createdBy',
|
|
287
|
-
'updatedBy',
|
|
288
|
-
'role',
|
|
289
|
-
]),
|
|
326
|
+
..._.pick(ctx.request.body, allowedKeys),
|
|
290
327
|
provider: 'local',
|
|
291
328
|
};
|
|
292
329
|
|
|
@@ -11,7 +11,7 @@ const utils = require('@strapi/utils');
|
|
|
11
11
|
const { getService } = require('../utils');
|
|
12
12
|
const { validateCreateUserBody, validateUpdateUserBody } = require('./validation/user');
|
|
13
13
|
|
|
14
|
-
const { sanitize } = utils;
|
|
14
|
+
const { sanitize, validate } = utils;
|
|
15
15
|
const { ApplicationError, ValidationError, NotFoundError } = utils.errors;
|
|
16
16
|
|
|
17
17
|
const sanitizeOutput = async (user, ctx) => {
|
|
@@ -21,6 +21,13 @@ const sanitizeOutput = async (user, ctx) => {
|
|
|
21
21
|
return sanitize.contentAPI.output(user, schema, { auth });
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
const validateQuery = async (query, ctx) => {
|
|
25
|
+
const schema = strapi.getModel('plugin::users-permissions.user');
|
|
26
|
+
const { auth } = ctx.state;
|
|
27
|
+
|
|
28
|
+
return validate.contentAPI.query(query, schema, { auth });
|
|
29
|
+
};
|
|
30
|
+
|
|
24
31
|
const sanitizeQuery = async (query, ctx) => {
|
|
25
32
|
const schema = strapi.getModel('plugin::users-permissions.user');
|
|
26
33
|
const { auth } = ctx.state;
|
|
@@ -143,6 +150,7 @@ module.exports = {
|
|
|
143
150
|
* @return {Object|Array}
|
|
144
151
|
*/
|
|
145
152
|
async find(ctx) {
|
|
153
|
+
await validateQuery(ctx.query, ctx);
|
|
146
154
|
const sanitizedQuery = await sanitizeQuery(ctx.query, ctx);
|
|
147
155
|
const users = await getService('user').fetchAll(sanitizedQuery);
|
|
148
156
|
|
|
@@ -155,6 +163,7 @@ module.exports = {
|
|
|
155
163
|
*/
|
|
156
164
|
async findOne(ctx) {
|
|
157
165
|
const { id } = ctx.params;
|
|
166
|
+
await validateQuery(ctx.query, ctx);
|
|
158
167
|
const sanitizedQuery = await sanitizeQuery(ctx.query, ctx);
|
|
159
168
|
|
|
160
169
|
let data = await getService('user').fetch(id, sanitizedQuery);
|
|
@@ -171,6 +180,7 @@ module.exports = {
|
|
|
171
180
|
* @return {Number}
|
|
172
181
|
*/
|
|
173
182
|
async count(ctx) {
|
|
183
|
+
await validateQuery(ctx.query, ctx);
|
|
174
184
|
const sanitizedQuery = await sanitizeQuery(ctx.query, ctx);
|
|
175
185
|
|
|
176
186
|
ctx.body = await getService('user').count(sanitizedQuery);
|
|
@@ -201,6 +211,7 @@ module.exports = {
|
|
|
201
211
|
return ctx.unauthorized();
|
|
202
212
|
}
|
|
203
213
|
|
|
214
|
+
await validateQuery(query, ctx);
|
|
204
215
|
const sanitizedQuery = await sanitizeQuery(query, ctx);
|
|
205
216
|
const user = await getService('user').fetch(authUser.id, sanitizedQuery);
|
|
206
217
|
|
package/.eslintrc.js
DELETED
package/admin/src/hooks/index.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useReducer, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useFetchClient, useNotification } from '@strapi/helper-plugin';
|
|
4
|
-
|
|
5
|
-
import pluginId from '../../pluginId';
|
|
6
|
-
|
|
7
|
-
import reducer, { initialState } from './reducer';
|
|
8
|
-
|
|
9
|
-
const useFetchRole = (id) => {
|
|
10
|
-
const [state, dispatch] = useReducer(reducer, initialState);
|
|
11
|
-
const toggleNotification = useNotification();
|
|
12
|
-
const isMounted = useRef(null);
|
|
13
|
-
const { get } = useFetchClient();
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
isMounted.current = true;
|
|
17
|
-
|
|
18
|
-
if (id) {
|
|
19
|
-
fetchRole(id);
|
|
20
|
-
} else {
|
|
21
|
-
dispatch({
|
|
22
|
-
type: 'GET_DATA_SUCCEEDED',
|
|
23
|
-
role: {},
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return () => (isMounted.current = false);
|
|
28
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
-
}, [id]);
|
|
30
|
-
|
|
31
|
-
const fetchRole = async (roleId) => {
|
|
32
|
-
try {
|
|
33
|
-
const {
|
|
34
|
-
data: { role },
|
|
35
|
-
} = await get(`/${pluginId}/roles/${roleId}`);
|
|
36
|
-
|
|
37
|
-
// Prevent updating state on an unmounted component
|
|
38
|
-
if (isMounted.current) {
|
|
39
|
-
dispatch({
|
|
40
|
-
type: 'GET_DATA_SUCCEEDED',
|
|
41
|
-
role,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
} catch (err) {
|
|
45
|
-
console.error(err);
|
|
46
|
-
|
|
47
|
-
dispatch({
|
|
48
|
-
type: 'GET_DATA_ERROR',
|
|
49
|
-
});
|
|
50
|
-
toggleNotification({
|
|
51
|
-
type: 'warning',
|
|
52
|
-
message: { id: 'notification.error' },
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const handleSubmitSucceeded = useCallback((data) => {
|
|
58
|
-
dispatch({
|
|
59
|
-
type: 'ON_SUBMIT_SUCCEEDED',
|
|
60
|
-
...data,
|
|
61
|
-
});
|
|
62
|
-
}, []);
|
|
63
|
-
|
|
64
|
-
return { ...state, onSubmitSucceeded: handleSubmitSucceeded };
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export default useFetchRole;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/* eslint-disable consistent-return */
|
|
2
|
-
import produce from 'immer';
|
|
3
|
-
|
|
4
|
-
export const initialState = {
|
|
5
|
-
role: {},
|
|
6
|
-
isLoading: true,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const reducer = (state, action) =>
|
|
10
|
-
produce(state, (draftState) => {
|
|
11
|
-
switch (action.type) {
|
|
12
|
-
case 'GET_DATA_SUCCEEDED': {
|
|
13
|
-
draftState.role = action.role;
|
|
14
|
-
draftState.isLoading = false;
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
case 'GET_DATA_ERROR': {
|
|
18
|
-
draftState.isLoading = false;
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
case 'ON_SUBMIT_SUCCEEDED': {
|
|
22
|
-
draftState.role.name = action.name;
|
|
23
|
-
draftState.role.description = action.description;
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
default:
|
|
27
|
-
return draftState;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
export default reducer;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useReducer, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useFetchClient, useNotification, useRBAC } from '@strapi/helper-plugin';
|
|
4
|
-
|
|
5
|
-
import reducer, { initialState } from './reducer';
|
|
6
|
-
|
|
7
|
-
const useUserForm = (endPoint, permissions) => {
|
|
8
|
-
const { isLoading: isLoadingForPermissions, allowedActions } = useRBAC(permissions);
|
|
9
|
-
const [{ isLoading, modifiedData }, dispatch] = useReducer(reducer, initialState);
|
|
10
|
-
const toggleNotification = useNotification();
|
|
11
|
-
const isMounted = useRef(true);
|
|
12
|
-
|
|
13
|
-
const { get } = useFetchClient();
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
const getData = async () => {
|
|
17
|
-
try {
|
|
18
|
-
dispatch({
|
|
19
|
-
type: 'GET_DATA',
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const { data } = await get(`/users-permissions/${endPoint}`);
|
|
23
|
-
|
|
24
|
-
dispatch({
|
|
25
|
-
type: 'GET_DATA_SUCCEEDED',
|
|
26
|
-
data,
|
|
27
|
-
});
|
|
28
|
-
} catch (err) {
|
|
29
|
-
// The user aborted the request
|
|
30
|
-
if (isMounted.current) {
|
|
31
|
-
dispatch({
|
|
32
|
-
type: 'GET_DATA_ERROR',
|
|
33
|
-
});
|
|
34
|
-
console.error(err);
|
|
35
|
-
toggleNotification({
|
|
36
|
-
type: 'warning',
|
|
37
|
-
message: { id: 'notification.error' },
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
if (!isLoadingForPermissions) {
|
|
44
|
-
getData();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return () => {
|
|
48
|
-
isMounted.current = false;
|
|
49
|
-
};
|
|
50
|
-
}, [isLoadingForPermissions, endPoint, get, toggleNotification]);
|
|
51
|
-
|
|
52
|
-
const dispatchSubmitSucceeded = useCallback((data) => {
|
|
53
|
-
dispatch({
|
|
54
|
-
type: 'ON_SUBMIT_SUCCEEDED',
|
|
55
|
-
data,
|
|
56
|
-
});
|
|
57
|
-
}, []);
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
allowedActions,
|
|
61
|
-
dispatchSubmitSucceeded,
|
|
62
|
-
isLoading,
|
|
63
|
-
isLoadingForPermissions,
|
|
64
|
-
modifiedData,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export default useUserForm;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import produce from 'immer';
|
|
2
|
-
|
|
3
|
-
const initialState = {
|
|
4
|
-
isLoading: true,
|
|
5
|
-
modifiedData: {},
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const reducer = (state, action) =>
|
|
9
|
-
// eslint-disable-next-line consistent-return
|
|
10
|
-
produce(state, (draftState) => {
|
|
11
|
-
switch (action.type) {
|
|
12
|
-
case 'GET_DATA': {
|
|
13
|
-
draftState.isLoading = true;
|
|
14
|
-
draftState.modifiedData = {};
|
|
15
|
-
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
case 'GET_DATA_SUCCEEDED': {
|
|
19
|
-
draftState.isLoading = false;
|
|
20
|
-
draftState.modifiedData = action.data;
|
|
21
|
-
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
case 'GET_DATA_ERROR': {
|
|
25
|
-
draftState.isLoading = true;
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
case 'ON_SUBMIT_SUCCEEDED': {
|
|
29
|
-
draftState.modifiedData = action.data;
|
|
30
|
-
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
default: {
|
|
34
|
-
return draftState;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
export default reducer;
|
|
40
|
-
export { initialState };
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useReducer, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useFetchClient, useNotification } from '@strapi/helper-plugin';
|
|
4
|
-
import get from 'lodash/get';
|
|
5
|
-
|
|
6
|
-
import pluginId from '../../pluginId';
|
|
7
|
-
|
|
8
|
-
import init from './init';
|
|
9
|
-
import reducer, { initialState } from './reducer';
|
|
10
|
-
|
|
11
|
-
const useRolesList = (shouldFetchData = true) => {
|
|
12
|
-
const [{ roles, isLoading }, dispatch] = useReducer(reducer, initialState, () =>
|
|
13
|
-
init(initialState, shouldFetchData)
|
|
14
|
-
);
|
|
15
|
-
const toggleNotification = useNotification();
|
|
16
|
-
|
|
17
|
-
const isMounted = useRef(true);
|
|
18
|
-
const fetchClient = useFetchClient();
|
|
19
|
-
|
|
20
|
-
const fetchRolesList = useCallback(async () => {
|
|
21
|
-
try {
|
|
22
|
-
dispatch({
|
|
23
|
-
type: 'GET_DATA',
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const {
|
|
27
|
-
data: { roles },
|
|
28
|
-
} = await fetchClient.get(`/${pluginId}/roles`);
|
|
29
|
-
|
|
30
|
-
dispatch({
|
|
31
|
-
type: 'GET_DATA_SUCCEEDED',
|
|
32
|
-
data: roles,
|
|
33
|
-
});
|
|
34
|
-
} catch (err) {
|
|
35
|
-
const message = get(err, ['response', 'payload', 'message'], 'An error occured');
|
|
36
|
-
|
|
37
|
-
if (isMounted.current) {
|
|
38
|
-
dispatch({
|
|
39
|
-
type: 'GET_DATA_ERROR',
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
if (message !== 'Forbidden') {
|
|
43
|
-
toggleNotification({
|
|
44
|
-
type: 'warning',
|
|
45
|
-
message,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}, [fetchClient, toggleNotification]);
|
|
51
|
-
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (shouldFetchData) {
|
|
54
|
-
fetchRolesList();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return () => {
|
|
58
|
-
isMounted.current = false;
|
|
59
|
-
};
|
|
60
|
-
}, [shouldFetchData, fetchRolesList]);
|
|
61
|
-
|
|
62
|
-
return { roles, isLoading, getData: fetchRolesList };
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export default useRolesList;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/* eslint-disable consistent-return */
|
|
2
|
-
import produce from 'immer';
|
|
3
|
-
|
|
4
|
-
export const initialState = {
|
|
5
|
-
roles: [],
|
|
6
|
-
isLoading: true,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const reducer = (state, action) =>
|
|
10
|
-
produce(state, (draftState) => {
|
|
11
|
-
switch (action.type) {
|
|
12
|
-
case 'GET_DATA': {
|
|
13
|
-
draftState.isLoading = true;
|
|
14
|
-
draftState.roles = [];
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
case 'GET_DATA_SUCCEEDED': {
|
|
18
|
-
draftState.roles = action.data;
|
|
19
|
-
draftState.isLoading = false;
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
case 'GET_DATA_ERROR': {
|
|
23
|
-
draftState.isLoading = false;
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
default:
|
|
27
|
-
return draftState;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
export default reducer;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { getFetchClient } from '@strapi/helper-plugin';
|
|
2
|
-
|
|
3
|
-
const fetchData = async () => {
|
|
4
|
-
const { get } = getFetchClient();
|
|
5
|
-
const { data } = await get('/users-permissions/advanced');
|
|
6
|
-
|
|
7
|
-
return data;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const putAdvancedSettings = (body) => {
|
|
11
|
-
const { put } = getFetchClient();
|
|
12
|
-
|
|
13
|
-
return put('/users-permissions/advanced', body);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export { fetchData, putAdvancedSettings };
|