infrasynth-backend-kit/infrasynth/features/decorators.py
2026-08-28 14:38:47 -05:00

21 lines
571 B
Python

from functools import wraps
from rest_framework.exceptions import NotFound
from .services import FeatureService
def feature_required(slug: str):
"""Decorator for views that require a feature flag to be enabled."""
def decorator(view_func):
@wraps(view_func)
def wrapper(request, *args, **kwargs):
fs = FeatureService()
if not fs.is_enabled(slug, user=getattr(request, "user", None)):
raise NotFound()
return view_func(request, *args, **kwargs)
return wrapper
return decorator