Files
ihrm/horilla_api/decorators.py

26 lines
627 B
Python
Raw Normal View History

2025-12-23 15:01:24 +05:30
"""
Decorators for API views
"""
2025-12-23 15:01:24 +05:30
from functools import wraps
2025-12-23 15:01:24 +05:30
from rest_framework import status
from rest_framework.response import Response
2025-12-23 15:01:24 +05:30
def api_authentication_required(view_func):
"""
Decorator to ensure API views require authentication
"""
2025-12-23 15:01:24 +05:30
@wraps(view_func)
def wrapped_view(request, *args, **kwargs):
if not request.user.is_authenticated:
return Response(
{"detail": "Authentication credentials were not provided."},
status=status.HTTP_401_UNAUTHORIZED,
2025-12-23 15:01:24 +05:30
)
return view_func(request, *args, **kwargs)
return wrapped_view