Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add root email support to bypass read-only mode
Marcin Gębala47b2ffa6f279
diff --git a/saleor/demo/settings.py b/saleor/demo/settings.pyindex fc11fff817..11895eba1a 100644--- a/saleor/demo/settings.py+++ b/saleor/demo/settings.py@@ -25,7 +25,7 @@ ROOT_URLCONF = "saleor.demo.urls"PLUGINS += ["saleor.plugins.anonymize.plugin.AnonymizePlugin"]-GRAPHENE["MIDDLEWARE"] += ["saleor.graphql.middleware.ReadOnlyMiddleware"] # type: ignore+GRAPHENE["MIDDLEWARE"].insert(0, "saleor.graphql.middleware.ReadOnlyMiddleware") # type: ignoreBRAINTREE_API_KEY = os.environ.get("BRAINTREE_API_KEY")BRAINTREE_MERCHANT_ID = os.environ.get("BRAINTREE_MERCHANT_ID")@@ -81,3 +81,6 @@ if DEMO_SENTRY_DSN:sentry_sdk.init(DEMO_SENTRY_DSN, integrations=[DjangoIntegration()], before_send=before_send,)+++ROOT_EMAIL = os.environ.get("ROOT_EMAIL")diff --git a/saleor/graphql/middleware.py b/saleor/graphql/middleware.pyindex 645e470e95..65f78d047c 100644--- a/saleor/graphql/middleware.py+++ b/saleor/graphql/middleware.py@@ -85,6 +85,15 @@ class ReadOnlyMiddleware:if operation != "mutation":return next_(root, info, **kwargs)+ # Bypass users authenticated with ROOT_EMAIL+ request = info.context+ user = getattr(request, "user", None)+ if user and not user.is_anonymous:+ user_email = user.email+ root_email = getattr(settings, "ROOT_EMAIL", None)+ if root_email and user_email == root_email:+ return next_(root, info, **kwargs)+for selection in info.operation.selection_set.selections:selection_name = str(selection.name.value)blocked = selection_name not in ReadOnlyMiddleware.ALLOWED_MUTATIONS