From 55da6a5c3f56113f3da1db5f17bce321cd2e79a3 Mon Sep 17 00:00:00 2001 From: Ivo Leist Date: Sun, 10 Dec 2023 21:28:19 +0100 Subject: [PATCH] started to implement server side validation for the number of expected uploaded files --- .../inputFilesPond/InputFilesPond.jsx | 1 + convertPheno_server/server/apis/submission.py | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/convertPheno_client/src/code/views/conversion/ components/submission/components/submissionForms/components/fileUpload/components/inputFilesPond/InputFilesPond.jsx b/convertPheno_client/src/code/views/conversion/ components/submission/components/submissionForms/components/fileUpload/components/inputFilesPond/InputFilesPond.jsx index 77ffa113..b224df6e 100644 --- a/convertPheno_client/src/code/views/conversion/ components/submission/components/submissionForms/components/fileUpload/components/inputFilesPond/InputFilesPond.jsx +++ b/convertPheno_client/src/code/views/conversion/ components/submission/components/submissionForms/components/fileUpload/components/inputFilesPond/InputFilesPond.jsx @@ -248,6 +248,7 @@ export default function InputFilesPond(props) { server={{ url: `${api_endpoint}api/submission/upload`, + timeout: 7000, // 7 seconds process: { headers: { Authorization: auth.getToken(), diff --git a/convertPheno_server/server/apis/submission.py b/convertPheno_server/server/apis/submission.py index d1f796a6..64b777c7 100644 --- a/convertPheno_server/server/apis/submission.py +++ b/convertPheno_server/server/apis/submission.py @@ -243,6 +243,36 @@ def post(self, userid, uuid): """ data = request.get_json() runExample = data["runExampleData"] + uploaded_files = data["uploadedFiles"] + input_format = data["inputFormat"] + + # vaidate the uploaded files + + # TODO + # additonal validation + # the expected file extension are still missing + + uploaded_files_count = len(uploaded_files) + if not runExample: + if uploaded_files_count in [0, 2] or uploaded_files_count > 3: + message = { + 0: "No files uploaded", + 2: "Uploaded file count can never be 2", + uploaded_files_count: "Too many files uploaded", + }.get(uploaded_files_count, "Invalid number of files") + return {"message": message}, 400 + + if uploaded_files_count == 1 and input_format in ["redcap", "cdisc"]: + return {"message": "3 files are expected"}, 400 + + if uploaded_files_count == 3 and input_format in ["pxf", "bff", "omop"]: + return {"message": "1 file is expected"}, 400 + + if uploaded_files_count == 3 and input_format in ["redcap", "cdisc"]: + uploaded_files_tuples = uploaded_files.values() + file_types = [sublist[0] for sublist in uploaded_files_tuples] + if len(file_types) != len(set(file_types)): + return {"message": "One file type is duplicated"}, 400 if runExample: ns.logger.info("run /w example data")