diff --git a/src/api/authentication.py b/src/api/authentication.py index e1665116a0024a61d1821f0632778b726c59a9bb..3d6e497386dfbae0593c9586bea07d6be134893b 100644 --- a/src/api/authentication.py +++ b/src/api/authentication.py @@ -135,6 +135,10 @@ class EffectiveViewPermissions(ViewPermissions): def api_moderator_route(require_csrf_token: bool = False): def decorator(func): + if hasattr(func, "is_api_route") and func.is_api_route: + raise Exception("@api_moderator_route() seems to be applied after @api_route(). @api_moderator_route() " + "should be the first (lowest) decorator!") + @wraps(func) def wrapper(*args, **kwargs): if not is_moderator(): diff --git a/src/api/routes/route.py b/src/api/routes/route.py index b9df1835a6d2c27fc7d07017d0534579ebc4c578..d65ca04614c98505135de6b3ca9610f8b80fb988 100644 --- a/src/api/routes/route.py +++ b/src/api/routes/route.py @@ -124,6 +124,9 @@ def api_add_route(path: str, methods: list[str], min_api_version: int = API_OLDEST_ACTIVE_VERSION, max_api_version: int = API_LATEST_VERSION): def decorator(func): + if not hasattr(func, "is_api_route") or not func.is_api_route: + raise Exception("@api_add_route() seems to be applied before @api_function()") + for version in range(min_api_version, max_api_version + 1): full_path = get_api_path(version, path) if DEBUG_ENABLED: @@ -139,6 +142,10 @@ def api_function(track_in_diagnostics: bool = True, allow_while_disabled: bool = False, rate_limiters: tuple[HostBasedCounterRateLimiter, ...] = _API_GLOBAL_RATE_LIMITERS): def decorator(func): + if hasattr(func, "is_api_route") and func.is_api_route: + raise Exception("An @api_function() decorator has already been applied. Are you using multiple @api_route()? " + "Use @api_add_route(...)@api_add_route(..)@api_function() instead") + call_counter = None if track_in_diagnostics: func_name: str = func.__name__ @@ -199,6 +206,7 @@ def api_function(track_in_diagnostics: bool = True, traceback.print_exception(e) return api_on_error(ERROR_INTERNAL_SERVER_ERROR) + wrapper.is_api_route = True return wrapper return decorator