Vérifie type id pour vues ScoDoc7

This commit is contained in:
Emmanuel Viennet 2023-01-17 10:57:49 -03:00
parent cada9c24d0
commit 1d5064c955

View File

@ -16,6 +16,7 @@ import flask_login
import app import app
from app.auth.models import User from app.auth.models import User
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
from app.scodoc.sco_exceptions import ScoValueError
class ZUser(object): class ZUser(object):
@ -180,19 +181,24 @@ def scodoc7func(func):
else: else:
arg_names = argspec.args arg_names = argspec.args
for arg_name in arg_names: # pour chaque arg de la fonction vue for arg_name in arg_names: # pour chaque arg de la fonction vue
if arg_name == "REQUEST": # ne devrait plus arriver ! # peut produire une KeyError s'il manque un argument attendu:
# debug check, TODO remove after tests v = req_args[arg_name]
raise ValueError("invalid REQUEST parameter !") # try to convert all arguments to INTEGERS
else: # necessary for db ids and boolean values
# peut produire une KeyError s'il manque un argument attendu: try:
v = req_args[arg_name] v = int(v) if v else v
# try to convert all arguments to INTEGERS except (ValueError, TypeError) as exc:
# necessary for db ids and boolean values if arg_name in {
try: "etudid",
v = int(v) "formation_id",
except (ValueError, TypeError): "formsemestre_id",
pass "module_id",
pos_arg_values.append(v) "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("pos_arg_values=%s" % pos_arg_values)
# current_app.logger.info("req_args=%s" % req_args) # current_app.logger.info("req_args=%s" % req_args)
# Add keyword arguments # Add keyword arguments