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 #18 from ScilifelabDataCentre/develop
Browse files Browse the repository at this point in the history
A couple of bugfixes for 0.1
  • Loading branch information
talavis authored May 13, 2020
2 parents 0c28609 + 97d6b44 commit 9f74405
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 21 deletions.
6 changes: 4 additions & 2 deletions backend/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def build_dataset_info(identifier: str):
dataset['related'].remove({'_id': dataset['_id'], 'title': dataset['title']})
dataset['projects'] = list(flask.g.db['projects'].find({'datasets': dataset_uuid},
{'title': 1}))
creator = flask.g.db['users'].find_one({'_id': order['creator']})['name']
creator = flask.g.db['users'].find_one({'_id': order['creator']})
if creator:
dataset['creator'] = creator
dataset['creator'] = creator['name']
else:
dataset['creator'] = order['creator']
return dataset
2 changes: 0 additions & 2 deletions backend/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ def add_order(): # pylint: disable=too-many-branches
if 'receiver' in indata:
if new_identifier := utils.check_email_uuid(indata['receiver']):
indata['receiver'] = new_identifier
else:
flask.abort(400)

order.update(indata)

Expand Down
7 changes: 3 additions & 4 deletions backend/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ def validate_creator(data: str) -> bool:
if not isinstance(data, str):
raise ValueError(f'Bad data type ({data})')

# Non-registered user (email instead of uuid)
if utils.is_email(data):
return True
# If it is a uuid, make sure it matches a user
try:
user_uuid = uuid.UUID(data)
Expand All @@ -73,7 +70,6 @@ def validate_creator(data: str) -> bool:
else:
if not flask.g.db['users'].find_one({'_id': user_uuid}):
raise ValueError(f'Uuid not in db ({data})')

return True


Expand Down Expand Up @@ -287,6 +283,9 @@ def validate_user(data: Union[str, list]) -> bool:
user_uuids = data
else:
raise ValueError(f'Bad data type ({data})')
# empty is ok
if not data:
return True
# Non-registered user (email instead of uuid)
for u_uuid in user_uuids:
if utils.is_email(u_uuid):
Expand Down
16 changes: 6 additions & 10 deletions frontend/src/components/datasets/DatasetAbout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<div class="dataset-description field" v-html="dataset.description"></div>
<table class="table is-hoverable is-striped">
<tbody>
<tr>
<tr v-if="dataset.creator.length > 0">
<th scope="row">
Dataset creator
Creator
</th>
<td>
{{ dataset.creator }}
Expand All @@ -23,6 +23,10 @@
</ul>
</td>
</tr>
<tr v-for="field in Object.keys(dataset.extra)" :key="field">
<th scope="row">{{ field }}</th>
<td>{{ dataset.extra[field] }}</td>
</tr>
<tr v-if="dataset.projects.length > 0">
<th scope="row">
Projects
Expand All @@ -43,14 +47,6 @@
</ul>
</td>
</tr>
<tr v-for="extraField in dataset.extras" :key="extraField.key">
<th scope="row" :rowspan="user.permissions.length">
{{ extraField.key }}
</th>
<td>
{{ extraField.value }}
</td>
</tr>
</tbody>
</table>
</div>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/orders/OrderEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<label class="label" for="order-creator">Creator</label>
<input id="order-creator"
class="input"
v-model="newOrder.creator.id"
v-model="newOrder.creator"
name="ORDER_CREATOR"
type="text"
placeholder="Data creator (e.g. facility name)" />
Expand Down Expand Up @@ -140,6 +140,7 @@ export default {
.then(() => {
this.newOrder = this.order;
this.newOrder.id = this.newOrder._id;
this.newOrder.creator = this.creator.id;
delete this.newOrder._id;
delete this.newOrder.datasets;
});
Expand Down
1 change: 0 additions & 1 deletion frontend/src/store/modules/order/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const actions = {
return new Promise((resolve, reject) => {
let uuid = payload.id;
delete payload.id;
payload.creator = payload.creator.id;
if (uuid === '') {
axios
.post('/api/order/',
Expand Down
2 changes: 1 addition & 1 deletion test/gen_test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def gen_datasets(db, nr_datasets: int = 500):
# add extra field
if random.random() > 0.7:
tag = random.choice(EXTRA_KEYS)
changes['extra'] = [{tag: random.choice(EXTRA_FIELDS[tag])}]
changes['extra'] = {tag: random.choice(EXTRA_FIELDS[tag])}
dataset.update(changes)
uuids.append(db['datasets'].insert_one(dataset).inserted_id)
make_log(db, action='add', data=dataset, data_type='dataset',comment='Generated', user='root')
Expand Down

0 comments on commit 9f74405

Please sign in to comment.