-
Notifications
You must be signed in to change notification settings - Fork 2
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
refactor(backend): context hook #1684
Conversation
where: { | ||
id: user.id, | ||
}, | ||
data, | ||
}) | ||
|
||
if (data.introduction === undefined) delete data.introduction | ||
if (data.availability === undefined) delete data.availability |
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 is something I don't understand: Why was the updatedUser
not returned?
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.
When I wrote this code I was confused as well. Check if the false positive is workuing
fbaaa28
to
c402711
Compare
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.
Nice refactor. Much better structured, and I like the context function. Please check for the false positive.
How do you want to realize the admin authorization? So far the single source of truth is authentik and therefore the token. When you touch the authChecker
function, the token is already `out of scope.
) | ||
} | ||
|
||
it('deletes introduction and availability', async () => { |
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 is a false positive as introduction and availability are already null.
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 will have a look into this, but is this a blocker for this PR?
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.
@Mogge it's addressed and certainly not a false negative anymore - I consider a failing test as positive (like a HIV-test) and a false positive a false alert. A false negative for me would be a test that does not fail but a bug is present.
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.
Did you change something? There is only one force pushed commit and I cannot see the changes done by the last commit. Was I wrong? Now the code looks fine
where: { | ||
id: user.id, | ||
}, | ||
data, | ||
}) | ||
|
||
if (data.introduction === undefined) delete data.introduction | ||
if (data.availability === undefined) delete data.availability |
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.
When I wrote this code I was confused as well. Check if the false positive is workuing
@@ -15,7 +15,7 @@ | |||
"coverageThreshold": { | |||
"global": { | |||
"statements": 95, | |||
"branches": 80, | |||
"branches": 79, |
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.
It would be nice to avoid the
const { user } = context
if (!user) throw new Error('User not found!')
construction in all resolvers that require a user. Can we somehow force the type UserWithProfile
for calls that require authorization?
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.
Yes, I will also have a look but this is out of scope of this PR, isn't it?
Maybe there is a typescript solution for this. Ideally Authorized()
would mark the context.user
as not null.
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.
@Mogge I think we're out of luck here: microsoft/TypeScript#49229
I would suggest we use a simple helper method:
const { user } = requireUser(context)
with:
const requireUser = (context: Context) => {
const { user } = context
if (!user) throw new Error('context.user must be present after authorization!')
return context
}
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 would not raise the coverage of our branches
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.
Could we have a dummy unauthenticated user that is set if there is no authentication?
Role based-authorization can be done with this: https://github.com/dreammall-earth/dreammall.earth/pull/1686/files#diff-ab0ffeecd111988f9570b4645447f2cf50e1aecc99eef4cc4d45fbfbe3314dcbR65 and we would create an admin group with Also, I vote to decode the |
a2a71f7
to
d3ffd1d
Compare
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.
We can merge this for now.
@roschaefer pls do your thing |
Motivation ---------- This fixes #1503. This is necessary before I can properly implement role based authorization (for the admins). How to test ----------- 1. CI should be green
d3ffd1d
to
a4d6a40
Compare
Motivation
This fixes #1503.
This is necessary before I can properly implement role based authorization (for the admins).
How to test