Skip to content

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

Refactor code

dominik-zeglenf459e9a84898
diff --git a/saleor/core/views.py b/saleor/core/views.py
index 9bba82e7cd..ea4cf58a46 100644
--- a/saleor/core/views.py
+++ b/saleor/core/views.py
@@ -4,6 +4,7 @@ from django.utils.translation import pgettext_lazy
from ..dashboard.views import staff_member_required
from ..product.utils import products_with_availability, products_for_homepage
+from ..settings import IMPERSONATE_GET_PARAM
def home(request):
@@ -11,7 +12,7 @@ def home(request):
products = products_with_availability(
products, discounts=request.discounts, local_currency=request.currency)
# TODO: Get rid of url parameters
- if request.GET.get('action') == 'impersonate':
+ if request.GET.get('action') == IMPERSONATE_GET_PARAM:
msg = pgettext_lazy('Impersonation message',
'You are now logged as %s') % request.user.email
messages.success(request, msg)
diff --git a/saleor/settings.py b/saleor/settings.py
index 47f840f735..ffdfdb2c24 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -420,6 +420,8 @@ CELERY_RESULT_BACKEND = 'django-db'
# IMPERSONATE SETTINGS
IMPERSONATE_URI_EXCLUSIONS = [r'^dashboard/']
IMPERSONATE_CUSTOM_USER_QUERYSET = 'saleor.userprofile.utils.get_customers'
-IMPERSONATE_REDIRECT_URL = '/?action=impersonate'
+IMPERSONATE_GET_PARAM = 'impersonate'
+IMPERSONATE_REDIRECT_URL = '/?action=' + IMPERSONATE_GET_PARAM
IMPERSONATE_USE_HTTP_REFERER = True
IMPERSONATE_CUSTOM_ALLOW = 'saleor.userprofile.utils.can_impersonate'
+
diff --git a/saleor/userprofile/utils.py b/saleor/userprofile/utils.py
index 211a44b974..b7b4d6acf7 100644
--- a/saleor/userprofile/utils.py
+++ b/saleor/userprofile/utils.py
@@ -21,4 +21,8 @@ def get_customers(request):
def can_impersonate(request):
+ '''This function checks if user has right permissions to impersonate customers.
+ It is required by django-impersonate module since it requires a function as
+ input argument, not just permission name.
+ '''
return request.user.has_perm('impersonate_user')
diff --git a/templates/dashboard/customer/detail.html b/templates/dashboard/customer/detail.html
index 555c89421b..9970031118 100644
--- a/templates/dashboard/customer/detail.html
+++ b/templates/dashboard/customer/detail.html
@@ -48,7 +48,7 @@
</a>
</li>
<li>
- <a href="/impersonate/{{ customer.pk }}">Impersonate customer</a>
+ <a href="{% url 'impersonate-start' uid=customer.pk %}">Impersonate customer</a>
</li>
</ul>
{% endif %}