Skip to content

Commit

Permalink
Replace superuser permission check with staff permission
Browse files Browse the repository at this point in the history
  • Loading branch information
akjanik committed Nov 17, 2017
1 parent e9f1d27 commit e1330a9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions saleor/core/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
MODELS_PERMISSIONS = [
'order.view_order',
'order.edit_order',
'product.view_attributes',
'product.edit_attributes',
'product.view_category',
'product.edit_category',
'product.view_class',
'product.edit_class',
'product.view_product',
'product.edit_product',
'product.view_stock_location',
Expand Down
12 changes: 8 additions & 4 deletions saleor/dashboard/product/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from . import forms


@superuser_required
@staff_member_required
@permission_required('product.view_class')
def product_class_list(request):
classes = ProductClass.objects.all().prefetch_related(
'product_attributes', 'variant_attributes').order_by('name')
Expand All @@ -39,7 +40,8 @@ def product_class_list(request):
ctx)


@superuser_required
@staff_member_required
@permission_required('product.edit_class')
def product_class_create(request):
product_class = ProductClass()
form = forms.ProductClassForm(request.POST or None,
Expand All @@ -57,7 +59,8 @@ def product_class_create(request):
ctx)


@superuser_required
@staff_member_required
@permission_required('product.edit_class')
def product_class_edit(request, pk):
product_class = get_object_or_404(
ProductClass, pk=pk)
Expand All @@ -76,7 +79,8 @@ def product_class_edit(request, pk):
ctx)


@superuser_required
@staff_member_required
@permission_required('product.edit_class')
def product_class_delete(request, pk):
product_class = get_object_or_404(ProductClass, pk=pk)
if request.method == 'POST':
Expand Down
8 changes: 7 additions & 1 deletion saleor/product/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ class Meta:
('view_product',
pgettext_lazy('Permission description', 'Can view products')),
('edit_product',
pgettext_lazy('Permission description', 'Can edit products')))
pgettext_lazy('Permission description', 'Can edit products')),
('view_class',
pgettext_lazy('Permission description',
'Can view product class')),
('edit_class',
pgettext_lazy('Permission description',
'Can edit product class')))

def __iter__(self):
if not hasattr(self, '__variants'):
Expand Down
6 changes: 5 additions & 1 deletion templates/dashboard/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,26 @@
</ul>
</li>
{% endif %}
{% if user.is_superuser %}
{% if perms.product.view_class or perms.product.view_attributes %}
<li class="side-nav-section">
<p>
{% trans "Configuration" context "Dashboard configuration" %}
</p>
<ul>
{% if perms.userprofile.view_class %}
<li class="{% block menu_product_classes_class %}{% endblock %}">
<a href="{% url 'dashboard:product-class-list' %}">
{% trans "Product types" context "Dashboard product types list" %}
</a>
</li>
{% endif %}
{% if perms.userprofile.view_attributes %}
<li class="{% block menu_attributes_class %}{% endblock %}">
<a href="{% url 'dashboard:product-attributes' %}">
{% trans "Attributes" context "Dashboard attributes list" %}
</a>
</li>
{% endif %}
<li class="{% block menu_delivery_class %}{% endblock %}">
<a href="{% url 'dashboard:shipping-methods' %}">
{% trans "Shipping methods" context "Dashboard shipping methods list" %}
Expand Down

0 comments on commit e1330a9

Please sign in to comment.