You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Seems there is no way to access Roles from User Object/API #1441
but when I try to query in user/{id}/roles output comes blank/empty array.
I also tried updating "principalType" : "user" to "principalType" : "USER" but nothing works.
Reacted by Wut Manintu, Robert J Miller, jongleb, Lasha Kakhidze, Ashish Gupta, dhhieu113, Murat Erdoğan, Farzin, Karin Romero Gonzalez, Moacir Rosa and 9 more
Reacted by jongleb, Murat Erdoğan, Farzin, Moacir Rosa, Joshua Ihejiamaizu, José Peña, Rajan Panigrahi, Mahesh Jaganiya and Tomek Nieżurawski
@khashayar that happens because you're using th e built in User model which doesn't have the relationships defined for it and not your custom built user model I believe.
@jannyHou And this is because with the workaround, a new RoleMapping is created in the database, with an ObjectId rather than a string for principalID. When you see RoleMapping, two objects exist, and the role is retrieved by the one with an objectId as principalId
Even with the workaround and a fresh database I can't get this to work. Looking at the security debug output it seems that no RoleMapping can be found.
There is a role and a user present and the role mapping record contains the corrects id's as an Object() instead of as string.
Is there a working solution for this issue now?
I have defined a "roles" relation on my custom user model (as described by @khashayar), but when querying a user's roles, the returned array is still empty.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.
Activity
mneil commentedon Jul 7, 2015
I just ran into this issue as well. Roles are always empty when using include on users with Mongo DB. Might be related to #274.
faridnsh commentedon Aug 13, 2015
I followed this gist and it works perfectly for me.
superkhau commentedon Aug 13, 2015
Can you provide a link to a test project on Github? See https://github.com/strongloop/loopback/wiki/Issues#bug-report
valllabh commentedon Aug 18, 2015
@superkhau is this for me?
superkhau commentedon Aug 18, 2015
@valllabh Yes please, I would like to try to reproduce the issue on my end to confirm the bug.
valllabh commentedon Aug 19, 2015
@superkhau alright give me some time to extract and prepare test project.
superkhau commentedon Aug 19, 2015
Thanks.
khashayar commentedon Oct 23, 2015
It only happens with MongoDB as a datasource.
@superkhau
Now check the [GET} /users result with
{include: "roles"}, the roles array for first user is empty!Adding the following lines inside the boot script would solve the problem:
faridnsh commentedon Oct 23, 2015
@khashayar that happens because you're using th e built in
Usermodel which doesn't have the relationships defined for it and not your custom builtusermodel I believe.khashayar commentedon Oct 23, 2015
@alFReD-NSH Actually I'm using my custom
usermodel. It was a typo once I entered the sample code here on Github. I updated the actual sample code.AurelieV commentedon Jan 30, 2016
OK @jannyHou let's continue the discussion here.
I have try this on my production server which have an other mongodb version, and still not working
db version v3.2.1
node version: v4.2.4
system: Ubuntu 15.04
38 remaining items
AurelieV commentedon Apr 7, 2016
@jannyHou but if one time I run it with the workaround, all the time after, even without workaround; it works
AurelieV commentedon Apr 7, 2016
@jannyHou And this is because with the workaround, a new RoleMapping is created in the database, with an ObjectId rather than a string for principalID. When you see RoleMapping, two objects exist, and the role is retrieved by the one with an objectId as principalId
jannyHou commentedon Apr 7, 2016
@AurelieV nice it makes sense! thank you
younes0x53 commentedon Jun 17, 2016
Hi,
Any updates on this issue ? the related #128 issue on loopback-connector-mongodb was fixed but the bug remains.
Thank you.
sschimmel commentedon Aug 19, 2016
Even with the workaround and a fresh database I can't get this to work. Looking at the security debug output it seems that no RoleMapping can be found.
There is a role and a user present and the role mapping record contains the corrects id's as an Object() instead of as string.
Debug output:
User database record:
{ "_id" : ObjectId("123456789a00000000000000"), "name" : "admin", "locale" : "nl-NL", "emailVerified" : true }Roles:
{ "_id" : ObjectId("57b6d236fe6478355e180818"), "name" : "admin", "created" : ISODate("2016-08-19T09:32:37.599Z"), "modified" : ISODate("2016-08-19T09:32:37.599Z") }RoleMapping:
{ "_id" : ObjectId("57b6d237fe6478355e180846"), "principalType" : "USER", "principalId" : ObjectId("123456789a00000000000000"), "roleId" : ObjectId("57b6d236fe6478355e180818") }bajtos commentedon Feb 17, 2017
A possible workaround is described in #3121 (comment).
rashmihunt commentedon Jun 29, 2017
@valllabh Are you good with the workaround suggested by @bajtos ?#3121 (comment) If yes, we like to close this item.
jmereaux commentedon Sep 23, 2017
Is there a working solution for this issue now?
I have defined a "roles" relation on my custom user model (as described by @khashayar), but when querying a user's roles, the returned array is still empty.
jmereaux commentedon Oct 2, 2017
Seems like adding the following does the trick:
"keyThrough": "roleId"on therolesrelation in the custom user model"keyThrough": "principalId"on theusersrelation in the custom role modeldmastag commentedon Apr 9, 2018
This is what I eventually put on my custom User Model
stale commentedon Mar 11, 2020
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
stale commentedon Mar 26, 2020
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the
CODEOWNERSfile at the top-level of this repository.