From df8b72e66cd986211f69ce23dcabc3770a757c64 Mon Sep 17 00:00:00 2001 From: aaronm-2112 Date: Tue, 29 Oct 2024 14:13:37 -0700 Subject: [PATCH] wip: add and get contributors --- src/pyflask/apis/__init__.py | 3 +- src/pyflask/apis/apiContributors.py | 2 ++ src/pyflask/contributors/__init__.py | 1 + src/pyflask/contributors/contributors.py | 34 +++++++++++++++++++ .../guided-mode/guided-curate-dataset.js | 1 + 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/pyflask/apis/apiContributors.py create mode 100644 src/pyflask/contributors/__init__.py create mode 100644 src/pyflask/contributors/contributors.py diff --git a/src/pyflask/apis/__init__.py b/src/pyflask/apis/__init__.py index 178515427..1334f2626 100644 --- a/src/pyflask/apis/__init__.py +++ b/src/pyflask/apis/__init__.py @@ -10,4 +10,5 @@ from .apiDatasets import api as datasets_resource from .apiCollections import api as collections_resource from .apiSkeleton import api as skeleton_resource -from .apiUploadManifests import api as upload_manifest_resource \ No newline at end of file +from .apiUploadManifests import api as upload_manifest_resource +from .apiContributors import api as contributors_resource \ No newline at end of file diff --git a/src/pyflask/apis/apiContributors.py b/src/pyflask/apis/apiContributors.py new file mode 100644 index 000000000..5e3c010a6 --- /dev/null +++ b/src/pyflask/apis/apiContributors.py @@ -0,0 +1,2 @@ +from flask_restx import Resource, fields, reqparse +from contributors import get_workspace_contributors, create_workspace_contributors \ No newline at end of file diff --git a/src/pyflask/contributors/__init__.py b/src/pyflask/contributors/__init__.py new file mode 100644 index 000000000..6ec35eb33 --- /dev/null +++ b/src/pyflask/contributors/__init__.py @@ -0,0 +1 @@ +from .contributors import (get_workspace_contributors, create_workspace_contributors) \ No newline at end of file diff --git a/src/pyflask/contributors/contributors.py b/src/pyflask/contributors/contributors.py new file mode 100644 index 000000000..063a12eac --- /dev/null +++ b/src/pyflask/contributors/contributors.py @@ -0,0 +1,34 @@ +import requests +from authentication import get_access_token +from utils import create_request_headers +from namespaces import NamespaceEnum, get_namespace_logger +from constants import PENNSIEVE_URL + + +namespace_logger = get_namespace_logger(NamespaceEnum.MANAGE_DATASETS) + +def get_workspace_contributors(): + try: + r = requests.get(f'{PENNSIEVE_URL}/contributors') + r.raise_for_status() + return r.json() + except Exception as e: + namespace_logger.error(e) + + +def create_workspace_contributors(contributors): + try: + for con in contributors: + payload = { + "email": con['email'], + "lastName": con['last_name'], + "firstName": con['first_name'], + "orcid": con['orcid'] + } + + # TODO: Handle if they contributor already exists? + r = requests.post(f'{PENNSIEVE_URL}/contributors', json=payload, headers=create_request_headers(get_access_token())) + r.raise_for_status() + except Exception as e: + namespace_logger.error(e) + raise e \ No newline at end of file diff --git a/src/renderer/src/scripts/guided-mode/guided-curate-dataset.js b/src/renderer/src/scripts/guided-mode/guided-curate-dataset.js index 712d3e4e4..3f79a1818 100644 --- a/src/renderer/src/scripts/guided-mode/guided-curate-dataset.js +++ b/src/renderer/src/scripts/guided-mode/guided-curate-dataset.js @@ -9322,6 +9322,7 @@ const handleAddContributorHeaderUI = () => { `; }); + // TODO: publishing-rework-end-to-end - Change the dropdown to include all organization wide contributors return `