-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Correct PrinciplaType for multiple extension of User models #3679
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
|
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
|
Can one of the admins verify this patch? |
3 similar comments
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
@ebarault I'm not part of the LB efforts anymore... I've switched to a selection of smaller components, mainly Koa2 and Objection.js, and so far it's going really well... |
|
Hi @ebarault I'm not sure if the fix is causing it to fail. But I believe the above fix was not to solve this test case rather to put the correct principalType while adding a principal. Please correct me if I am wrong. |
|
hi @akki-ng knowing the root cause, i was suspecting this PR wouldn't be enough to fix it, but i wanted to give it a try. that being said, as it does not fix this test, i'm wondering what the PR fixes, which I can't tell until more tests are added. although it might be a step forward to the solution, without knowing the added value or the side effects, we cannot move on with this PR as is i'm afraid. |
|
Hi @ebarault, After seeing this test I understand that its a not a complete solution to said problem. By this statement I meant that I could user $owner successfully on the extended User model.
A A StoreUser can be added by In this cases getting the correct PrincipalType in role resolver will give information about the current logged in User and such decision over the role of Perhaps @ebarault Let me know if this PR makes any sense else we can close it down. |
|
I think it is a step forward to the solution, but i would need to dive in the code again to make sure the objective is met the proper way. |
|
@ebarault I would love to solve the issue completely. Can you help me with some of the use-cases of test case with example. And how exactly belongsTo relation configuration being changed to support polymorphic behaviour and is there any config which says 'isOwner' in belongsTo config? These info will help me get started. |
|
@akki-ng Thanks for the fix. I have the same problem of having multiple extended models of |
|
@Mr-Wiredancer Welcome :-) This fix will solve many use-cases. But I believe the real issue is a bigger one where a single entity may have many I was busy earlier so could not do a complete fix. I'll try to fix the real issue and submit a PR soon. |
|
@Mr-Wiredancer looks like the bigger problem is already solved. Have a look. |
| this.addPrincipal(Principal.USER, token.userId); | ||
| var userPrincipalType = | ||
| (this.accessToken && this.accessToken.principalType) || Principal.USER; | ||
| this.addPrincipal(userPrincipalType, token.userId); |
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.
This change looks very reasonable to me 👍 and I am ok with landing it as an incremental improvement.
However, I need you to add a test that fails on the current master, passes with your fix in place - this will verify your fix and prevent regressions in the future.
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.
| if (token.userId) { | ||
| this.addPrincipal(Principal.USER, token.userId); | ||
| var userPrincipalType = | ||
| (this.accessToken && this.accessToken.principalType) || Principal.USER; |
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.
I think this can be shortened by using token instead of accessToken?
Also please use const instead of var in new code - see http://loopback.io/doc/en/contrib/style-guide.html#variable-declarations
const userPrincipalType = token.principalType || Principal.USER;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.
I'll complete the patch soon.
|
@akki-ng Hello akki, how does it look like with the patch? |
|
@MartinCerny-awin @bajtos @Mr-Wiredancer Guys, please follow up on new PR #3823 |
|
See #3883 |
Get the polymorphic PrincipalType while creating pricipal when multiple extensions of
Usermodel is usedThe app configuration follows the multiple user models setup as described in http://ibm.biz/setup-loopback-auth The built-in role resolver $owner is not currently compatible with this configuration and should not be used in production.With this pull request $owner can be used.