Skip to content

Commit 7ce2d49

Browse files
sgeulettechris-adam
authored andcommitted
Added iconified related steps in migration
1 parent c635b36 commit 7ce2d49

File tree

10 files changed

+201
-9
lines changed

10 files changed

+201
-9
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Changelog
1818
[sgeulette]
1919
- Used session from imio.esign.
2020
[sgeulette]
21+
- Added 'imio.annex' and iconified categories to dms files and dms appendix files.
22+
[chris-adam]
2123

2224
3.0 (2021-09-30)
2325
----------------

imio/dms/mail/examples.py

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from collective.dms.mailcontent.dmsmail import internalReferenceOutgoingMailDefaultValue
1313
from collective.dms.mailcontent.dmsmail import mailDateDefaultValue
1414
from collective.dms.mailcontent.dmsmail import receptionDateDefaultValue
15+
from collective.iconifiedcategory.utils import calculate_category_id
1516
from DateTime.DateTime import DateTime
1617
from imio.dms.mail import _tr as _
1718
from imio.dms.mail import BLDT_DIR
@@ -98,8 +99,10 @@ def add_test_annexes_types(context):
9899
site = context.getSite()
99100
logger.info("Adding annexes types")
100101
ccc = site["annexes_types"]
102+
103+
# Content Category Group for classification folders
101104
if "annexes" not in ccc:
102-
category_group = api.content.create(
105+
annexes_category_group = api.content.create(
103106
type="ContentCategoryGroup",
104107
title="Annexes",
105108
container=ccc,
@@ -108,10 +111,11 @@ def add_test_annexes_types(context):
108111
# to_be_printed_activated=True,
109112
# signed_activated=True,
110113
# publishable_activated=True,
114+
# approved_activated=True,
111115
)
112-
do_transitions(category_group, ["show_internally"])
116+
do_transitions(annexes_category_group, ["show_internally"])
113117
else:
114-
category_group = ccc["annexes"]
118+
annexes_category_group = ccc["annexes"]
115119
icats = (
116120
("annex", u"Annexe", u"attach.png", True),
117121
("deliberation", u"Délibération", u"deliberation_signed.png", True),
@@ -129,7 +133,92 @@ def add_test_annexes_types(context):
129133
type="ContentCategory",
130134
title=title,
131135
description=u"",
132-
container=category_group,
136+
container=annexes_category_group,
137+
icon=icon,
138+
id=oid,
139+
predefined_title=title,
140+
# confidential=True,
141+
# to_print=True,
142+
# to_sign=True,
143+
# signed=True,
144+
# publishable=True,
145+
# only_pdf=True,
146+
show_preview=show_pv,
147+
)
148+
149+
# Content Category Group for dms main files and dms appendix files
150+
if "signable_files" not in ccc:
151+
signable_files_category_group = api.content.create(
152+
type="ContentCategoryGroup",
153+
title="Fichiers signables",
154+
container=ccc,
155+
id="signable_files",
156+
# confidentiality_activated=True,
157+
to_be_printed_activated=True,
158+
signed_activated=True,
159+
# publishable_activated=True,
160+
approved_activated=True,
161+
)
162+
do_transitions(signable_files_category_group, ["show_internally"])
163+
else:
164+
signable_files_category_group = ccc["signable_files"]
165+
icats = (
166+
("signable-ged-file", u"Fichier signable", u"attach.png", True),
167+
)
168+
for oid, title, img, show_pv in icats:
169+
if oid in ccc["signable_files"]:
170+
continue
171+
icon_path = os.path.join(context._profile_path, "images", img)
172+
with open(icon_path, "rb") as fl:
173+
icon = NamedBlobImage(fl.read(), filename=img)
174+
api.content.create(
175+
type="ContentCategory",
176+
title=title,
177+
description=u"",
178+
container=signable_files_category_group,
179+
icon=icon,
180+
id=oid,
181+
predefined_title=title,
182+
# confidential=True,
183+
# to_print=True,
184+
# to_sign=True,
185+
# signed=True,
186+
# publishable=True,
187+
# only_pdf=True,
188+
# approved=False,
189+
show_preview=show_pv,
190+
)
191+
192+
# Content Category Group for dms main files and dms appendix files
193+
if "classic_files" not in ccc:
194+
classic_files_category_group = api.content.create(
195+
type="ContentCategoryGroup",
196+
title="Fichiers classiques",
197+
container=ccc,
198+
id="classic_files",
199+
# confidentiality_activated=True,
200+
# to_be_printed_activated=True,
201+
# signed_activated=True,
202+
# publishable_activated=True,
203+
# approved_activated=True,
204+
)
205+
do_transitions(classic_files_category_group, ["show_internally"])
206+
else:
207+
classic_files_category_group = ccc["classic_files"]
208+
icats = (
209+
("classic-ged-file", u"Fichier classique", u"attach.png", True),
210+
)
211+
for oid, title, img, show_pv in icats:
212+
if oid in ccc["classic_files"]:
213+
continue
214+
icon_path = os.path.join(context._profile_path, "images", img)
215+
with open(icon_path, "rb") as fl:
216+
icon = NamedBlobImage(fl.read(), filename=img)
217+
api.content.create(
218+
type="ContentCategory",
219+
title=title,
220+
description=u"",
221+
container=classic_files_category_group,
133222
icon=icon,
134223
id=oid,
135224
predefined_title=title,
@@ -139,6 +228,7 @@ def add_test_annexes_types(context):
139228
# signed=True,
140229
# publishable=True,
141230
# only_pdf=True,
231+
# approved=False,
142232
show_preview=show_pv,
143233
)
144234

@@ -467,6 +557,7 @@ def add_test_mails(context):
467557
file=file_object,
468558
scan_id="0509999000000%02d" % i,
469559
scan_date=scan_date,
560+
content_category=calculate_category_id(api.portal.get()["annexes_types"]["signable_files"]["signable-ged-file"]),
470561
)
471562

472563
# tasks
@@ -525,7 +616,14 @@ def add_test_mails(context):
525616
filename = next(files_cycle)
526617
with open(u"%s/%s" % (filespath, filename), "rb") as fo:
527618
file_object = NamedBlobFile(fo.read(), filename=filename)
528-
createContentInContainer(mail, "dmsommainfile", id="1", title="", file=file_object)
619+
createContentInContainer(
620+
mail,
621+
"dmsommainfile",
622+
id="1",
623+
title="",
624+
file=file_object,
625+
content_category=calculate_category_id(api.portal.get()["annexes_types"]["signable_files"]["signable-ged-file"]),
626+
)
529627

530628

531629
def add_test_plonegroup_services(context):
@@ -946,7 +1044,7 @@ def configure_imio_dms_mail(context):
9461044
u"transfer_email_pat": u"",
9471045
u"original_email_pat": u"",
9481046
u"tal_condition_1": u"python: agent_id and 'encodeurs' in modules['imio.dms.mail.utils']."
949-
u"current_user_groups_ids(userid=agent_id)",
1047+
u"current_user_groups_ids(userid=agent_id)",
9501048
u"user_value": u"_empty_",
9511049
u"tal_condition_2": u"",
9521050
u"tg_value": u"_empty_",
@@ -969,7 +1067,7 @@ def configure_imio_dms_mail(context):
9691067
u"transfer_email_pat": u"",
9701068
u"original_email_pat": u"",
9711069
u"tal_condition_1": u"",
972-
u"state_value": u"proposed_to_agent"
1070+
u"state_value": u"proposed_to_agent",
9731071
},
9741072
]
9751073

imio/dms/mail/migrations/migrate_to_3_1.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# -*- coding: utf-8 -*-
2+
from collective.iconifiedcategory.utils import calculate_category_id
3+
from collective.iconifiedcategory.utils import update_categorized_elements
24
from collective.messagesviewlet.utils import add_message
35
from collective.wfadaptations.api import apply_from_registry
46
from collective.wfadaptations.api import get_applied_adaptations
@@ -77,6 +79,9 @@ def run(self):
7779
self.runProfileSteps("imio.dms.mail", steps=["catalog", "plone.app.registry"])
7880
load_type_from_package("dmsoutgoingmail", "profile-imio.dms.mail:default") # behavior
7981
load_type_from_package("held_position", "profile-imio.dms.mail:default") # behavior
82+
load_type_from_package("dmsappendixfile", "profile-imio.dms.mail:default") # iconified
83+
load_type_from_package("dmsommainfile", "profile-imio.dms.mail:default") # iconified
84+
self.runProfileSteps('imio.dms.mail', steps=['imiodmsmail-add-test-annexes-types'], profile='examples')
8085

8186
# Update wf changes
8287
reset = load_workflow_from_package("outgoingmail_workflow", "imio.dms.mail:default")
@@ -175,6 +180,44 @@ def run(self):
175180
obj = brain._unrestrictedGetObject()
176181
obj.reindexObject(idxs=["markers"])
177182

183+
# imio.annex integration to dms files with iconified category
184+
self.context.runImportStepFromProfile('collective.dms.basecontent:default', 'catalog')
185+
self.context.runImportStepFromProfile('imio.dms.mail:default', 'catalog')
186+
load_type_from_package("dmsmainfile", "imio.dms.mail:default")
187+
load_type_from_package("dmsommainfile", "imio.dms.mail:default")
188+
load_type_from_package("dmsappendixfile", "imio.dms.mail:default")
189+
self.context.runImportStepFromProfile(u'imio.dms.mail:examples', u'imiodmsmail-add-test-annexes-types')
190+
files = self.portal.portal_catalog.unrestrictedSearchResults(portal_type=["dmsmainfile", "dmsommainfile", "dmsappendixfile"])
191+
category = self.portal["annexes_types"]["signable_files"]["signable-ged-file"]
192+
for f in files:
193+
obj = f.getObject()
194+
if not hasattr(obj, "approved"):
195+
obj.approved = False
196+
if not hasattr(obj, "to_print"):
197+
obj.to_print = False
198+
if not hasattr(obj, "content_category"):
199+
obj.content_category = calculate_category_id(category)
200+
update_categorized_elements(obj.aq_parent, obj, category)
201+
catalog = self.portal.portal_catalog
202+
indexes = catalog.indexes()
203+
wanted = [
204+
('to_print', 'BooleanIndex'),
205+
('to_be_signed', 'BooleanIndex'),
206+
('signed', 'BooleanIndex'),
207+
('approved', 'BooleanIndex'),
208+
]
209+
added = set()
210+
for name, meta_type in wanted:
211+
if name not in indexes:
212+
catalog.addIndex(name, meta_type)
213+
added.add(name)
214+
if added:
215+
self.reindexIndexes(idxs=list(added),
216+
portal_types=["dmsmainfile", "dmsommainfile", "dmsappendixfile"],
217+
update_metadata=True)
218+
219+
# END
220+
178221
# END
179222

180223
# finished = True # can be eventually returned and set by batched method

imio/dms/mail/profiles/default/types/dmsappendixfile.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
<element value="view"/>
99
<element value="documentviewer"/>
1010
</property>
11+
<property name="behaviors" purge="False">
12+
<element value="collective.iconifiedcategory.behaviors.iconifiedcategorization.IIconifiedCategorization" />
13+
</property>
1114
</object>

imio/dms/mail/profiles/default/types/dmsmainfile.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?xml version="1.0"?>
22
<object name="dmsmainfile" meta_type="Dexterity FTI">
33
<property name="behaviors" purge="False">
4-
<element value="plone.app.lockingbehavior.behaviors.ILocking" />
5-
<element value="collective.dms.scanbehavior.behaviors.behaviors.IScanFields"/>
64
<element value="collective.dexteritytextindexer.behavior.IDexterityTextIndexer" />
5+
<element value="collective.dms.scanbehavior.behaviors.behaviors.IScanFields" />
6+
<element value="plone.app.content.interfaces.INameFromTitle" />
7+
<element value="plone.app.lockingbehavior.behaviors.ILocking" />
78
</property>
89
<property name="default_view">documentviewer</property>
910
<property name="view_methods">

imio/dms/mail/profiles/default/types/dmsommainfile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<element value="plone.app.lockingbehavior.behaviors.ILocking" />
2525
<element value="collective.dms.scanbehavior.behaviors.behaviors.IScanFields"/>
2626
<element value="collective.dexteritytextindexer.behavior.IDexterityTextIndexer" />
27+
<element value="collective.iconifiedcategory.behaviors.iconifiedcategorization.IIconifiedCategorization" />
2728
</property>
2829
<property name="schema" />
2930
<!-- DO NOT use a model_source or it removes manually added fields while reapplying the profile -->

imio/dms/mail/setuphandlers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,17 @@ def postInstall(context):
535535
# hide plone.portalheader message viewlet
536536
site.portal_setup.runImportStepFromProfile("profile-plonetheme.imioapps:default", "viewlets")
537537

538+
# Annexes Types
539+
portal = api.portal.get()
540+
if 'annexes_types' not in portal:
541+
api.content.create(
542+
container=portal,
543+
id='annexes_types',
544+
title=_(u"Annexes Types"),
545+
type="ContentCategoryConfiguration",
546+
exclude_from_nav=True
547+
)
548+
538549

539550
def blacklistPortletCategory(obj, category=CONTEXT_CATEGORY, utilityname=u"plone.leftcolumn", value=True):
540551
"""

imio/dms/mail/vocabularies.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from collective.contact.plonegroup.utils import get_organizations
99
from collective.contact.plonegroup.utils import get_person_from_userid
1010
from collective.contact.plonegroup.utils import organizations_with_suffixes
11+
from collective.iconifiedcategory.vocabularies import CategoryVocabulary
1112
from ftw.labels.interfaces import ILabelJar
1213
from imio.dms.mail import _
1314
from imio.dms.mail import _tr
@@ -710,3 +711,23 @@ def __call__(self, context):
710711
return SimpleVocabulary(
711712
[SimpleTerm("active", title=pmf(u"Active")), SimpleTerm("deactivated", title=pmf(u"Deactivated"))]
712713
)
714+
715+
716+
class DmsFilesCategoryVocabulary(CategoryVocabulary):
717+
""""""
718+
719+
implements(IVocabularyFactory)
720+
721+
def _get_categories(self, context, only_enabled=True):
722+
if context.portal_type in ("dmsmainfile", "dmsommainfile", "dmsappendixfile", "dmsincomingmail", "dmsoutgoingmail"):
723+
catalog = api.portal.get_tool('portal_catalog')
724+
query = {
725+
'object_provides': 'collective.iconifiedcategory.content.category.ICategory',
726+
'enabled': True,
727+
'path': [
728+
'/{}/annexes_types/signable_files'.format(api.portal.get().getId()),
729+
'/{}/annexes_types/classic_files'.format(api.portal.get().getId()),
730+
],
731+
}
732+
return [b.getObject() for b in catalog.unrestrictedSearchResults(**query)]
733+
return super(DmsFilesCategoryVocabulary, self)._get_categories(context, only_enabled)

imio/dms/mail/vocabularies.zcml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,15 @@
159159
factory="imio.dms.mail.vocabularies.ActiveInactiveStatesVocabulary"
160160
/>
161161

162+
<unconfigure package="collective.iconifiedcategory">
163+
<utility
164+
name="collective.iconifiedcategory.categories"
165+
provides="zope.schema.interfaces.IVocabularyFactory"
166+
/>
167+
</unconfigure>
168+
<utility
169+
name="collective.iconifiedcategory.categories"
170+
factory="imio.dms.mail.vocabularies.DmsFilesCategoryVocabulary"
171+
/>
172+
162173
</configure>

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"collective.externaleditor",
6464
"collective.fontawesome",
6565
"collective.iconifieddocumentactions",
66+
"collective.iconifiedcategory",
6667
"collective.js.fancytree",
6768
"collective.js.tooltipster",
6869
"collective.messagesviewlet",

0 commit comments

Comments
 (0)