From 2c01068afd919e7bcdbec3849d6203c42e470d60 Mon Sep 17 00:00:00 2001 From: Alexander Berger Date: Tue, 29 Oct 2024 15:21:18 -0400 Subject: [PATCH 1/6] Adding new threshold page --- pyproject.toml | 2 +- src/application.py | 66 ++++++++++- src/config.py | 1 + src/templates/viewThreshold.html | 3 + src/templates/viewThreshold_new.html | 164 +++++++++++++++++++++++++++ 5 files changed, 230 insertions(+), 6 deletions(-) create mode 100644 src/templates/viewThreshold_new.html diff --git a/pyproject.toml b/pyproject.toml index bf9abf73..5e9761c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "geneweaver-legacy" -version = "1.4.7" +version = "1.5.0" description = "" authors = ["Alexander Berger "] readme = "README.md" diff --git a/src/application.py b/src/application.py index 16f5a80e..7d35fced 100644 --- a/src/application.py +++ b/src/application.py @@ -155,7 +155,9 @@ api_base_url=f'https://{config.get("auth", "domain")}/', access_token_url=f'https://{config.get("auth", "domain")}/{config.get("auth", "token_endpoint")}', authorize_url=f'https://{config.get("auth", "domain")}/{config.get("auth", "auth_endpoint")}', - client_kwargs={'scope': 'openid profile email'}, + client_kwargs={ + 'scope': 'openid profile email', + }, server_metadata_url=f'https://{config.get("auth", "domain")}/.well-known/openid-configuration', jwks_uri=f'https://{config.get("auth", "domain")}/{config.get("auth", "jwks_endpoint")}' ) @@ -378,7 +380,11 @@ def login_as(as_user_id): @app.route('/login', methods=['GET']) @app.route('/ssologin', methods=['GET']) def sso_login(): - return auth0.authorize_redirect(redirect_uri=url_for('callback_handling', _external=True)) + redirect_uri = url_for('callback_handling', _external=True) + return auth0.authorize_redirect( + redirect_uri=redirect_uri, + audience=config.get('auth', 'audience') + ) @app.route('/ssosignup', methods=['GET']) def sso_signup(): @@ -387,9 +393,18 @@ def sso_signup(): @app.route('/callback') def callback_handling(): + response = make_response(redirect('/')) # Handles response from token endpoint try: - auth0.authorize_access_token() + token = auth0.authorize_access_token() + flask.session['access_token'] = token + response.set_cookie( + 'access_token', + token['access_token'], + httponly=False, + secure=True, + samesite='Strict' + ) except OAuthError as e: if e.description == "Jax users must use Jax connection to log in.": _logout() @@ -437,7 +452,7 @@ def callback_handling(): flask.session['remote_addr'] = remote_addr geneweaverdb.update_user_seen(user.user_id) - return redirect('/') + return response @app.route('/callback/errors/email-mismatch') def callback_error_jax_email(): @@ -1939,9 +1954,50 @@ def render_remove_genesets(gs_id): gs_and_proj = geneweaverdb.get_selected_genesets_by_projects(gs_id) return render_template('removegenesets.html', user_id=user_id, gs_and_proj=gs_and_proj) - @app.route('/setthreshold/') def render_set_threshold(gs_id): + user_id = session['user_id'] if 'user_id' in session else 0 + user_info = geneweaverdb.get_user(user_id) + geneset = geneweaverdb.get_geneset(gs_id, user_id) + if user_id != 0: + view = 'True' if user_info.is_admin or user_info.is_curator or geneset.user_id == user_id else None + + if view is None and geneweaverdb.user_is_assigned_curation(user_id, gs_id): + view = 'curator' + else: + view = None + # Determine if this is bi-modal, we won't display these + is_bimodal = geneweaverdb.get_bimodal_threshold(gs_id) + gsv_values = geneweaverdb.get_all_geneset_values(gs_id) + threshold_type = geneset.threshold_type + threshold = str(geneset.threshold) + thresh = threshold.split(',') + if len(thresh) == 1: + thresh.append(str(0)) + minVal = float(thresh[0]) + maxVal = float(thresh[1]) + if gsv_values is not None: + for k in gsv_values: + k_first_value = list(k.values())[0] + maxVal = float(k_first_value) if float(k_first_value) > maxVal else maxVal + minVal = float(k_first_value) if float(k_first_value) < minVal else minVal + score_types = { + 1: "p-value", + 2: "q-value", + 3: "binary", + 4: "correlation", + 5: "effect" + } + + return render_template('viewThreshold_new.html', geneset=geneset, + user_id=user_id, view=view, is_bimodal=is_bimodal, + threshold=thresh, threshold_type=threshold_type, + minVal=minVal, maxVal=maxVal, + scoreType=score_types[threshold_type]) + + +@app.route('/setthreshold-legacy/') +def render_set_threshold_legacy(gs_id): d3BarChart = [] user_id = session['user_id'] if 'user_id' in session else 0 user_info = geneweaverdb.get_user(user_id) diff --git a/src/config.py b/src/config.py index ea5d5264..d9a65e03 100644 --- a/src/config.py +++ b/src/config.py @@ -76,6 +76,7 @@ class Auth(BaseModel): token_endpoint: str = Field("oauth/token", validation_alias="tokenendpoint") userinfo_endpoint: str = Field("oauth/userinfo", validation_alias="userinfoendpoint") jwks_endpoint: str = Field(".well-known/jwks.json", validation_alias="jwksendpoint") + audience: str = "https://cube.jax.org" class GeneweaverLegacyConfig(BaseSettings): diff --git a/src/templates/viewThreshold.html b/src/templates/viewThreshold.html index 7f70e8fd..1a0ca04f 100644 --- a/src/templates/viewThreshold.html +++ b/src/templates/viewThreshold.html @@ -156,6 +156,9 @@

Set GeneSet Threshold

+ + New Page + {% if view is defined %} + + + + {% else %} +
+ + + + + +
+ +
+ Manually enter a threshold value. + Set to: {{ threshold_symbol }} < + +
+ +
+
+
+ {% endif %} + + + {# right side menu #} +
+ {% set return_page = 'curategeneset' if view == 'curator' else 'viewgenesetdetails' %} + + Back to GeneSet + + + Legacy Page + +
+ + + + + {% endif %} + + + +{% endif %} + +{% include 'footer.html' %} From c538e7afe0d060026a2211269b65935a952f556e Mon Sep 17 00:00:00 2001 From: Alexander Berger Date: Wed, 30 Oct 2024 07:50:29 -0400 Subject: [PATCH 2/6] Removing hard coded ajax reference --- src/templates/viewThreshold_new.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/viewThreshold_new.html b/src/templates/viewThreshold_new.html index aa7d54f4..a9ba39dd 100644 --- a/src/templates/viewThreshold_new.html +++ b/src/templates/viewThreshold_new.html @@ -141,7 +141,7 @@

Set GeneSet Threshold

} $.ajax({ type: 'POST', - url: 'https://geneweaver-dev.jax.org/api/genesets/{{ geneset.geneset_id }}/threshold', + url: '../api/genesets/{{ geneset.geneset_id }}/threshold', contentType: 'application/json', data: JSON.stringify(newTresh), dataType: 'json', From 4483f613b5ef8b9fe6ad29c716c7076a5d9db655 Mon Sep 17 00:00:00 2001 From: Alexander Berger Date: Wed, 30 Oct 2024 07:51:50 -0400 Subject: [PATCH 3/6] Add a comment on using this code in development --- src/templates/viewThreshold_new.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/templates/viewThreshold_new.html b/src/templates/viewThreshold_new.html index a9ba39dd..c73f4e6f 100644 --- a/src/templates/viewThreshold_new.html +++ b/src/templates/viewThreshold_new.html @@ -141,6 +141,11 @@

Set GeneSet Threshold

} $.ajax({ type: 'POST', + {# + Note: If you are doing local development, you will probably + need to change this url to point at the dev API: + url: 'http://geneweaver-dev.jax.org/api/genesets/{{ geneset.geneset_id }}/threshold', + #} url: '../api/genesets/{{ geneset.geneset_id }}/threshold', contentType: 'application/json', data: JSON.stringify(newTresh), From 99e89f0e648b9aa2ed9bcdd035be90fa6d93a009 Mon Sep 17 00:00:00 2001 From: Alexander Berger Date: Wed, 30 Oct 2024 08:02:05 -0400 Subject: [PATCH 4/6] Fix ajax method type --- src/templates/viewThreshold_new.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/viewThreshold_new.html b/src/templates/viewThreshold_new.html index c73f4e6f..db657de2 100644 --- a/src/templates/viewThreshold_new.html +++ b/src/templates/viewThreshold_new.html @@ -140,7 +140,7 @@

Set GeneSet Threshold

}; } $.ajax({ - type: 'POST', + type: 'PUT', {# Note: If you are doing local development, you will probably need to change this url to point at the dev API: From 0b1fcf86929da23ac939048cc6f175a61393352a Mon Sep 17 00:00:00 2001 From: Alexander Berger Date: Wed, 30 Oct 2024 09:08:02 -0400 Subject: [PATCH 5/6] Imrovments to display logic --- src/templates/viewThreshold_new.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/templates/viewThreshold_new.html b/src/templates/viewThreshold_new.html index db657de2..03f29b87 100644 --- a/src/templates/viewThreshold_new.html +++ b/src/templates/viewThreshold_new.html @@ -49,11 +49,10 @@

Set GeneSet Threshold

{% endif %} - {% if view is defined %}
-
+ {% if view is defined and is_bimodal == 'False' %} {% if threshold_type == 4 or threshold_type == 5 %}
@@ -93,6 +92,7 @@

Set GeneSet Threshold

{% endif %} + {% endif %}
{# right side menu #} @@ -101,13 +101,15 @@

Set GeneSet Threshold

Back to GeneSet + {% if view is defined and is_bimodal == 'False' %} Legacy Page + {% endif %}
- + {% if view is defined and is_bimodal == 'False' %} - {% endif %} + {% endif %} From 22b0a8366a5b9199fa3f59e39b0ec7b5578c1a47 Mon Sep 17 00:00:00 2001 From: Alexander Berger Date: Tue, 5 Nov 2024 10:12:16 -0500 Subject: [PATCH 6/6] Removing access_token from flask session --- src/application.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/application.py b/src/application.py index 7d35fced..04de147e 100644 --- a/src/application.py +++ b/src/application.py @@ -397,7 +397,6 @@ def callback_handling(): # Handles response from token endpoint try: token = auth0.authorize_access_token() - flask.session['access_token'] = token response.set_cookie( 'access_token', token['access_token'],