[layerindex-web][PATCH] admin.py: Remove has_delete_permission()


Robert Yang
 

The following commit has added on_delete=models.CASCADE to the ForeignKey:

===
commit 2d526f9b0d363f3e442abc97ef9bd9fab37ee5e4
Author: Amber Elliot <amber.n.elliot@...>
Date: Thu Jun 25 15:57:34 2020 -0700

Updating models and imports for Django 2.2 upgrade.
===

The on_delete=models.CASCADE will remove the objects which references the
removing objects, so there will be errors when removing a LayerBranch
with admin permissions:

===
Cannot delete layer branch
Deleting the selected layer branch would result in deleting related objects, but your account doesn't have permission to delete the following types of objects:

Append
distro
===

This is because has_delete_permission() always return False, remove it to use
Django's implementation to fix the problem.

Signed-off-by: Robert Yang <liezhi.yang@...>
---
layerindex/admin.py | 17 -----------------
1 file changed, 17 deletions(-)

diff --git a/layerindex/admin.py b/layerindex/admin.py
index 9ed6102..f8b2f6e 100644
--- a/layerindex/admin.py
+++ b/layerindex/admin.py
@@ -102,8 +102,6 @@ class RecipeAdmin(admin.ModelAdmin):
return rofields
def has_add_permission(self, request, obj=None):
return False
- def has_delete_permission(self, request, obj=None):
- return False

class PackageConfigAdmin(admin.ModelAdmin):
search_fields = ['feature', 'recipe__pn']
@@ -132,8 +130,6 @@ class ClassicRecipeAdmin(admin.ModelAdmin):
return rofields
def has_add_permission(self, request, obj=None):
return False
- def has_delete_permission(self, request, obj=None):
- return False

class MachineAdmin(admin.ModelAdmin):
search_fields = ['name']
@@ -141,8 +137,6 @@ class MachineAdmin(admin.ModelAdmin):
readonly_fields = [f.name for f in Machine._meta.get_fields()]
def has_add_permission(self, request, obj=None):
return False
- def has_delete_permission(self, request, obj=None):
- return False

class DistroAdmin(admin.ModelAdmin):
search_fields = ['name']
@@ -150,9 +144,6 @@ class DistroAdmin(admin.ModelAdmin):
readonly_fields = [f.name for f in Distro._meta.get_fields()]
def has_add_permission(self, request, obj=None):
return False
- def has_delete_permission(self, request, obj=None):
- return False
-

class BBAppendAdmin(admin.ModelAdmin):
search_fields = ['filename']
@@ -160,8 +151,6 @@ class BBAppendAdmin(admin.ModelAdmin):
readonly_fields = [f.name for f in BBAppend._meta.get_fields()]
def has_add_permission(self, request, obj=None):
return False
- def has_delete_permission(self, request, obj=None):
- return False

class BBClassAdmin(admin.ModelAdmin):
search_fields = ['name']
@@ -169,8 +158,6 @@ class BBClassAdmin(admin.ModelAdmin):
readonly_fields = [f.name for f in BBClass._meta.get_fields()]
def has_add_permission(self, request, obj=None):
return False
- def has_delete_permission(self, request, obj=None):
- return False

class PatchAdmin(admin.ModelAdmin):
search_fields = ['path']
@@ -178,8 +165,6 @@ class PatchAdmin(admin.ModelAdmin):
readonly_fields = [f.name for f in Patch._meta.get_fields()]
def has_add_permission(self, request, obj=None):
return False
- def has_delete_permission(self, request, obj=None):
- return False

class PatchDispositionAdmin(admin.ModelAdmin):
fields = ['patch', 'user', 'disposition', 'comment']
@@ -199,8 +184,6 @@ class IncFileAdmin(admin.ModelAdmin):
readonly_fields = [f.name for f in IncFile._meta.get_fields()]
def has_add_permission(self, request, obj=None):
return False
- def has_delete_permission(self, request, obj=None):
- return False

class RecipeChangeInline(admin.StackedInline):
model = RecipeChange
--
2.37.1