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

WEB-4029 : File and Image content types don't have WF so we set effective date equal to created date #5

Merged
merged 1 commit into from
Dec 12, 2023
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
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"])
Loading