-
-
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
Conversation
Signed-off-by: harimkims <harimkims@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #11960 +/- ##
==========================================
- Coverage 47.89% 47.88% -0.02%
==========================================
Files 231 231
Lines 8629 8633 +4
Branches 1935 1935
==========================================
+ Hits 4133 4134 +1
- Misses 3697 3700 +3
Partials 799 799
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
@iicdii you are amazing, I hope you know that. 🤗 |
|
Alex/others I've added this to the v4.0.1 milestone just in hopes of pushing it through on release as we are getting -a lot- of questions about this. If it's not possible feel free to remove. |
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: https://forum.strapi.io/t/populate-users-permissions-to-get-user-avatar/13701/2 |
|
Thanks! 😊 Yeah I've already seen many questions about this issue on Discord too. Hope it could be merged into v4.0.1! |
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: https://forum.strapi.io/t/strapi-v4-no-relation-fields-in-user-collection-types/13226/8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening yet another PR! 🙌
Tbh, I don't think this logic belongs to the REST controller. Even if for now the GQL resolvers are directly calling UP controllers (it's temporary), the goal is to make them both call a common service where we could put common transformations etc...
Also, I'm kinda curious about why we're not using the entity service API to fetch the entries in the UP's user service. Since the convertPopulate & other transformers would be called automatically.
@alexandrebodin do you remember why this choice has been made? Is there a particular reason? Or could we replace those queries with entity service's ones?
tl;dr: this logic is already handled by the entity service, maybe we can make the UP user service use it instead of doing DB queries directly + it would create a common API for both REST controllers & GraphQL resolvers.
|
Actually I've tried to convert them to entityService in previous PR, He said it like below which is the reason why I don't use entityService
|
|
Then we'll keep it that way and convert everything to ES later. But we'll definitely have to take care of this ASAP imo. |
|
Could you update your branch with master, please? |
Ah might have gotten skipped in the rush for v4 launch. Can take that later on aye |
|
FYI this API never was meant to have the same features as the auto-generated content APIs. There are some security concerns around users and we just cannot expose a complete populate option without more considerations 1st. I'll flag the PR so we can review the logic thoroughly before moving forward |
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: https://forum.strapi.io/t/strapi-v4-no-relation-fields-in-user-collection-types/13226/12 |
|
@jonasstams best bet is to create custom endpoints on the server-strapi.js file and override the existing ones. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for your commitment & your dedication to this @iicdii.
I've added some comments, tell me what you think 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice job, I think both the community & the Strapi team owes you a big one for this.
I'll play a bit with it before merging it. I'll try to do it fast so that it can be part of the next release tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this fix @iicdii 💯
We will probably have to rethink the sanitizers approach soon but this is a working solution that will please a lot of users so we will merge it now and handle the core code soon.
|
Thank you @iicdii 🙏 |
|
@iicdii Thank you! what a legend |
|
Hi @iicdii and thanks A LOT for your work! ❤️ However I have a question: how to handle extra fields in register({ strapi }) {
const extensionService = strapi.plugin("graphql").service("extension");
extensionService.use(({ nexus }) => ({
types: [
nexus.extendType({
type: "UsersPermissionsMe",
definition(t) {
// here define fields you need
t.string("firstName");
t.string("lastName");
t.field("acl", { type: "JSON" });
t.dateTime("deletedAt");
}
})
]
}));
},in Also, the added fields are still present in GraphQL documentation but doesn't return any data while fetched. EDIT: after rollbacking on v4.1.9, I was still facing the same issue. Deeper debug reveal that my |
|
I'm not sure if I'am doing well but even after version update to 4.1.10 I can't populate fields with the /api/users/me controller e.g.:
So I put this code based on some code I found somewhere here: |
I'm experiencing the same problem with version 4.1.12. Populating works on 'api/users' but not on 'api/users/me'. |
The same with 4.2.0😫 |
|
Going to lock this as it's pretty much confirmed that it's fixed as of v4.2.2+ If anyone else hits this issue or something like it please open a new bug report. |




Signed-off-by: harimkims harimkims@gmail.com
What does it do?
Why is it needed?
How to test it?
http://localhost:1337/api/users?populate=*http://localhost:1337/api/users/<userId>?populate=*Related issue(s)/PR(s)
Closes #11957