Separated category from part permissions and location from stock item permissions

This commit is contained in:
eeintech 2021-01-13 13:35:49 -05:00
parent eedd8059d8
commit 59c0a50289
7 changed files with 43 additions and 26 deletions

View File

@ -9,7 +9,7 @@
{% if category %}
<h3>
{{ category.name }}
{% if user.is_staff and roles.part.change %}
{% if user.is_staff and roles.part_category.change %}
<a href="{% url 'admin:part_partcategory_change' category.pk %}"><span title="{% trans 'Admin view' %}" class='fas fa-user-shield'></span></a>
{% endif %}
</h3>
@ -20,18 +20,18 @@
{% endif %}
<p>
<div class='btn-group action-buttons'>
{% if roles.part.add %}
{% if roles.part_category.add %}
<button class='btn btn-default' id='cat-create' title='{% trans "Create new part category" %}'>
<span class='fas fa-plus-circle icon-green'/>
</button>
{% endif %}
{% if category %}
{% if roles.part.change %}
{% if roles.part_category.change %}
<button class='btn btn-default' id='cat-edit' title='{% trans "Edit part category" %}'>
<span class='fas fa-edit icon-blue'/>
</button>
{% endif %}
{% if roles.part.delete %}
{% if roles.part_category.delete %}
<button class='btn btn-default' id='cat-delete' title='{% trans "Delete part category" %}'>
<span class='fas fa-trash-alt icon-red'/>
</button>

View File

@ -2088,7 +2088,7 @@ class CategoryDetail(InvenTreeRoleMixin, DetailView):
queryset = PartCategory.objects.all().prefetch_related('children')
template_name = 'part/category_partlist.html'
role_required = 'part.view'
role_required = ['part_category.view', 'part.view']
def get_context_data(self, **kwargs):
@ -2138,7 +2138,7 @@ class CategoryEdit(AjaxUpdateView):
ajax_template_name = 'modal_form.html'
ajax_form_title = _('Edit Part Category')
role_required = 'part.change'
role_required = 'part_category.change'
def get_context_data(self, **kwargs):
context = super(CategoryEdit, self).get_context_data(**kwargs).copy()
@ -2177,7 +2177,7 @@ class CategoryDelete(AjaxDeleteView):
context_object_name = 'category'
success_url = '/part/'
role_required = 'part.delete'
role_required = 'part_category.delete'
def get_data(self):
return {
@ -2193,7 +2193,7 @@ class CategoryCreate(AjaxCreateView):
ajax_template_name = 'modal_form.html'
form_class = part_forms.EditCategoryForm
role_required = 'part.add'
role_required = 'part_category.add'
def get_context_data(self, **kwargs):
""" Add extra context data to template.
@ -2233,7 +2233,7 @@ class CategoryCreate(AjaxCreateView):
class CategoryParameterTemplateCreate(AjaxCreateView):
""" View for creating a new PartCategoryParameterTemplate """
role_required = 'part.add'
role_required = 'part_category.change'
model = PartCategoryParameterTemplate
form_class = part_forms.EditCategoryParameterTemplateForm
@ -2336,7 +2336,7 @@ class CategoryParameterTemplateCreate(AjaxCreateView):
class CategoryParameterTemplateEdit(AjaxUpdateView):
""" View for editing a PartCategoryParameterTemplate """
role_required = 'part.change'
role_required = 'part_category.change'
model = PartCategoryParameterTemplate
form_class = part_forms.EditCategoryParameterTemplateForm
@ -2395,7 +2395,7 @@ class CategoryParameterTemplateEdit(AjaxUpdateView):
class CategoryParameterTemplateDelete(AjaxDeleteView):
""" View for deleting an existing PartCategoryParameterTemplate """
role_required = 'part.delete'
role_required = 'part_category.change'
model = PartCategoryParameterTemplate
ajax_form_title = _("Delete Category Parameter Template")

View File

@ -8,7 +8,7 @@
{% if location %}
<h3>
{{ location.name }}
{% if user.is_staff and roles.stock.change %}
{% if user.is_staff and roles.stock_location.change %}
<a href="{% url 'admin:stock_stocklocation_change' location.pk %}"><span title="{% trans 'Admin view' %}" class='fas fa-user-shield'></span></a>
{% endif %}
</h3>
@ -18,7 +18,7 @@
<p>{% trans "All stock items" %}</p>
{% endif %}
<div class='btn-group action-buttons' role='group'>
{% if roles.stock.add %}
{% if roles.stock_location.add %}
<button class='btn btn-default' id='location-create' title='{% trans "Create new stock location" %}'>
<span class='fas fa-plus-circle icon-green'/>
</button>
@ -41,11 +41,13 @@
{% trans "Count stock" %}</a></li>
</ul>
</div>
{% endif %}
{% if roles.stock_location.change %}
<div class='btn-group'>
<button id='location-actions' title='{% trans "Location actions" %}' class='btn btn-default dropdown-toggle' type='button' data-toggle="dropdown"><span class='fas fa-sitemap'></span> <span class='caret'></span></button>
<ul class='dropdown-menu' role='menu'>
<li><a href='#' id='location-edit'><span class='fas fa-edit icon-green'></span> {% trans "Edit location" %}</a></li>
{% if roles.stock.delete %}
{% if roles.stock_location.delete %}
<li><a href='#' id='location-delete'><span class='fas fa-trash-alt icon-red'></span> {% trans "Delete location" %}</a></li>
{% endif %}
</ul>

View File

@ -1,6 +1,6 @@
{% extends "collapse.html" %}
{% if roles.stock.view %}
{% if roles.stock_location.view or roles.stock.view %}
{% block collapse_title %}
Sub-Locations<span class='badge'>{{ children|length }}</span>
{% endblock %}

View File

@ -73,7 +73,7 @@ class StockLocationDetail(InvenTreeRoleMixin, DetailView):
template_name = 'stock/location.html'
queryset = StockLocation.objects.all()
model = StockLocation
role_required = 'stock.view'
role_required = ['stock_location.view', 'stock.view']
class StockItemDetail(InvenTreeRoleMixin, DetailView):
@ -121,7 +121,7 @@ class StockLocationEdit(AjaxUpdateView):
context_object_name = 'location'
ajax_template_name = 'modal_form.html'
ajax_form_title = _('Edit Stock Location')
role_required = 'stock.change'
role_required = 'stock_location.change'
def get_form(self):
""" Customize form data for StockLocation editing.
@ -146,7 +146,7 @@ class StockLocationQRCode(QRCodeView):
""" View for displaying a QR code for a StockLocation object """
ajax_form_title = _("Stock Location QR code")
role_required = 'stock.view'
role_required = ['stock_location.view', 'stock.view']
def get_qr_data(self):
""" Generate QR code data for the StockLocation """
@ -1361,7 +1361,7 @@ class StockLocationCreate(AjaxCreateView):
context_object_name = 'location'
ajax_template_name = 'modal_form.html'
ajax_form_title = _('Create new Stock Location')
role_required = 'stock.add'
role_required = 'stock_location.add'
def get_initial(self):
initials = super(StockLocationCreate, self).get_initial().copy()
@ -1748,7 +1748,7 @@ class StockLocationDelete(AjaxDeleteView):
ajax_template_name = 'stock/location_delete.html'
context_object_name = 'location'
ajax_form_title = _('Delete Stock Location')
role_required = 'stock.delete'
role_required = 'stock_location.delete'
class StockItemDelete(AjaxDeleteView):

View File

@ -30,6 +30,8 @@ class RuleSetInline(admin.TabularInline):
max_num = len(RuleSet.RULESET_CHOICES)
min_num = 1
extra = 0
# TODO: find better way to order inlines
ordering = ['name']
class InvenTreeGroupAdminForm(forms.ModelForm):
@ -87,7 +89,8 @@ class RoleGroupAdmin(admin.ModelAdmin):
RuleSetInline,
]
list_display = ('name', 'admin', 'part', 'stock', 'build', 'purchase_order', 'sales_order')
list_display = ('name', 'admin', 'part_category', 'part', 'stock_location',
'stock_item', 'build', 'purchase_order', 'sales_order')
def get_rule_set(self, obj, rule_set_type):
''' Return list of permissions for the given ruleset '''
@ -130,10 +133,16 @@ class RoleGroupAdmin(admin.ModelAdmin):
def admin(self, obj):
return self.get_rule_set(obj, 'admin')
def part_category(self, obj):
return self.get_rule_set(obj, 'part_category')
def part(self, obj):
return self.get_rule_set(obj, 'part')
def stock(self, obj):
def stock_location(self, obj):
return self.get_rule_set(obj, 'stock_location')
def stock_item(self, obj):
return self.get_rule_set(obj, 'stock')
def build(self, obj):

View File

@ -25,8 +25,10 @@ class RuleSet(models.Model):
RULESET_CHOICES = [
('admin', _('Admin')),
('part_category', _('Part Categories')),
('part', _('Parts')),
('stock', _('Stock')),
('stock_location', _('Stock Locations')),
('stock', _('Stock Items')),
('build', _('Build Orders')),
('purchase_order', _('Purchase Orders')),
('sales_order', _('Sales Orders')),
@ -48,21 +50,25 @@ class RuleSet(models.Model):
'authtoken_token',
'users_ruleset',
],
'part_category': [
'part_partcategory',
'part_partcategoryparametertemplate',
],
'part': [
'part_part',
'part_bomitem',
'part_partcategory',
'part_partattachment',
'part_partsellpricebreak',
'part_parttesttemplate',
'part_partparametertemplate',
'part_partparameter',
'part_partrelated',
'part_partcategoryparametertemplate',
],
'stock_location': [
'stock_stocklocation',
],
'stock': [
'stock_stockitem',
'stock_stocklocation',
'stock_stockitemattachment',
'stock_stockitemtracking',
'stock_stockitemtestresult',