From 16b54f9409d0de352759351a79e236c9ff4fb274 Mon Sep 17 00:00:00 2001 From: Gregor Sturm Date: Mon, 18 Jan 2021 16:59:15 +0100 Subject: [PATCH 01/10] Use url_for to generate URLs --- cellxgene_gateway/filecrawl.py | 10 ++++------ cellxgene_gateway/templates/index.html | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cellxgene_gateway/filecrawl.py b/cellxgene_gateway/filecrawl.py index cf0b443..1001276 100644 --- a/cellxgene_gateway/filecrawl.py +++ b/cellxgene_gateway/filecrawl.py @@ -14,6 +14,7 @@ from cellxgene_gateway.dir_util import ( make_annotations, annotations_suffix, ) +from flask import url_for def recurse_dir(path): @@ -44,13 +45,10 @@ def recurse_dir(path): "name": x[:-13] if (len(x) > 13 and x[-13] in ["-", "_"]) else (x[:-4] if x.endswith(".csv") else x), - "path": os.path.join(full_path, x).replace( - env.cellxgene_data, "" - ), + "path": os.path.join(full_path, x).replace(env.cellxgene_data, ""), } for x in sorted(os.listdir(full_path)) - if x.endswith(".csv") - and os.path.isfile(os.path.join(full_path, x)) + if x.endswith(".csv") and os.path.isfile(os.path.join(full_path, x)) ] return [ { @@ -91,7 +89,7 @@ def render_entries(entries): def get_url(entry): - return f"/view/{ entry['path'].lstrip('/') }/" + return url_for("do_view", entry) def get_class(entry): diff --git a/cellxgene_gateway/templates/index.html b/cellxgene_gateway/templates/index.html index 3d95124..250dd58 100644 --- a/cellxgene_gateway/templates/index.html +++ b/cellxgene_gateway/templates/index.html @@ -35,12 +35,12 @@ Links:
- + File Crawler: Allows you to view all uploaded data.
- + Cache Status: view status of launched cellxgene servers.
From 068e8f763397dd3f29810b82af4751cc9e65d692 Mon Sep 17 00:00:00 2001 From: Gregor Sturm Date: Mon, 18 Jan 2021 18:09:45 +0100 Subject: [PATCH 02/10] Fix url_for --- cellxgene_gateway/filecrawl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cellxgene_gateway/filecrawl.py b/cellxgene_gateway/filecrawl.py index 1001276..aa15eef 100644 --- a/cellxgene_gateway/filecrawl.py +++ b/cellxgene_gateway/filecrawl.py @@ -89,7 +89,7 @@ def render_entries(entries): def get_url(entry): - return url_for("do_view", entry) + return url_for("do_view", path=entry["path"]) def get_class(entry): From 94062c2d64b9fb209ece57b9fd7885a0dfd9a053 Mon Sep 17 00:00:00 2001 From: Gregor Sturm Date: Mon, 18 Jan 2021 18:19:25 +0100 Subject: [PATCH 03/10] apply proxy fix --- cellxgene_gateway/gateway.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/cellxgene_gateway/gateway.py b/cellxgene_gateway/gateway.py index 723d488..dfea656 100644 --- a/cellxgene_gateway/gateway.py +++ b/cellxgene_gateway/gateway.py @@ -25,7 +25,7 @@ from flask import ( ) from flask_api import status from werkzeug.utils import secure_filename - +from werkzeug.middleware.proxy_fix import ProxyFix from cellxgene_gateway import env from cellxgene_gateway.backend_cache import BackendCache from cellxgene_gateway.cache_entry import CacheEntryStatus @@ -50,6 +50,7 @@ def _force_https(app): app.wsgi_app = _force_https(app.wsgi_app) +app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1) cache = BackendCache() location = f"{env.external_protocol}://{env.external_host}" @@ -149,11 +150,7 @@ def upload_file(): if "file" in request.files: f = request.files["file"] if f and f.filename.endswith(".h5ad"): - f.save( - os.path.join( - full_upload_path, secure_filename(f.filename) - ) - ) + f.save(os.path.join(full_upload_path, secure_filename(f.filename))) return redirect("/filecrawl.html", code=302) else: raise CellxgeneException( @@ -166,21 +163,15 @@ def upload_file(): status.HTTP_400_BAD_REQUEST, ) else: - raise CellxgeneException( - "Invalid directory.", status.HTTP_400_BAD_REQUEST - ) + raise CellxgeneException("Invalid directory.", status.HTTP_400_BAD_REQUEST) return redirect(location, code=302) if env.enable_upload: app.add_url_rule("/make_user", "make_user", make_user, methods=["POST"]) - app.add_url_rule( - "/make_subdir", "make_subdir", make_subdir, methods=["POST"] - ) - app.add_url_rule( - "/upload_file", "upload_file", upload_file, methods=["POST"] - ) + app.add_url_rule("/make_subdir", "make_subdir", make_subdir, methods=["POST"]) + app.add_url_rule("/upload_file", "upload_file", upload_file, methods=["POST"]) def set_no_cache(resp): From 8c5a635de9253e3a4cfdb929dbd69f7b7d9634fd Mon Sep 17 00:00:00 2001 From: Gregor Sturm Date: Mon, 18 Jan 2021 19:44:55 +0100 Subject: [PATCH 04/10] Use url_for in all templates --- cellxgene_gateway/filecrawl.py | 9 ++++++--- cellxgene_gateway/templates/cellxgene_error.html | 4 ++-- cellxgene_gateway/templates/filecrawl.html | 4 ++-- cellxgene_gateway/templates/loading.html | 4 ++-- cellxgene_gateway/templates/process_error.html | 4 ++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cellxgene_gateway/filecrawl.py b/cellxgene_gateway/filecrawl.py index aa15eef..b83d70d 100644 --- a/cellxgene_gateway/filecrawl.py +++ b/cellxgene_gateway/filecrawl.py @@ -45,10 +45,13 @@ def recurse_dir(path): "name": x[:-13] if (len(x) > 13 and x[-13] in ["-", "_"]) else (x[:-4] if x.endswith(".csv") else x), - "path": os.path.join(full_path, x).replace(env.cellxgene_data, ""), + "path": os.path.join(full_path, x).replace( + env.cellxgene_data, "" + ), } for x in sorted(os.listdir(full_path)) - if x.endswith(".csv") and os.path.isfile(os.path.join(full_path, x)) + if x.endswith(".csv") + and os.path.isfile(os.path.join(full_path, x)) ] return [ { @@ -89,7 +92,7 @@ def render_entries(entries): def get_url(entry): - return url_for("do_view", path=entry["path"]) + return url_for("do_view", path=entry["path"].lstrip("/")) def get_class(entry): diff --git a/cellxgene_gateway/templates/cellxgene_error.html b/cellxgene_gateway/templates/cellxgene_error.html index 908b5bf..aea6764 100644 --- a/cellxgene_gateway/templates/cellxgene_error.html +++ b/cellxgene_gateway/templates/cellxgene_error.html @@ -28,11 +28,11 @@

{{ message }}

- + Please click here to be redirected to the file directory.
- + Please click here to return to the homepage. diff --git a/cellxgene_gateway/templates/filecrawl.html b/cellxgene_gateway/templates/filecrawl.html index 7d59e34..e31f54d 100644 --- a/cellxgene_gateway/templates/filecrawl.html +++ b/cellxgene_gateway/templates/filecrawl.html @@ -36,10 +36,10 @@ Navigation: