Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use data from association when validating #2309

Merged
merged 1 commit into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions apps/publish/content/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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):
Expand Down
38 changes: 35 additions & 3 deletions features/content_publish.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2297,26 +2297,40 @@ 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"
"""
[{"name": "Sports"}]
"""
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
"""
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion features/publish_embedded.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down