Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #107 from ScilifelabDataCentre/develop
Browse files Browse the repository at this point in the history
Frontend testing and bug fixing
  • Loading branch information
talavis authored Jul 5, 2021
2 parents 6abeec4 + 371f57a commit 83a7514
Show file tree
Hide file tree
Showing 72 changed files with 6,243 additions and 1,554 deletions.
3 changes: 2 additions & 1 deletion Dockerfiles/Dockerfile.frontend.dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ FROM node:14-alpine

RUN yarn global add @quasar/cli

COPY .frontend/package.json /package.json
COPY ./frontend/package.json /package.json
COPY ./frontend/yarn.lock /yarn.lock
RUN yarn install

ADD ./frontend /code/
Expand Down
26 changes: 20 additions & 6 deletions backend/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,23 @@ def add_collection():
if not validation.result:
flask.abort(status=validation.status)

# add current user to editors if no editors are defined
if not indata.get("editors"):
indata["editors"] = [flask.g.current_user["_id"]]
# add current user if missing and only DATA_EDIT
elif (
not utils.req_has_permission("DATA_MANAGEMENT")
and str(flask.g.current_user["_id"]) not in indata["editors"]
):
indata["editors"].append(flask.g.current_user["_id"])

# convert all incoming uuids to uuid.UUID
indata = utils.prepare_for_db(indata)

# convert entries to uuids
for field in ("datasets", "editors"):
if field in indata:
indata[field] = [utils.str_to_uuid(value) for value in indata[field]]

collection["description"] = utils.secure_description(collection["description"])

collection.update(indata)

# add to db
Expand Down Expand Up @@ -177,14 +183,22 @@ def update_collection(identifier):
if not validation.result:
flask.abort(status=validation.status)

# DATA_EDIT may not delete itself from editors
if (
not utils.req_has_permission("DATA_MANAGEMENT")
and indata.get("editors")
and str(flask.g.current_user["_id"]) not in indata["editors"]
):
flask.abort(status=400)

# convert all incoming uuids to uuid.UUID
indata = utils.prepare_for_db(indata)

# convert entries to uuids
for field in ("datasets", "editors"):
if field in indata:
indata[field] = [utils.str_to_uuid(value) for value in indata[field]]

if "description" in indata:
indata["description"] = utils.secure_description(indata["description"])

is_different = False
for field in indata:
if indata[field] != collection[field]:
Expand Down
26 changes: 11 additions & 15 deletions backend/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,35 +227,31 @@ def build_dataset_info(identifier: str):
Returns:
dict: The prepared dataset entry.
"""
try:
dataset_uuid = utils.str_to_uuid(identifier)
except ValueError:
return None
dataset = flask.g.db["datasets"].find_one({"_id": dataset_uuid})
dataset = utils.req_get_entry("datasets", identifier)
if not dataset:
return None
order = flask.g.db["orders"].find_one({"datasets": dataset_uuid})
order = flask.g.db["orders"].find_one({"datasets": dataset["_id"]})
if flask.g.current_user:
curr_user = flask.g.current_user["_id"]
else:
curr_user = None

if (
utils.req_has_permission("DATA_MANAGEMENT")
or flask.g.db.current_user["id"] in order["editors"]
):
dataset["order"] = order["_id"]
if utils.req_has_permission("DATA_MANAGEMENT") or curr_user in order["editors"]:
dataset["order"] = {"_id": order["_id"], "title": order["title"]}
dataset["related"] = list(
flask.g.db["datasets"].find({"_id": {"$in": order["datasets"]}}, {"title": 1})
)
dataset["related"].remove({"_id": dataset["_id"], "title": dataset["title"]})
dataset["collections"] = list(
flask.g.db["projects"].find({"datasets": dataset_uuid}, {"title": 1})
flask.g.db["collections"].find({"datasets": dataset["_id"]}, {"title": 1})
)
for field in ("editors", "generators", "authors"):
if field == "editors" and (
not utils.req_has_permission("DATA_MANAGEMENT")
and flask.g.db.current_user["id"] not in order[field]
not utils.req_has_permission("DATA_MANAGEMENT") and curr_user not in order[field]
):
continue
dataset[field] = utils.user_uuid_data(order[field], flask.g.db)

dataset["organisation"] = utils.user_uuid_data(order[field], flask.g.db)
dataset["organisation"] = utils.user_uuid_data(order["organisation"], flask.g.db)
dataset["organisation"] = dataset["organisation"][0] if dataset["organisation"] else ""
return dataset
2 changes: 1 addition & 1 deletion backend/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def add_order():
# add current user if missing and only DATA_EDIT
elif (
not utils.req_has_permission("DATA_MANAGEMENT")
and flask.g.current_user["_id"] not in indata["editors"]
and str(flask.g.current_user["_id"]) not in indata["editors"]
):
indata["editors"].append(flask.g.current_user["_id"])

Expand Down
2 changes: 1 addition & 1 deletion backend/tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_get_dataset(mdb):
* Confirm that the dataset is not listed in ``related``
"""
session = requests.Session()
for _ in range(10):
for _ in range(2):
orig = mdb["datasets"].aggregate([{"$sample": {"size": 1}}]).next()
response = helpers.make_request(session, f'/api/v1/dataset/{orig["_id"]}')
assert response[1] == 200
Expand Down
2 changes: 1 addition & 1 deletion backend/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def validate_orcid(data: str) -> bool:
"""
if not isinstance(data, str):
raise ValueError(f"Not a str ({data})")
if not ORCID_REGEX.fullmatch(data):
if data and not ORCID_REGEX.fullmatch(data):
raise ValueError(f"Not an orcid ({data})")
return True

Expand Down
1 change: 1 addition & 0 deletions docs/build/html/code.app.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions docs/build/html/code.collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions docs/build/html/code.config.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions docs/build/html/code.dataset.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions docs/build/html/code.db_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions docs/build/html/code.developer.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
10 changes: 10 additions & 0 deletions docs/build/html/code.migrations.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
</ul>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="migrations.migrate_v2_to_v3">
<span class="sig-prename descclassname"><span class="pre">migrations.</span></span><span class="sig-name descname"><span class="pre">migrate_v2_to_v3</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">db</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="modules/migrations.html#migrate_v2_to_v3"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#migrations.migrate_v2_to_v3" title="Permalink to this definition"></a></dt>
<dd><p>Update the database fields to match the changes in the data structure.</p>
<ul class="simple">
<li><p>Remove the <code class="docutils literal notranslate"><span class="pre">DATA_LIST</span></code> and <code class="docutils literal notranslate"><span class="pre">STATISTICS</span></code> permissions from all users.</p></li>
</ul>
</dd></dl>

</div>


Expand Down Expand Up @@ -80,6 +89,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions docs/build/html/code.order.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions docs/build/html/code.schema.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions docs/build/html/code.structure.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions docs/build/html/code.user.html
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions docs/build/html/code.utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions docs/build/html/code.validate.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
6 changes: 6 additions & 0 deletions docs/build/html/development.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ <h1>Development<a class="headerlink" href="#development" title="Permalink to thi
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html#add-test-data">Add test data</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="development.testing.html">Testing</a><ul>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html#backend">Backend</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html#frontend">Frontend</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="modules.html">Code reference</a><ul>
<li class="toctree-l2"><a class="reference internal" href="code.app.html">app.py</a></li>
<li class="toctree-l2"><a class="reference internal" href="code.collection.html">collection.py</a></li>
Expand Down Expand Up @@ -89,6 +94,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Development</a><ul>
<li class="toctree-l2"><a class="reference internal" href="development.quick_environment.html">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand Down
5 changes: 3 additions & 2 deletions docs/build/html/development.quick_environment.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<script src="static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Code reference" href="modules.html" />
<link rel="next" title="Testing" href="development.testing.html" />
<link rel="prev" title="Development" href="development.html" />

<link rel="stylesheet" href="static/custom.css" type="text/css" />
Expand Down Expand Up @@ -88,6 +88,7 @@ <h3>Navigation</h3>
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="development.html">Development</a><ul class="current">
<li class="toctree-l2 current"><a class="current reference internal" href="#">System for development</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.testing.html">Testing</a></li>
<li class="toctree-l2"><a class="reference internal" href="modules.html">Code reference</a></li>
</ul>
</li>
Expand All @@ -99,7 +100,7 @@ <h3>Related Topics</h3>
<li><a href="index.html">Documentation overview</a><ul>
<li><a href="development.html">Development</a><ul>
<li>Previous: <a href="development.html" title="previous chapter">Development</a></li>
<li>Next: <a href="modules.html" title="next chapter">Code reference</a></li>
<li>Next: <a href="development.testing.html" title="next chapter">Testing</a></li>
</ul></li>
</ul></li>
</ul>
Expand Down
Loading

0 comments on commit 83a7514

Please sign in to comment.