diff --git a/assets/monitoring/components/MonitoringApp.jsx b/assets/monitoring/components/MonitoringApp.jsx index 7dddf96ac..5a1ab3550 100644 --- a/assets/monitoring/components/MonitoringApp.jsx +++ b/assets/monitoring/components/MonitoringApp.jsx @@ -79,7 +79,7 @@ class MonitoringApp extends React.Component {
{this.sections.map((section) => ( @@ -111,7 +111,7 @@ class MonitoringApp extends React.Component { if (field === 'company') { this.props.setCompany(value); } - + this.props.fetchMonitoring(); } } diff --git a/assets/wire/utils.js b/assets/wire/utils.js index eac00259c..9258df0db 100644 --- a/assets/wire/utils.js +++ b/assets/wire/utils.js @@ -28,7 +28,7 @@ export function getIntVersion(item) { * @return {Array} */ export function getVideos(item) { - return item.type === 'video' ? [item] : Object.values(get(item, 'associations', {})).filter((assoc) => get(assoc, 'type') === 'video'); + return item.type === 'video' ? [item] : Object.values(get(item, 'associations', {}) || {}).filter((assoc) => get(assoc, 'type') === 'video'); } @@ -45,7 +45,7 @@ export function getPicture(item) { } function getBodyPicture(item) { - const pictures = Object.values(get(item, 'associations', {})).filter((assoc) => get(assoc, 'type') === 'picture'); + const pictures = Object.values(get(item, 'associations', {}) || {}).filter((assoc) => get(assoc, 'type') === 'picture'); return pictures.length ? pictures[0] : null; } diff --git a/newsroom/push.py b/newsroom/push.py index 1be533b33..eec764e9d 100644 --- a/newsroom/push.py +++ b/newsroom/push.py @@ -80,8 +80,8 @@ def push(): superdesk.get_resource_service('agenda').enhance_items([agenda]) notify_new_item(agenda, check_topics=True) elif item.get('type') == 'text': - orig = app.data.find_one('wire_search', req=None, _id=item['guid']) - item['_id'] = publish_item(item, is_new=orig is None) + orig = superdesk.get_resource_service('items').find_one(req=None, _id=item['guid']) + item['_id'] = publish_item(item, orig) notify_new_item(item, check_topics=orig is None) elif item['type'] == 'planning_featured': publish_planning_featured(item) @@ -101,7 +101,7 @@ def set_dates(doc): doc.setdefault(app.config['VERSION'], 1) -def publish_item(doc, is_new): +def publish_item(doc, original): """Duplicating the logic from content_api.publish service.""" set_dates(doc) doc['firstpublished'] = parse_date_str(doc.get('firstpublished')) @@ -130,8 +130,10 @@ def publish_item(doc, is_new): agenda_items = superdesk.get_resource_service('agenda').set_delivery(doc) if agenda_items: [notify_new_item(item, check_topics=False) for item in agenda_items] - publish_item_signal.send(app._get_current_object(), item=doc, is_new=is_new) + publish_item_signal.send(app._get_current_object(), item=doc, is_new=original is None) _id = service.create([doc])[0] + if 'associations' not in doc and original is not None and bool(original.get('associations', {})): + service.patch(_id, updates={'associations': None}) if 'evolvedfrom' in doc and parent_item: service.system_update(parent_item['_id'], {'nextversion': _id}, parent_item) return _id diff --git a/tests/test_push.py b/tests/test_push.py index 9e9ffe3a7..a1accbdbd 100644 --- a/tests/test_push.py +++ b/tests/test_push.py @@ -160,6 +160,55 @@ def test_push_featuremedia_generates_renditions(client): assert 200 == resp.status_code +def test_push_update_removes_featuremedia(client): + media_id = str(bson.ObjectId()) + upload_binary('picture.jpg', client, media_id=media_id) + item = { + 'guid': 'test', + 'type': 'text', + 'version': 1, + 'associations': { + 'featuremedia': { + 'type': 'picture', + 'mimetype': 'image/jpeg', + 'renditions': { + '4-3': { + 'media': media_id, + }, + 'baseImage': { + 'media': media_id, + }, + 'viewImage': { + 'media': media_id, + } + } + } + } + } + + resp = client.post('/push', data=json.dumps(item), content_type='application/json') + assert 200 == resp.status_code + + resp = client.get('/wire/test?format=json') + data = json.loads(resp.get_data()) + assert 200 == resp.status_code + assert data['associations'] is not None + + item = { + 'guid': 'test', + 'type': 'text', + 'version': 2, + } + + resp = client.post('/push', data=json.dumps(item), content_type='application/json') + assert 200 == resp.status_code + + resp = client.get('/wire/test?format=json') + data = json.loads(resp.get_data()) + assert 200 == resp.status_code + assert data['associations'] is None + + def test_push_featuremedia_has_renditions_for_existing_media(client): media_id = str(bson.ObjectId()) upload_binary('picture.jpg', client, media_id=media_id)