-
Notifications
You must be signed in to change notification settings - Fork 335
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
[ENG-6668] Add Contributor Page Improvements for Institutional Access #10825
Merged
brianjgeiger
merged 9 commits into
CenterForOpenScience:feature/institutional_access
from
Johnetordoff:institutional-access-insti-admin-validation
Jan 13, 2025
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4e507b1
validate curator's non-biblio status and display details on contrbut…
52d1a43
add is _curator in it's own migration file
d1a7412
refactor and split up permissions checks and improve `.save` conditio…
5c33833
add positive test cases for institutional access project curator vali…
756a53d
redo do contributor.mako logic to work for new more specific curator …
8ef8cd6
ensure insti admins are only labeled as such when they make insti req…
0da606a
revert last commit and fix data model by adding more booleans and ser…
2bbcf07
fix update contributor check
6c8eb0a
fix conditional for is_curator check in contributor management method
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
api_tests/nodes/views/test_node_contributor_insti_admin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import pytest | ||
from osf.models import Contributor | ||
from osf_tests.factories import ( | ||
AuthUserFactory, | ||
ProjectFactory, | ||
InstitutionFactory, | ||
) | ||
from api.base.settings.defaults import API_BASE | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestChangeInstitutionalAdminContributor: | ||
|
||
@pytest.fixture() | ||
def project_admin(self): | ||
return AuthUserFactory() | ||
|
||
@pytest.fixture() | ||
def project_admin2(self): | ||
return AuthUserFactory() | ||
|
||
@pytest.fixture() | ||
def institution(self): | ||
return InstitutionFactory() | ||
|
||
@pytest.fixture() | ||
def institutional_admin(self, institution): | ||
admin_user = AuthUserFactory() | ||
institution.get_group('institutional_admins').user_set.add(admin_user) | ||
return admin_user | ||
|
||
@pytest.fixture() | ||
def project(self, project_admin, project_admin2, institutional_admin): | ||
project = ProjectFactory(creator=project_admin) | ||
project.add_contributor(project_admin2, permissions='admin', visible=False) | ||
project.add_contributor(institutional_admin, visible=False) | ||
return project | ||
|
||
@pytest.fixture() | ||
def url_contrib(self, project, institutional_admin): | ||
return f'/{API_BASE}nodes/{project._id}/contributors/{institutional_admin._id}/' | ||
|
||
def test_cannot_set_institutional_admin_contributor_bibliographic(self, app, project_admin, project, | ||
institutional_admin, url_contrib): | ||
res = app.put_json_api( | ||
url_contrib, | ||
{ | ||
'data': { | ||
'id': f'{project._id}-{institutional_admin._id}', | ||
'type': 'contributors', | ||
'attributes': { | ||
'bibliographic': True, | ||
} | ||
} | ||
}, | ||
auth=project_admin.auth, | ||
expect_errors=True | ||
) | ||
|
||
assert res.status_code == 409 | ||
assert res.json['errors'][0]['detail'] == 'Curators cannot be made bibliographic contributors' | ||
|
||
contributor = Contributor.objects.get( | ||
node=project, | ||
user=institutional_admin | ||
) | ||
assert not contributor.visible |
2 changes: 1 addition & 1 deletion
2
...request_requested_permissions_and_more.py → ...s/0025_contributor_is_curator_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.13 on 2025-01-09 21:22 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('osf', '0025_contributor_is_curator_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='contributor', | ||
name='is_curator', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import pytest | ||
from osf.models import Contributor | ||
from osf_tests.factories import ( | ||
AuthUserFactory, | ||
ProjectFactory, | ||
InstitutionFactory | ||
) | ||
from django.db.utils import IntegrityError | ||
|
||
@pytest.mark.django_db | ||
class TestContributorModel: | ||
|
||
@pytest.fixture() | ||
def user(self): | ||
return AuthUserFactory() | ||
|
||
@pytest.fixture() | ||
def project(self): | ||
return ProjectFactory() | ||
|
||
@pytest.fixture() | ||
def institution(self): | ||
return InstitutionFactory() | ||
|
||
@pytest.fixture() | ||
def institutional_admin(self, institution): | ||
admin_user = AuthUserFactory() | ||
institution.get_group('institutional_admins').user_set.add(admin_user) | ||
return admin_user | ||
|
||
@pytest.fixture() | ||
def curator(self, institutional_admin, project): | ||
return Contributor( | ||
user=institutional_admin, | ||
node=project, | ||
visible=False, | ||
is_curator=True | ||
) | ||
|
||
def test_contributor_with_visible_and_institutional_admin_raises_error(self, curator, project, institution): | ||
curator.save() | ||
curator.visible = True | ||
with pytest.raises(IntegrityError, match='Curators cannot be made bibliographic contributors'): | ||
curator.save() | ||
|
||
assert curator.visible | ||
curator.refresh_from_db() | ||
assert not curator.visible | ||
|
||
# save completes when valid | ||
curator.visible = False | ||
curator.save() | ||
|
||
def test_regular_visible_contributor_is_saved(self, user, project): | ||
contributor = Contributor( | ||
user=user, | ||
node=project, | ||
visible=True, | ||
is_curator=False | ||
) | ||
contributor.save() | ||
saved_contributor = Contributor.objects.get(pk=contributor.pk) | ||
assert saved_contributor.user == user | ||
assert saved_contributor.node == project | ||
assert saved_contributor.visible is True | ||
assert saved_contributor.is_curator is False | ||
|
||
def test_invisible_curator_is_saved(self, institutional_admin, curator, project): | ||
curator.save() | ||
saved_curator = Contributor.objects.get(pk=curator.pk) | ||
assert curator == saved_curator | ||
assert saved_curator.user == institutional_admin | ||
assert saved_curator.node == project | ||
assert saved_curator.visible is False | ||
assert saved_curator.is_curator is True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,8 @@ def serialize_user(user, node=None, admin=False, full=False, is_profile=False, i | |
'surname': user.family_name, | ||
'fullname': fullname, | ||
'shortname': fullname if len(fullname) < 50 else fullname[:23] + '...' + fullname[-23:], | ||
'is_institutional_admin': user.is_institutional_admin(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this for this view? It looks like it's being used, but is it being used properly? See below for more. |
||
'is_curator': user.is_institutional_curator(node), | ||
'profile_image_url': user.profile_image_url(size=settings.PROFILE_IMAGE_MEDIUM), | ||
'active': user.is_active, | ||
} | ||
|
@@ -199,7 +201,10 @@ def serialize_access_requests(node): | |
'requested_permissions': access_request.requested_permissions, | ||
'id': access_request._id | ||
} for access_request in node.requests.filter( | ||
request_type=workflows.RequestTypes.ACCESS.value, | ||
request_type__in=[ | ||
workflows.NodeRequestTypes.ACCESS.value, | ||
workflows.NodeRequestTypes.INSTITUTIONAL_REQUEST.value | ||
], | ||
machine_state=workflows.DefaultStates.PENDING.value | ||
).select_related('creator') | ||
] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overwriting
save
doesn't always cut it, but this looks like that only place we.update
visibility, arguably we want to retain the ability to change the visibility which leans away from placing in DB constraints. However I think this is all visibility updates in the existing code.