Skip to content

Commit

Permalink
AAP-35609 Allow for ServiceTokenAuth in IsSuperUserOrAuditor
Browse files Browse the repository at this point in the history
  • Loading branch information
john-westcott-iv committed Dec 5, 2024
1 parent 48fd1ec commit 26e0d3c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ansible_base/lib/utils/views/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ def try_add_oauth2_scope_permission(permission_classes: list):
return permission_classes


def check_service_token_auth(request, view):
if hasattr(view, 'allow_service_token') and getattr(view, 'allow_service_token') is True and request.auth == 'ServiceTokenAuthentication':
return True
return False


class IsSuperuser(BasePermission):
"""
Allows access only to superusers.
"""

def has_permission(self, request, view):
if check_service_token_auth(request, view):
return True

return bool(request.user and request.user.is_authenticated and request.user.is_superuser)


Expand All @@ -37,6 +46,8 @@ class IsSuperuserOrAuditor(BasePermission):
"""

def has_permission(self, request, view):
if check_service_token_auth(request, view):
return True
if not (request.user and request.user.is_authenticated):
return False
if request.user.is_superuser:
Expand Down

0 comments on commit 26e0d3c

Please sign in to comment.