diff --git a/api/actions/serializers.py b/api/actions/serializers.py index d572ee41654..a4ab5b71d83 100644 --- a/api/actions/serializers.py +++ b/api/actions/serializers.py @@ -26,6 +26,7 @@ ) from osf.utils.workflows import ( + ApprovalStates, DefaultStates, DefaultTriggers, ReviewStates, @@ -278,6 +279,31 @@ def create(self, validated_data): comment = validated_data.pop('comment', '') user = validated_data.pop('user') + pending_schema_response_updates = target.schema_responses.filter( + reviews_state__in=[ + ApprovalStates.UNAPPROVED.db_name, + ApprovalStates.PENDING_MODERATION.db_name, + ], + previous_response__isnull=False, # Only updates, not initial submissions + ).order_by('-created') + + if pending_schema_response_updates.exists(): + pending_response = pending_schema_response_updates.first() + short_message = 'This registration has a pending update' + long_message = ( + f'This registration has a pending schema response update (ID: {pending_response._id}) ' + f'that must be moderated. Please use the schema response actions endpoint to approve or reject ' + f'the update instead of creating a registration action.' + ) + raise HTTPError( + http_status.HTTP_400_BAD_REQUEST, + data={ + 'message_short': short_message, + 'message_long': long_message, + 'schema_response_id': pending_response._id, + }, + ) + sanction = target.sanction try: