mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Fix issue with tests. Reverted to overriding the permissions map as the only viable option
This commit is contained in:
parent
542fa71267
commit
67b6857745
@ -141,18 +141,25 @@ class TokenPermissions(DjangoObjectPermissions):
|
||||
permission = self.perms_map.get(method)[0] if len(self.perms_map.get(method)) > 0 else None
|
||||
if permission:
|
||||
# Remove app and model label
|
||||
action = resolve_permission(permission)
|
||||
app_label, action, model_name = resolve_permission(permission)
|
||||
return action
|
||||
return None
|
||||
|
||||
|
||||
class RequireViewOnlyPermissions(TokenPermissions):
|
||||
|
||||
# Only return view as the action
|
||||
def get_action(self, method):
|
||||
if method != 'OPTIONS':
|
||||
return 'view'
|
||||
return None
|
||||
"""
|
||||
Overrides permission map to return only view permissions as required
|
||||
"""
|
||||
# Override the stock perm_map to enforce view permissions
|
||||
perms_map = {
|
||||
'GET': ['%(app_label)s.view_%(model_name)s'],
|
||||
'OPTIONS': [],
|
||||
'HEAD': ['%(app_label)s.view_%(model_name)s'],
|
||||
'POST': ['%(app_label)s.view_%(model_name)s'],
|
||||
'PUT': ['%(app_label)s.view_%(model_name)s'],
|
||||
'PATCH': ['%(app_label)s.view_%(model_name)s'],
|
||||
'DELETE': ['%(app_label)s.view_%(model_name)s'],
|
||||
}
|
||||
|
||||
|
||||
class IsAuthenticatedOrLoginNotRequired(BasePermission):
|
||||
|
@ -33,7 +33,11 @@ def resolve_permission(name):
|
||||
"""
|
||||
try:
|
||||
app_label, codename = name.split('.')
|
||||
action, model_name = codename.rsplit('_', 1)
|
||||
if '%' in codename:
|
||||
action, model_name = codename.split('_%')
|
||||
model_name = '%' + model_name
|
||||
else:
|
||||
action, model_name = codename.rsplit('_', 1)
|
||||
except ValueError:
|
||||
raise ValueError(
|
||||
_("Invalid permission name: {name}. Must be in the format <app_label>.<action>_<model>").format(name=name)
|
||||
|
Loading…
Reference in New Issue
Block a user