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 13, 2023
1 parent 7626a45 commit 2b5fd2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
4 changes: 0 additions & 4 deletions api/nodes/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1618,10 +1618,6 @@ def create(self, validated_data):
if registration_responses:
self.update_registration_responses(draft, registration_responses)

if affiliate_user_institutions and isinstance(draft.branched_from, DraftNode):
for institution in draft.creator.get_institution_affiliations():
draft.affiliated_institutions.add(*draft.creator.affiliated_institutions.all())

return draft

class Meta:
Expand Down
35 changes: 12 additions & 23 deletions osf/models/registrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,42 +1251,31 @@ def system_tags(self):

@classmethod
def create_from_node(cls, user, schema, node=None, data=None, provider=None):
if not provider:
provider = RegistrationProvider.get_default()
provider = provider or 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)
else:
if provider.is_default and provider.schemas.exists() or not provider.is_default:
provider.validate_schema(schema)

excluded_attributes = []
if not node:
# If no node provided, a DraftNode is created for you
node = DraftNode.objects.create(creator=user, title=settings.DEFAULT_DRAFT_NODE_TITLE)
# Force the user to add their own title for no-project
excluded_attributes.append('title')

if not (isinstance(node, Node) or isinstance(node, DraftNode)):
raise DraftRegistrationStateError()
if node:
branched_from = node
excluded_attributes = []
else:
branched_from = DraftNode.objects.create(creator=user, title=settings.DEFAULT_DRAFT_NODE_TITLE)
excluded_attributes = ['title']

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,
save=True,
excluded_attributes=excluded_attributes
)
draft.copy_editable_fields(branched_from, excluded_attributes=excluded_attributes)
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 2b5fd2e

Please sign in to comment.