Skip to content

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

Add permissions

dominik-zeglen1b3f8a6b291f
diff --git a/saleor/settings.py b/saleor/settings.py
index 6c955027d2..47f840f735 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -421,3 +421,5 @@ CELERY_RESULT_BACKEND = 'django-db'
IMPERSONATE_URI_EXCLUSIONS = [r'^dashboard/']
IMPERSONATE_CUSTOM_USER_QUERYSET = 'saleor.userprofile.utils.get_customers'
IMPERSONATE_REDIRECT_URL = '/?action=impersonate'
+IMPERSONATE_USE_HTTP_REFERER = True
+IMPERSONATE_CUSTOM_ALLOW = 'saleor.userprofile.utils.can_impersonate'
diff --git a/saleor/userprofile/migrations/0011_auto_20171117_0733.py b/saleor/userprofile/migrations/0011_auto_20171117_0733.py
new file mode 100644
index 0000000000..59becf7d19
--- /dev/null
+++ b/saleor/userprofile/migrations/0011_auto_20171117_0733.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.5 on 2017-11-17 13:33
+from __future__ import unicode_literals
+
+from django.db import migrations
+import phonenumber_field.modelfields
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('userprofile', '0010_auto_20170919_0839'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='address',
+ name='phone',
+ field=phonenumber_field.modelfields.PhoneNumberField(blank=True, default='', max_length=128, verbose_name='phone number'),
+ ),
+ ]
diff --git a/saleor/userprofile/migrations/0012_auto_20171117_0811.py b/saleor/userprofile/migrations/0012_auto_20171117_0811.py
new file mode 100644
index 0000000000..56a813e6c0
--- /dev/null
+++ b/saleor/userprofile/migrations/0012_auto_20171117_0811.py
@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.5 on 2017-11-17 14:11
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('userprofile', '0011_auto_20171117_0733'),
+ ]
+
+ operations = [
+ ]
diff --git a/saleor/userprofile/models.py b/saleor/userprofile/models.py
index 98cefd2fa5..c16c6525e1 100644
--- a/saleor/userprofile/models.py
+++ b/saleor/userprofile/models.py
@@ -167,7 +167,9 @@ class User(PermissionsMixin, AbstractBaseUser, index.Indexed):
('view_staff',
pgettext_lazy('Permission description', 'Can view staff')),
('edit_staff',
- pgettext_lazy('Permission description', 'Can edit staff')))
+ pgettext_lazy('Permission description', 'Can edit staff')),
+ ('impersonate_user',
+ pgettext_lazy('Permission description', 'Can impersonate users')))
def get_full_name(self):
return self.email
diff --git a/saleor/userprofile/utils.py b/saleor/userprofile/utils.py
index 2fcf0358f6..211a44b974 100644
--- a/saleor/userprofile/utils.py
+++ b/saleor/userprofile/utils.py
@@ -15,5 +15,10 @@ def store_user_address(user, address, billing=False, shipping=False):
user.save()
return entry
+
def get_customers(request):
return User.objects.filter(is_staff=False, is_superuser=False)
+
+
+def can_impersonate(request):
+ return request.user.has_perm('impersonate_user')