From 6ac0c86b9e184dbcac12b01ff1611d35602448f2 Mon Sep 17 00:00:00 2001 From: Petr Jasek Date: Wed, 22 Dec 2021 15:42:58 +0100 Subject: [PATCH] use data from association when validating SDESK-6345 --- apps/publish/content/common.py | 9 ++++---- features/content_publish.feature | 38 ++++++++++++++++++++++++++++--- features/publish_embedded.feature | 2 +- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/apps/publish/content/common.py b/apps/publish/content/common.py index 1d5fb0a257..061380c442 100644 --- a/apps/publish/content/common.py +++ b/apps/publish/content/common.py @@ -618,7 +618,7 @@ def _validate_associated_items(self, original_item, updates=None, validation_err associations = deepcopy(original_item.get(ASSOCIATIONS, {})) associations.update(updates.get(ASSOCIATIONS, {})) - items = [value for value in associations.values()] + items = [value for value in associations.values() if value] if original_item[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE and self.publish_type == ITEM_PUBLISH: items.extend(self.package_service.get_residrefs(original_item)) @@ -629,10 +629,9 @@ def _validate_associated_items(self, original_item, updates=None, validation_err for item in items: orig = None if type(item) == dict and item.get(config.ID_FIELD): - doc = item - orig = super().find_one(req=None, _id=item[config.ID_FIELD]) - if not app.settings.get("COPY_METADATA_FROM_PARENT") and orig: - doc = orig + orig = super().find_one(req=None, _id=item[config.ID_FIELD]) or {} + doc = copy(orig) + doc.update(item) try: doc.update({"lock_user": orig["lock_user"]}) except (TypeError, KeyError): diff --git a/features/content_publish.feature b/features/content_publish.feature index 9d50e29cdb..adaa6895a5 100644 --- a/features/content_publish.feature +++ b/features/content_publish.feature @@ -2297,7 +2297,8 @@ Feature: Content Publishing """ [{"_id": "publish_embedded", "type": "picture", "act": "publish", "embedded": true, "schema": {"headline": {"type": "string","required": true}}}, - {"_id": "publish_text", "type": "text", "act": "publish", "schema": {}}] + {"_id": "publish_text", "type": "text", "act": "publish", "schema": {}} + ] """ And "desks" """ @@ -2305,18 +2306,31 @@ Feature: Content Publishing """ And "archive" """ - [{"guid": "123", "type": "text", "headline": "test", "_current_version": 1, "state": "in_progress", + [ + {"_id": "234", "type": "picture", "_current_version": 1, "guid": "234", "state": "in_progress"}, + {"guid": "123", "type": "text", "headline": "test", "_current_version": 1, "state": "in_progress", "task": {"desk": "#desks._id#", "stage": "#desks.incoming_stage#", "user": "#CONTEXT_USER_ID#"}, "subject":[{"qcode": "17004000", "name": "Statistics"}], "body_html": "Test Document body", "associations": { "featureimage": { "_id": "234", + "_current_version": 1, "guid": "234", "alt_text": "alt_text", "description_text": "description_text", "type": "picture", "slugline": "s234", - "state": "in_progress"}}}] + "state": "in_progress" + } + } + } + ] + """ + And "content_types" + """ + [ + {"_id": "picture", "schema": {"headline": {"required": true}, "copyrightholder": {"required": true}}} + ] """ When we post to "/products" with success """ @@ -2337,6 +2351,24 @@ Feature: Content Publishing """ {"_issues": {"validator exception": "[[\"MEDIA'S HEADLINE is a required field\"]]"}, "_status": "ERR"} """ + When we publish "#archive._id#" with "publish" type and "published" state + """ + { + "associations": { + "featureimage": { + "headline": "test", + "_id": "234", + "guid": "234", + "alt_text": "alt_text", + "description_text": "description_text", + "type": "picture", + "slugline": "s234", + "state": "in_progress" + } + } + } + """ + Then we get ok response @auth Scenario: Publish fails when embedded item does not exist diff --git a/features/publish_embedded.feature b/features/publish_embedded.feature index a17fdaeea7..2ed3ed280a 100644 --- a/features/publish_embedded.feature +++ b/features/publish_embedded.feature @@ -520,7 +520,7 @@ Feature: Publish embedded items feature When we publish "foo" with "publish" type and "published" state Then we get error 400 """ - {"_issues": {"validator exception": "['Associated item #archive._id#: SLUGLINE is a required field']"}} + {"_issues": {"validator exception": "['Associated item test: SLUGLINE is a required field']"}} """ Then we set copy metadata from parent flag When we publish "foo" with "publish" type and "published" state