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

ZO-4687: Store our own date_last_modified instead of relying on DAV #623

Merged
merged 10 commits into from
Feb 16, 2024
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/ZO-4687.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ZO-4687: Store our own date_last_modified instead of relying on DAV
1 change: 0 additions & 1 deletion core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ dependencies = [
"zope.copypastemove",
"zope.deferredimport", # undeclared by zc.form
"zope.dottedname",
"zope.dublincore",
"zope.event",
"zope.exceptions",
"zope.file",
Expand Down
14 changes: 7 additions & 7 deletions core/src/zeit/cms/browser/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from zeit.cms.i18n import MessageFactory as _
import zeit.cms.browser.interfaces
import zeit.cms.content.sources
import zeit.cms.workflow.interfaces


logger = logging.getLogger('zeit.cms.browser.listing')
Expand Down Expand Up @@ -41,18 +42,17 @@ def url(self):

@property
def modifiedOn(self):
return self._dc_date_helper('modified')
return self._date_helper('date_last_modified')

@property
def createdOn(self):
return self._dc_date_helper('created')
return self._date_helper('date_created')

def _dc_date_helper(self, attribute):
try:
times = zope.dublincore.interfaces.IDCTimes(self.context)
except TypeError:
def _date_helper(self, attribute):
modified = zeit.cms.workflow.interfaces.IModified(self.context, None)
if modified is None:
return None
return getattr(times, attribute)
return getattr(modified, attribute)

@property
def type(self):
Expand Down
4 changes: 2 additions & 2 deletions core/src/zeit/cms/browser/listing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ When we have local modifications the we get the third indicator. Let's try some
>>> import zeit.connector.interfaces
>>> import zope.component
>>> connector = zope.component.getUtility(zeit.connector.interfaces.IConnector)
>>> connector._properties[uid][('getlastmodified', 'DAV:')] = (
>>> connector._properties[uid][('date_last_modified', 'http://namespaces.zeit.de/CMS/document')] = (
... datetime.datetime(2007, 12, 6, 12, 00, tzinfo=pytz.UTC).isoformat())

We don't know when the object was published. Assume it's fresh:
Expand Down Expand Up @@ -156,7 +156,7 @@ When the modification date is not known we also assume it is fresh. Note that
this case is rather constructed because in reality all objects have a
modification time.

>>> connector._properties[uid][('getlastmodified', 'DAV:')] = None
>>> connector._properties[uid][('date_last_modified', 'http://namespaces.zeit.de/CMS/document')] = None
>>> browser.open('http://localhost/++skin++cms/repository/online/2007/01')
>>> print(browser.contents)
<?xml ...
Expand Down
1 change: 0 additions & 1 deletion core/src/zeit/cms/browser/objectdetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import zope.annotation.interfaces
import zope.cachedescriptors.property
import zope.component
import zope.dublincore.interfaces
import zope.interface

import zeit.cms.browser.interfaces
Expand Down
2 changes: 1 addition & 1 deletion core/src/zeit/cms/browser/tests/test_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ def test_columns_ignore_exceptions(self):
# Check that the cells are present but empty.
self.assertEllipsis(
'...<td> <span class="filename">testcontent</span> </td>'
' <td> 2008 ... </td> <td> </td> <td> </td>...',
' <td> </td> <td> </td>...',
b.contents,
)
1 change: 0 additions & 1 deletion core/src/zeit/cms/checkout/browser/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import zope.browser.interfaces
import zope.cachedescriptors.property
import zope.component
import zope.dublincore.interfaces
import zope.formlib.form
import zope.i18n

Expand Down
15 changes: 13 additions & 2 deletions core/src/zeit/cms/checkout/manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import grokcore.component as grok
import pendulum
import zope.app.locking.interfaces
import zope.cachedescriptors.property
import zope.component
import zope.container.interfaces
import zope.dublincore.interfaces
import zope.event
import zope.interface
import zope.security.proxy
Expand Down Expand Up @@ -132,18 +132,26 @@ def checkin(self, event=True, semantic_change=None, ignore_conflicts=False, publ
raise zeit.cms.checkout.interfaces.CheckinCheckoutError(
self.context.uniqueId, 'Cannot checkin: %s' % reason
)

workingcopy = self.context.__parent__

modified = zeit.cms.workflow.interfaces.IModified(self.context, None)
if not publishing and modified is not None:
zope.security.proxy.getObject(modified).date_last_modified = pendulum.now()

sc = zeit.cms.content.interfaces.ISemanticChange(self.context)
if semantic_change is None:
semantic_change = sc.has_semantic_change
if semantic_change:
sc.update()
zope.security.proxy.getObject(sc).last_semantic_change = modified.date_last_modified

if event:
zope.event.notify(
zeit.cms.checkout.interfaces.BeforeCheckinEvent(
self.context, workingcopy, self.principal, publishing
)
)

if ignore_conflicts:
adapter_name = 'non-conflicting'
else:
Expand All @@ -152,6 +160,7 @@ def checkin(self, event=True, semantic_change=None, ignore_conflicts=False, publ
self.context, zeit.cms.checkout.interfaces.IRepositoryContent, name=adapter_name
)
del workingcopy[self.context.__name__]

if event:
zope.event.notify(
zeit.cms.checkout.interfaces.AfterCheckinEvent(
Expand All @@ -164,6 +173,7 @@ def checkin(self, event=True, semantic_change=None, ignore_conflicts=False, publ
else:
msg = _('Checked in')
zeit.objectlog.interfaces.ILog(added).log(msg)

lockable = zope.app.locking.interfaces.ILockable(added, None)
# Since publishing starts and ends with its own lock()/unlock(), it
# would be premature to already unlock during the cycle() step.
Expand All @@ -173,6 +183,7 @@ def checkin(self, event=True, semantic_change=None, ignore_conflicts=False, publ
except zope.app.locking.interfaces.LockingError:
# object was not locked
pass

return added

def delete(self):
Expand Down
15 changes: 0 additions & 15 deletions core/src/zeit/cms/content/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,6 @@
<subscriber handler=".xmlsupport.map_dav_property_to_xml" />
<subscriber handler=".xmlsupport.map_dav_properties_to_xml_before_checkin" />

<!-- dublin core -->
<class class=".dublincore.RepositoryDCTimes">
<require
interface="zope.dublincore.interfaces.IDCTimes"
permission="zope.View"
/>
</class>

<class class=".dublincore.LocalDCTimes">
<require
interface="zope.dublincore.interfaces.IDCTimes"
permission="zope.View"
/>
</class>

<!-- semantic changes -->
<class class=".semanticchange.SemanticChange">
<require
Expand Down
42 changes: 0 additions & 42 deletions core/src/zeit/cms/content/dublincore.py

This file was deleted.

67 changes: 0 additions & 67 deletions core/src/zeit/cms/content/dublincore.txt

This file was deleted.

3 changes: 0 additions & 3 deletions core/src/zeit/cms/content/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,6 @@ class ISemanticChange(zope.interface.Interface):
title=_('Update last semantic change'), required=False, default=False
)

def update():
"""Set last semantic change to last modified."""


class IUUID(zope.interface.Interface):
"""Accessing the uuid of a content object."""
Expand Down
7 changes: 2 additions & 5 deletions core/src/zeit/cms/content/semanticchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import zeit.cms.content.dav
import zeit.cms.content.interfaces
import zeit.cms.interfaces
import zeit.cms.workflow.interfaces


@zope.interface.implementer(zeit.cms.content.interfaces.ISemanticChange)
Expand All @@ -29,11 +30,7 @@ def has_semantic_change(self):
@has_semantic_change.setter
def has_semantic_change(self, value):
if value:
self.update()

def update(self):
dc = zope.dublincore.interfaces.IDCTimes(self.context)
self.last_semantic_change = dc.modified
self.last_semantic_change = datetime.datetime.now(pytz.UTC)


hsc_field = zeit.cms.content.interfaces.ISemanticChange['has_semantic_change']
Expand Down
1 change: 0 additions & 1 deletion core/src/zeit/cms/content/tests/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def test_suite():
'contentmemo.txt',
'contentuuid.txt',
'dav.txt',
'dublincore.txt',
'field.txt',
'liveproperty.txt',
'lxmlpickle.txt',
Expand Down
15 changes: 1 addition & 14 deletions core/src/zeit/cms/content/xmlsupport.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from io import StringIO
import datetime

import gocept.lxml.objectify
import grokcore.component as grok
import lxml.objectify
import persistent
import persistent.interfaces
import pytz
import zope.interface
import zope.security.interfaces
import zope.security.proxy
Expand Down Expand Up @@ -110,18 +108,7 @@ class PropertyToXMLAttribute:

def __init__(self, context):
self.context = context
dav_properties = zeit.connector.interfaces.IWebDAVProperties(context)

# Set the date-last-modified to now
try:
dav_properties[
('date-last-modified', zeit.cms.interfaces.DOCUMENT_SCHEMA_NS)
] = datetime.datetime.now(pytz.UTC).isoformat()
except zope.security.interfaces.Forbidden:
# Don't do this for live properties.
pass

self.properties = dict(dav_properties)
self.properties = dict(zeit.connector.interfaces.IWebDAVProperties(context))

# Now get the current live-properties
repository = zope.component.queryUtility(zeit.cms.repository.interfaces.IRepository)
Expand Down
5 changes: 0 additions & 5 deletions core/src/zeit/cms/ftesting-securitypolicy.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<securityPolicy
component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy" />

<include package="zope.dublincore" />
<include package="zeit.cms" file="permissions.zcml" />

<!-- Roles -->
Expand Down Expand Up @@ -79,10 +78,6 @@
<!-- Grants -->
<grantAll role="zope.Manager" />

<grant
principal="zope.Authenticated"
permission="zope.dublincore.view"
/>
<grant
principal="zope.Authenticated"
permission="zope.View"
Expand Down
1 change: 0 additions & 1 deletion core/src/zeit/cms/ui.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@

<!-- Additional packages -->

<include package="zope.dublincore" />
<include package="zope.formlib" />

<include package="zope.i18n.locales"/>
Expand Down
Loading
Loading