Skip to content

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

Change templates and tests

michal07995dec570a
diff --git a/saleor/dashboard/groups/forms.py b/saleor/dashboard/groups/forms.py
index 9959f4b54f..e76fea8ab7 100644
--- a/saleor/dashboard/groups/forms.py
+++ b/saleor/dashboard/groups/forms.py
@@ -10,6 +10,6 @@ class PermissionsForm(forms.ModelForm):
fields = ['name', 'permissions']
permissions = forms.ModelMultipleChoiceField(
- get_permissions(),
+ queryset=get_permissions(),
widget=forms.CheckboxSelectMultiple
)
diff --git a/saleor/dashboard/groups/urls.py b/saleor/dashboard/groups/urls.py
index 181bcc4a55..5a809481d4 100644
--- a/saleor/dashboard/groups/urls.py
+++ b/saleor/dashboard/groups/urls.py
@@ -6,6 +6,5 @@ from . import views
urlpatterns = [
url(r'^$', views.groups_list, name="groups-list"),
url(r'^group-create/$', views.group_create, name="group-create"),
-
url(r'^(?P<pk>[0-9]+)/$', views.groups_details, name='group-details'),
]
diff --git a/templates/dashboard/base.html b/templates/dashboard/base.html
index 58e01c8e53..1919b72763 100644
--- a/templates/dashboard/base.html
+++ b/templates/dashboard/base.html
@@ -91,7 +91,7 @@
{% trans "Catalogue" context "Dashboard catalogue" %}
</p>
<ul>
- {% if perms.product.view %}
+ {% if perms.product.view_product %}
<li class="{% block menu_products_class %}{% endblock %}">
<a href="{% url 'dashboard:product-list' %}">
{% trans "Products" context "Dashboard products list" %}
diff --git a/templates/dashboard/groups/detail.html b/templates/dashboard/groups/detail.html
index 7c90590624..1a2911cb33 100644
--- a/templates/dashboard/groups/detail.html
+++ b/templates/dashboard/groups/detail.html
@@ -37,8 +37,8 @@
{% block content %}
<div class="row">
<div class="col s12 l8">
- <div class="card">
- {% if form %}
+ {% if form %}
+ <form method="post" class="card">
<div class="card">
<div class="data-table-header">
<h5 class="data-table-title">
@@ -47,18 +47,24 @@
</div>
<div class="card-content">
<div class="data">
- <form method="post">
+
{% csrf_token %}
+ <div class="row">
{{ form|materializecss }}
- <button type="submit" class="btn waves-effect waves-light">
- {% trans "Update" context "Dashboard update action" %}
- </button>
- </form>
+ </div>
</div>
</div>
+ <div class="card-action right-align">
+ <a href="{% url 'dashboard:groups-list' %}" class="btn btn-flat">
+ {% trans "Cancel" context "Dashboard cancel action" %}
+ </a>
+ <button type="submit" class="btn waves-effect waves-light">
+ {% trans "Update" context "Dashboard update action" %}
+ </button>
+ </div>
</div>
- {% endif %}
- </div>
+ </form>
+ {% endif %}
</div>
</div>
{% endblock %}
diff --git a/templates/dashboard/groups/list.html b/templates/dashboard/groups/list.html
index 843ee7b1fd..a86197966e 100644
--- a/templates/dashboard/groups/list.html
+++ b/templates/dashboard/groups/list.html
@@ -13,15 +13,13 @@
{% block menu_groups_class %}active{% endblock %}
{% block header_extra %}
- {% if groups %}
<div class="fixed-action-btn">
<a class="btn-fab btn-floating btn-large waves-effect waves-light teal"
- title="{% trans "Add group" context "Category list add button text" %}"
- href="{% url 'dashboard:group-create' %}">
- <svg data-src="{% static "dashboard/images/add.svg" %}" />
- </a>
+ title="{% trans "Add group" context "Category list add button text" %}"
+ href="{% url 'dashboard:group-create' %}">
+ <svg data-src="{% static "dashboard/images/add.svg" %}" />
+ </a>
</div>
- {% endif %}
{% endblock %}
{% block breadcrumbs %}
@@ -41,7 +39,7 @@
{{ group.name }}
<p class="list-item-desc">
<span>
-
+ {{ group.permissions }}
</span>
</p>
</a>
diff --git a/templates/dashboard/staff/detail.html b/templates/dashboard/staff/detail.html
index 3bdfc71ed5..669ca2956f 100644
--- a/templates/dashboard/staff/detail.html
+++ b/templates/dashboard/staff/detail.html
@@ -37,26 +37,26 @@
{% block content %}
<div class="row">
<div class="col s12 l8">
- <div class="card">
- {% if form %}
- <div class="data-table-header">
- <h5 class="data-table-title">
- Groups
- </h5>
- </div>
+ {% if form %}
+ <form class="card" method="post">
<div class="card-content">
+ <span class="card-title">
+ User groups
+ </span>
<div class="data">
- <form method="post">
{% csrf_token %}
- {{ form|materializecss }}
- <button type="submit" class="btn waves-effect waves-light">
- {% trans "Update" context "Dashboard update action" %}
- </button>
- </form>
+ <div class="row">
+ {{ form|materializecss }}
+ </div>
</div>
</div>
- {% endif %}
- </div>
+ <div class="card-action right-align">
+ <button type="submit" class="btn waves-effect waves-light">
+ {% trans "Update" context "Dashboard update action" %}
+ </button>
+ </div>
+ </form>
+ {% endif %}
<div class="card">
<div class="data-table-header{% if not customer_orders %} data-table-header--no-data{% endif %}">
<h5 class="data-table-title">
diff --git a/tests/conftest.py b/tests/conftest.py
index 223af08627..759632852e 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -144,12 +144,12 @@ def staff_group():
@pytest.fixture
-def product_permission_view():
+def permission_view_product():
return Permission.objects.get(codename='view_product')
@pytest.fixture
-def product_permission_edit():
+def permission_edit_product():
return Permission.objects.get(codename='edit_product')
diff --git a/tests/dashboard/test_permissions.py b/tests/dashboard/test_permissions.py
index e888ae0774..fd2f58c5c8 100644
--- a/tests/dashboard/test_permissions.py
+++ b/tests/dashboard/test_permissions.py
@@ -54,9 +54,9 @@ def test_staff_cant_access_product_list(staff_client, staff_user):
def test_staff_can_access_product_list(
- staff_client, staff_user, product_permission_view):
+ staff_client, staff_user, permission_view_product):
assert not staff_user.has_perm("product.view_product")
- staff_user.user_permissions.add(product_permission_view)
+ staff_user.user_permissions.add(permission_view_product)
del staff_user._perm_cache
del staff_user._user_perm_cache
assert staff_user.has_perm("product.view_product")
@@ -73,12 +73,26 @@ def test_staff_cant_access_product_update(
def test_staff_can_access_product_update(
- staff_client, staff_user, product_in_stock, product_permission_edit):
+ staff_client, staff_user, product_in_stock, permission_edit_product):
assert not staff_user.has_perm("product.edit_product")
- staff_user.user_permissions.add(product_permission_edit)
+ staff_user.user_permissions.add(permission_edit_product)
del staff_user._perm_cache
del staff_user._user_perm_cache
assert staff_user.has_perm("product.edit_product")
response = staff_client.get(
"/dashboard/products/%s/update/" % product_in_stock.pk)
assert response.status_code == 200
+
+
+def test_staff_group_member_can_view_products(
+ staff_client, staff_user, staff_group, permission_view_product):
+ assert not staff_user.has_perm("product.view_product")
+ response = staff_client.get('/dashboard/products/')
+ assert response.status_code == 302
+ staff_group.permissions.add(permission_view_product)
+ staff_user.groups.add(staff_group)
+ del staff_user._perm_cache
+ del staff_user._user_perm_cache
+ # assert staff_user.has_perm("product.view_product")
+ response = staff_client.get('/dashboard/products/')
+ assert response.status_code == 200