Prevent unprivileged users from deleting inventory sources

This commit is contained in:
Aaron Tan
2017-07-27 16:29:03 -04:00
parent a8b7e2608b
commit 5a540a877e
2 changed files with 16 additions and 1 deletions

View File

@@ -795,7 +795,8 @@ class InventorySourceAccess(BaseAccess):
update_on_project_update=True, source='scm').exists())
def can_delete(self, obj):
if not (self.user.is_superuser or not (obj and obj.inventory and self.user.can_access(Inventory, 'admin', obj.inventory, None))):
if not self.user.is_superuser and \
not (obj and obj.inventory and self.user.can_access(Inventory, 'admin', obj.inventory, None)):
return False
active_jobs_qs = InventoryUpdate.objects.filter(inventory_source=obj, status__in=ACTIVE_STATES)
if active_jobs_qs.exists():