-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Fix unable to populate User in Users-Permissions #11960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5ba0d2d
Fix unable to populate user
iicdii 54d10ec
Fix e2e test
iicdii 8ad9185
Merge branch 'master' into fix/populate-user
iicdii 2b877b3
Merge branch 'strapi:master' into fix/populate-user
iicdii 4a71a9c
Add new sanitizer to remove user relation from role entities
iicdii 5678165
Rename getRoles, getRole to find, findOne
iicdii 183bad0
Replace fetch, fetchAll query with entityService
iicdii f8d920a
Add test to verify population in users-api
iicdii 59a3b7e
Merge branch 'strapi:master' into fix/populate-user
iicdii 683f048
Fix wrong input parameter in user update controller
iicdii e019154
Merge branch 'strapi:master' into fix/populate-user
iicdii 0b60be2
Add sanitizers registry to container
f6c01bd
Add fake container to pass i18n unit test
4429381
Merge branch 'strapi:master' into fix/populate-user
iicdii 5959788
Refactor sanitizers module to be maintained easily
iicdii e918293
Update sanitizer mocking in i18n test
iicdii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = strapi => { | ||
| strapi.container.get('sanitizers').set('content-api', { input: [], output: [] }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| 'use strict'; | ||
|
|
||
| const _ = require('lodash'); | ||
|
|
||
| const sanitizersRegistry = () => { | ||
| const sanitizers = {}; | ||
|
|
||
| return { | ||
| get(path) { | ||
| return _.get(sanitizers, path, []); | ||
| }, | ||
| add(path, sanitizer) { | ||
| this.get(path).push(sanitizer); | ||
| return this; | ||
| }, | ||
| set(path, value = []) { | ||
| _.set(sanitizers, path, value); | ||
| return this; | ||
| }, | ||
| has(path) { | ||
| return _.has(sanitizers, path); | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
iicdii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| module.exports = sanitizersRegistry; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| 'use strict'; | ||
|
|
||
| const sanitize = require('./sanitize'); | ||
|
|
||
| const getService = name => { | ||
| return strapi.plugin('users-permissions').service(name); | ||
| }; | ||
|
|
||
| module.exports = { | ||
| getService, | ||
| sanitize, | ||
| }; |
9 changes: 9 additions & 0 deletions
9
packages/plugins/users-permissions/server/utils/sanitize/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| 'use strict'; | ||
|
|
||
| const visitors = require('./visitors'); | ||
| const sanitizers = require('./sanitizers'); | ||
|
|
||
| module.exports = { | ||
| sanitizers, | ||
| visitors, | ||
| }; |
19 changes: 19 additions & 0 deletions
19
packages/plugins/users-permissions/server/utils/sanitize/sanitizers.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| 'use strict'; | ||
|
|
||
| const { curry } = require('lodash/fp'); | ||
| const { traverseEntity, pipeAsync } = require('@strapi/utils'); | ||
|
|
||
| const { removeUserRelationFromRoleEntities } = require('./visitors'); | ||
|
|
||
| const sanitizeUserRelationFromRoleEntities = curry((schema, entity) => { | ||
| return traverseEntity(removeUserRelationFromRoleEntities, { schema }, entity); | ||
| }); | ||
|
|
||
| const defaultSanitizeOutput = curry((schema, entity) => { | ||
| return pipeAsync(sanitizeUserRelationFromRoleEntities(schema))(entity); | ||
| }); | ||
|
|
||
| module.exports = { | ||
| sanitizeUserRelationFromRoleEntities, | ||
| defaultSanitizeOutput, | ||
| }; |
5 changes: 5 additions & 0 deletions
5
packages/plugins/users-permissions/server/utils/sanitize/visitors/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = { | ||
| removeUserRelationFromRoleEntities: require('./remove-user-relation-from-role-entities'), | ||
| }; |
11 changes: 11 additions & 0 deletions
11
...ers-permissions/server/utils/sanitize/visitors/remove-user-relation-from-role-entities.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = ({ schema, key, attribute }, { remove }) => { | ||
| if ( | ||
| attribute.type === 'relation' && | ||
| attribute.target === 'plugin::users-permissions.user' && | ||
| schema.uid === 'plugin::users-permissions.role' | ||
| ) { | ||
| remove(key); | ||
| } | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.