Skip to content

Commit

Permalink
WEB-4029 : File and Image content types don't have WF so we set effec…
Browse files Browse the repository at this point in the history
…tive date equal to created date
  • Loading branch information
boulch committed Dec 11, 2023
1 parent 1b999d6 commit 4e91e5d
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
1.2.5 (unreleased)
------------------

- Nothing changed yet.
- WEB-4029 : File and Image content types don't have WF so we set effective date equal to created date
[boulch]


1.2.4 (2023-12-07)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"plone.testing>=5.0.0",
"plone.app.robotframework[debug]",
"plone.restapi[test]",
"freezegun",
"mock",
],
},
Expand Down
2 changes: 1 addition & 1 deletion src/imio/smartweb/common/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<version>1024</version>
<version>1025</version>
<dependencies>
<dependency>profile-plone.restapi:default</dependency>
<dependency>profile-eea.facetednavigation:default</dependency>
Expand Down
4 changes: 4 additions & 0 deletions src/imio/smartweb/common/subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from imio.smartweb.common.utils import clean_invisible_char
from plone import api
from plone.app.contenttypes.interfaces import IFile
from plone.app.contenttypes.interfaces import IImage
from plone.app.dexterity.behaviors.metadata import IBasic
from plone.app.textfield.value import IRichTextValue
from plone.app.textfield.value import RichTextValue
Expand Down Expand Up @@ -32,6 +34,8 @@ def reindex_breadcrumb(obj, event):

def added_content(obj, event):
for schema in iterSchemata(obj):
if (IFile).providedBy(obj) or (IImage).providedBy(obj):
obj.setEffectiveDate(obj.created())
for name, field in getFields(schema).items():
value = getattr(obj, name)
if IRichTextValue.providedBy(value):
Expand Down
46 changes: 46 additions & 0 deletions src/imio/smartweb/common/tests/test_subscribers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-

from DateTime import DateTime
from freezegun import freeze_time
from imio.smartweb.common.testing import IMIO_SMARTWEB_COMMON_INTEGRATION_TESTING
from plone import api
from plone.app.contenttypes.interfaces import IFile
from plone.app.contenttypes.interfaces import IImage
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.namedfile.file import NamedBlobFile
from plone.namedfile.file import NamedBlobImage

import unittest


class TestDescription(unittest.TestCase):
layer = IMIO_SMARTWEB_COMMON_INTEGRATION_TESTING

def setUp(self):
"""Custom shared utility setup for tests"""
self.request = self.layer["request"]
self.portal = self.layer["portal"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])

@freeze_time("2023-12-14 9:00:00")
def test_added_content_image(self):
# content types for which effective date is equal to created date (thank to subrscriber)
content_types = ["File", "Image"]
frozen_time = DateTime()

for ct in content_types:
obj = api.content.create(
container=self.portal,
type=ct,
title=f"My {ct}",
)
if IFile.providedBy(obj):
obj.file = NamedBlobFile(data="file data", filename="file.txt")

elif IImage.providedBy(obj):
obj.image = NamedBlobImage(data="file data", filename="file.txt")

self.assertEqual(obj.effective(), frozen_time)
# subscriber added_content fix effective as created date for Image content type
self.assertEqual(obj.effective(), obj.created())
8 changes: 8 additions & 0 deletions src/imio/smartweb/common/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,12 @@
/>
</genericsetup:upgradeSteps>

<genericsetup:upgradeStep
title="Set effective date equal to created_date for File and Image"
source="1024"
destination="1025"
handler=".upgrades.set_effective_date_equal_to_created_date"
profile="imio.smartweb.common:default"
/>

</configure>
17 changes: 17 additions & 0 deletions src/imio/smartweb/common/upgrades/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,20 @@ def fix_missing_values_for_lists(context):
obj.iam = []
catalog.catalog_object(obj, idxs=["iam"])
logger.info(f"Fixed None list for Iam on {obj.absolute_url()}")


def set_effective_date_equal_to_created_date(context):
"""Image and File content types have no workflow
So, effective date was 1969/12/31 00:00:00 GMT+1"""

with api.env.adopt_user(username="admin"):
brains = api.content.find(
portal_type=[
"File",
"Image",
]
)
for brain in brains:
obj = brain.getObject()
obj.setEffectiveDate(obj.created())
obj.reindexObject(idxs=["effective"])

0 comments on commit 4e91e5d

Please sign in to comment.