def _broadcast_kill_email(self, original): """ Sends the broadcast email to all subscribers (including in-active subscribers) :param original: Document to kill """ # Get all subscribers subscribers = list(get_resource_service('subscribers').get(req=None, lookup=None)) recipients = [s.get('email') for s in subscribers if s.get('email')] # send kill email. send_article_killed_email(original, recipients, utcnow())
def broadcast_kill_email(self, original, updates): """ Sends the broadcast email to all subscribers (including in-active subscribers) :param dict original: Document to kill :param dict updates: kill updates """ # Get all subscribers subscribers = list(get_resource_service('subscribers').get(req=None, lookup=None)) recipients = [s.get('email').split(',') for s in subscribers if s.get('email')] recipients = list(set(chain(*recipients))) # send kill email. kill_article = deepcopy(original) kill_article['body_html'] = updates.get('body_html') kill_article['desk_name'] = get_resource_service('desks').get_desk_name(kill_article.get('task', {}).get('desk')) kill_article['city'] = get_dateline_city(kill_article.get('dateline')) send_article_killed_email(kill_article, recipients, utcnow())
def broadcast_kill_email(self, original, updates): """Sends the broadcast email to all subscribers (including in-active subscribers) :param dict original: Document to kill :param dict updates: kill updates """ # Get all subscribers subscribers = list(get_resource_service('subscribers').get(req=None, lookup=None)) recipients = [s.get('email').split(',') for s in subscribers if s.get('email')] recipients = list(set(chain(*recipients))) # send kill email. kill_article = deepcopy(original) kill_article['body_html'] = updates.get('body_html') kill_article['headline'] = updates.get('headline') kill_article['desk_name'] = get_resource_service('desks').get_desk_name(kill_article.get('task', {}).get('desk')) kill_article['city'] = get_dateline_city(kill_article.get('dateline')) kill_article['action'] = self.item_operation send_article_killed_email(kill_article, recipients, utcnow())
def broadcast_kill_email(self, original, updates): """Sends the broadcast email to all subscribers (including in-active subscribers) :param dict original: Document to kill :param dict updates: kill updates """ # Get all subscribers subscribers = list(get_resource_service("subscribers").get(req=None, lookup=None)) recipients = [s.get("email").split(",") for s in subscribers if s.get("email")] recipients = list(set(chain(*recipients))) # send kill email. kill_article = deepcopy(original) kill_article["body_html"] = updates.get("body_html") kill_article["headline"] = updates.get("headline") kill_article["desk_name"] = get_resource_service("desks").get_desk_name( kill_article.get("task", {}).get("desk") ) kill_article["city"] = get_dateline_city(kill_article.get("dateline")) kill_article["action"] = self.item_operation send_article_killed_email(kill_article, recipients, utcnow())
def test_send_email_kill_for_AAP(self): with self.app.app_context(): with self.app.mail.record_messages() as outbox: assert len(outbox) == 0 article = { 'place': [{'qcode': 'NSW', 'name': 'NSW'}], 'slugline': 'slugline', 'dateline': { 'located': { 'city': 'Test, Test' }, 'text': 'Test, Test, July 9 AAP -' }, 'body_html': 'body', 'desk_name': 'Sports', 'city': 'Test, Test' } send_article_killed_email(article, ['*****@*****.**'], utcnow()) self.assertEqual(len(outbox), 1) self.assertEqual(outbox[0].subject, 'Kill Notification') self.assertIn('body', outbox[0].body)
def test_send_email_kill_for_NZN(self): with self.app.app_context(): with self.app.mail.record_messages() as outbox: assert len(outbox) == 0 article = { 'headline': 'headline', 'place': [{'qcode': 'NSW', 'name': 'NSW'}], 'slugline': 'slugline', 'dateline': { 'located': { 'city': 'Test, Test' }, 'text': 'Test, Test, July 9 AAP -' }, 'body_html': 'body', 'desk_name': 'New Zealand', 'city': 'Test, Test' } send_article_killed_email(article, ['*****@*****.**'], utcnow()) self.assertEqual(len(outbox), 1) self.assertEqual(outbox[0].subject, 'Transmission from circuit: E_KILL_') self.assertIn('body', outbox[0].body)
def publish(self, doc, updates, target_media_type=None): """ 1. Sets the Metadata Properties - source and pubstatus 2. Formats and queues the article to subscribers based on the state of the article: a. If the state of the article is killed then: i. An email should be sent to all Subscribers irrespective of their status. ii. The article should be formatted as per the type of the format and then queue article to the Subscribers who received the article previously. b. If the state of the article is corrected then: i. The article should be formatted as per the type of the format and then queue article to the Subscribers who received the article previously. ii. Fetch Active Subscribers and exclude those who received the article previously. iii. If article has 'targeted_for' property then exclude subscribers of type Internet from Subscribers list. iv. For each subscriber in the list, check if the article matches against publish filters and global filters if configured for the subscriber. If matches then the article should be formatted as per the type of the format and then queue article to the subscribers. c. If the state of the article is published then: i. Fetch Active Subscribers. ii. If article has 'targeted_for' property then exclude subscribers of type Internet from Subscribers list. iii. For each subscriber in the list, check if the article matches against publish filters and global filters if configured for the subscriber. If matches then the article should be formatted as per the type of the format and then queue article. 3. Sends notification if no formatter has found for any of the formats configured in Subscriber. """ queued = True no_formatters = [] updated = doc.copy() # Step 1 if updates: desk = None if doc.get('task', {}).get('desk'): desk = get_resource_service('desks').find_one(req=None, _id=doc['task']['desk']) if not doc.get('ingest_provider'): updates['source'] = desk['source'] if desk and desk.get('source', '') \ else DEFAULT_SOURCE_VALUE_FOR_MANUAL_ARTICLES updates['pubstatus'] = PUB_STATUS.CANCELED if self.publish_type == 'killed' else PUB_STATUS.USABLE updated.update(updates) # Step 2(a) if self.published_state == 'killed': req = ParsedRequest() req.sort = '[("completed_at", 1)]' queued_items = get_resource_service('publish_queue').get( req=req, lookup={'item_id': updated[config.ID_FIELD]}) if queued_items.count(): queued_items = list(queued_items) # Step 2(a)(i) subscribers = list(get_resource_service('subscribers').get(req=None, lookup=None)) recipients = [s.get('email') for s in subscribers if s.get('email')] send_article_killed_email(doc, recipients, queued_items[0].get('completed_at')) # Step 2(a)(ii) no_formatters, queued = self.queue_transmission(updated, subscribers, None) elif self.published_state == 'corrected': # Step 2(b) subscribers, subscribers_yet_to_receive = self.get_subscribers(updated) if subscribers: no_formatters, queued = self.queue_transmission(updated, subscribers) if subscribers_yet_to_receive: # Step 2(b)(iv) formatters_not_found, queued_new_subscribers = \ self.queue_transmission(updated, subscribers_yet_to_receive, target_media_type) no_formatters.extend(formatters_not_found) elif self.published_state == 'published': # Step 2(c) subscribers, subscribers_yet_to_receive = self.get_subscribers(updated) # Step 2(c)(iii) no_formatters, queued = self.queue_transmission(updated, subscribers, target_media_type) # Step 3 user = get_user() if len(no_formatters) > 0: push_notification('item:publish:wrong:format', item=str(doc[config.ID_FIELD]), unique_name=doc['unique_name'], desk=str(doc.get('task', {}).get('desk', '')), user=str(user.get(config.ID_FIELD, '')), formats=no_formatters) if not target_media_type and not queued: raise PublishQueueError.item_not_queued_error(Exception('Nothing is saved to publish queue'), None) return queued