mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Implement RestrictedQuerySet as a manager
This commit is contained in:
19
netbox/utilities/mptt.py
Normal file
19
netbox/utilities/mptt.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from mptt.managers import TreeManager as TreeManager_
|
||||
from mptt.querysets import TreeQuerySet as TreeQuerySet_
|
||||
|
||||
from django.db.models import Manager
|
||||
from .querysets import RestrictedQuerySet
|
||||
|
||||
|
||||
class TreeQuerySet(TreeQuerySet_, RestrictedQuerySet):
|
||||
"""
|
||||
Mate django-mptt's TreeQuerySet with our RestrictedQuerySet for permissions enforcement.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class TreeManager(Manager.from_queryset(TreeQuerySet), TreeManager_):
|
||||
"""
|
||||
Extend django-mptt's TreeManager to incorporate RestrictedQuerySet().
|
||||
"""
|
||||
pass
|
@@ -27,7 +27,7 @@ class RestrictedQuerySet(QuerySet):
|
||||
# Determine what constraints (if any) have been placed on this user for this action and model
|
||||
# TODO: Find a better way to ensure permissions are cached
|
||||
if not hasattr(user, '_object_perm_cache'):
|
||||
user.get_all_permisisons()
|
||||
user.get_all_permissions()
|
||||
obj_perm_attrs = user._object_perm_cache[permission_required]
|
||||
|
||||
# Filter the queryset to include only objects with allowed attributes
|
||||
|
Reference in New Issue
Block a user