diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5593088e2..3a906e053 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,6 +17,10 @@ Unreleased ---------- * nothing unreleased +[4.23.4] +--------- +* refactor: added logs for data dog inspection for permission check in handler function. + [4.23.3] --------- * fix: add missing migration for content_filter help text diff --git a/enterprise/__init__.py b/enterprise/__init__.py index 2ddd42912..4ce1828e6 100644 --- a/enterprise/__init__.py +++ b/enterprise/__init__.py @@ -2,4 +2,4 @@ Your project description goes here. """ -__version__ = "4.23.3" +__version__ = "4.23.4" diff --git a/enterprise/api/v1/decorators.py b/enterprise/api/v1/decorators.py index 254b0118b..24c447687 100644 --- a/enterprise/api/v1/decorators.py +++ b/enterprise/api/v1/decorators.py @@ -6,6 +6,10 @@ from rest_framework.exceptions import PermissionDenied, ValidationError +from enterprise.logging import getEnterpriseLogger + +LOGGER = getEnterpriseLogger(__name__) + def require_at_least_one_query_parameter(*query_parameter_names): """ @@ -57,14 +61,31 @@ def _wrapped_view(request, *args, **kwargs): user = request.user pk = fn(request, **kwargs) if fn else kwargs.get('pk') + LOGGER.info( + f"[User_Permissions_Check] Checking permissions for user {user.username}, " + f"permission: {permission}, " + f"group: {group_name}, " + f"pk: {pk}" + ) + if pk: has_permission = user.has_perm(permission, pk) else: has_permission = user.has_perm(permission) - if has_permission or user.groups.filter(name=group_name).exists(): + LOGGER.info(f"[User_Permissions_Check] User {user.username} has permission: {has_permission}") + + is_in_group = user.groups.filter(name=group_name).exists() + LOGGER.info(f"[User_Permissions_Check] User {user.username} is in group {group_name}: {is_in_group}") + + if has_permission or is_in_group: return view_func(request, *args, **kwargs) + LOGGER.error( + f"[User_Permissions_Check] Access denied for user {user.username} to {view_func.__name__}. " + f"Method: {request.method}, " + f"URL: {request.get_full_path()}" + ) raise PermissionDenied( "Access denied: Only admins and provisioning admins are allowed to access this endpoint.")