diff --git a/client/pages/phenotypes.vue b/client/pages/phenotypes.vue index fbf1383304e1379070032d1d263545b681b5de26..26a2fa994f46a4800bf91213f508e8341b208a8d 100644 --- a/client/pages/phenotypes.vue +++ b/client/pages/phenotypes.vue @@ -45,7 +45,11 @@ Please select the traits you want to analyze jointly with the Omnibus test. A re <script> export default { async asyncData({ $axios, params, $auth }) { - const phenotypes = await $axios.$get('/phenotypes') + const data = { + initTableName: "initTable.hdf5" + // initTableName: "initTableTest.hdf5" + }; + const phenotypes = await $axios.$post('/phenotypes', data) return { phenotypes, } diff --git a/jass/models/phenotype.py b/jass/models/phenotype.py index 885cf05428ea0be79212961083ba0a110e962357..c99b7d4b04f97f861590f289ec047ff3733daa4c 100644 --- a/jass/models/phenotype.py +++ b/jass/models/phenotype.py @@ -1,8 +1,9 @@ # coding: utf-8 -from typing import List +from typing import List, Optional import pandas -from pydantic import BaseModel +import re +from pydantic import BaseModel, validator class Phenotype(BaseModel): @@ -72,5 +73,17 @@ def get_available_phenotypes(init_file_path: str): return phenotypes +_initTableNamePattern = re.compile("^([A-Z]*[a-z]*-*\.?[0-9]*)+$") + + +class ProjectNameModel(BaseModel): + initTableName: Optional[str] = "initTable.hdf5" + + @validator("initTableName") + def validate_path_injection(cls, value): + if not _initTableNamePattern.match(value): + raise ValueError(f"Prohibited char, only \"{_initTableNamePattern.pattern}\" allowed.") + return value + class PhenotypeIdList(BaseModel): phenotypeID: List[str] = [] diff --git a/jass/server.py b/jass/server.py index 2912409ee55d497e8b0c0acd2b89cf536f96d966..aaa029cc7056705fd899e26eba7765441f32b681 100644 --- a/jass/server.py +++ b/jass/server.py @@ -52,10 +52,10 @@ async def read_index(): return RedirectResponse(url="/webui/") -@app.get("/api/phenotypes", response_model=List[Phenotype]) -def phenotypes_list(): +@app.post("/api/phenotypes", response_model=List[Phenotype]) +def phenotypes_list(project_name: ProjectNameModel): """List phenotypes""" - return get_available_phenotypes(os.path.join(config["DATA_DIR"], "initTable.hdf5")) + return get_available_phenotypes(os.path.join(config["DATA_DIR"], project_name.initTableName)) @app.get("/api/initmeta") def inittable_meta(): diff --git a/jass/test/data_real/initTableTest1.hdf5 b/jass/test/data_real/initTableTest1.hdf5 new file mode 100644 index 0000000000000000000000000000000000000000..d49423695dca6a4ffa014e0aaf0ec45f02ffb68c Binary files /dev/null and b/jass/test/data_real/initTableTest1.hdf5 differ diff --git a/test_docker_compose.sh b/test_docker_compose.sh index 63e88f45f3bd0198e44c12b03da1eb6aba8f25f6..b524ce6545114784d105567054cd854c5df516c5 100755 --- a/test_docker_compose.sh +++ b/test_docker_compose.sh @@ -25,6 +25,30 @@ curl -I http://0.0.0.0:3001/phenotypes/ \ if [ "$(cat log/02-*.log | grep "200 OK" | wc -l)" == "0" ]; then exit 02; fi +echo "Test fetching phenotypes through API" +curl --location --request POST http://0.0.0.0:8080/api/phenotypes/ \ +--header 'Content-Type: application/json' \ +--data-raw '{"initTableName":"initTableTest1.hdf5"}' \ + -o log/11-post-phenotypes.json \ + 1> log/11-post-phenotypes.log \ + 2> log/11-post-phenotypes.err + +if [ "$(cat log/11-*.json | grep "Internal Server Error" | wc -l)" == "1" ]; then exit 11; fi + + +echo "Test fetching phenotypes through API" +curl --location --request POST http://0.0.0.0:8080/api/phenotypes/ \ +--header 'Content-Type: application/json' \ +--data-raw '{"initTableName":"initTable.hdf5"}' \ + -o log/12-post-phenotypes.json \ + 1> log/12-post-phenotypes.log \ + 2> log/12-post-phenotypes.err + +if [ "$(cat log/12-*.json | grep "Internal Server Error" | wc -l)" == "1" ]; then exit 12; fi + +if [ "$(cat log/11-*.json)" == "$(cat log/12-*.json)" ]; then echo "should not be equal"; exit 12; fi + + echo "Testing project creation" curl --location --request POST 'http://0.0.0.0:8080/api/projects' \ --header 'Accept: text/html' \