21 lines
571 B
Python
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
|