diff --git a/admin_tests/preprints/test_views.py b/admin_tests/preprints/test_views.py index 1273a3a6363..d66869bfe95 100644 --- a/admin_tests/preprints/test_views.py +++ b/admin_tests/preprints/test_views.py @@ -22,6 +22,7 @@ from osf.models.spam import SpamStatus from osf.utils.workflows import DefaultStates, RequestTypes from osf.utils.permissions import ADMIN +from framework.auth import Auth from admin_tests.utilities import setup_view, setup_log_view, handle_post_view_request @@ -834,3 +835,42 @@ def test_admin_user_can_add_new_version_one(self, user, preprint, plain_view): preprint.refresh_from_db() assert len(preprint.get_preprint_versions()) == 2 + + def test_osf_admin_can_create_new_version_with_unregistered_contributors(self, plain_view): + # user isn't admin contributor in the preprint + osf_admin = AuthUserFactory() + admin_group = Group.objects.get(name='osf_admin') + admin_group.permissions.add(Permission.objects.get(codename='change_node')) + osf_admin.groups.add(admin_group) + + user = AuthUserFactory() + preprint_admin = AuthUserFactory() + preprint = PreprintFactory(creator=user) + + preprint.add_permission( + preprint_admin, + ADMIN, + save=True + ) + + # assume admin contributor added an unregistered contributor + preprint.add_unregistered_contributor( + 'Rheisen Dennis', + 'reason@gmail.com', + auth=Auth(preprint_admin), + save=True + ) + + # osf admin recreates a new version 1 that forces to add unregistered contributors + # to this preprint + request = RequestFactory().post( + reverse('preprints:re-version-preprint', + kwargs={'guid': preprint._id}), + data={'file_versions': ['1']} + ) + request.user = osf_admin + + plain_view.as_view()(request, guid=preprint._id) + preprint.refresh_from_db() + + assert len(preprint.get_preprint_versions()) == 2 diff --git a/api/institutions/serializers.py b/api/institutions/serializers.py index fac33923905..5beffe60348 100644 --- a/api/institutions/serializers.py +++ b/api/institutions/serializers.py @@ -230,6 +230,9 @@ class Meta: name = ser.CharField(read_only=True) number_of_users = ser.IntegerField(read_only=True) + def get_absolute_url(self, obj): + raise NotImplementedError() + class InstitutionUserMetricsSerializer(JSONAPISerializer): '''serializer for institution-users metrics @@ -285,6 +288,9 @@ def get_contacts(self, obj): ).order_by('sender_name') return list(results) + def get_absolute_url(self, obj): + raise NotImplementedError() + class InstitutionSummaryMetricsSerializer(JSONAPISerializer): '''serializer for institution-summary metrics @@ -316,6 +322,9 @@ class Meta: related_view_kwargs={'institution_id': ''}, ) + def get_absolute_url(self, obj): + raise NotImplementedError() + class InstitutionRelated(JSONAPIRelationshipSerializer): id = ser.CharField(source='_id', required=False, allow_null=True) diff --git a/osf/models/preprint.py b/osf/models/preprint.py index 864f5558e8b..75f9f5f05e2 100644 --- a/osf/models/preprint.py +++ b/osf/models/preprint.py @@ -529,6 +529,7 @@ def create_version(cls, create_from_guid, auth, assign_version_number=None, igno referrer=auth.user, email=contributor.user.email, given_name=contributor.user.fullname, + skip_referrer_permissions=auth.user.groups.filter(name='osf_admin').exists() ) except ValidationError as e: sentry.log_exception(e)