Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-6845][ENG-6864] Fix contributors during preprint version creation #10899

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
15 changes: 7 additions & 8 deletions osf/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,15 +1383,14 @@ def add_contributor(self, contributor, permissions=None, visible=True,
)
if save:
self.save()
# TODO: Remove this comment after `Preprint.save()` has been fixed. There is a bug for Preprint when the
# first `.save()` is called. It triggers a series of events which includes adding creator as one
# contributor. However, with versioned guid, there is a gap between when preprint os saved and when
# guid and versioned guid are saved. During this gap, `self._id` is unfortunately `None` and the
# signal can not be be sent.
if self._id and contrib_to_add:
project_signals.contributor_added.send(self,
contributor=contributor,
auth=auth, email_template=send_email, permissions=permissions)
project_signals.contributor_added.send(
self,
contributor=contributor,
auth=auth,
email_template=send_email,
permissions=permissions
)

# enqueue on_node_updated/on_preprint_updated to update DOI metadata when a contributor is added
if getattr(self, 'get_identifier_value', None) and self.get_identifier_value('doi'):
Expand Down
19 changes: 15 additions & 4 deletions osf/models/preprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
from osf.exceptions import (
PreprintStateError,
InvalidTagError,
TagNotFoundError
TagNotFoundError,
UserStateError,
ValidationValueError,
)
from django.contrib.postgres.fields import ArrayField
from api.share.utils import update_share
Expand Down Expand Up @@ -427,9 +429,18 @@ def create_version(cls, create_from_guid, auth):
preprint.save(guid_ready=True, first_save=True)

# Add contributors
for contributor_info in latest_version.contributor_set.exclude(user=latest_version.creator).values('visible', 'user_id', '_order'):
preprint.contributor_set.create(**{**contributor_info, 'preprint_id': preprint.id})

for contributor in latest_version.contributor_set.exclude(user=latest_version.creator):
try:
preprint.add_contributor(
contributor.user,
permissions=contributor.permission,
visible=contributor.visible,
save=True
)
except (ValidationValueError, UserStateError) as e:
sentry.log_exception(e)
sentry.log_message(f'Contributor was not added to new preprint version due to error: '
f'[preprint={preprint._id}, user={contributor.user._id}]')
# Add affiliated institutions
for institution in latest_version.affiliated_institutions.all():
preprint.add_affiliated_institution(institution, auth.user, ignore_user_affiliation=True)
Expand Down
Loading