Skip to content

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

* Add permissions for promoting customers to staff

akjanik0f2d6eb2f05b
diff --git a/saleor/core/permissions.py b/saleor/core/permissions.py
index 038ccb90a3..01d1c9cdec 100644
--- a/saleor/core/permissions.py
+++ b/saleor/core/permissions.py
@@ -24,6 +24,7 @@ MODELS_PERMISSIONS = [
'user.view_group',
'user.edit_group',
'user.view_staff',
+ 'user.edit_staff',
'voucher.view_voucher',
'voucher.edit_voucher',
]
diff --git a/saleor/dashboard/customer/views.py b/saleor/dashboard/customer/views.py
index a3610db771..b1d128d469 100644
--- a/saleor/dashboard/customer/views.py
+++ b/saleor/dashboard/customer/views.py
@@ -10,7 +10,7 @@ from django.utils.translation import pgettext_lazy
from ...core.utils import get_paginator_items
from ...userprofile.models import User
from ...settings import DASHBOARD_PAGINATE_BY
-from ..views import staff_member_required, superuser_required
+from ..views import staff_member_required
@staff_member_required
@@ -42,7 +42,9 @@ def customer_details(request, pk):
return TemplateResponse(request, 'dashboard/customer/detail.html', ctx)
-@superuser_required
+@staff_member_required
+@permission_required('userprofile.edit_staff')
+@permission_required('userprofile.edit_user')
def customer_promote_to_staff(request, pk):
customer = get_object_or_404(User, pk=pk)
if request.method == 'POST':
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 94b7eaa684..95f67816bf 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -162,17 +162,17 @@ class Product(models.Model, ItemRange, index.Indexed):
('edit_product',
pgettext_lazy('Permission description', 'Can edit products')),
('view_classes',
- pgettext_lazy('Permission description',
- 'Can view product types')),
+ pgettext_lazy(
+ 'Permission description', 'Can view product types')),
('edit_classes',
- pgettext_lazy('Permission description',
- 'Can edit product types')),
+ pgettext_lazy(
+ 'Permission description', 'Can edit product types')),
('view_attributes',
- pgettext_lazy('Permission description',
- 'Can view product attributes')),
+ pgettext_lazy(
+ 'Permission description', 'Can view product attributes')),
('edit_attributes',
- pgettext_lazy('Permission description',
- 'Can edit product attributes')))
+ pgettext_lazy(
+ 'Permission description', 'Can edit product attributes')))
def __iter__(self):
if not hasattr(self, '__variants'):
diff --git a/templates/dashboard/base.html b/templates/dashboard/base.html
index e82d574489..48cd721fe6 100644
--- a/templates/dashboard/base.html
+++ b/templates/dashboard/base.html
@@ -188,13 +188,13 @@
</ul>
</li>
{% endif %}
- {% if perms.product.view_class or perms.product.view_attributes or perms.shipping.view_shipping %}
+ {% if perms.product.view_class or perms.product.view_attributes or perms.shipping.view_shipping or perms.product.view_classes %}
<li class="side-nav-section">
<p>
{% trans "Configuration" context "Dashboard configuration" %}
</p>
<ul>
- {% if perms.product.view_class %}
+ {% if perms.product.view_classes %}
<li class="{% block menu_product_classes_class %}{% endblock %}">
<a href="{% url 'dashboard:product-class-list' %}">
{% trans "Product types" context "Dashboard product types list" %}
diff --git a/templates/dashboard/customer/detail.html b/templates/dashboard/customer/detail.html
index 61dc2dadbf..1668004c95 100644
--- a/templates/dashboard/customer/detail.html
+++ b/templates/dashboard/customer/detail.html
@@ -36,7 +36,7 @@
{% block header_extra %}
- {% if customer.pk and not customer.is_staff and request.user.is_superuser %}
+ {% if customer.pk and not customer.is_staff and perms.userprofile.edit_staff and perms.userprofile.edit_user %}
<a class="dropdown-button right" href="#" data-activates="context-menu" data-constrainwidth="false">
<svg data-src="{% static "dashboard/images/more_vert.svg" %}" height="24" width="24" />
</a>
diff --git a/templates/dashboard/discount/sale/list.html b/templates/dashboard/discount/sale/list.html
index 2635152073..869d06fc84 100644
--- a/templates/dashboard/discount/sale/list.html
+++ b/templates/dashboard/discount/sale/list.html
@@ -22,7 +22,7 @@
{% block menu_discounts_class %} active{% endblock %}
{% block content %}
- {% if perms.sale.edit_sale %}
+ {% if perms.discount.edit_sale %}
<div class="fixed-action-btn">
<a href="{% url 'dashboard:sale-add' %}" class="btn-fab btn-floating btn-large waves-effect waves-light"
title="{% trans "Add sale" context "Sale (discount) list add button text" %}">
@@ -46,7 +46,7 @@
<tbody>
{% if sales %}
{% for sale in sales %}
- <tr data-action-go="{% if perms.sale.edit_sale %}{% url 'dashboard:sale-update' pk=sale.pk %}{% endif %}">
+ <tr data-action-go="{% if perms.discount.edit_sale %}{% url 'dashboard:sale-update' pk=sale.pk %}{% endif %}">
<td>
{{ sale }}
</td>
diff --git a/templates/dashboard/discount/voucher/list.html b/templates/dashboard/discount/voucher/list.html
index 827fed8300..838ea6a5bd 100644
--- a/templates/dashboard/discount/voucher/list.html
+++ b/templates/dashboard/discount/voucher/list.html
@@ -24,7 +24,7 @@
{% block menu_discounts_class %} active{% endblock %}
{% block content %}
- {% if perms.voucher.edit_voucher %}
+ {% if perms.discount.edit_voucher %}
<div class="fixed-action-btn">
<a href="{% url 'dashboard:voucher-add' %}" class="btn-fab btn-floating btn-large waves-effect waves-light"
title="{% trans "Add voucher" context "Voucher list add button text" %}">
@@ -63,7 +63,7 @@
</thead>
{% for voucher in vouchers %}
<tbody>
- <tr data-action-go="{% if perms.voucher.edit_voucher %}{% url 'dashboard:voucher-update' pk=voucher.pk %}{% endif %}">
+ <tr data-action-go="{% if perms.discount.edit_voucher %}{% url 'dashboard:voucher-update' pk=voucher.pk %}{% endif %}">
<td>
{{ voucher }}
</td>
diff --git a/tests/conftest.py b/tests/conftest.py
index 9f7f0ba10b..0348d04371 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -511,4 +511,9 @@ def permission_view_shipping():
@pytest.fixture
def permission_edit_shipping():
- return Permission.objects.get(codename='edit_shipping')
\ No newline at end of file
+ return Permission.objects.get(codename='edit_shipping')
+
+
+def permission_edit_user():
+ return Permission.objects.get(codename='edit_user')
diff --git a/tests/dashboard/test_permissions.py b/tests/dashboard/test_permissions.py
index b3b64be053..4d4d189f26 100644
--- a/tests/dashboard/test_permissions.py
+++ b/tests/dashboard/test_permissions.py
@@ -893,3 +893,27 @@ def test_staff_with_permissions_can_update_add_and_delete_shipping_method(
assert response.status_code == 200
response = staff_client.get(reverse('dashboard:shipping-method-add'))
assert response.status_code == 200
+
+
+def test_staff_with_permissions_can_promote_customer(
+ staff_client, staff_user, staff_group, customer_user,
+ permission_edit_staff, permission_edit_user):
+ assert not staff_user.has_perm("userprofile.edit_user")
+ assert not staff_user.has_perm("userprofile.edit_staff")
+ assert not customer_user.is_staff
+ response = staff_client.get(reverse('dashboard:customer-promote',
+ args=[customer_user.pk]))
+ assert response.status_code == 302
+ staff_group.permissions.add(permission_edit_user)
+ staff_group.permissions.add(permission_edit_staff)
+ staff_user.groups.add(staff_group)
+ staff_user = User.objects.get(pk=staff_user.pk)
+ assert staff_user.has_perm("userprofile.edit_user")
+ assert staff_user.has_perm("userprofile.edit_staff")
+ response = staff_client.get(reverse('dashboard:customer-promote',
+ args=[customer_user.pk]))
+ assert response.status_code == 200
+ response = staff_client.post(reverse('dashboard:customer-promote',
+ args=[customer_user.pk]))
+ customer_user = User.objects.get(pk=customer_user.pk)
+ assert customer_user.is_staff