-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
move extracting requester to utils #5152
move extracting requester to utils #5152
Conversation
@@ -141,9 +142,7 @@ def resolve_products( | |||
**_kwargs, | |||
): | |||
|
|||
user = info.context.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.
Probably we should use get_requester_from_context
in almost all places where user = info.context.user
appear in code. All query and mutation should work for user and service account with proper permissions.
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.
Sometimes we want to get only user and sometimes user or service account. This is the second case. For getting user from the context we could also have a helper.
Codecov Report
@@ Coverage Diff @@
## master #5152 +/- ##
=======================================
Coverage 91.56% 91.56%
=======================================
Files 260 260
Lines 16802 16802
Branches 1471 1471
=======================================
Hits 15385 15385
Misses 1035 1035
Partials 382 382 Continue to review full report at Codecov.
|
Here is the report for 4bcfead (kswiatek92/saleor @ move-getting-requester-to-utils) No differences were found. (click me)
# api.benchmark checkout
test name left count right count duplicate count
------------------------------------------- ----------- ----------- ---------------
add billing address to checkout 34 34 20
add shipping to checkout 7 7 0
checkout payment charge 10 10 0
complete checkout 8 8 0
create checkout 50 50 24
# api.benchmark homepage
test name left count right count duplicate count
------------------------------------------- ----------- ----------- ---------------
retrieve main menu 5 5 0
retrieve product list 4 4 0
retrieve secondary menu 5 5 0
retrieve shop 2 2 0
# api.benchmark product
test name left count right count duplicate count
------------------------------------------- ----------- ----------- ---------------
product details 14 14 2
retrieve product attributes 9 9 0
# api.benchmark variant
test name left count right count duplicate count
------------------------------------------- ----------- ----------- ---------------
product variant bulk create 51 51 3
retrieve variant list 16 16 6
# api product sorting attributes
test name left count right count duplicate count
------------------------------------------- ----------- ----------- ---------------
sort product not having attribute data 21 21 0 |
@@ -141,9 +142,7 @@ def resolve_products( | |||
**_kwargs, | |||
): | |||
|
|||
user = info.context.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.
Sometimes we want to get only user and sometimes user or service account. This is the second case. For getting user from the context we could also have a helper.
saleor/graphql/utils.py
Outdated
@@ -183,3 +183,9 @@ def create_jwt_payload(user, context=None): | |||
payload["is_staff"] = user.is_staff | |||
payload["is_superuser"] = user.is_superuser | |||
return payload | |||
|
|||
|
|||
def get_requester_from_context(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.
Maybe get_user_or_service_account_from_context
? A bit long but I assume we could also have get_user_from_context
and just get_service_account_from_context
.
07c977b
to
dcc7147
Compare
dcc7147
to
4bcfead
Compare
service account can be None
but user will always be set (user or anonymous)
previous
info.context.user or info.context.service_account
always returned userPull Request Checklist