From 36e43f4ce647e6fdc1b78cb697fc086c9195eea0 Mon Sep 17 00:00:00 2001 From: Ostap Zherebetskyi Date: Fri, 17 Jan 2025 13:22:40 +0200 Subject: [PATCH] added bypass for the node permission requirement during version creation --- osf/models/preprint.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/osf/models/preprint.py b/osf/models/preprint.py index c1109c00c04..11b437841c0 100644 --- a/osf/models/preprint.py +++ b/osf/models/preprint.py @@ -405,8 +405,6 @@ def create_version(cls, create_from_guid, auth): 'copyright_holders': latest_version.license.copyright_holders, 'year': latest_version.license.year } - if latest_version.node: - data_to_update['node'] = latest_version.node # Create a preprint obj for the new version preprint = cls( @@ -452,6 +450,9 @@ def create_version(cls, create_from_guid, auth): guid_obj.content_type = ContentType.objects.get_for_model(preprint) guid_obj.save() + if latest_version.node: + preprint.set_supplemental_node(latest_version.node, auth, save=False, ignore_node_permissions=True) + return preprint, data_to_update @property @@ -984,11 +985,11 @@ def remove_tag(self, tag, auth, save=True): update_or_enqueue_on_preprint_updated(preprint_id=self._id, saved_fields=['tags']) return True - def set_supplemental_node(self, node, auth, save=False): + def set_supplemental_node(self, node, auth, save=False, ignore_node_permissions=False): if not self.has_permission(auth.user, WRITE): raise PermissionsError('You must have write permissions to set a supplemental node.') - if not node.has_permission(auth.user, WRITE): + if not node.has_permission(auth.user, WRITE) and not ignore_node_permissions: raise PermissionsError('You must have write permissions on the supplemental node to attach.') if node.is_deleted: