Skip to content

Commit

Permalink
Merge pull request #10924 from Ostap-Zherebetskyi/fix/preprint_node
Browse files Browse the repository at this point in the history
[ENG-6886] Bypass for the node permission requirement during version creation
  • Loading branch information
cslzchen authored Jan 17, 2025
2 parents 80d4263 + 36e43f4 commit 4903a34
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions osf/models/preprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4903a34

Please sign in to comment.