Skip to content

Commit

Permalink
Revert "Revert the log changes, see if it still passes"
Browse files Browse the repository at this point in the history
This reverts commit e23ba9b.
  • Loading branch information
relrod committed Jun 7, 2024
1 parent e23ba9b commit 5f1ed6c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ansible_base/oauth2_provider/views/permissions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import logging

from django.conf import settings
from rest_framework.permissions import SAFE_METHODS, BasePermission

logger = logging.getLogger('ansible_base.oauth2_provider.views.permissions')


class OAuth2TokenPermission(BasePermission):
# An app token is a token that has an application attached to it
Expand All @@ -27,11 +31,19 @@ def has_permission(self, request, view):
return request.user.is_authenticated

def has_object_permission(self, request, view, obj):
logger.error(f"Checking object permissions for {request.user}")
if request.method in SAFE_METHODS and getattr(request.user, 'is_system_auditor', False):
logger.error("Is system auditor and safe method")
return True
if request.user.is_superuser:
logger.error("Is super user")
return True
if 'ansible_base.rbac' in settings.INSTALLED_APPS:
logger.error(f"RBAC INSTALLED {obj.application}")
if obj.application:
logger.error(obj.application.organization.access_qs(request.user, "change").exists())
if obj.application and obj.application.organization.access_qs(request.user, "change").exists():
logger.error("obj check worked")
return True
logger.error(f"Defaulting to am I the user {request.user} {obj.user}")
return request.user == obj.user

0 comments on commit 5f1ed6c

Please sign in to comment.