Skip to content

Commit

Permalink
CR Response
Browse files Browse the repository at this point in the history
* Fixed self url for PreprintsInstitutionsRelationshipSerializer
* Removed the superfluous 'html' link that is not part of JSON:API
* Fixed incorrect tests
  • Loading branch information
cslzchen committed Sep 16, 2024
1 parent 9bcd800 commit f7fda0a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
6 changes: 1 addition & 5 deletions api/preprints/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,14 +625,10 @@ class PreprintsInstitutionsRelationshipSerializer(BaseAPISerializer):

links = LinksField({
'self': 'get_self_url',
'html': 'get_related_url',
})

def get_self_url(self, obj):
return obj['self'].absolute_api_v2_url

def get_related_url(self, obj):
return f"{obj['self'].absolute_api_v2_url}institutions/"
return obj['self'].institutions_relationship_url

class Meta:
type_ = 'institutions'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,22 @@ def test_update_affiliated_institutions_remove_write_user(self, app, write_user_
preprint.affiliated_institutions.add(institution_A)
preprint.save()
update_institutions_payload = {'data': []}
res = app.put_json_api(url, update_institutions_payload, auth=write_user_with_institutional_affiliation.auth, expect_errors=True)
res = app.put_json_api(url, update_institutions_payload, auth=write_user_with_institutional_affiliation.auth)
assert res.status_code == 200
preprint.reload()
assert institution_A in preprint.affiliated_institutions.all()

def test_update_affiliated_institutions_remove_admin_without_affiliation(self, app, admin_without_institutional_affiliation, preprint, url, institution_A):
"""
Test that admins without affiliation can remove institutions.
Test that admins without affiliation cannot remove institutions.
"""
preprint.affiliated_institutions.add(institution_A)
preprint.save()
update_institutions_payload = {'data': []}
res = app.put_json_api(url, update_institutions_payload, auth=admin_without_institutional_affiliation.auth)
assert res.status_code == 200
preprint.reload()
assert institution_A in preprint.affiliated_institutions.all()

def test_update_affiliated_institutions_remove_admin_with_affiliation(self, app, admin_with_institutional_affiliation, preprint, url, institution_A):
"""
Expand All @@ -198,16 +202,16 @@ def test_update_affiliated_institutions_remove_admin_with_affiliation(self, app,

def test_preprint_institutions_list_get_unauthenticated(self, app, url):
"""
Test that unauthenticated users cannot retrieve the list of affiliated institutions for a preprint.
Test that unauthenticated users can retrieve the list of affiliated institutions for a preprint.
"""
res = app.get(url, expect_errors=True)
res = app.get(url)
assert res.status_code == 200

def test_preprint_institutions_list_get_no_permissions(self, app, user, url):
"""
Test that users without permissions cannot retrieve the list of affiliated institutions for a preprint.
Test that users without permissions can retrieve the list of affiliated institutions for a preprint.
"""
res = app.get(url, auth=user.auth, expect_errors=True)
res = app.get(url, auth=user.auth)
assert res.status_code == 200

def test_preprint_institutions_list_get_read_user(self, app, read_user_with_institutional_affiliation, preprint, url):
Expand Down
4 changes: 4 additions & 0 deletions osf/models/preprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ def display_absolute_url(self):
def linked_nodes_self_url(self):
return self.absolute_api_v2_url + 'relationships/node/'

@property
def institutions_relationship_url(self):
return self.absolute_api_v2_url + 'relationships/institutions/'

@property
def admin_contributor_or_group_member_ids(self):
# Overrides ContributorMixin
Expand Down

0 comments on commit f7fda0a

Please sign in to comment.