Skip to content

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

Added 'Staff' section in Dashboard with only staff members. Deleted staff members from the customer list in dashboard. Added new templates for Staff section. Prepared siple form for future permission handling for staff members.

michal185fa557304e
diff --git a/.gitignore b/.gitignore
index 298dfab37d..4a9739dadc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,6 +14,7 @@
*.log
*.pot
*.pyc
+.envrc
local_settings.py
__pycache__/
build/
diff --git a/saleor/core/templatetags/materializecss.py b/saleor/core/templatetags/materializecss.py
index 5423e453a4..70ba1f6f2d 100644
--- a/saleor/core/templatetags/materializecss.py
+++ b/saleor/core/templatetags/materializecss.py
@@ -82,3 +82,4 @@ def is_select(field):
@register.filter
def is_checkbox_select_multiple(field):
return isinstance(field.field.widget, forms.CheckboxSelectMultiple)
+
diff --git a/saleor/dashboard/customer/views.py b/saleor/dashboard/customer/views.py
index 65cc88a232..eb0039e2ac 100644
--- a/saleor/dashboard/customer/views.py
+++ b/saleor/dashboard/customer/views.py
@@ -17,7 +17,9 @@ def customer_list(request):
.select_related('default_billing_address', 'default_shipping_address')
.annotate(
num_orders=Count('orders', distinct=True),
- last_order=Max('orders', distinct=True)))
+ last_order=Max('orders', distinct=True))
+ .filter(is_staff=False)
+ )
customers = get_paginator_items(customers, 30, request.GET.get('page'))
ctx = {'customers': customers}
return TemplateResponse(request, 'dashboard/customer/list.html', ctx)
diff --git a/saleor/dashboard/staff/__init__.py b/saleor/dashboard/staff/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/dashboard/staff/forms.py b/saleor/dashboard/staff/forms.py
new file mode 100644
index 0000000000..3eaf61b992
--- /dev/null
+++ b/saleor/dashboard/staff/forms.py
@@ -0,0 +1,18 @@
+from django.contrib.auth.models import Permission
+from django import forms
+
+
+class PermissionsForm(forms.Form):
+ permission_options = (
+ ('view', u'View'),
+ ('edit', u'Edit'),
+ )
+ product = forms.MultipleChoiceField(label='Product',
+ required=False,
+ choices=permission_options,
+ widget=forms.CheckboxSelectMultiple)
+ categories = forms.MultipleChoiceField(label='Categories',
+ required=False,
+ choices=permission_options,
+ widget=forms.CheckboxSelectMultiple)
+
diff --git a/saleor/dashboard/staff/urls.py b/saleor/dashboard/staff/urls.py
new file mode 100644
index 0000000000..c93c1ffbd2
--- /dev/null
+++ b/saleor/dashboard/staff/urls.py
@@ -0,0 +1,9 @@
+from django.conf.urls import url
+
+from . import views
+
+
+urlpatterns = [
+ url(r'^$', views.staff_list, name='staff'),
+ url(r'^(?P<pk>[0-9]+)/$', views.staff_details, name='staff-details')
+]
diff --git a/saleor/dashboard/staff/views.py b/saleor/dashboard/staff/views.py
new file mode 100644
index 0000000000..1e533a8d2f
--- /dev/null
+++ b/saleor/dashboard/staff/views.py
@@ -0,0 +1,47 @@
+from __future__ import unicode_literals
+
+from django import forms
+from django.shortcuts import get_object_or_404
+from django.template.response import TemplateResponse
+from django.contrib.auth.models import Permission
+
+from .forms import PermissionsForm
+from ..views import staff_member_required
+from ...core.utils import get_paginator_items
+from ...userprofile.models import User
+
+
+@staff_member_required
+def staff_list(request):
+ staff_members = (
+ User.objects
+ .filter(is_staff=True)
+ )
+ staff_members = get_paginator_items(staff_members, 30, request.GET.get('page'))
+ ctx = {'staff': staff_members}
+ return TemplateResponse(request, 'dashboard/staff/list.html', ctx)
+
+
+@staff_member_required
+def staff_details(request, pk):
+ queryset = User.objects.filter(is_staff=True)
+ staff_member = get_object_or_404(queryset, pk=pk)
+
+ form = PermissionsForm(request.POST or None)
+
+ if form.is_valid():
+ print form.cleaned_data
+
+ for category, permissions in form.cleaned_data.items():
+ add_permissions(user=staff_member, category=category,
+ permissions=permissions)
+
+ ctx = {'staff_member': staff_member, 'form': form, "permissions": permissions}
+ return TemplateResponse(request, 'dashboard/staff/detail.html', ctx)
+
+
+def add_permissions(user, category, permissions):
+ print user.user_permissions
+ # user.user_permissions.set(['product_view'])
+ print user.user_permissions
+
diff --git a/saleor/dashboard/urls.py b/saleor/dashboard/urls.py
index 06dbe20f4c..120ef1ba37 100644
--- a/saleor/dashboard/urls.py
+++ b/saleor/dashboard/urls.py
@@ -3,6 +3,8 @@ from django.conf.urls import url, include
from . import views as core_views
from .category.urls import urlpatterns as category_urls
from .customer.urls import urlpatterns as customer_urls
+from .staff.urls import urlpatterns as staff_urls
+
from .order.urls import urlpatterns as order_urls
from .product.urls import urlpatterns as product_urls
from .discount.urls import urlpatterns as discount_urls
@@ -17,6 +19,7 @@ urlpatterns = [
url(r'^orders/', include(order_urls)),
url(r'^products/', include(product_urls)),
url(r'^customers/', include(customer_urls)),
+ url(r'^staff/', include(staff_urls)),
url(r'^discounts/', include(discount_urls)),
url(r'^search/', include(search_urls)),
url(r'^settings/', include(site_urls)),
diff --git a/templates/dashboard/base.html b/templates/dashboard/base.html
index 8afe60ec31..52acb1fd48 100644
--- a/templates/dashboard/base.html
+++ b/templates/dashboard/base.html
@@ -147,6 +147,11 @@
{% trans "Configuration" context "Dashboard configuration" %}
</p>
<ul>
+ <li class="{% block menu_staff_class %}{% endblock %}">
+ <a href="{% url 'dashboard:staff' %}">
+ {% trans "Staff" context "Dashboard staff members list" %}
+ </a>
+ </li>
<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/staff/detail.html b/templates/dashboard/staff/detail.html
new file mode 100644
index 0000000000..7b1c02dc76
--- /dev/null
+++ b/templates/dashboard/staff/detail.html
@@ -0,0 +1,167 @@
+{% extends "dashboard/base.html" %}
+{% load materializecss %}
+{% load prices_i18n %}
+{% load i18n %}
+{% load status %}
+{% load staticfiles %}
+
+{% block title %}
+ {{ staff_member }} - {% trans "Customers" context "Dashboard customers list" %} - {{ block.super }}
+{% endblock %}
+
+{% block body_class %}body-customers{% endblock %}
+
+{% block menu_staff_class %}active{% endblock %}
+
+{% block header_menu %}
+ {% url "dashboard:staff" as url %}
+ {% include "dashboard/includes/_back-link.html" with url=url %}
+{% endblock %}
+
+{% block breadcrumbs %}
+ <ul class="breadcrumbs breadcrumbs--history">
+ <li>
+ <a href="{% url "dashboard:staff" %}">
+ {% trans "Customers" context "Dashboard customers list" %}
+ </a>
+ </li>
+ <li class="back-mobile">
+ <a href="{% url "dashboard:staff" %}">
+ <svg data-src="{% static "dashboard/images/arrow_left.svg" %}" fill="#fff" width="20px" height="20px" />
+ </a>
+ </li>
+ <li><span class="breadcrumbs--elipsed-item">{{ staff_member }}</span></li>
+ </ul>
+{% endblock %}
+
+{% block content %}
+ <div class="row">
+ <div class="col s12 l8">
+
+ <div class="card">
+ <div class="data-table-header">
+ <h5 class="data-table-title">
+ Permissions
+ </h5>
+ </div>
+
+ <div class="card-content">
+
+
+
+ <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>
+
+
+
+
+ </div>
+
+ </div>
+
+
+ <div class="card">
+ <div class="data-table-header{% if not customer_orders %} data-table-header--no-data{% endif %}">
+ <h5 class="data-table-title">
+ {% trans "Order history" context "Customer orders table title" %}
+ </h5>
+ </div>
+ {% if customer_orders %}
+ <div class="data-table-container">
+ <table class="bordered highlight responsive data-table">
+ <thead>
+ <tr>
+ <th>
+ {% trans "Number" context "Customer orders table header" %}
+ </th>
+ <th>
+ {% trans "Placed on" context "Customer orders table header" %}
+ </th>
+ <th>
+ {% trans "Order status" context "Customer orders table header" %}
+ </th>
+ <th class="right-align">
+ {% trans "Total" context "Customer orders table header" %}
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for order in customer_orders %}
+ <tr data-action-go="{% url 'dashboard:order-details' order_pk=order.pk %}">
+ <td>
+ {{ order }}
+ </td>
+ <td>
+ {{ order.created }}
+ </td>
+ <td>
+ {% render_status order.status order.get_status_display %}
+ </td>
+ <td class="right-align">
+ {% gross order.get_total html=True %}
+ </td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ {% else %}
+ <div class="card-content card-content--no-data">
+ <p>
+ {% trans "No orders found." context "Empty customer orders table message" %}
+ </p>
+ </div>
+ {% endif %}
+ </div>
+ </div>
+ <div class="col s12 l4">
+ <div class="row">
+ <div class="col s12 m6 p6 l12">
+ <div class="card equal-height-on-med">
+ <div class="card-content">
+ <span class="card-title black-text">
+ {% trans "Default shipping address" context "Customer default shipping address card title" %}
+ </span>
+ {% if customer.default_shipping_address %}
+ {% with customer.default_shipping_address as address %}
+ {% include 'dashboard/includes/_address.html' with address=address only %}
+ {% endwith %}
+ {% else %}
+ <div>{% trans "No default shipping address." context "Customer without default shipping address message" %}</div>
+ {% endif %}
+ <svg data-src="{% static "dashboard/images/email.svg" %}" width="14" height="14" />
+ <a href="mailto:{{ customer.email }}">
+ {{ customer.email }}
+ </a>
+ </div>
+ </div>
+ </div>
+ <div class="col s12 m6 p6 l12">
+ <div class="card equal-height-on-med">
+ <div class="card-content">
+ <span class="card-title black-text">
+ {% trans "Default billing address" context "Customer default billing address card title" %}
+ </span>
+ {% if customer.default_billing_address %}
+ {% with customer.default_billing_address as address %}
+ {% include 'dashboard/includes/_address.html' with address=address only %}
+ {% endwith %}
+ {% else %}
+ <div>
+ {% trans "No default billing address." context "Customer without default billing address message" %}
+ </div>
+ {% endif %}
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+{% endblock %}
diff --git a/templates/dashboard/staff/list.html b/templates/dashboard/staff/list.html
new file mode 100644
index 0000000000..bb15f78935
--- /dev/null
+++ b/templates/dashboard/staff/list.html
@@ -0,0 +1,69 @@
+{% extends "dashboard/base.html" %}
+{% load i18n %}
+{% load prices_i18n %}
+{% load materializecss %}
+
+{% block title %}
+ {% trans "Staff" context "Dashboard staff members list" %} - {{ block.super }}
+{% endblock %}
+
+{% block body_class %}body-customers{% endblock %}
+
+{% block menu_staff_class %}active{% endblock %}
+
+{% block breadcrumbs %}
+ <ul class="breadcrumbs">
+ <li class="visible-s">
+ {% trans "Staff" context "Dashboard staff members list" %}
+ </li>
+ </ul>
+{% endblock %}
+
+{% block content %}
+ {% if staff %}
+ <div class="card">
+ <div class="data-table-container">
+ <table class="bordered highlight responsive data-table">
+ <thead>
+ <tr>
+ <th>
+ {% trans "Email" context "Customers table header" %}
+ </th>
+ <th class="wide">
+ {% trans "Name" context "Customers table header" %}
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for user in staff %}
+ <tr data-action-go="{% url "dashboard:staff-details" pk=user.pk %}">
+ {% with user.default_billing_address as default_address %}
+ <td>
+ {{ user.email }}
+ </td>
+ {% if default_address %}
+ <td>
+ {{ default_address.first_name }} {{ default_address.last_name }}
+ </td>
+ <td>
+ {{ default_address.city }}, {{ default_address.get_country_display }}
+ </td>
+ {% else %}
+ <td colspan="2"></td>
+ {% endif %}
+ {% endwith %}
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ </div>
+ {% else %}
+ <div class="card-content card-content--no-data not-found">
+ <p class="grey-text">
+ {% trans "No customers found." context "Empty customers table message" %}
+ </p>
+ </div>
+ {% endif %}
+ {% include "dashboard/includes/_pagination.html" with page_obj=customers %}
+{% endblock %}
diff --git a/templates/materializecssform/field.html b/templates/materializecssform/field.html
index 37e1870731..985834744d 100644
--- a/templates/materializecssform/field.html
+++ b/templates/materializecssform/field.html
@@ -35,7 +35,7 @@
{% endif %}
{% for choice in field %}
<p>
- <input id="{{ choice.id_for_label }}" name="{{ choice.name }}" class="filled-in" type="checkbox" value="{{ choice.choice_value }}" {% if choice.choice_value in choice.value %} checked="checked" {% endif %}>
+ <input id="{{ choice.id_for_label }}" name="{{ choice.data.name }}" class="filled-in" type="checkbox" value="{{ choice.data.value }}" {% if choice.data.selected%} checked="checked" {% endif %}>
<label for="{{ choice.id_for_label }}">
{{ choice.choice_label }}
</label>
diff --git a/tests/dashboard/test_permissions.py b/tests/dashboard/test_permissions.py
new file mode 100644
index 0000000000..2b21e3f3b7
--- /dev/null
+++ b/tests/dashboard/test_permissions.py
@@ -0,0 +1,3 @@
+from __future__ import unicode_literals
+
+import pytest