Skip to content

Commit

Permalink
Merge pull request #1338 from MarkLark86/1.7
Browse files Browse the repository at this point in the history
Release 1.7.0
  • Loading branch information
MarkLark86 authored Sep 20, 2019
2 parents 5b697df + b893414 commit 7608b96
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 20 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Superdesk Planning Changelog

## [1.7.0] Not released yet
## [1.7.0] 2019-09-20
### Features
- [SDESK-4427] New Event action 'Mark as Completed' (#1273)
- [SDNTB-584] feat(draggable): Added ability to make modals draggable (#1294)
Expand All @@ -12,6 +12,7 @@
- [SDESK-4595] Move the attachment icon in lists (#1311)
- [SDESK-4651] Show all desks by default in Fulfil Assignment modal (#1305)
- [SDESK-4676] Hide 'all day' as an event form option (#1320)
- [SDESK-4705] modify the internal note message (#1334)

### Fixes
- [SDESK-4427] Mark for complete fix to cater for events that start on same day but ahead in time. (#1278)
Expand All @@ -28,6 +29,9 @@
- fix(import ui-framework): Add helpers and colors to scss imports (#1323)
- fix to use modal__backdrop class locally (#1326)
- [SDESK-4691] Planning was not published when event was completed (#1330)
- fix(assignment templates) handle missing bits of address, add slugline to subject (#1333)
- [SDESK-4704] Send Assignment notification when Event is updated (#1337)
- [SDNTB-599] 'duplicate_from' was missing when duplicating an Event. (#1335)

## [1.6.2] 2019-08-21
### Features
Expand Down
1 change: 1 addition & 0 deletions client/actions/tests/autosave_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ describe('actions.autosave', () => {
const expectedItem = {
...data.events[1],
_id: 'tempId-e4',
duplicate_from: 'e1',
lock_action: 'create',
lock_user: store.initialState.session.identity._id,
lock_session: store.initialState.session.sessionId,
Expand Down
2 changes: 1 addition & 1 deletion client/constants/autosave.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export const AUTOSAVE = {
INTERVAL: 3000,
IGNORE_FIELDS: ['planning_ids', 'reason', 'update_method', 'expired', 'version', 'previous_recurrence_id',
'versioncreated', 'event_lastmodified', 'relationships', 'expiry', 'duplicate_to', 'original_creator',
'revert_state', 'version_creator', 'duplicate_from', 'unique_id'],
'revert_state', 'version_creator', 'unique_id'],
};
1 change: 1 addition & 0 deletions client/utils/testData.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ export const events = [
},
{
_id: 'e2',
duplicate_from: 'e1',
type: 'event',
slugline: 'test slugline 2',
name: 'Event 2',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "superdesk-planning",
"version": "1.7.0-rc2",
"version": "1.7.0",
"license": "AGPL-3.0",
"description": "",
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion server/features/planning.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ Feature: Planning
"event": "activity",
"extra": {
"activity": {
"message" : "{{coverage_type}} coverage \"slugline\": {{internal_note}}",
"message" : "{{coverage_type}} coverage \"{{slugline}}\" internal note: \"{{internal_note}}\"",
"data" : {
"coverage_type" : "Text",
"internal_note" : "Mostly harmless",
Expand Down
6 changes: 5 additions & 1 deletion server/planning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import jinja2
import os
from datetime import timedelta
from superdesk import register_jinja_filter
from .common import get_formatted_address

from .commands import FlagExpiredItems, DeleteSpikedItems, DeleteMarkedAssignments
import planning.commands # noqa
Expand All @@ -42,7 +44,7 @@
import planning.output_formatters # noqa
from planning.planning_download import init_app as init_planning_download_app

__version__ = '1.7.0-rc2'
__version__ = '1.7.0'


def init_app(app):
Expand Down Expand Up @@ -239,6 +241,8 @@ def init_app(app):
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates'))])
app.jinja_loader = custom_loaders

register_jinja_filter('formatted_address', get_formatted_address)


@celery.task(soft_time_limit=600)
def flag_expired():
Expand Down
1 change: 1 addition & 0 deletions server/planning/assignments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def init_app(app):
app.on_item_lock += assignments_publish_service.validate_assignment_lock
app.on_item_locked += assignments_publish_service.sync_assignment_lock
app.on_item_unlocked += assignments_publish_service.sync_assignment_unlock
app.on_updated_events += assignments_publish_service.on_events_updated

# Track updates for an assignment if it's news story was updated
if app.config.get('PLANNING_LINK_UPDATES_TO_COVERAGES', False):
Expand Down
45 changes: 45 additions & 0 deletions server/planning/assignments/assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,51 @@ def update_assignment_on_archive_operation(self, updates, original, operation=No
no_email=True
)

def on_events_updated(self, updates, original):
"""Send assignment notifications if any relevant Event metadata has changed"""

event = deepcopy(original)
event.update(updates)
plannings = list(get_resource_service('events').get_plannings_for_event(event))

if not plannings:
# If this Event has no associated Planning items
# then there is no need to send notifications
return

changed_fields = []

for field in ['location', 'event_contact_info', 'files', 'links']:
if (updates.get(field) or []) != (original.get(field) or []):
changed_fields.append(field)

if not changed_fields:
# If no relevant Event fields have changed
# then there is no need to send notifications
return

# Add 'assigned_to' details to all the coverages
get_resource_service('planning').generate_related_assignments(plannings)

for planning in plannings:
for coverage in planning.get('coverages') or []:
assigned_to = coverage.get('assigned_to') or {}

slugline = (coverage.get('planning') or {}).get('slugline') or ''
coverage_type = (coverage.get('planning') or {}).get('g2_content_type') or ''

PlanningNotifications().notify_assignment(
coverage_status=(coverage.get('assigned_to') or {}).get('state'),
target_user=assigned_to.get('user'),
target_desk=assigned_to.get('desk') if not assigned_to.get('user') else None,
message='assignment_event_metadata_msg',
slugline=slugline,
coverage_type=get_coverage_type_name(coverage_type),
event=event,
client_url=app.config['CLIENT_URL'],
no_email=True
)

def create_delivery_for_content_update(self, items):
"""Duplicates the coverage/assignment for the archive rewrite
Expand Down
14 changes: 12 additions & 2 deletions server/planning/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def is_locked_in_this_session(item, user_id=None, session_id=None):
return str(item.get(LOCK_USER)) == user_id and str(item.get(LOCK_SESSION)) == session_id


def format_address(location=None):
def format_address(location=None, seperator=' '):
"""Location is enhanced with the formatted address
:param dict location:
Expand All @@ -162,7 +162,17 @@ def format_address(location=None):
formatted_address.append(address.get('postal_code'))
formatted_address.append(address.get('country'))

location['formatted_address'] = " ".join([a for a in formatted_address if a]).strip()
location['formatted_address'] = seperator.join([a for a in formatted_address if a]).strip()


def get_formatted_address(location, seperator=' '):
"""Return the formatted address for the loaction
:param location:
:return:
"""
format_address(location, seperator=seperator)
return location.get('name', '') + seperator + location.get('formatted_address', '')


def get_street_map_url(current_app=None):
Expand Down
16 changes: 8 additions & 8 deletions server/planning/planning/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
class PlanningService(superdesk.Service):
"""Service class for the planning model."""

def __generate_related_assignments(self, docs):
def generate_related_assignments(self, docs):
coverages = {}
for doc in docs:
if not doc.get('coverages'):
Expand Down Expand Up @@ -87,15 +87,15 @@ def __generate_related_assignments(self, docs):
coverage['assigned_to']['priority'] = assignment.get('priority')

def on_fetched(self, docs):
self.__generate_related_assignments(docs.get(config.ITEMS))
self.generate_related_assignments(docs.get(config.ITEMS))

def on_fetched_item(self, doc):
self.__generate_related_assignments([doc])
self.generate_related_assignments([doc])

def find_one(self, req, **lookup):
item = super().find_one(req, **lookup)
if item:
self.__generate_related_assignments([item])
self.generate_related_assignments([item])
for coverage in item.get('coverages', []):
if coverage.get('planning', {}).get('scheduled') and \
not isinstance(coverage['planning']['scheduled'], datetime):
Expand Down Expand Up @@ -132,7 +132,7 @@ def on_created(self, docs):
event_item=doc.get('event_item', None)
)
self._update_event_history(doc)
self.__generate_related_assignments(docs)
self.generate_related_assignments(docs)

def _update_event_history(self, doc):
if 'event_item' not in doc:
Expand Down Expand Up @@ -166,7 +166,7 @@ def on_duplicated(self, doc, parent_id):
)

def on_locked_planning(self, item, user_id):
self.__generate_related_assignments([item])
self.generate_related_assignments([item])

def update(self, id, updates, original):
updates.setdefault('versioncreated', utcnow())
Expand Down Expand Up @@ -248,7 +248,7 @@ def on_updated(self, updates, original):

doc = deepcopy(original)
doc.update(updates)
self.__generate_related_assignments([doc])
self.generate_related_assignments([doc])
updates['coverages'] = doc.get('coverages') or []

posted = update_post_item(updates, original)
Expand Down Expand Up @@ -605,7 +605,7 @@ def duplicate_coverage_for_article_rewrite(self, planning_id, coverage_id, updat
'Planning does not exist'
)

self.__generate_related_assignments([planning])
self.generate_related_assignments([planning])
coverages = planning.get('coverages') or []
try:
coverage = next(c for c in coverages if c.get('coverage_id') == coverage_id)
Expand Down
14 changes: 11 additions & 3 deletions server/planning/planning_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ def _get_email_message_string(message, meta_message, data):
:return: The message with the data applied
"""
template_string = Template(message).render(data)
template_meta_string = render_template(meta_message + '.txt', **data) if meta_message else ''
try:
template_meta_string = render_template(meta_message + '.txt', **data) if meta_message else ''
except Exception:
logger.exception('Failed to apply meta text template: {}'.format(meta_message))
template_meta_string = None

if template_meta_string:
return template_string + '\n\n' + template_meta_string
Expand All @@ -205,7 +209,11 @@ def _get_email_message_html(message, meta_message, data):
:return: The message with the data applied
"""
template_string = Template(message).render(data)
template_meta_string = render_template(meta_message + '.html', **data) if meta_message else ''
try:
template_meta_string = render_template(meta_message + '.html', **data) if meta_message else ''
except Exception:
logger.exception('Failed to apply meta html template: {}'.format(meta_message))
template_meta_string = None

if template_meta_string:
return template_string + '<br><br>' + template_meta_string
Expand Down Expand Up @@ -248,7 +256,7 @@ def _send_user_email(user_id, text_message, html_message, data):
fp = media.read()
attachments.append(Attachment(filename=media.name, content_type=media.content_type, data=fp))

send_email(subject='Superdesk assignment',
send_email(subject='Superdesk assignment' + ': {}'.format(data.get('slugline') if data.get('slugline') else ''),
sender=admins[0],
recipients=[user_email],
text_body=text_message,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The event associated with {{coverage_type}} coverage "{{slugline}}" has been updated
2 changes: 1 addition & 1 deletion server/planning/templates/assignment_internal_note_msg.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{coverage_type}} coverage "slugline": {{internal_note}}
{{coverage_type}} coverage "{{slugline}}" internal note: "{{internal_note}}"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="superdesk-planning",
version="1.7.0-rc2",
version="1.7.0",
package_dir={'': 'server'},
packages=find_packages('server'),
package_data=package_data,
Expand Down

0 comments on commit 7608b96

Please sign in to comment.