aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/tests/integration/wqflask/test_metadata_edits.py43
-rw-r--r--wqflask/wqflask/decorators.py23
-rw-r--r--wqflask/wqflask/metadata_edits.py113
-rw-r--r--wqflask/wqflask/templates/edit_phenotype.html3
4 files changed, 1 insertions, 181 deletions
diff --git a/wqflask/tests/integration/wqflask/test_metadata_edits.py b/wqflask/tests/integration/wqflask/test_metadata_edits.py
deleted file mode 100644
index ba7a18c9..00000000
--- a/wqflask/tests/integration/wqflask/test_metadata_edits.py
+++ /dev/null
@@ -1,43 +0,0 @@
-"""Tests for wqflask/wqflask/metadata_edits.py"""
-import unittest
-from unittest import mock
-
-from wqflask import app
-
-
-class MetadataEditsTest(unittest.TestCase):
- """Test Cases for MetadataEdits"""
-
- def setUp(self):
- self.app = app.test_client()
- self.app_context = app.app_context()
- self.app_context.push()
-
- def tearDown(self):
- self.app_context.pop()
-
- @unittest.skip("TO-FIX or Delete")
- @mock.patch("wqflask.metadata_edits.database_connection")
- @mock.patch("wqflask.metadata_edits.get_case_attributes")
- def test_show_case_attributes(self, mock_case_attrs, mock_conn):
- """Test that case attributes are displayed correctly"""
- mock_case_attrs.return_value = {
- "Condition (1)": "",
- "Tissue": "",
- "Age": "Cum sociis natoque penatibus et magnis dis",
- "Condition (4)": "Description A",
- "Condition (5)": "Description B",
- }
- response = self.app.get(
- "/datasets/case-attributes", follow_redirects=True
- ).data.decode()
- self.assertIn(
- "<td>Condition (1)</td><td>No description</td>", response
- )
- self.assertIn("<td>Tissue</td><td>No description</td>", response)
- self.assertIn(
- "<td>Age</td><td>Cum sociis natoque penatibus et magnis dis</td>",
- response,
- )
- self.assertIn("<td>Condition (4)</td><td>Description A</td>", response)
- self.assertIn("<td>Condition (5)</td><td>Description B</td>", response)
diff --git a/wqflask/wqflask/decorators.py b/wqflask/wqflask/decorators.py
index a69ad868..41d23084 100644
--- a/wqflask/wqflask/decorators.py
+++ b/wqflask/wqflask/decorators.py
@@ -7,7 +7,6 @@ from urllib.parse import urljoin
from functools import wraps
from gn3.authentication import AdminRole
from gn3.authentication import DataRole
-from gn3.authentication import get_groups_by_user_uid
import json
import requests
@@ -79,25 +78,3 @@ def edit_admins_access_required(f):
return redirect(url_for("no_access_page"))
return f(*args, **kwargs)
return wrap
-
-
-def case_attributes_edit_access(f):
- """Use this for endpoints for editing case
- attributes. Only members in the 'editors'
- group are allowed here!"""
- @wraps(f)
- def wrap(*args, **kwargs):
- groups = []
- for _, value in get_groups_by_user_uid(
- user_uid=((g.user_session.record.get(b"user_id") or
- b"").decode("utf-8")
- or g.user_session.record.get("user_id") or ""),
- conn=redis.from_url(current_app.config["REDIS_URL"],
- decode_responses=True)).items():
- for items in value:
- if (i_ := items.get("name")):
- groups.append(i_)
- if "groups" in groups:
- return redirect(url_for("no_access_page"))
- return f(*args, **kwargs)
- return wrap
diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py
index 383316e4..2827e617 100644
--- a/wqflask/wqflask/metadata_edits.py
+++ b/wqflask/wqflask/metadata_edits.py
@@ -23,7 +23,6 @@ from wqflask.database import database_connection
from wqflask.decorators import edit_access_required
from wqflask.decorators import edit_admins_access_required
from wqflask.decorators import login_required
-from wqflask.decorators import case_attributes_edit_access
from gn3.authentication import AdminRole
from gn3.authentication import get_highest_user_access_role
@@ -47,11 +46,6 @@ from gn3.db.sample_data import delete_sample_data
from gn3.db.sample_data import get_trait_csv_sample_data
from gn3.db.sample_data import insert_sample_data
from gn3.db.sample_data import update_sample_data
-from gn3.db.case_attributes import get_case_attributes
-from gn3.db.case_attributes import get_unreviewed_diffs
-from gn3.db.case_attributes import insert_case_attribute_audit
-from gn3.db.case_attributes import reject_case_attribute
-from gn3.db.case_attributes import approve_case_attribute
metadata_edit = Blueprint("metadata_edit", __name__)
@@ -146,7 +140,6 @@ def display_phenotype_metadata(dataset_id: str, name: str):
dataset_id=dataset_id,
name=name,
resource_id=request.args.get("resource-id"),
- headers=get_case_attributes(conn),
version=os.environ.get("GN_VERSION"),
)
@@ -196,8 +189,7 @@ def update_phenotype(dataset_id: str, name: str):
)
diff_data = {}
with database_connection() as conn:
- headers = ["Strain Name", "Value", "SE", "Count"] + list(
- map(lambda x: x[1], get_case_attributes(conn)))
+ headers = ["Strain Name", "Value", "SE", "Count"]
diff_data = remove_insignificant_edits(
diff_data=csv_diff(
base_csv=(
@@ -706,106 +698,3 @@ def approve_data(resource_id: str, file_name: str):
"warning",
)
return redirect(url_for("metadata_edit.list_diffs"))
-
-
-@metadata_edit.route("/case-attributes")
-@case_attributes_edit_access
-@login_required
-def show_case_attribute_columns():
- diff_data = None
- with database_connection() as conn:
- diff_data = get_unreviewed_diffs(conn)
- modifications, deletions, inserts = [], [], []
- if diff_data:
- for id_, author, diff in diff_data:
- diff = json.loads(diff)
- author = get_user_info_by_key(
- key="user_id",
- value=author,
- conn=redis.from_url(
- current_app.config["REDIS_URL"], decode_responses=True
- ),
- ).get("full_name")
- if m_ := diff.get("Modification"):
- m_["author"] = author
- m_["id"] = id_
- if m_.get("description"):
- m_["description"]["Diff"] = "\n".join(
- difflib.ndiff(
- [m_.get("description")["Original"]],
- [m_.get("description")["Current"]],
- )
- )
- if m_.get("name"):
- m_["name"]["Diff"] = "\n".join(
- difflib.ndiff(
- [m_.get("name")["Original"]],
- [m_.get("name")["Current"]],
- )
- )
- if any([m_.get("description"), m_.get("name")]):
- modifications.append(m_)
- if d_ := diff.get("Deletion"):
- d_["author"] = author
- d_["id"] = id_
- deletions.append(d_)
- if i_ := diff.get("Insert"):
- i_["author"] = author
- i_["id"] = id_
- inserts.append(i_)
- with database_connection() as cursor:
- return render_template(
- "case_attributes.html",
- case_attributes=get_case_attributes(cursor),
- modifications=modifications,
- deletions=deletions,
- inserts=inserts,
- )
-
-
-@metadata_edit.route("/case-attributes", methods=("POST",))
-@case_attributes_edit_access
-@login_required
-def update_case_attributes():
- data_ = request.form.to_dict().get("data")
- if data_:
- author = (
- (g.user_session.record.get(b"user_id") or b"").decode("utf-8")
- or g.user_session.record.get("user_id")
- or ""
- )
- with database_connection() as conn:
- insert_case_attribute_audit(
- conn=conn, status="review", author=author, data=data_
- )
- return redirect(url_for("metadata_edit.show_case_attribute_columns"))
-
-
-@metadata_edit.route(
- "/case-attributes/reject",
- methods=[
- "POST",
- ],
-)
-@case_attributes_edit_access
-@login_required
-def reject_case_attribute_data():
- case_attr_id = request.form.to_dict().get("id")
- with database_connection() as conn:
- reject_case_attribute(conn=conn, case_attr_audit_id=int(case_attr_id))
- return redirect(url_for("metadata_edit.show_case_attribute_columns"))
-
-
-@metadata_edit.route(
- "/case-attributes/approve",
- methods=[
- "POST",
- ],
-)
-@case_attributes_edit_access
-@login_required
-def approve_case_attribute_data():
- case_attr_id = request.form.to_dict().get("id")
- with database_connection() as conn:
- approve_case_attribute(conn=conn, case_attr_audit_id=case_attr_id)
- return redirect(url_for("metadata_edit.show_case_attribute_columns"))
diff --git a/wqflask/wqflask/templates/edit_phenotype.html b/wqflask/wqflask/templates/edit_phenotype.html
index a7ecc027..ea480f4e 100644
--- a/wqflask/wqflask/templates/edit_phenotype.html
+++ b/wqflask/wqflask/templates/edit_phenotype.html
@@ -38,9 +38,6 @@
<div class="form-group">
<input type = "file" class="col-md-4 control-label text-left" name = "file" />
</div>
- <div class="form-group">
- <a href="{{url_for('metadata_edit.show_case_attribute_columns')}}" target="_blank" style="margin-left: 25px;">(You can find sample metadata column descriptions here)</a>
- </div>
<input type="submit" style="width: 125px; margin-right: 25px;" class="btn btn-success form-control changed" value="Submit Change">
</div>
<hr>