Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WCM-489: add functionality to ignore uniqueids on publish #972

Merged
merged 7 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/docs/changelog/WCM-498.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WCM-498: WCM-489: add functionality to ignore uniqueids on publish
26 changes: 15 additions & 11 deletions core/src/zeit/workflow/publish_3rdparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -437,18 +444,15 @@ 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 {
'properties': self.properties,
'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):
Expand Down
13 changes: 13 additions & 0 deletions core/src/zeit/workflow/tests/test_publish_3rdparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down