From 39cfe46ab4664eb5f9ec5d9d4bedd643a2b8552d Mon Sep 17 00:00:00 2001 From: John Tordoff <> Date: Tue, 17 Oct 2023 21:26:33 +0800 Subject: [PATCH] use all_tags as m2m value when copying tags --- .../views/test_draft_registration_list.py | 1 - osf/models/mixins.py | 11 +++++++---- osf/models/registrations.py | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api_tests/draft_registrations/views/test_draft_registration_list.py b/api_tests/draft_registrations/views/test_draft_registration_list.py index f7d6a48ad350..3878e9d60014 100644 --- a/api_tests/draft_registrations/views/test_draft_registration_list.py +++ b/api_tests/draft_registrations/views/test_draft_registration_list.py @@ -270,7 +270,6 @@ def test_affiliated_institutions_are_copied_from_node_no_institutions(self, app, """ project = ProjectFactory(is_public=True, creator=user) payload['data']['relationships']['branched_from']['data']['id'] = project._id - res = app.post_json_api( url_draft_registrations, payload, diff --git a/osf/models/mixins.py b/osf/models/mixins.py index 1b7332ca115d..01e22b2f2196 100644 --- a/osf/models/mixins.py +++ b/osf/models/mixins.py @@ -2265,7 +2265,9 @@ def copy_editable_fields( self, resource, alternative_resource=None, include_contributors=True, save=True, excluded_attributes=None ): """ - Copy editable fields from 'resource' to the current object. + Copy editable fields from 'resource' to the current object. DraftRegistrations have different rules for creation + based on whether they are based on OSF Projects or are 'no-project` Registrations that will copu default + metadata information from the user, or some other source other then an OSF Project or Node. :param Object resource: Primary resource to copy attributes from :param Object alternative_resource: Backup resource for copying attributes @@ -2288,17 +2290,18 @@ def copy_editable_fields( self.save() def _copy_basic_attributes(self, resource, alternative_resource, excluded_attributes): - # Copy basic attributes such as title, description, category, and node_license for attribute in ['title', 'description', 'category', 'node_license']: if attribute not in excluded_attributes: self.set_editable_attribute(attribute, resource, alternative_resource) def _copy_m2m_fields(self, resource, alternative_resource, excluded_attributes): - # Copy m2m fields like tags, subjects, and affiliated_institutions m2m_fields = ['tags', 'subjects', 'affiliated_institutions'] for field in m2m_fields: if field not in excluded_attributes: - getattr(self, field).add(*self.stage_m2m_values(field, resource, alternative_resource)) + if field == 'tags': # special case tags with value `all_tags' + self.tags.add(*self.stage_m2m_values('all_tags', resource, alternative_resource)) + else: + getattr(self, field).add(*self.stage_m2m_values(field, resource, alternative_resource)) class Meta: abstract = True diff --git a/osf/models/registrations.py b/osf/models/registrations.py index aba81cf40f18..fe31d306f428 100644 --- a/osf/models/registrations.py +++ b/osf/models/registrations.py @@ -1280,13 +1280,13 @@ def create_from_node(cls, user, schema, node=None, data=None, provider=None): provider=provider, ) draft.save() - draft.update(data, auth=Auth(user)) draft.copy_editable_fields( branched_from, Auth(user), save=True, excluded_attributes=excluded_attributes ) + draft.update(data, auth=Auth(user)) if not node: draft.affiliated_institutions.add(*draft.creator.get_affiliated_institutions())