Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Prevent from impersonating staff and superuser

dominik-zeglen5063e63a0875
diff --git a/saleor/settings.py b/saleor/settings.py
index 669cd22d92..c14181df70 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -416,3 +416,7 @@ CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_RESULT_BACKEND = 'django-db'
+
+# IMPERSONATE SETTINGS
+IMPERSONATE_URI_EXCLUSIONS = [r'^dashboard/']
+IMPERSONATE_CUSTOM_USER_QUERYSET = 'saleor.userprofile.utils.can_impersonate'
diff --git a/saleor/userprofile/utils.py b/saleor/userprofile/utils.py
index 1048fa42cc..f286371de9 100644
--- a/saleor/userprofile/utils.py
+++ b/saleor/userprofile/utils.py
@@ -1,4 +1,4 @@
-from .models import Address
+from .models import Address, User
def store_user_address(user, address, billing=False, shipping=False):
@@ -14,3 +14,6 @@ def store_user_address(user, address, billing=False, shipping=False):
if changed:
user.save()
return entry
+
+def can_impersonate(request):
+ return User.objects.filter(is_staff=False, is_superuser=False)