Skip to content

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

Add user impersonation

dominik-zeglenfcb800c7f855
diff --git a/requirements.in b/requirements.in
index bdda1551d9..5b2f3e5eab 100644
--- a/requirements.in
+++ b/requirements.in
@@ -9,6 +9,7 @@ django-bootstrap3>=8.2.1
django-cache-url>=1.0.0
django-countries>=4.1
django-filter==1.0.4
+django-impersonate==1.1
django-mptt>=0.7.1
django-payments>=0.12.1
django-prices>=0.4.11
diff --git a/requirements.txt b/requirements.txt
index 741346d6bc..b76f7224a9 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -28,6 +28,7 @@ django-cache-url==1.3.1
django-celery-results==1.0.1
django-countries==4.6.1
django-filter==1.0.4
+django-impersonate==1.1
django-mptt==0.8.7
django-payments==0.12.1
django-prices-openexchangerates==0.1.15
diff --git a/saleor/settings.py b/saleor/settings.py
index fd839ab000..669cd22d92 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -139,6 +139,7 @@ MIDDLEWARE = [
'saleor.core.middleware.CurrencyMiddleware',
'saleor.core.middleware.ClearSiteCacheMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware',
+ 'impersonate.middleware.ImpersonateMiddleware'
]
INSTALLED_APPS = [
@@ -185,6 +186,7 @@ INSTALLED_APPS = [
'django_countries',
'django_filters',
'django_celery_results',
+ 'impersonate'
]
LOGGING = {
diff --git a/saleor/urls.py b/saleor/urls.py
index fa2fc534a2..046825b9b4 100644
--- a/saleor/urls.py
+++ b/saleor/urls.py
@@ -27,6 +27,7 @@ urlpatterns = [
url(r'^dashboard/',
include((dashboard_urls, 'dashboard'), namespace='dashboard')),
url(r'^graphql', GraphQLView.as_view(graphiql=settings.DEBUG)),
+ url(r'^impersonate/', include('impersonate.urls')),
url(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),
url(r'^order/', include((order_urls, 'order'), namespace='order')),
url(r'^products/',
diff --git a/templates/base.html b/templates/base.html
index 6a7d8a06ab..2cf9302eaf 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -47,10 +47,18 @@
<a href="{% url "profile:details" %}">
{% trans "Your account" context "Main navigation item" %}</a>
</li>
- <li>
- <a href="{% url "account_logout" %}">
- {% trans "Log out" context "Main navigation item" %}</a>
- </li>
+ {% if user.is_impersonate %}
+ <li>
+ <a href="{% url "impersonate-stop" %}">
+ {% trans 'Stop impersonating' context 'Main navigation item' %}
+ </a>
+ </li>
+ {% else %}
+ <li>
+ <a href="{% url "account_logout" %}">
+ {% trans "Log out" context "Main navigation item" %}</a>
+ </li>
+ {% endif %}
{% else %}
<li>
<a href="{% url "account_signup" %}">
@@ -196,10 +204,18 @@
{% trans "Your account" context "Main navigation item" %}
</a>
</li>
- <li>
- <a href="{% url "account_logout" %}">
- {% trans "Log out" context "Main navigation item" %}</a>
- </li>
+ {% if user.is_impersonate %}
+ <li>
+ <a href="{% url "impersonate-stop" %}">
+ {% trans 'Stop impersonating' context 'Main navigation item' %}
+ </a>
+ </li>
+ {% else %}
+ <li>
+ <a href="{% url "account_logout" %}">
+ {% trans "Log out" context "Main navigation item" %}</a>
+ </li>
+ {% endif %}
{% else %}
<li>
<a href="{% url "account_signup" %}">
diff --git a/templates/dashboard/customer/detail.html b/templates/dashboard/customer/detail.html
index 1668004c95..555c89421b 100644
--- a/templates/dashboard/customer/detail.html
+++ b/templates/dashboard/customer/detail.html
@@ -47,6 +47,9 @@
{% trans 'Promote to staff' context 'Customer promote to staff member action' %}
</a>
</li>
+ <li>
+ <a href="/impersonate/{{ customer.pk }}">Impersonate customer</a>
+ </li>
</ul>
{% endif %}
{% endblock %}