mirror of
https://github.com/ansible/awx.git
synced 2026-03-07 11:41:08 -03:30
Add some spacing to make things easier to read.
This commit is contained in:
@@ -45,7 +45,7 @@ class CustomRbac(permissions.BasePermission):
|
|||||||
# because it is first called with obj=None?
|
# because it is first called with obj=None?
|
||||||
if getattr(view, 'is_variable_data', False):
|
if getattr(view, 'is_variable_data', False):
|
||||||
return check_user_access(request.user, view.model, 'change', obj,
|
return check_user_access(request.user, view.model, 'change', obj,
|
||||||
{'variables': request.DATA})
|
dict(variables=request.DATA))
|
||||||
else:
|
else:
|
||||||
return check_user_access(request.user, view.model, 'change', obj,
|
return check_user_access(request.user, view.model, 'change', obj,
|
||||||
request.DATA)
|
request.DATA)
|
||||||
@@ -57,23 +57,26 @@ class CustomRbac(permissions.BasePermission):
|
|||||||
return check_user_access(request.user, view.model, 'delete', obj)
|
return check_user_access(request.user, view.model, 'delete', obj)
|
||||||
|
|
||||||
def _check_permissions(self, request, view, obj=None):
|
def _check_permissions(self, request, view, obj=None):
|
||||||
#if not obj and hasattr(view, 'get_object'):
|
|
||||||
# obj = view.get_object()
|
|
||||||
# Check that obj (if given) is active, otherwise raise a 404.
|
# Check that obj (if given) is active, otherwise raise a 404.
|
||||||
active = getattr(obj, 'active', getattr(obj, 'is_active', True))
|
active = getattr(obj, 'active', getattr(obj, 'is_active', True))
|
||||||
if callable(active):
|
if callable(active):
|
||||||
active = active()
|
active = active()
|
||||||
if not active:
|
if not active:
|
||||||
raise Http404()
|
raise Http404()
|
||||||
|
|
||||||
# Don't allow anonymous users. 401, not 403, hence no raised exception.
|
# Don't allow anonymous users. 401, not 403, hence no raised exception.
|
||||||
if not request.user or request.user.is_anonymous():
|
if not request.user or request.user.is_anonymous():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Don't allow inactive users (and respond with a 403).
|
# Don't allow inactive users (and respond with a 403).
|
||||||
if not request.user.is_active:
|
if not request.user.is_active:
|
||||||
raise PermissionDenied('your account is inactive')
|
raise PermissionDenied('your account is inactive')
|
||||||
|
|
||||||
# Always allow superusers (as long as they are active).
|
# Always allow superusers (as long as they are active).
|
||||||
if request.user.is_superuser:
|
if request.user.is_superuser:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Check permissions for the given view and object, based on the request
|
# Check permissions for the given view and object, based on the request
|
||||||
# method used.
|
# method used.
|
||||||
check_method = getattr(self, '_check_%s_permissions' % \
|
check_method = getattr(self, '_check_%s_permissions' % \
|
||||||
@@ -81,9 +84,11 @@ class CustomRbac(permissions.BasePermission):
|
|||||||
result = check_method and check_method(request, view, obj)
|
result = check_method and check_method(request, view, obj)
|
||||||
if not result:
|
if not result:
|
||||||
raise PermissionDenied()
|
raise PermissionDenied()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# If no obj is given, check list permissions.
|
# If no obj is given, check list permissions.
|
||||||
|
|
||||||
if obj is None:
|
if obj is None:
|
||||||
if getattr(view, 'list_permissions_check', None):
|
if getattr(view, 'list_permissions_check', None):
|
||||||
if not view.list_permissions_check(request):
|
if not view.list_permissions_check(request):
|
||||||
@@ -92,13 +97,16 @@ class CustomRbac(permissions.BasePermission):
|
|||||||
raise Exception('internal error, list_permissions_check or '
|
raise Exception('internal error, list_permissions_check or '
|
||||||
'item_permissions_check must be defined')
|
'item_permissions_check must be defined')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Otherwise, check the item permissions for the given obj.
|
# Otherwise, check the item permissions for the given obj.
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if not view.item_permissions_check(request, obj):
|
if not view.item_permissions_check(request, obj):
|
||||||
raise PermissionDenied()
|
raise PermissionDenied()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def has_permission(self, request, view, obj=None):
|
def has_permission(self, request, view, obj=None):
|
||||||
|
|
||||||
logger.debug('has_permission(user=%s method=%s data=%r, %s, %r)',
|
logger.debug('has_permission(user=%s method=%s data=%r, %s, %r)',
|
||||||
request.user, request.method, request.DATA,
|
request.user, request.method, request.DATA,
|
||||||
view.__class__.__name__, obj)
|
view.__class__.__name__, obj)
|
||||||
@@ -117,16 +125,20 @@ class CustomRbac(permissions.BasePermission):
|
|||||||
class JobCallbackPermission(CustomRbac):
|
class JobCallbackPermission(CustomRbac):
|
||||||
|
|
||||||
def has_permission(self, request, view, obj=None):
|
def has_permission(self, request, view, obj=None):
|
||||||
|
|
||||||
# If another authentication method was used other than the one for job
|
# If another authentication method was used other than the one for job
|
||||||
# callbacks, return True to fall through to the next permission class.
|
# callbacks, return True to fall through to the next permission class.
|
||||||
if request.user or not request.auth:
|
if request.user or not request.auth:
|
||||||
return super(JobCallbackPermission, self).has_permission(request, view, obj)
|
return super(JobCallbackPermission, self).has_permission(request, view, obj)
|
||||||
|
|
||||||
# FIXME: Verify that inventory or job event requested are for the same
|
# FIXME: Verify that inventory or job event requested are for the same
|
||||||
# job ID present in the auth token, etc.
|
# job ID present in the auth token, etc.
|
||||||
|
|
||||||
#try:
|
#try:
|
||||||
# job = Job.objects.get(active=True, status='running', pk=int(request.auth.split('-')[0]))
|
# job = Job.objects.get(active=True, status='running', pk=int(request.auth.split('-')[0]))
|
||||||
#except Job.DoesNotExist:
|
#except Job.DoesNotExist:
|
||||||
# return False
|
# return False
|
||||||
|
|
||||||
if view.model == Inventory and request.method.lower() in ('head', 'get'):
|
if view.model == Inventory and request.method.lower() in ('head', 'get'):
|
||||||
return True
|
return True
|
||||||
elif view.model == JobEvent and request.method.lower() == 'post':
|
elif view.model == JobEvent and request.method.lower() == 'post':
|
||||||
|
|||||||
Reference in New Issue
Block a user