Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update dataset metadata endpoints #16

Merged
merged 54 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
4d2e840
chore: reconfigure dataset metadata
Aydawka Oct 15, 2023
43b7ef5
chore: remove ids from 1-to-1 study metadata
Aydawka Oct 15, 2023
16872ff
style: format
Aydawka Oct 15, 2023
cc2c2b0
chore: dataset models and endpoints refactored
Aydawka Oct 15, 2023
7263b53
chore: study models refactored
Aydawka Oct 15, 2023
797e73b
chore: dataset metadata functions were changed
Aydawka Oct 15, 2023
78c0aa9
fix: contributor and creator endpoints
Aydawka Oct 16, 2023
6e41496
chore: refactor dataset metadata endpoints
Aydawka Oct 16, 2023
3843967
style: flake8 errors
Aydawka Oct 16, 2023
c291d12
style: poe format
Aydawka Oct 16, 2023
9ca67a6
style: pylint format check
Aydawka Oct 16, 2023
0690e05
style: 🎨 fix code style issues with Black
lint-action Oct 16, 2023
2d2d258
fix: study identification checked
Aydawka Oct 16, 2023
6d58c40
wip: related item endpoint
Aydawka Oct 16, 2023
80675f9
wip: dataset related item endpoint
Aydawka Oct 16, 2023
a6cd250
wip: pylint errors
Aydawka Oct 17, 2023
619eb41
🔐 fix: update secret key length
megasanjay Oct 17, 2023
cd0821d
fix: dataset medata relate item title
Aydawka Oct 17, 2023
e864de2
wip: related item in dataset metadata
Aydawka Oct 17, 2023
eafc854
Merge remote-tracking branch 'origin/dataset-metadata' into dataset-m…
Aydawka Oct 17, 2023
3aa36fc
style: 🎨 fix code style issues with Black
lint-action Oct 17, 2023
cf995dc
fix: dataset metadata related item
Aydawka Oct 20, 2023
575cd65
fix: study identifiers model
Aydawka Oct 20, 2023
aa8cd3c
style: format errors check
Aydawka Oct 20, 2023
2c33730
Merge remote-tracking branch 'origin/dataset-metadata' into dataset-m…
Aydawka Oct 20, 2023
5d3fc11
style: pylint format
Aydawka Oct 20, 2023
a73e643
style: 🎨 fix code style issues with Black
lint-action Oct 20, 2023
98ab3b3
style: permissions added to dataset metadata
Aydawka Oct 20, 2023
0bb4d7d
style: formatting
Aydawka Oct 21, 2023
c7617d0
Merge remote-tracking branch 'origin/dataset-metadata' into dataset-m…
Aydawka Oct 21, 2023
03551b6
style: 🎨 fix code style issues with Black
lint-action Oct 21, 2023
f62f1e0
fix: dataset other
Aydawka Oct 21, 2023
d070f57
Merge remote-tracking branch 'origin/dataset-metadata' into dataset-m…
Aydawka Oct 21, 2023
f72557c
feat: dataset version GET
Aydawka Oct 23, 2023
62f5a09
fix: study identifiers
Aydawka Oct 23, 2023
27099b3
fix: dataset identifier
Aydawka Oct 23, 2023
61fa643
fix: dataset related item other field
Aydawka Oct 23, 2023
2fdf7ae
style: format
Aydawka Oct 23, 2023
1dbd866
feat: add version readme to the model
Aydawka Oct 23, 2023
bfbdca9
feat: dataset title permission
Aydawka Oct 24, 2023
5f8dfb1
feat: dataset description permission
Aydawka Oct 24, 2023
729bd10
style:format
Aydawka Oct 24, 2023
3449664
style: 🎨 fix code style issues with Black
lint-action Oct 24, 2023
c134a72
fix: minor fixes in dataset metadata
Aydawka Oct 24, 2023
9e7a5fa
Merge remote-tracking branch 'origin/dataset-metadata' into dataset-m…
Aydawka Oct 24, 2023
53cbeab
style: 🎨 fix code style issues with Black
lint-action Oct 24, 2023
a096d5a
Merge remote-tracking branch 'origin/staging' into dataset-metadata
Aydawka Oct 24, 2023
681267d
feat: updates to dataset metadata
Aydawka Oct 24, 2023
98a85c8
fix: dataset metadata and docker file
Aydawka Oct 24, 2023
6454893
style: 🎨 fix code style issues with Black
lint-action Oct 24, 2023
7919c40
fix: dataset metadata
Aydawka Oct 24, 2023
7516e8e
Merge remote-tracking branch 'origin/dataset-metadata' into dataset-m…
Aydawka Oct 24, 2023
1565d3a
fix: minor fix for contributor metadata
Aydawka Oct 24, 2023
f73191a
Merge remote-tracking branch 'origin/dataset-metadata' into dataset-m…
Aydawka Oct 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions alembic/versions/32e5ff331a78_add_token_blacklist.py

This file was deleted.

26 changes: 0 additions & 26 deletions alembic/versions/639a13561089_delete_token_blacklist.py

This file was deleted.

26 changes: 0 additions & 26 deletions alembic/versions/6d4271d33834_remove_column_in_token_blacklist.py

This file was deleted.

26 changes: 0 additions & 26 deletions alembic/versions/e6cc254fc968_token_blacklist.py

This file was deleted.

16 changes: 2 additions & 14 deletions apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,15 @@
from .dataset_metadata.dataset_access import api as access
from .dataset_metadata.dataset_alternate_identifier import api as alternate_identifier
from .dataset_metadata.dataset_consent import api as consent
from .dataset_metadata.dataset_contributor import api as dataset_contributor
from .dataset_metadata.dataset_date import api as date
from .dataset_metadata.dataset_de_ident_level import api as de_ident_level
from .dataset_metadata.dataset_description import api as description
from .dataset_metadata.dataset_funder import api as funder
from .dataset_metadata.dataset_managing_organization import api as managing_organization
from .dataset_metadata.dataset_other import api as dataset_other
from .dataset_metadata.dataset_readme import api as readme
from .dataset_metadata.dataset_record_keys import api as record_keys
from .dataset_metadata.dataset_related_item import api as related_item
from .dataset_metadata.dataset_related_item_contributor import (
api as related_item_contributor,
)
from .dataset_metadata.dataset_related_item_identifier import (
api as related_item_identifier,
)
from .dataset_metadata.dataset_related_item_other import api as related_item_other
from .dataset_metadata.dataset_related_item_title import api as related_item_title
from .dataset_metadata.dataset_rights import api as rights
from .dataset_metadata.dataset_subject import api as subject
from .dataset_metadata.dataset_title import api as title
Expand Down Expand Up @@ -69,16 +61,11 @@
"de_ident_level",
"description",
"funder",
"managing_organization",
"dataset_other",
"readme",
"record_keys",
"related_item",
"related_item_contributor",
"related_item_identifier",
"api",
"related_item_other",
"related_item_title",
"rights",
"subject",
"title",
Expand All @@ -101,6 +88,7 @@
"user",
"identification",
"study_description",
"dataset_contributor",
]


Expand Down
3 changes: 3 additions & 0 deletions apis/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ def is_granted(permission: str, study=None):
"add_dataset",
"update_dataset",
"delete_dataset",
"version",
"publish_version",
"participant",
"study_metadata",
Expand All @@ -314,6 +315,7 @@ def is_granted(permission: str, study=None):
"add_dataset",
"update_dataset",
"delete_dataset",
"version",
"publish_version",
"participant",
"study_metadata",
Expand All @@ -329,6 +331,7 @@ def is_granted(permission: str, study=None):
"delete_dataset",
"participant",
"study_metadata",
"version",
"dataset_metadata",
],
"viewer": ["viewer", "view"],
Expand Down
14 changes: 14 additions & 0 deletions apis/contributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from .authentication import is_granted


api = Namespace("Contributor", description="Contributors", path="/")


Expand Down Expand Up @@ -44,15 +45,28 @@ def post(self, study_id: int):
if not is_granted("invite_contributor", study_obj):
return "Access denied, you can not modify", 403
data: Union[dict, Any] = request.json

email_address = data["email_address"]
user = model.User.query.filter_by(email_address=email_address).first()
permission = data["role"]
# encoded_jwt_code = jwt.encode(
# {
# "user": user.id,
# "exp": datetime.datetime.now(timezone.utc)
# + datetime.timedelta(minutes=180), # noqa: W503
# "jti": str(uuid.uuid4()),
# }, # noqa: W503
# config.FAIRHUB_SECRET,
# algorithm="HS256",
# )
contributor_ = None

try:
if user:
contributor_ = study_obj.add_user_to_study(user, permission)
else:
contributor_ = study_obj.invite_user_to_study(email_address, permission)

except model.StudyException as ex:
return ex.args[0], 409
model.db.session.commit()
Expand Down
56 changes: 47 additions & 9 deletions apis/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,20 @@ def post(self, study_id):
if not is_granted("add_dataset", study):
return "Access denied, you can not modify", 403
# todo if study.participant id== different study Throw error
# data: typing.Union[typing.Any, dict] = request.json
data: typing.Union[typing.Any, dict] = request.json
dataset_ = model.Dataset.from_data(study)
model.db.session.add(dataset_)

title_element = model.DatasetTitle.query.filter_by(
dataset_id=dataset_.id
).first()
title_element.title = data["title"]

description_element = model.DatasetDescription.query.filter_by(
dataset_id=dataset_.id
).first()
description_element.description = data["description"]

model.db.session.commit()
return dataset_.to_dict()

Expand Down Expand Up @@ -114,7 +125,6 @@ class VersionResource(Resource):
@api.response(201, "Success")
@api.response(400, "Validation Error")
@api.doc("dataset version")
@api.marshal_with(dataset_versions_model)
def get(
self, study_id: int, dataset_id: int, version_id: int
): # pylint: disable= unused-argument
Expand Down Expand Up @@ -148,19 +158,47 @@ def delete(


@api.route("/study/<study_id>/dataset/<dataset_id>/version")
@api.response(201, "Success")
@api.response(400, "Validation Error")
class VersionList(Resource):
@api.response(201, "Success")
@api.response(400, "Validation Error")
@api.doc("versions")
def get(self, study_id: int, dataset_id: int):
study = model.Study.query.get(study_id)
if not is_granted("version", study):
return "Access denied, you can not modify", 403
dataset_obj = model.Dataset.query.get(dataset_id)
return [i.to_dict() for i in dataset_obj.dataset_versions.all()], 200

@api.response(201, "Success")
@api.response(400, "Validation Error")
@api.doc("version add")
def post(self, study_id: int, dataset_id: int):
study = model.Study.query.get(study_id)
if not is_granted("publish_version", study):
if not is_granted("version", study):
return "Access denied, you can not modify", 403

data: typing.Union[typing.Any, dict] = request.json
data["participants"] = [
model.Participant.query.get(i) for i in data["participants"]
]
# data["participants"] = [
# model.Participant.query.get(i) for i in data["participants"]
# ]
data_obj = model.Dataset.query.get(dataset_id)
dataset_versions = model.Version.from_data(data_obj, data)
model.db.session.add(dataset_versions)
model.db.session.commit()
return jsonify(dataset_versions.to_dict())
return dataset_versions.to_dict()


@api.route("/study/<study_id>/dataset/<dataset_id>/version/<version_id>/publish")
class PublishResource(Resource):
@api.response(201, "Success")
@api.response(400, "Validation Error")
@api.doc("version publish")
def post(self, study_id: int, dataset_id: int):
study = model.Study.query.get(study_id)
if not is_granted("publish_version", study):
return "Access denied, you can not modify", 403
data_obj = model.Dataset.query.get(dataset_id)
data: typing.Union[typing.Any, dict] = request.json
dataset_versions = model.Version.from_data(data_obj, data)
model.db.session.commit()
return dataset_versions.to_dict()
Empty file.
20 changes: 14 additions & 6 deletions apis/dataset_metadata/dataset_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from flask_restx import Resource, fields

import model
from apis.authentication import is_granted
from apis.dataset_metadata_namespace import api

dataset_access = api.model(
Expand All @@ -21,14 +22,21 @@ class DatasetAccessResource(Resource):
@api.doc("access")
@api.response(200, "Success")
@api.response(400, "Validation Error")
@api.marshal_with(dataset_access)
def get(self, study_id: int, dataset_id: int):
# @api.marshal_with(dataset_access)
def get(self, study_id: int, dataset_id: int): # pylint: disable= unused-argument
dataset_ = model.Dataset.query.get(dataset_id)
dataset_access_ = dataset_.dataset_access
return [d.to_dict() for d in dataset_access_]
return dataset_access_.to_dict()

@api.doc("update access")
@api.response(200, "Success")
@api.response(400, "Validation Error")
def put(self, study_id: int, dataset_id: int): # pylint: disable= unused-argument
study_obj = model.Study.query.get(study_id)
if not is_granted("dataset_metadata", study_obj):
return "Access denied, you can not make any change in dataset metadata", 403

def put(self, study_id: int, dataset_id: int):
dataset_ = model.Dataset.query.get(dataset_id)
dataset_access_ = dataset_.dataset_access.update(request.json)
dataset_.dataset_access.update(request.json)
model.db.session.commit()
return dataset_access_.to_dict()
return dataset_.dataset_access.to_dict()
Loading