aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-02-24 12:37:01 +0300
committerFrederick Muriuki Muriithi2023-02-24 12:37:39 +0300
commit0c64b1f87739bd9298a182a7a7fca241b33d10cf (patch)
tree169cc0837f231beb51c42fdaba49a9a8a2836cb6
parent98d04dd71d99a6e65fee9b83afffc52e27b67e8c (diff)
downloadgenenetwork2-0c64b1f87739bd9298a182a7a7fca241b33d10cf.tar.gz
oauth2: resources: Enable linking data to resources
-rw-r--r--wqflask/wqflask/oauth2/data.py4
-rw-r--r--wqflask/wqflask/oauth2/resources.py33
-rw-r--r--wqflask/wqflask/templates/oauth2/view-resource.html13
3 files changed, 42 insertions, 8 deletions
diff --git a/wqflask/wqflask/oauth2/data.py b/wqflask/wqflask/oauth2/data.py
index b080d4df..cb9c1000 100644
--- a/wqflask/wqflask/oauth2/data.py
+++ b/wqflask/wqflask/oauth2/data.py
@@ -41,7 +41,7 @@ def list_data():
return __render__(**{**groups, **roles})
data_items = oauth2_get(
- f"oauth2/resource/{dataset_type}/ungrouped-data?offset={offset}").either(
+ f"oauth2/group/{dataset_type}/ungrouped-data?offset={offset}").either(
lambda err: {"data_items_error": process_error(err)},
lambda data: {"data_items": data})
return __render__(**{
@@ -69,7 +69,7 @@ def link_data():
"dataset_type": form["dataset_type"],
"offset": form.get("offset", 0)}
return oauth2_post(
- "oauth2/resource/data/link",
+ "oauth2/group/data/link",
data={
"dataset_type": form["dataset_type"],
"dataset_id": form["dataset_id"],
diff --git a/wqflask/wqflask/oauth2/resources.py b/wqflask/wqflask/oauth2/resources.py
index 2a79f6cd..1551dc8a 100644
--- a/wqflask/wqflask/oauth2/resources.py
+++ b/wqflask/wqflask/oauth2/resources.py
@@ -56,7 +56,7 @@ def view_resource(resource_id: uuid.UUID):
# Metadata edit maybe?
def __resource_success__(resource):
dataset_type = resource["resource_category"]["resource_category_key"]
- return oauth2_get(f"oauth2/resource/{dataset_type}/unlinked-data").either(
+ return oauth2_get(f"oauth2/group/{dataset_type}/unlinked-data").either(
lambda err: render_template(
"oauth2/view-resource.html", resource=resource,
unlinked_error=process_error(err)),
@@ -69,6 +69,37 @@ def view_resource(resource_id: uuid.UUID):
resource=None, error=process_error(err)),
__resource_success__)
+@resources.route("/data/link", methods=["POST"])
+@require_oauth2
+def link_data_to_resource():
+ """Link group data to a resource"""
+ form = request.form
+ try:
+ assert "resource_id" in form, "Resource ID not provided."
+ assert "dataset_id" in form, "Dataset ID not provided."
+ assert "dataset_type" in form, "Dataset type not specified"
+ assert form["dataset_type"].lower() in (
+ "mrna", "genotype", "phenotype"), "Invalid dataset type provided."
+ resource_id = form["resource_id"]
+
+ def __error__(error):
+ err = process_error(error)
+ flash(f"{err['error']}: {err['error_description']}", "alert-danger")
+ return redirect(url_for(
+ "oauth2.resource.view_resource", resource_id=resource_id))
+
+ def __success__(success):
+ flash(f"Data linked to resource successfully", "alert-success")
+ return redirect(url_for(
+ "oauth2.resource.view_resource", resource_id=resource_id))
+ return oauth2_post("oauth2/resource/data/link", data=dict(form)).either(
+ __error__,
+ __success__)
+ except AssertionError as aserr:
+ flash(aserr.args[0], "alert-danger")
+ return redirect(url_for(
+ "oauth2.resource.view_resource", resource_id=form["resource_id"]))
+
@resources.route("/edit/<uuid:resource_id>", methods=["GET"])
@require_oauth2
def edit_resource(resource_id: uuid.UUID):
diff --git a/wqflask/wqflask/templates/oauth2/view-resource.html b/wqflask/wqflask/templates/oauth2/view-resource.html
index 4ae276f8..04be2a4c 100644
--- a/wqflask/wqflask/templates/oauth2/view-resource.html
+++ b/wqflask/wqflask/templates/oauth2/view-resource.html
@@ -65,7 +65,7 @@
<form action="#" method="POST">
<input type="hidden" name="resource_id"
value="{{resource.resource_id}}" />
- <input type="hidden" name="data_id"
+ <input type="hidden" name="dataset_id"
value="{{data_item.dataset_or_trait_id}}" />
<input type="submit" value="Unlink" class="btn btn-danger" />
</form>
@@ -96,7 +96,7 @@
</thead>
<tbody>
{%if unlinked_error is defined%}
- display_error("Unlinked Data Error", unlinked_error)
+ {{display_error("Unlinked Data Error", unlinked_error)}}
{%else%}
{%for data_item in unlinked_data:%}
<tr>
@@ -107,13 +107,16 @@
</a>
</td>
<td>
- <form method="POST" action="#">
+ <form method="POST"
+ action="{{url_for('oauth2.resource.link_data_to_resource')}}">
<input type="hidden" name="resource_id"
value="{{resource.resource_id}}" />
- <input type="hidden" name="data_id"
+ <input type="hidden" name="dataset_id"
value="{{data_item.dataset_or_trait_id}}" />
+ <input type="hidden" name="dataset_type"
+ value="{{data_item.dataset_type}}" />
<input type="submit" value="Link" class="btn btn-info"
- {%if resource.resource_category.resource_category_description == "mRNA Dataset"%}
+ {%if resource.resource_category.resource_category_description == "mRNA Dataset" and resource.resource_data | count != 0%}
disabled="disabled"
{%endif%} />
</form>