Skip to content

Commit

Permalink
Update Preprint Serializer and Views for New Fields and Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Uditi Mehta authored and Uditi Mehta committed Aug 2, 2024
1 parent 0b6a3da commit 55e7b97
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
7 changes: 7 additions & 0 deletions api/preprints/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,13 @@ def update(self, preprint, validated_data):
save_preprint = False
recently_published = False

status_changed = False

primary_file = validated_data.pop('primary_file', None)
if primary_file:
self.set_field(preprint.set_primary_file, primary_file, auth)
save_preprint = True
status_changed = True

old_tags = set(preprint.tags.values_list('name', flat=True))
if 'tags' in validated_data:
Expand Down Expand Up @@ -426,6 +429,10 @@ def update(self, preprint, validated_data):
if save_preprint:
preprint.save()

if status_changed:
preprint.status = 'waiting_for_moderation'
preprint.save()

if recently_published:
for author in preprint.contributors:
if author != auth.user:
Expand Down
31 changes: 30 additions & 1 deletion api/preprints/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rest_framework import permissions as drf_permissions

from framework.auth.oauth_scopes import CoreScopes
from osf.models import ReviewAction, Preprint, PreprintContributor
from osf.models import ReviewAction, Preprint, PreprintContributor, PreprintLog
from osf.utils.requests import check_select_for_update

from api.actions.permissions import ReviewActionPermission
Expand Down Expand Up @@ -197,6 +197,35 @@ def get_parser_context(self, http_request):
res['legacy_type_allowed'] = True
return res

def perform_update(self, serializer):
instance = serializer.save()
request = self.request
auth = get_user_auth(request)

if 'primary_file' in request.data:
instance.set_primary_file(instance.primary_file, auth)
instance.add_log(
action=PreprintLog.FILE_UPDATED,
params={
'preprint': instance._id,
'file': instance.primary_file._id
},
auth=auth,
)

if 'is_published' in request.data:
published = request.data['is_published']
instance.set_published(published, auth)
if published:
instance.add_log(
action=PreprintLog.PUBLISHED,
params={'preprint': instance._id},
auth=auth,
)
instance.notify_user_submitted(auth.user)

instance.save()


class PreprintNodeRelationship(JSONAPIBaseView, generics.RetrieveUpdateAPIView, PreprintMixin):
permission_classes = (
Expand Down

0 comments on commit 55e7b97

Please sign in to comment.