Skip to content

Enforcing permissions with constraints in NetBox plugins #19518

Discussion options

You must be logged in to vote

netbox.authentication.ObjectPermissionMixin.has_perm() seems to do what I'm looking for:

from netbox.authentication import ObjectPermissionMixin

class MyDeviceManglingView(ObjectPermissionMixin, View):
    def get(self, request, device_id: int):
        device = Device.objects.get(id=device_id)
        if not self.has_perm(request.user, "dcim.view_device", device):
            return _my_custom_error_response("No permission to the device")
        ...

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by markkuleinio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant