fix: Use bound fields in rights management system

- Replace raw field objects with bound fields in get_permission_groups()
- Bound fields render properly as HTML checkboxes in templates
- Fixes display of Django field object strings instead of actual form inputs
- Rights management system now shows proper checkboxes with permission names
This commit is contained in:
2025-10-05 23:03:56 +02:00
parent efd0088124
commit ca3bf0f296

View File

@@ -1348,6 +1348,9 @@ class UserPermissionForm(forms.Form):
permission = Permission.objects.get(id=perm_id) permission = Permission.objects.get(id=perm_id)
label = permission.name.lower() label = permission.name.lower()
codename = permission.codename.lower() codename = permission.codename.lower()
# Get bound field for proper template rendering
bound_field = self[field_name]
# More precise categorization based on both name and codename # More precise categorization based on both name and codename
if ( if (
@@ -1365,7 +1368,7 @@ class UserPermissionForm(forms.Form):
or "view_" in codename or "view_" in codename
): ):
groups["entities"]["permissions"].append( groups["entities"]["permissions"].append(
(field_name, field, permission) (field_name, bound_field, permission)
) )
elif ( elif (
any( any(
@@ -1374,7 +1377,7 @@ class UserPermissionForm(forms.Form):
or "dokument" in label or "dokument" in label
): ):
groups["documents"]["permissions"].append( groups["documents"]["permissions"].append(
(field_name, field, permission) (field_name, bound_field, permission)
) )
elif any( elif any(
word in codename word in codename
@@ -1394,7 +1397,7 @@ class UserPermissionForm(forms.Form):
] ]
): ):
groups["financial"]["permissions"].append( groups["financial"]["permissions"].append(
(field_name, field, permission) (field_name, bound_field, permission)
) )
elif any( elif any(
word in codename word in codename
@@ -1416,11 +1419,11 @@ class UserPermissionForm(forms.Form):
] ]
): ):
groups["administration"]["permissions"].append( groups["administration"]["permissions"].append(
(field_name, field, permission) (field_name, bound_field, permission)
) )
else: else:
groups["system"]["permissions"].append( groups["system"]["permissions"].append(
(field_name, field, permission) (field_name, bound_field, permission)
) )
except Permission.DoesNotExist: except Permission.DoesNotExist:
# Create a fallback permission-like object with proper display # Create a fallback permission-like object with proper display
@@ -1430,7 +1433,8 @@ class UserPermissionForm(forms.Form):
self.codename = field_name self.codename = field_name
fallback_perm = FallbackPermission(field_name) fallback_perm = FallbackPermission(field_name)
groups["system"]["permissions"].append((field_name, field, fallback_perm)) bound_field = self[field_name] # Get bound field for exception case too
groups["system"]["permissions"].append((field_name, bound_field, fallback_perm))
return groups return groups