diff --git a/apps/archive/archive.py b/apps/archive/archive.py index 9bab997751..20dd6765fa 100644 --- a/apps/archive/archive.py +++ b/apps/archive/archive.py @@ -464,8 +464,13 @@ def _handle_media_updates(self, updates, original, user): item_id = item_obj[config.ID_FIELD] media_item = self.find_one(req=None, _id=item_id) - if app.settings.get("COPY_METADATA_FROM_PARENT") and item_obj.get(ITEM_TYPE) in MEDIA_TYPES: - stored_item = (original.get(ASSOCIATIONS) or {}).get(item_name) or item_obj + parent = (original.get(ASSOCIATIONS) or {}).get(item_name) or item_obj + if ( + app.settings.get("COPY_METADATA_FROM_PARENT") + and item_obj.get(ITEM_TYPE) in MEDIA_TYPES + and item_id == parent.get(config.ID_FIELD) + ): + stored_item = parent else: stored_item = media_item if not stored_item: diff --git a/features/archive.feature b/features/archive.feature index 76a2931d2b..6ccdff4d6c 100644 --- a/features/archive.feature +++ b/features/archive.feature @@ -1285,3 +1285,256 @@ Feature: News Items Archive } } """ + + @auth + @vocabulary + Scenario: Update feature media with different item and copy metadata flag + Given "archive" + """ + [ + { + "guid": "tag:example.com,0000:newsml_BRE9A605", + "associations": { + "featuremedia": { + "_id": "urn:newsml:localhost:5000:2018-12-14T11:31:26.088056:5c45850b-2985-42b3-9ae3-a42ad3c3bc28", + "media": "5c13867efe985edfc9223480", + "type": "picture", + "format": "HTML", + "renditions": { + "original": { + "href": "http://localhost:5000/api/upload-raw/orig.jpg", + "media": "orig", + "mimetype": "image/jpeg", + "width": 4032, + "height": 3024, + "poi": { + "x": 3024, + "y": 756 + } + }, + "baseImage": { + "href": "http://localhost:5000/api/upload-raw/baseImage.jpg", + "media": "baseImage", + "mimetype": "image/jpeg", + "width": 1400, + "height": 1050, + "poi": { + "x": 1050, + "y": 262 + } + }, + "thumbnail": { + "href": "http://localhost:5000/api/upload-raw/thumbnail.jpg", + "media": "thumbnail", + "mimetype": "image/jpeg", + "width": 160, + "height": 120, + "poi": { + "x": 120, + "y": 30 + } + }, + "viewImage": { + "href": "http://localhost:5000/api/upload-raw/viewImage.jpg", + "media": "viewImage", + "mimetype": "image/jpeg", + "width": 640, + "height": 480, + "poi": { + "x": 480, + "y": 120 + } + }, + "4-3": { + "poi": { + "x": 3012, + "y": 759 + }, + "CropLeft": 12, + "CropRight": 4032, + "CropTop": -3, + "CropBottom": 3024, + "width": 800, + "height": 600, + "href": "http://localhost:5000/api/upload-raw/600x800.jpg", + "media": "600x800", + "mimetype": "image/jpeg" + } + } + } + } + }, + { + "_id": "urn:newsml:localhost:5000:2018-12-14T11:31:26.088056:5c45850b-2985-42b3-9ae3-new", + "type": "picture", + "format": "HTML", + "renditions": { + "original": { + "href": "http://localhost:5000/api/upload-raw/orig_new.jpg", + "media": "orig", + "mimetype": "image/jpeg", + "width": 4032, + "height": 3024, + "poi": { + "x": 3024, + "y": 756 + } + }, + "baseImage": { + "href": "http://localhost:5000/api/upload-raw/baseImage_new.jpg", + "media": "baseImage", + "mimetype": "image/jpeg", + "width": 1400, + "height": 1050, + "poi": { + "x": 1050, + "y": 262 + } + }, + "thumbnail": { + "href": "http://localhost:5000/api/upload-raw/thumbnail_new.jpg", + "media": "thumbnail", + "mimetype": "image/jpeg", + "width": 160, + "height": 120, + "poi": { + "x": 120, + "y": 30 + } + }, + "viewImage": { + "href": "http://localhost:5000/api/upload-raw/viewImage_new.jpg", + "media": "viewImage", + "mimetype": "image/jpeg", + "width": 640, + "height": 480, + "poi": { + "x": 480, + "y": 120 + } + } + } + } + ] + """ + Then we set copy metadata from parent flag + When we patch given + """ + { + "associations": { + "featuremedia": { + "_id": "urn:newsml:localhost:5000:2018-12-14T11:31:26.088056:5c45850b-2985-42b3-9ae3-new", + "media": "5c13867efe985edfc9223480", + "type": "picture", + "format": "HTML", + "renditions": { + "original": { + "href": "http://localhost:5000/api/upload-raw/orig_new.jpg", + "media": "orig_new", + "mimetype": "image/jpeg", + "width": 4032, + "height": 3024, + "poi": { + "x": 3024, + "y": 756 + } + }, + "baseImage": { + "href": "http://localhost:5000/api/upload-raw/baseImage_new.jpg", + "media": "baseImage_new", + "mimetype": "image/jpeg", + "width": 1400, + "height": 1050, + "poi": { + "x": 1050, + "y": 262 + } + }, + "thumbnail": { + "href": "http://localhost:5000/api/upload-raw/thumbnail_new.jpg", + "media": "thumbnail_new", + "mimetype": "image/jpeg", + "width": 160, + "height": 120, + "poi": { + "x": 120, + "y": 30 + } + }, + "viewImage": { + "href": "http://localhost:5000/api/upload-raw/viewImage_new.jpg", + "media": "viewImage_new", + "mimetype": "image/jpeg", + "width": 640, + "height": 480, + "poi": { + "x": 480, + "y": 120 + } + } + } + } + } + } + """ + When we get "/archive/tag:example.com,0000:newsml_BRE9A605" + Then we get existing resource + """ + { + "associations": { + "featuremedia": { + "_id": "urn:newsml:localhost:5000:2018-12-14T11:31:26.088056:5c45850b-2985-42b3-9ae3-new", + "media": "5c13867efe985edfc9223480", + "type": "picture", + "format": "HTML", + "renditions": { + "original": { + "href": "http://localhost:5000/api/upload-raw/orig_new.jpg", + "media": "orig_new", + "mimetype": "image/jpeg", + "width": 4032, + "height": 3024, + "poi": { + "x": 3024, + "y": 756 + } + }, + "baseImage": { + "href": "http://localhost:5000/api/upload-raw/baseImage_new.jpg", + "media": "baseImage_new", + "mimetype": "image/jpeg", + "width": 1400, + "height": 1050, + "poi": { + "x": 1050, + "y": 262 + } + }, + "thumbnail": { + "href": "http://localhost:5000/api/upload-raw/thumbnail_new.jpg", + "media": "thumbnail_new", + "mimetype": "image/jpeg", + "width": 160, + "height": 120, + "poi": { + "x": 120, + "y": 30 + } + }, + "viewImage": { + "href": "http://localhost:5000/api/upload-raw/viewImage_new.jpg", + "media": "viewImage_new", + "mimetype": "image/jpeg", + "width": 640, + "height": 480, + "poi": { + "x": 480, + "y": 120 + } + }, + "4-3": "__none__" + } + } + } + } + """