from functools import wraps from flask import jsonify def require_active_service(service_id: str): """Decorator: return 404 if the named service is not installed. Apply to all email/calendar/files routes except /status endpoints, so the UI can always check installation state without being blocked. """ def decorator(fn): @wraps(fn) def wrapper(*args, **kwargs): from app import service_registry if service_registry.get(service_id) is None: return jsonify({'error': f'Service {service_id!r} is not installed'}), 404 return fn(*args, **kwargs) return wrapper return decorator