Skip to content

Commit

Permalink
Merge branch 'feature/preprints-affiliations' of https://github.com/C…
Browse files Browse the repository at this point in the history
…enterForOpenScience/osf.io into clean-up-preprint-permissions

* 'feature/preprints-affiliations' of https://github.com/CenterForOpenScience/osf.io:
  add test confirming preprint affiliated institution data is sent to SHARE
  add tests for self link
  fix self link
  • Loading branch information
John Tordoff committed Aug 13, 2024
2 parents 0933861 + 33af3e7 commit 61b0eeb
Show file tree
Hide file tree
Showing 28 changed files with 578 additions and 469 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.cache
key: reqs_${{ hashFiles('**/pyproject.toml') }}
key: reqs_${{ hashFiles('**/requirements.txt') }}
restore-keys: reqs
- run: |
mkdir -p ~/.cache/downloads
Expand Down
1 change: 1 addition & 0 deletions addons/bitbucket/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# no requirements
5 changes: 5 additions & 0 deletions addons/boa/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Requirements for the boa add-on
boa-api==0.1.14

# Requirements for running asyncio in celery, using 3.4.1 for Python 3.6 compatibility
asgiref==3.7.2
1 change: 1 addition & 0 deletions addons/box/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
boxsdk==3.9.2
3 changes: 3 additions & 0 deletions addons/dataverse/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Allow for optional timeout parameter.
# https://github.com/IQSS/dataverse-client-python/pull/27
git+https://github.com/CenterForOpenScience/dataverse-client-python.git@2b3827578048e6df3818f82381c7ea9a2395e526 # branch is feature/dv-client-updates
1 change: 1 addition & 0 deletions addons/dropbox/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dropbox==11.36.2
1 change: 1 addition & 0 deletions addons/figshare/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions addons/github/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cachecontrol==0.14.0
github3.py==4.0.1
uritemplate==4.1.1
1 change: 1 addition & 0 deletions addons/gitlab/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-gitlab==4.4.0
2 changes: 2 additions & 0 deletions addons/mendeley/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# up-to-date with mendeley's master + add folder support and future dep updates
git+https://github.com/CenterForOpenScience/mendeley-python-sdk.git@be8a811fa6c3b105d9f5c656cabb6b1ba855ed5b # branch is feature/osf-dep-updates
Empty file.
2 changes: 2 additions & 0 deletions addons/owncloud/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Requirements for the owncloud add-on
pyocclient==0.6.0
1 change: 1 addition & 0 deletions addons/s3/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
boto3==1.34.60
1 change: 1 addition & 0 deletions addons/twofactor/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyotp==2.9.0
1 change: 1 addition & 0 deletions addons/wiki/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pymongo==4.6.3
1 change: 1 addition & 0 deletions addons/zotero/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pyzotero==1.5.18
4 changes: 2 additions & 2 deletions api/base/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from furl import furl
from urllib.parse import urlunsplit, urlsplit, parse_qs, urlencode
from urllib.parse import urlunsplit, urlsplit, parse_qs, urlencode, quote
from packaging.version import Version
from hashids import Hashids

Expand Down Expand Up @@ -236,7 +236,7 @@ def waterbutler_api_url_for(node_id, provider, path='/', _internal=False, base_u
# NOTE: furl encoding to be verified later
url = furl(website_settings.WATERBUTLER_INTERNAL_URL if _internal else (base_url or website_settings.WATERBUTLER_URL))
segments = ['v1', 'resources', node_id, 'providers', provider] + path.split('/')[1:]
url.add(path=segments)
url.add(path=[quote(x) for x in segments])
url.args.update(kwargs)
return url.url

Expand Down
2 changes: 1 addition & 1 deletion api/preprints/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class PreprintSerializer(TaxonomizableSerializerMixin, MetricsSerializerMixin, J
affiliated_institutions = RelationshipField(
related_view='preprints:preprints-institutions',
related_view_kwargs={'preprint_id': '<_id>'},
self_view='preprints:preprints-institutions',
self_view='preprints:preprint-relationships-institutions',
self_view_kwargs={'preprint_id': '<_id>'},
read_only=False,
required=False,
Expand Down
2 changes: 2 additions & 0 deletions api_tests/preprints/views/test_preprint_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def test_return_affiliated_institutions(self, app, user, preprint, institution,
assert res.status_code == 200
relationship_link = res.json['data']['relationships']['affiliated_institutions']['links']['related']['href']
assert f'/v2/preprints/{preprint._id}/institutions/' in relationship_link
relationship_link = res.json['data']['relationships']['affiliated_institutions']['links']['self']['href']
assert f'/v2/preprints/{preprint._id}/relationships/institutions/' in relationship_link


@pytest.mark.django_db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ def institution_E(self):
def institution_F(self):
return InstitutionFactory()


@pytest.fixture()
def admin_with_institutional_affiliation(self, institution_A, institution_B, institution_C, preprint):
def admin_with_institutional_affiliation(self, institution_A, institution_B, institution_C, preprint):
user = AuthUserFactory()
preprint.add_contributor(user, permissions=ADMIN)
user.add_or_update_affiliated_institution(institution_A)
Expand Down
3 changes: 2 additions & 1 deletion api_tests/preprints/views/test_preprint_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def test_return_affiliated_institutions(self):
assert res.content_type == 'application/vnd.api+json'
relationship_link = res.json['data'][0]['relationships']['affiliated_institutions']['links']['related']['href']
assert f'/v2/preprints/{self.preprint._id}/institutions/' in relationship_link

relationship_link = res.json['data'][0]['relationships']['affiliated_institutions']['links']['self']['href']
assert f'/v2/preprints/{self.preprint._id}/relationships/institutions/' in relationship_link

class TestPreprintsListFiltering(PreprintsListFilteringMixin):

Expand Down
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,15 @@ services:
- /bin/bash
- -c
- python -m venv /tmp/venv
&& /tmp/venv/bin/pip install poetry==1.8.3 &&
&& /tmp/venv/bin/pip install poetry==1.8.0 &&
/tmp/venv/bin/poetry install --no-root --without release --compile --sync &&
rm -rf /python3.12/* &&
cp -Rf -p /usr/local/lib/python3.12 /
restart: 'no'
environment:
DJANGO_SETTINGS_MODULE: api.base.settings
volumes:
- ./pyproject.toml:/code/pyproject.toml
- ./poetry.lock:/code/poetry.lock
- ./:/code:cached
- osf_requirements_3_12_vol:/python3.12

assets:
Expand Down
10 changes: 10 additions & 0 deletions osf_tests/metadata/test_osf_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ def test_gather_affiliated_institutions(self):
institution_iri = URIRef(institution.ror_uri)
self.user__admin.add_or_update_affiliated_institution(institution)
self.project.add_affiliated_institution(institution, self.user__admin)
self.preprint.add_affiliated_institution(institution, self.user__admin)
assert_triples(osf_gathering.gather_affiliated_institutions(self.projectfocus), {
(self.projectfocus.iri, OSF.affiliation, institution_iri),
(institution_iri, RDF.type, DCTERMS.Agent),
Expand All @@ -559,6 +560,15 @@ def test_gather_affiliated_institutions(self):
assert_triples(osf_gathering.gather_affiliated_institutions(self.registrationfocus), set())
# focus: file
assert_triples(osf_gathering.gather_affiliated_institutions(self.filefocus), set())
# focus: preprint
assert_triples(osf_gathering.gather_affiliated_institutions(self.preprintfocus), {
(self.preprintfocus.iri, OSF.affiliation, institution_iri),
(institution_iri, RDF.type, DCTERMS.Agent),
(institution_iri, RDF.type, FOAF.Organization),
(institution_iri, FOAF.name, Literal(institution.name)),
(institution_iri, DCTERMS.identifier, Literal(institution.identifier_domain)),
(institution_iri, DCTERMS.identifier, Literal(institution.ror_uri)),
})

def test_gather_funding(self):
# focus: project
Expand Down
Loading

0 comments on commit 61b0eeb

Please sign in to comment.