mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Call permission_is_exempt() to check for exempt permissions
This commit is contained in:
parent
3a9512f086
commit
b6c38ceb73
@ -6,14 +6,14 @@ from django.contrib.auth.models import Group
|
|||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
from users.models import ObjectPermission
|
from users.models import ObjectPermission
|
||||||
from utilities.permissions import resolve_permission
|
from utilities.permissions import permission_is_exempt, resolve_permission
|
||||||
|
|
||||||
|
|
||||||
class ObjectPermissionBackend(ModelBackend):
|
class ObjectPermissionBackend(ModelBackend):
|
||||||
|
|
||||||
def get_all_permissions(self, user_obj, obj=None):
|
def get_all_permissions(self, user_obj, obj=None):
|
||||||
if not user_obj.is_active or user_obj.is_anonymous:
|
if not user_obj.is_active or user_obj.is_anonymous:
|
||||||
return set()
|
return dict()
|
||||||
if not hasattr(user_obj, '_object_perm_cache'):
|
if not hasattr(user_obj, '_object_perm_cache'):
|
||||||
user_obj._object_perm_cache = self.get_object_permissions(user_obj)
|
user_obj._object_perm_cache = self.get_object_permissions(user_obj)
|
||||||
return user_obj._object_perm_cache
|
return user_obj._object_perm_cache
|
||||||
@ -49,16 +49,9 @@ class ObjectPermissionBackend(ModelBackend):
|
|||||||
if user_obj.is_active and user_obj.is_superuser:
|
if user_obj.is_active and user_obj.is_superuser:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# If this is a view permission, check whether the model has been exempted from enforcement
|
# Permission is exempt from enforcement (i.e. listed in EXEMPT_VIEW_PERMISSIONS)
|
||||||
if action == 'view':
|
if permission_is_exempt(perm):
|
||||||
if (
|
return True
|
||||||
# All models are exempt from view permission enforcement
|
|
||||||
'*' in settings.EXEMPT_VIEW_PERMISSIONS
|
|
||||||
) or (
|
|
||||||
# This specific model is exempt from view permission enforcement
|
|
||||||
'{}.{}'.format(app_label, model_name) in settings.EXEMPT_VIEW_PERMISSIONS
|
|
||||||
):
|
|
||||||
return True
|
|
||||||
|
|
||||||
# Handle inactive/anonymous users
|
# Handle inactive/anonymous users
|
||||||
if not user_obj.is_active or user_obj.is_anonymous:
|
if not user_obj.is_active or user_obj.is_anonymous:
|
||||||
|
Loading…
Reference in New Issue
Block a user