mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-27 03:09:31 +02:00
Move ObjectPermissionRequiredMixin to utilities.views
This commit is contained in:
15
netbox/utilities/permissions.py
Normal file
15
netbox/utilities/permissions.py
Normal file
@@ -0,0 +1,15 @@
|
||||
def get_permission_for_model(model, action):
|
||||
"""
|
||||
Resolve the named permission for a given model (or instance) and action (e.g. view or add).
|
||||
|
||||
:param model: A model or instance
|
||||
:param action: View, add, change, or delete (string)
|
||||
"""
|
||||
if action not in ('view', 'add', 'change', 'delete'):
|
||||
raise ValueError(f"Unsupported action: {action}")
|
||||
|
||||
return '{}.{}_{}'.format(
|
||||
model._meta.app_label,
|
||||
action,
|
||||
model._meta.model_name
|
||||
)
|
||||
Reference in New Issue
Block a user