Skip to content

Commit

Permalink
fix: avoid calling undefined method for anonymous users (#15440)
Browse files Browse the repository at this point in the history
  • Loading branch information
pb82 authored Aug 22, 2024
1 parent c6223c0 commit 3f8274d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions awx/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import gettext_lazy as _


# Django REST Framework
from rest_framework.exceptions import APIException, PermissionDenied, ParseError, NotFound
from rest_framework.parsers import FormParser
Expand Down Expand Up @@ -130,7 +129,6 @@
from awx.api.pagination import UnifiedJobEventPagination
from awx.main.utils import set_environ


logger = logging.getLogger('awx.api.views')


Expand Down Expand Up @@ -2394,9 +2392,12 @@ class JobTemplateList(ListCreateAPIView):

def check_permissions(self, request):
if request.method == 'POST':
can_access, messages = request.user.can_access_with_errors(self.model, 'add', request.data)
if not can_access:
self.permission_denied(request, message=messages)
if request.user.is_anonymous:
self.permission_denied(request)
else:
can_access, messages = request.user.can_access_with_errors(self.model, 'add', request.data)
if not can_access:
self.permission_denied(request, message=messages)

super(JobTemplateList, self).check_permissions(request)

Expand Down Expand Up @@ -3121,9 +3122,12 @@ class WorkflowJobTemplateList(ListCreateAPIView):

def check_permissions(self, request):
if request.method == 'POST':
can_access, messages = request.user.can_access_with_errors(self.model, 'add', request.data)
if not can_access:
self.permission_denied(request, message=messages)
if request.user.is_anonymous:
self.permission_denied(request)
else:
can_access, messages = request.user.can_access_with_errors(self.model, 'add', request.data)
if not can_access:
self.permission_denied(request, message=messages)

super(WorkflowJobTemplateList, self).check_permissions(request)

Expand Down

0 comments on commit 3f8274d

Please sign in to comment.