Skip to content
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

Merged

Conversation

kswiatek92
Copy link

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 user

Pull Request Checklist

  1. Privileged views and APIs are guarded by proper permission checks.
  2. All visible strings are translated with proper context.
  3. All data-formatting is locale-aware (dates, numbers, and so on).
  4. Database queries are optimized and the number of queries is constant.
  5. Database migration files are up to date.
  6. The changes are tested.
  7. GraphQL schema and type definitions are up to date.
  8. Changes are mentioned in the changelog.

@@ -141,9 +142,7 @@ def resolve_products(
**_kwargs,
):

user = info.context.user
Copy link
Member

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.

Copy link
Member

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
Copy link

codecov bot commented Jan 9, 2020

Codecov Report

Merging #5152 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4bcfead...beaed68. Read the comment docs.

Copy link

django-queries commented Jan 9, 2020

Here is the report for 4bcfead (kswiatek92/saleor @ move-getting-requester-to-utils)
Base comparison is a0c379e.

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
Copy link
Member

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.

@@ -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):
Copy link
Member

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.

@kswiatek92 kswiatek92 force-pushed the move-getting-requester-to-utils branch from 07c977b to dcc7147 Compare January 9, 2020 13:41
@kswiatek92 kswiatek92 force-pushed the move-getting-requester-to-utils branch from dcc7147 to 4bcfead Compare January 9, 2020 14:18
@maarcingebala maarcingebala merged commit 57d6dd4 into saleor:master Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants