From 1d5064c955c2e0b073c24389a08dea80c7ab07c4 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 17 Jan 2023 10:57:49 -0300 Subject: [PATCH] =?UTF-8?q?V=C3=A9rifie=20type=20id=20pour=20vues=20ScoDoc?= =?UTF-8?q?7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/decorators.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/app/decorators.py b/app/decorators.py index 83441275..5338828f 100644 --- a/app/decorators.py +++ b/app/decorators.py @@ -16,6 +16,7 @@ import flask_login import app from app.auth.models import User import app.scodoc.sco_utils as scu +from app.scodoc.sco_exceptions import ScoValueError class ZUser(object): @@ -180,19 +181,24 @@ def scodoc7func(func): else: arg_names = argspec.args for arg_name in arg_names: # pour chaque arg de la fonction vue - if arg_name == "REQUEST": # ne devrait plus arriver ! - # debug check, TODO remove after tests - raise ValueError("invalid REQUEST parameter !") - else: - # peut produire une KeyError s'il manque un argument attendu: - v = req_args[arg_name] - # try to convert all arguments to INTEGERS - # necessary for db ids and boolean values - try: - v = int(v) - except (ValueError, TypeError): - pass - pos_arg_values.append(v) + # peut produire une KeyError s'il manque un argument attendu: + v = req_args[arg_name] + # try to convert all arguments to INTEGERS + # necessary for db ids and boolean values + try: + v = int(v) if v else v + except (ValueError, TypeError) as exc: + if arg_name in { + "etudid", + "formation_id", + "formsemestre_id", + "module_id", + "moduleimpl_id", + "partition_id", + "ue_id", + }: + raise ScoValueError("page introuvable (id invalide)") from exc + pos_arg_values.append(v) # current_app.logger.info("pos_arg_values=%s" % pos_arg_values) # current_app.logger.info("req_args=%s" % req_args) # Add keyword arguments