Skip to content

Commit

Permalink
when publishing associated item use latest changes (#2727)
Browse files Browse the repository at this point in the history
instead of overriding it from the standalone media item
if that was not updated.

SDCP-851
  • Loading branch information
petrjasek authored Oct 9, 2024
1 parent 913eacb commit eade9cb
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/publish/content/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,14 @@ def _set_updates_for_media_items(self, doc, updates):

for key in DEFAULT_SCHEMA.keys():
if doc.get(key):
updates[key] = doc[key]
if (
doc.get("_current_version")
and updates.get("_current_version")
and doc["_current_version"] <= updates["_current_version"]
): # media item was not changed outside, only populate missing data
updates.setdefault(key, doc[key])
else: # media item could be updated outside, so update all fields
updates[key] = doc[key]

def _refresh_associated_items(self, original, skip_related=False):
"""Refreshes associated items with the latest version. Any further updates made to basic metadata done after
Expand Down
66 changes: 66 additions & 0 deletions features/content_publish.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4883,3 +4883,69 @@ Feature: Content Publishing
"""
{"JobId": "1234", "Title": "test publish"}
"""

@auth
Scenario: We update associated picture metadata on publish
Given "archive"
"""
[
{
"_current_version": 1,
"type": "picture",
"guid": "picture",
"slugline": "picture",
"state": "fetched"
},
{
"guid": "story",
"type": "text",
"slugline": "story",
"headline": "story headline",
"state": "in_progress",
"associations": {
"picture": {
"_current_version": 1,
"guid": "picture",
"slugline": "picture",
"state": "fetched",
"type": "picture"
}
}
}
]
"""
And "desks"
"""
[{"name": "Sports", "members":[{"user":"#CONTEXT_USER_ID#"}]}]
"""
When we publish "story" with "publish" type and "published" state
"""
{
"guid": "story",
"type": "text",
"slugline": "story",
"state": "in_progress",
"headline": "story headline",
"associations": {
"picture": {
"_id": "picture",
"_current_version": 1,
"guid": "picture",
"slugline": "updated slugline",
"type": "picture",
"state": "fetched"
}
}
}
"""
Then we get OK response
When we get "/published"
Then we get list with 2 items
"""
{
"_items": [
{"_id": "picture", "slugline": "updated slugline"},
{"_id": "story", "associations": {"picture": {"slugline": "updated slugline"}}}
]
}
"""

0 comments on commit eade9cb

Please sign in to comment.