Skip to content

Commit 9b15446

Browse files
[ENG-9060] Osf admin can recreate preprint version 1 with unregistered contributors (#11362)
* osf admin can recreate preprint version 1 with unregistered contributors * fix test (#11394) * fix test * fix other serializers * linting * osf admin can recreate preprint version 1 with unregistered contributors --------- Co-authored-by: Yuhuai Liu <[email protected]>
1 parent 9337848 commit 9b15446

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

admin_tests/preprints/test_views.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from osf.models.spam import SpamStatus
2323
from osf.utils.workflows import DefaultStates, RequestTypes
2424
from osf.utils.permissions import ADMIN
25+
from framework.auth import Auth
2526

2627
from admin_tests.utilities import setup_view, setup_log_view, handle_post_view_request
2728

@@ -834,3 +835,42 @@ def test_admin_user_can_add_new_version_one(self, user, preprint, plain_view):
834835
preprint.refresh_from_db()
835836

836837
assert len(preprint.get_preprint_versions()) == 2
838+
839+
def test_osf_admin_can_create_new_version_with_unregistered_contributors(self, plain_view):
840+
# user isn't admin contributor in the preprint
841+
osf_admin = AuthUserFactory()
842+
admin_group = Group.objects.get(name='osf_admin')
843+
admin_group.permissions.add(Permission.objects.get(codename='change_node'))
844+
osf_admin.groups.add(admin_group)
845+
846+
user = AuthUserFactory()
847+
preprint_admin = AuthUserFactory()
848+
preprint = PreprintFactory(creator=user)
849+
850+
preprint.add_permission(
851+
preprint_admin,
852+
ADMIN,
853+
save=True
854+
)
855+
856+
# assume admin contributor added an unregistered contributor
857+
preprint.add_unregistered_contributor(
858+
'Rheisen Dennis',
859+
860+
auth=Auth(preprint_admin),
861+
save=True
862+
)
863+
864+
# osf admin recreates a new version 1 that forces to add unregistered contributors
865+
# to this preprint
866+
request = RequestFactory().post(
867+
reverse('preprints:re-version-preprint',
868+
kwargs={'guid': preprint._id}),
869+
data={'file_versions': ['1']}
870+
)
871+
request.user = osf_admin
872+
873+
plain_view.as_view()(request, guid=preprint._id)
874+
preprint.refresh_from_db()
875+
876+
assert len(preprint.get_preprint_versions()) == 2

osf/models/preprint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ def create_version(cls, create_from_guid, auth, assign_version_number=None, igno
532532
referrer=auth.user,
533533
email=contributor.user.email,
534534
given_name=contributor.user.fullname,
535+
skip_referrer_permissions=auth.user.groups.filter(name='osf_admin').exists()
535536
)
536537
except ValidationError as e:
537538
sentry.log_exception(e)

0 commit comments

Comments
 (0)