Skip to content

Commit

Permalink
Merged from master
Browse files Browse the repository at this point in the history
  • Loading branch information
Tolga Akin committed Mar 26, 2020
2 parents b3da2d8 + 92b64c0 commit cf10f8f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
4 changes: 2 additions & 2 deletions assets/monitoring/components/MonitoringApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MonitoringApp extends React.Component {
<Fragment>
<ListBar
onNewItem={this.isScheduleMode() ? null : this.props.newMonitoringProfile}
buttonText={gettext('New Monitoring Profile')}
buttonName={gettext('Monitoring Profile')}
noSearch>
<div className="btn-group btn-group--navbar ml-0 mr-3">
{this.sections.map((section) => (
Expand Down Expand Up @@ -111,7 +111,7 @@ class MonitoringApp extends React.Component {
if (field === 'company') {
this.props.setCompany(value);
}

this.props.fetchMonitoring();
}
}
Expand Down
4 changes: 2 additions & 2 deletions assets/wire/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}


Expand All @@ -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;
}
Expand Down
10 changes: 6 additions & 4 deletions newsroom/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'))
Expand Down Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions tests/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cf10f8f

Please sign in to comment.