initial
This commit is contained in:
22
frontend/permissions.py
Normal file
22
frontend/permissions.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# frontend/permissions.py
|
||||
from mikrotik.models import IPAddress
|
||||
|
||||
def user_can_access_container(user_profile, container):
|
||||
"""Prüft, ob der Benutzer Zugriff auf den Container hat."""
|
||||
if user_profile.is_internal():
|
||||
return True
|
||||
if user_profile.user.is_superuser:
|
||||
return True
|
||||
|
||||
# Für externe Benutzer: Nur Container im eigenen Netzwerkbereich
|
||||
ldap_uid = user_profile.ldap_uid
|
||||
ip_addresses = IPAddress.objects.filter(comment__icontains=f' {ldap_uid} ')
|
||||
|
||||
# Prüfen, ob Container-Netzwerk mit einer der IP-Adressen übereinstimmt
|
||||
networks = [ip.network for ip in ip_addresses]
|
||||
|
||||
if hasattr(container, 'lease') and container.lease:
|
||||
container_network = '.'.join(container.lease.address.split('.')[:3])
|
||||
return any(network.startswith(container_network) for network in networks)
|
||||
|
||||
return False
|
||||
Reference in New Issue
Block a user