diff --git a/core/docs/changelog/WCM-498.change b/core/docs/changelog/WCM-498.change new file mode 100644 index 0000000000..1ede20c23a --- /dev/null +++ b/core/docs/changelog/WCM-498.change @@ -0,0 +1 @@ +WCM-498: WCM-489: add functionality to ignore uniqueids on publish \ No newline at end of file diff --git a/core/src/zeit/workflow/publish_3rdparty.py b/core/src/zeit/workflow/publish_3rdparty.py index c8d58e4886..63243920c8 100644 --- a/core/src/zeit/workflow/publish_3rdparty.py +++ b/core/src/zeit/workflow/publish_3rdparty.py @@ -249,9 +249,10 @@ class IgnoreMixin: #: map article attributes to settings attr_setting_mapping = { - 'genre': 'genres', - 'template': 'templates', - 'ressort': 'ressorts', + 'genre': ('genres', zeit.content.article.interfaces.IArticleMetadata), + 'template': ('templates', zeit.content.article.interfaces.IArticleMetadata), + 'ressort': ('ressorts', zeit.cms.content.interfaces.ICommonMetadata), + 'uniqueId': ('uniqueids', zeit.cms.interfaces.ICMSContent), } @property @@ -260,15 +261,21 @@ def name(self): return self.__class__.__dict__['grokcore.component.directive.name'] def ignore(self, method): - if self.context.product and self.context.product.is_news: + if ( + zeit.cms.content.interfaces.ICommonMetadata.providedBy(self.context) + and self.context.product + and self.context.product.is_news + ): return True if method == 'publish': for attribute, setting in self.attr_setting_mapping.items(): - if self.is_on_ignorelist(attribute, setting): + if self.is_on_ignorelist(attribute, *setting): return True return False - def is_on_ignorelist(self, attribute, setting): + def is_on_ignorelist(self, attribute, setting, interface): + if not interface.providedBy(self.context): + return False ignore_list = ( zeit.cms.config.get('zeit.workflow', f'{self.name}-ignore-{setting}', '') .lower() @@ -437,8 +444,8 @@ class CenterPageIndexNow(grok.Adapter, IndexNowMixin): grok.name('indexnow') -class DataScienceMixin(PropertiesMixin): - def publish_json(self): +class DataScienceMixin(PropertiesMixin, IgnoreMixin): + def _json(self): if self.properties is None: return None return { @@ -446,9 +453,6 @@ def publish_json(self): 'body': lxml.etree.tostring(self.context.xml, encoding='unicode'), } - def retract_json(self): - return {} - @grok.implementer(zeit.workflow.interfaces.IPublisherData) class ArticleDataScience(grok.Adapter, DataScienceMixin): diff --git a/core/src/zeit/workflow/tests/test_publish_3rdparty.py b/core/src/zeit/workflow/tests/test_publish_3rdparty.py index 2e792f6653..bb3b6dfc43 100644 --- a/core/src/zeit/workflow/tests/test_publish_3rdparty.py +++ b/core/src/zeit/workflow/tests/test_publish_3rdparty.py @@ -580,6 +580,19 @@ def test_datascience_payload_article(self): payload = zeit.workflow.testing.publish_json(article, 'datascience') self.assertEqual(payload['body'], lxml.etree.tostring(article.xml, encoding=str)) + def test_datascience_payload_ignore_article(self): + article = zeit.content.article.testing.create_article() + zeit.cms.config.set( + 'zeit.workflow', + 'datascience-ignore-uniqueids', + 'http://xml.zeit.de/article http://xml.zeit.de/article-two', + ) + p = article.body.create_item('p') + p.text = 'foo' + article = self.repository['article'] = article + payload = zeit.workflow.testing.publish_json(article, 'datascience') + self.assertEqual(payload, None) + def test_datascience_payload_centerpage(self): cp = self.repository['testcontent'] zope.interface.alsoProvides(cp, zeit.content.cp.interfaces.ICenterPage)