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
7 changes: 7 additions & 0 deletions api/preprints/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,13 @@ def create(self, validated_data):
raise Conflict(detail='Failed to create a new preprint version due to unpublished pending version exists.')
if not preprint:
raise NotFound(detail='Failed to create a new preprint version due to source preprint not found.')
for contributor in preprint.contributor_set.filter(user__is_registered=False):
contributor.user.add_unclaimed_record(
claim_origin=preprint,
referrer=auth.user,
email=contributor.user.email,
given_name=contributor.user.fullname,
)
if data_to_update:
return self.update(preprint, data_to_update)
return preprint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def handle(self, *args, **options):
dry_run = options.get('dry_run', False)
update_unclaimed_records_for_preprint_versions(dry_run=dry_run)

def safe_sort_key(x, delimiter):
parts = x.split(delimiter)
if len(parts) > 1:
try:
return int(parts[1])
except (ValueError, TypeError):
return 0
return 0


def update_unclaimed_records_for_preprint_versions(dry_run=False):
Preprint = apps.get_model('osf.Preprint')
Expand Down Expand Up @@ -70,13 +79,15 @@ def update_unclaimed_records_for_preprint_versions(dry_run=False):
latest_version_number = latest_version_through.version
unregistered_contributors = preprint.contributor_set.filter(user__is_registered=False)
logger.info(f'Found {unregistered_contributors.count()} unregistered contributors for preprint {preprint._id}')

delimiter = Preprint.GUID_VERSION_DELIMITER
for contributor in unregistered_contributors:
try:
records_key_for_current_guid = [key for key in contributor.user.unclaimed_records.keys() if guid in key]
records_key_for_current_guid = [
key for key in contributor.user.unclaimed_records.keys() if guid in key and delimiter in key
]
if records_key_for_current_guid:
records_key_for_current_guid.sort(
key=lambda x: int(x.split(Preprint.GUID_VERSION_DELIMITER)[1]),
key=lambda x: safe_sort_key(x, delimiter),
)
record_info = contributor.user.unclaimed_records[records_key_for_current_guid[0]]
for current_version in range(1, int(latest_version_number) + 1):
Expand All @@ -101,7 +112,6 @@ def update_unclaimed_records_for_preprint_versions(dry_run=False):
referrer=referrer,
given_name=record_info.get('name', None),
email=record_info.get('email', None),
provided_pid=preprint_id,
)
contributor.user.save()
updated_count += 1
Expand All @@ -127,7 +137,6 @@ def update_unclaimed_records_for_preprint_versions(dry_run=False):
referrer=current_preprint.creator,
given_name=contributor.user.fullname,
email=contributor.user.username,
provided_pid=preprint_id,
)
contributor.user.save()
updated_count += 1
Expand Down
Loading