Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions admin_tests/preprints/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions api/institutions/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -316,6 +322,9 @@ class Meta:
related_view_kwargs={'institution_id': '<institution_id>'},
)

def get_absolute_url(self, obj):
raise NotImplementedError()


class InstitutionRelated(JSONAPIRelationshipSerializer):
id = ser.CharField(source='_id', required=False, allow_null=True)
Expand Down
1 change: 1 addition & 0 deletions osf/models/preprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading