Skip to content

Commit

Permalink
wip: add and get contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronm-2112 committed Oct 29, 2024
1 parent 84061cc commit df8b72e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/pyflask/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
from .apiUploadManifests import api as upload_manifest_resource
from .apiContributors import api as contributors_resource
2 changes: 2 additions & 0 deletions src/pyflask/apis/apiContributors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from flask_restx import Resource, fields, reqparse
from contributors import get_workspace_contributors, create_workspace_contributors
1 change: 1 addition & 0 deletions src/pyflask/contributors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .contributors import (get_workspace_contributors, create_workspace_contributors)
34 changes: 34 additions & 0 deletions src/pyflask/contributors/contributors.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -9322,6 +9322,7 @@ const handleAddContributorHeaderUI = () => {
`;
});

// TODO: publishing-rework-end-to-end - Change the dropdown to include all organization wide contributors
return `
<label class="guided--form-label centered mb-2" style="font-size: 1em !important;">
If the contributor has been previously added, select them from the dropdown below.
Expand Down

0 comments on commit df8b72e

Please sign in to comment.