Skip to content

Commit

Permalink
fix draft registrations affiliated institution default value for no-p…
Browse files Browse the repository at this point in the history
…roject registrations and clean-up code
  • Loading branch information
John Tordoff committed Oct 16, 2023
1 parent b032af0 commit 6ebb513
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
10 changes: 0 additions & 10 deletions api/nodes/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -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:
Expand Down
17 changes: 8 additions & 9 deletions osf/models/registrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,25 +1261,24 @@ def create_from_node(cls, user, schema, node=None, data=None, provider=None):
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')

if not (isinstance(node, Node) or isinstance(node, DraftNode)):
raise DraftRegistrationStateError()
if node:
branched_from = node
else:
branched_from = DraftNode.objects.create(creator=user, title='Untitled')

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)
draft.update(data, auth=Auth(user))

if node.type == 'osf.draftnode':
if not node:
draft.affiliated_institutions.add(*draft.creator.get_institution_affiliations())
initiator_permissions = draft.contributor_set.get(user=user).permission
signals.contributor_added.send(
draft,
Expand Down

0 comments on commit 6ebb513

Please sign in to comment.