simple-plant-archive-django/plant_catalog/catalog/permissions.py

11 lines
434 B
Python
Raw Normal View History

2024-12-22 03:07:07 +01:00
from rest_framework.permissions import SAFE_METHODS, BasePermission
class IsAuthenticatedOrReadOnly(BasePermission):
"""
Allows GET, HEAD, OPTIONS for everyone, but restricts POST, PUT, DELETE to authenticated users.
"""
def has_permission(self, request, view):
if request.method in SAFE_METHODS:
return True # Allow read-only access
return request.user and request.user.is_authenticated