Beispiel #1
0
    def delete(self, lookup):
        """
        Overriding to handle with Kill workflow in the Archived repo:
            1. Check if Article has an associated Digital Story and if Digital Story has more Takes.
               If both Digital Story and more Takes exists then all of them would be killed along with the one requested
            2. For each article being killed do the following:
                i.   Apply the Kill Template and create an entry in archive, archive_versions and published collections.
                ii.  Query the Publish Queue in Legal Archive and find the subscribers who received the article
                     previously and create transmission entries in Publish Queue.
                iii. Change the state of the article to Killed in Legal Archive.
                iv.  Delete all the published versions from Archived.
                v.   Send a broadcast email to all subscribers.
        :param lookup: query to find the article in archived repo
        :type lookup: dict
        """

        if app.testing and len(lookup) == 0:
            super().delete(lookup)
            return

        # Step 1
        articles_to_kill = self._find_articles_to_kill(lookup)
        articles_to_kill.sort(key=itemgetter(ITEM_TYPE), reverse=True)  # Needed because package has to be inserted last
        kill_service = KillPublishService()

        for article in articles_to_kill:
            # Step 2(i)
            to_apply_template = {'template_name': 'kill', 'item': article}
            get_resource_service('content_templates_apply').post([to_apply_template])
            article = to_apply_template['item']
            self._remove_and_set_kill_properties(article, articles_to_kill)

            # Step 2(ii)
            transmission_details = list(
                get_resource_service(LEGAL_PUBLISH_QUEUE_NAME).get(req=None,
                                                                   lookup={'item_id': article[config.ID_FIELD]}))

            if transmission_details:
                subscriber_ids = [t['_subscriber_id'] for t in transmission_details]
                query = {'$and': [{config.ID_FIELD: {'$in': subscriber_ids}}]}
                subscribers = list(get_resource_service('subscribers').get(req=None, lookup=query))

                kill_service.queue_transmission(article, subscribers)

            # Step 2(iii)
            import_into_legal_archive.apply_async(kwargs={'doc': article})

            # Step 2(iv)
            super().delete({'item_id': article[config.ID_FIELD]})

            # Step 2(i) - Creating entries in published collection
            docs = [article]
            get_resource_service(ARCHIVE).post(docs)
            insert_into_versions(doc=article)
            get_resource_service('published').post(docs)

            # Step 2(v)
            kill_service.broadcast_kill_email(article)
Beispiel #2
0
    def update(self, id, updates, original):
        """
        Overriding to handle with Kill workflow in the Archived repo:
            1. Check if Article has an associated Digital Story and if Digital Story has more Takes.
               If both Digital Story and more Takes exists then all of them would be killed along with the one requested
            2. If the item is flagged as archived only then it was never created by or published from the system so all
                that needs to be done is to delete it and send an email to all subscribers
            3. For each article being killed do the following:
                i.   Create an entry in archive, archive_versions and published collections.
                ii.  Query the Publish Queue in Legal Archive and find the subscribers who received the article
                     previously and create transmission entries in Publish Queue.
                iii. Change the state of the article to Killed in Legal Archive.
                iv.  Delete all the published versions from Archived.
                v.   Send a broadcast email to all subscribers.
        :param id: primary key of the item to be killed
        :type id: str
        :param updates: updates to be applied on the article before saving
        :type updates: dict
        :param original:
        :type original: dict
        """

        # Step 1
        articles_to_kill = self._find_articles_to_kill({'_id': id})
        logger.info('Fetched articles to kill for id: {}'.format(id))
        articles_to_kill.sort(
            key=itemgetter(ITEM_TYPE),
            reverse=True)  # Needed because package has to be inserted last

        updated = original.copy()
        updated.update(updates)

        for article in articles_to_kill:

            # Step 2, If it is flagged as archived only it has no related items in the system so can be deleted.
            # An email is sent to all subscribers
            if original.get('flags', {}).get('marked_archived_only', False):
                super().delete({'item_id': article['item_id']})
                logger.info('Delete for article: {}'.format(
                    article[config.ID_FIELD]))

                KillPublishService().broadcast_kill_email(article)
                logger.info('Broadcast kill email for article: {}'.format(
                    article[config.ID_FIELD]))
                continue

            # Step 3(i)
            self._remove_and_set_kill_properties(article, articles_to_kill,
                                                 updated)
            logger.info(
                'Removing and setting properties for article: {}'.format(
                    article[config.ID_FIELD]))

            # Step 3(ii)
            transmission_details = list(
                get_resource_service(LEGAL_PUBLISH_QUEUE_NAME).get(
                    req=None, lookup={'item_id': article['item_id']}))

            if transmission_details:
                subscriber_ids = [
                    t['_subscriber_id'] for t in transmission_details
                ]
                query = {'$and': [{config.ID_FIELD: {'$in': subscriber_ids}}]}
                subscribers = list(
                    get_resource_service('subscribers').get(req=None,
                                                            lookup=query))

                EnqueueKilledService().queue_transmission(article, subscribers)
                logger.info('Queued Transmission for article: {}'.format(
                    article[config.ID_FIELD]))

            article[config.ID_FIELD] = article.pop('item_id',
                                                   article['item_id'])

            # Step 3(iv)
            super().delete({'item_id': article[config.ID_FIELD]})
            logger.info('Delete for article: {}'.format(
                article[config.ID_FIELD]))

            # Step 3(i) - Creating entries in published collection
            docs = [article]
            get_resource_service(ARCHIVE).post(docs)
            insert_into_versions(doc=article)
            published_doc = deepcopy(article)
            published_doc[QUEUE_STATE] = PUBLISH_STATE.QUEUED
            get_resource_service('published').post([published_doc])
            logger.info(
                'Insert into archive and published for article: {}'.format(
                    article[config.ID_FIELD]))

            # Step 3(iii)
            import_into_legal_archive.apply_async(
                countdown=3, kwargs={'item_id': article[config.ID_FIELD]})
            logger.info('Legal Archive import for article: {}'.format(
                article[config.ID_FIELD]))

            # Step 3(v)
            KillPublishService().broadcast_kill_email(article)
            logger.info('Broadcast kill email for article: {}'.format(
                article[config.ID_FIELD]))
Beispiel #3
0
    def update(self, id, updates, original):
        """
        Overriding to handle with Kill workflow in the Archived repo:
            1. Check if Article has an associated Digital Story and if Digital Story has more Takes.
               If both Digital Story and more Takes exists then all of them would be killed along with the one requested
            2. If the item is flagged as archived only then it was never created by or published from the system so all
                that needs to be done is to delete it and send an email to all subscribers
            3. For each article being killed do the following:
                i.   Create an entry in archive, archive_versions and published collections.
                ii.  Query the Publish Queue in Legal Archive and find the subscribers who received the article
                     previously and create transmission entries in Publish Queue.
                iii. Change the state of the article to Killed in Legal Archive.
                iv.  Delete all the published versions from Archived.
                v.   Send a broadcast email to all subscribers.
        :param id: primary key of the item to be killed
        :type id: str
        :param updates: updates to be applied on the article before saving
        :type updates: dict
        :param original:
        :type original: dict
        """

        # Step 1
        articles_to_kill = self._find_articles_to_kill({'_id': id})
        logger.info('Fetched articles to kill for id: {}'.format(id))
        articles_to_kill.sort(key=itemgetter(ITEM_TYPE), reverse=True)  # Needed because package has to be inserted last
        kill_service = KillPublishService()

        updated = original.copy()
        updated.update(updates)

        for article in articles_to_kill:

            # Step 2, If it is flagged as archived only it has no related items in the system so can be deleted.
            # An email is sent to all subscribers
            if original.get('flags', {}).get('marked_archived_only', False):
                super().delete({'item_id': article['item_id']})
                logger.info('Delete for article: {}'.format(article[config.ID_FIELD]))

                kill_service.broadcast_kill_email(article)
                logger.info('Broadcast kill email for article: {}'.format(article[config.ID_FIELD]))
                continue

            # Step 3(i)
            self._remove_and_set_kill_properties(article, articles_to_kill, updated)
            kill_service.apply_kill_override(article, article)
            logger.info('Removing and setting properties for article: {}'.format(article[config.ID_FIELD]))

            # Step 3(ii)
            transmission_details = list(
                get_resource_service(LEGAL_PUBLISH_QUEUE_NAME).get(req=None,
                                                                   lookup={'item_id': article['item_id']}))

            if transmission_details:
                subscriber_ids = [t['_subscriber_id'] for t in transmission_details]
                query = {'$and': [{config.ID_FIELD: {'$in': subscriber_ids}}]}
                subscribers = list(get_resource_service('subscribers').get(req=None, lookup=query))

                EnqueueKilledService().queue_transmission(article, subscribers)
                logger.info('Queued Transmission for article: {}'.format(article[config.ID_FIELD]))

            article[config.ID_FIELD] = article.pop('item_id', article['item_id'])

            # Step 3(iv)
            super().delete({'item_id': article[config.ID_FIELD]})
            logger.info('Delete for article: {}'.format(article[config.ID_FIELD]))

            # Step 3(i) - Creating entries in published collection
            docs = [article]
            get_resource_service(ARCHIVE).post(docs)
            insert_into_versions(doc=article)
            published_doc = deepcopy(article)
            published_doc[QUEUE_STATE] = PUBLISH_STATE.QUEUED
            get_resource_service('published').post([published_doc])
            logger.info('Insert into archive and published for article: {}'.format(article[config.ID_FIELD]))

            # Step 3(iii)
            import_into_legal_archive.apply_async(countdown=3, kwargs={'item_id': article[config.ID_FIELD]})
            logger.info('Legal Archive import for article: {}'.format(article[config.ID_FIELD]))

            # Step 3(v)
            kill_service.broadcast_kill_email(article)
            logger.info('Broadcast kill email for article: {}'.format(article[config.ID_FIELD]))
Beispiel #4
0
    def delete(self, lookup):
        """
        Overriding to handle with Kill workflow in the Archived repo:
            1. Check if Article has an associated Digital Story and if Digital Story has more Takes.
               If both Digital Story and more Takes exists then all of them would be killed along with the one requested
            2. For each article being killed do the following:
                i.   Apply the Kill Template and create an entry in archive, archive_versions and published collections.
                ii.  Query the Publish Queue in Legal Archive and find the subscribers who received the article
                     previously and create transmission entries in Publish Queue.
                iii. Change the state of the article to Killed in Legal Archive.
                iv.  Delete all the published versions from Archived.
                v.   Send a broadcast email to all subscribers.
        :param lookup: query to find the article in archived repo
        :type lookup: dict
        """

        if app.testing and len(lookup) == 0:
            super().delete(lookup)
            return

        # Step 1
        articles_to_kill = self._find_articles_to_kill(lookup)
        articles_to_kill.sort(
            key=itemgetter(ITEM_TYPE),
            reverse=True)  # Needed because package has to be inserted last
        kill_service = KillPublishService()

        for article in articles_to_kill:
            # Step 2(i)
            to_apply_template = {'template_name': 'kill', 'item': article}
            get_resource_service('content_templates_apply').post(
                [to_apply_template])
            article = to_apply_template['item']
            self._remove_and_set_kill_properties(article, articles_to_kill)

            # Step 2(ii)
            transmission_details = list(
                get_resource_service(LEGAL_PUBLISH_QUEUE_NAME).get(
                    req=None, lookup={'item_id': article[config.ID_FIELD]}))

            if transmission_details:
                subscriber_ids = [
                    t['_subscriber_id'] for t in transmission_details
                ]
                query = {'$and': [{config.ID_FIELD: {'$in': subscriber_ids}}]}
                subscribers = list(
                    get_resource_service('subscribers').get(req=None,
                                                            lookup=query))

                kill_service.queue_transmission(article, subscribers)

            # Step 2(iii)
            import_into_legal_archive.apply_async(kwargs={'doc': article})

            # Step 2(iv)
            super().delete({'item_id': article[config.ID_FIELD]})

            # Step 2(i) - Creating entries in published collection
            docs = [article]
            get_resource_service(ARCHIVE).post(docs)
            insert_into_versions(doc=article)
            get_resource_service('published').post(docs)

            # Step 2(v)
            kill_service.broadcast_kill_email(article)