From c46e4437ecbe3a70a1f5aee4a84de3b90eb974d5 Mon Sep 17 00:00:00 2001 From: John Tordoff <> Date: Mon, 16 Oct 2023 21:26:41 +0800 Subject: [PATCH] fix draft registrations affiliated institution default value for no-project registrations and clean-up code --- api/nodes/serializers.py | 10 ---------- osf/models/registrations.py | 20 +++++++++----------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/api/nodes/serializers.py b/api/nodes/serializers.py index aaff14ac1b95..918f156ce3de 100644 --- a/api/nodes/serializers.py +++ b/api/nodes/serializers.py @@ -1557,12 +1557,6 @@ class DraftRegistrationLegacySerializer(JSONAPISerializer): 'html': 'get_absolute_url', }) - affiliate_user_institutions = ser.BooleanField( - required=False, - default=True, - help_text='Specify whether user institution affiliations should be copied over to the draft registration.', - ) - def get_absolute_url(self, obj): return obj.absolute_url @@ -1603,7 +1597,6 @@ def create(self, validated_data): registration_responses = validated_data.pop('registration_responses', None) schema = validated_data.pop('registration_schema') provider = validated_data.pop('provider', None) - affiliate_user_institutions = validated_data.pop('affiliate_user_institutions', True) self.enforce_metadata_or_registration_responses(metadata, registration_responses) @@ -1618,9 +1611,6 @@ def create(self, validated_data): if registration_responses: self.update_registration_responses(draft, registration_responses) - if affiliate_user_institutions and draft.branched_from_type == DraftNode: - draft.affiliated_institutions.set(draft.creator.affiliated_institutions.all()) - return draft class Meta: diff --git a/osf/models/registrations.py b/osf/models/registrations.py index acf50e6d385d..df82699b299c 100644 --- a/osf/models/registrations.py +++ b/osf/models/registrations.py @@ -1254,32 +1254,30 @@ def create_from_node(cls, user, schema, node=None, data=None, provider=None): if not provider: provider = RegistrationProvider.get_default() - if provider.is_default: - # If the default provider doesn't have schemas specified yet, allow all schemas - if provider.schemas.exists(): - provider.validate_schema(schema) + # Check if the provider is the default one and if it has schemas specified. + if provider.is_default and not provider.schemas.exists(): + provider.validate_schema(schema) else: provider.validate_schema(schema) - if not node: - # If no node provided, a DraftNode is created for you - node = DraftNode.objects.create(creator=user, title='Untitled') + branched_from = node or DraftNode.objects.create(creator=user, title='Untitled') - if not (isinstance(node, Node) or isinstance(node, DraftNode)): + if not isinstance(branched_from, (Node, DraftNode)): raise DraftRegistrationStateError() draft = cls( initiator=user, - branched_from=node, + branched_from=branched_from, registration_schema=schema, registration_metadata=data or {}, provider=provider, ) draft.save() - draft.copy_editable_fields(node, Auth(user), save=True) + draft.copy_editable_fields(branched_from, Auth(user), save=True) draft.update(data, auth=Auth(user)) - if node.type == 'osf.draftnode': + if not node: + draft.affiliated_institutions.add(*draft.creator.get_affiliated_institutions()) initiator_permissions = draft.contributor_set.get(user=user).permission signals.contributor_added.send( draft,