Skip to content

Commit 2d99573

Browse files
committed
Handled multiple sessions for one context
1 parent f7c5959 commit 2d99573

File tree

9 files changed

+94
-74
lines changed

9 files changed

+94
-74
lines changed

imio/dms/mail/adapters.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,8 +1141,8 @@ class OMApprovalAdapter(object):
11411141
Annotation structure: metadata + 2D matrix with n signers and m files
11421142
11431143
### Metadata
1144-
self.annot["session_id"] = str
1145-
The unique id of the internal approval session
1144+
self.annot["session_ids"] = list[session_id]
1145+
The list of esign session ids
11461146
self.annot["signers"] = list[n] (userid, name, label)
11471147
The list of signers for the approval process
11481148
self.annot["approvers"] = list[n] tuple(userids)
@@ -1170,7 +1170,7 @@ def __init__(self, context):
11701170
{
11711171
# Metadata
11721172
"current_nb": None,
1173-
"session_id": None,
1173+
"session_ids": PersistentList(),
11741174
"signers": PersistentList(),
11751175
"editors": PersistentList(),
11761176
"approvers": PersistentList(),
@@ -1186,7 +1186,7 @@ def reset(self):
11861186
"""Reset approval annotation."""
11871187
# Metadata
11881188
self.annot["current_nb"] = None
1189-
self.annot["session_id"] = None
1189+
self.annot["session_ids"] = PersistentList()
11901190
self.annot["signers"] = PersistentList()
11911191
self.annot["editors"] = PersistentList()
11921192
self.annot["approvers"] = PersistentList()
@@ -1196,9 +1196,9 @@ def reset(self):
11961196
self.annot["approval"] = PersistentList()
11971197

11981198
@property
1199-
def session_id(self):
1200-
"""Return the unique session id of the approval process."""
1201-
return self.annot["session_id"]
1199+
def session_ids(self):
1200+
"""Return all session ids for this approval."""
1201+
return self.annot.get("session_ids", PersistentList())
12021202

12031203
@property
12041204
def files_uids(self):
@@ -1856,17 +1856,27 @@ def add_mail_files_to_session(self):
18561856
signers.append((signer, email, name, label))
18571857
watcher_users = api.user.get_users(groupname="esign_watchers")
18581858
watcher_emails = [user.getProperty("email") for user in watcher_users]
1859-
session_id, session = add_files_to_session(signers, session_file_uids, bool(self.context.seal),
1860-
title=_("[ia.docs] Session {sign_id}"),
1861-
watchers=watcher_emails)
1862-
self.annot["session_id"] = session_id
1863-
session_len = len(session_file_uids)
1864-
if session_len > 1:
1865-
return True, _("${count} files added to session number ${session_id}",
1866-
mapping={"count": session_len, "session_id": session_id})
1859+
# Add one file at a time so max_session_size discrimination splits sessions naturally
1860+
new_session_ids = []
1861+
for pdf_uid in session_file_uids:
1862+
sid, _session = add_files_to_session(signers, [pdf_uid], bool(self.context.seal),
1863+
title=_("[ia.docs] Session {sign_id}"),
1864+
watchers=watcher_emails)
1865+
if sid not in new_session_ids:
1866+
new_session_ids.append(sid)
1867+
if new_session_ids:
1868+
session_ids = set(self.session_ids).union(set(new_session_ids))
1869+
self.annot["session_ids"] = PersistentList(list(session_ids))
18671870
else:
1868-
return True, _("${count} file added to session number ${session_id}",
1869-
mapping={"count": session_len, "session_id": session_id})
1871+
# All PDFs already existed — reuse the previously stored session ids
1872+
new_session_ids = list(self.session_ids)
1873+
session_len = sum(len(p) for p in self.pdf_files_uids)
1874+
n_sessions = len(new_session_ids)
1875+
if n_sessions == 1:
1876+
return True, _("${count} file(s) added to session number ${session_id}",
1877+
mapping={"count": session_len, "session_id": new_session_ids[0]})
1878+
return True, _("${count} file(s) added to ${n} sessions",
1879+
mapping={"count": session_len, "n": n_sessions})
18701880

18711881

18721882
class DmsCategorizedObjectInfoAdapter(CategorizedObjectInfoAdapter):

imio/dms/mail/locales/en/LC_MESSAGES/imio.dms.mail.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ msgstr ""
1616
"X-is-fallback-for: en-au en-ca en-gb en-us\n"
1717

1818
#: ./adapters.py:1877
19-
msgid "${count} file added to session number ${session_id}"
19+
msgid "${count} file(s) added to session number ${session_id}"
2020
msgstr ""
2121

2222
#: ./adapters.py:1874

imio/dms/mail/locales/fr/LC_MESSAGES/imio.dms.mail.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ msgstr ""
1818
"X-Generator: Poedit 1.8.4\n"
1919

2020
#: ./adapters.py:1877
21-
msgid "${count} file added to session number ${session_id}"
21+
msgid "${count} file(s) added to session number ${session_id}"
2222
msgstr "${count} fichier a été ajouté à la session numéro ${session_id}"
2323

2424
#: ./adapters.py:1874

imio/dms/mail/locales/generated.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ msgstr ""
1818
"Domain: imio.dms.mail\n"
1919

2020
#: ./adapters.py:1877
21-
msgid "${count} file added to session number ${session_id}"
21+
msgid "${count} file(s) added to session number ${session_id}"
2222
msgstr ""
2323

2424
#: ./adapters.py:1874

imio/dms/mail/locales/imio.dms.mail.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ msgstr ""
1818
"Domain: imio.dms.mail\n"
1919

2020
#: ./adapters.py:1877
21-
msgid "${count} file added to session number ${session_id}"
21+
msgid "${count} file(s) added to session number ${session_id}"
2222
msgstr ""
2323

2424
#: ./adapters.py:1874

imio/dms/mail/skins/imio_dms_mail/imiodmsmail.css.dtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,11 +1064,11 @@ div.faceted-session-info {
10641064
padding-bottom: 0px;
10651065
}
10661066

1067-
#content table#context_viewlet_signers_table {
1067+
#content table.context_viewlet_signers_table {
10681068
margin-bottom: 0px;
10691069
}
10701070

1071-
#context_viewlet_signers_table td {
1071+
.context_viewlet_signers_table td {
10721072
padding-right: 10px;
10731073
}
10741074

imio/dms/mail/subscribers.py

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from imio.dms.mail import IM_EDITOR_SERVICE_FUNCTIONS
3333
from imio.dms.mail import IM_READER_SERVICE_FUNCTIONS
3434
from imio.dms.mail.adapters import OMApprovalAdapter
35+
3536
# from imio.dms.mail import MAIN_FOLDERS
3637
from imio.dms.mail.browser.settings import default_creating_group
3738
from imio.dms.mail.browser.settings import IImioDmsMailConfig
@@ -41,6 +42,7 @@
4142
from imio.dms.mail.interfaces import IPersonnelContact
4243
from imio.dms.mail.interfaces import IProtectedItem
4344
from imio.dms.mail.setuphandlers import blacklistPortletCategory
45+
4446
# from imio.dms.mail.utils import separate_fullname
4547
from imio.dms.mail.utils import create_personnel_content
4648
from imio.dms.mail.utils import create_read_label_cron_task
@@ -60,6 +62,7 @@
6062
from imio.esign.utils import remove_files_from_session
6163
from imio.helpers.cache import invalidate_cachekey_volatile_for
6264
from imio.helpers.cache import setup_ram_cache
65+
6366
# from imio.helpers.content import get_vocab_values
6467
from imio.helpers.content import object_values
6568
from imio.helpers.content import uuidToObject
@@ -89,6 +92,7 @@
8992
from z3c.relationfield.relation import RelationValue
9093
from zc.relation.interfaces import ICatalog # noqa
9194
from zExceptions import Redirect
95+
9296
# from zope.component.interfaces import ComponentLookupError
9397
from zope.annotation import IAnnotations
9498
from zope.component import getAdapter
@@ -130,6 +134,7 @@
130134
class IReferenceable(Interface):
131135
pass
132136

137+
133138
logger = logging.getLogger("imio.dms.mail: events")
134139

135140

@@ -421,19 +426,26 @@ def dmsoutgoingmail_transition(mail, event):
421426
approval.start_approval_process()
422427
if not mail.esign:
423428
# if not mail.seal, we render odt to remove download subdocument comment
424-
if (not mail.seal and event.transition
425-
and event.transition.id in ("set_validated", "set_to_print", "propose_to_be_signed", "mark_as_sent")):
426-
for afile in object_values(mail, ("ImioDmsFile", )):
429+
if (
430+
not mail.seal
431+
and event.transition
432+
and event.transition.id in ("set_validated", "set_to_print", "propose_to_be_signed", "mark_as_sent")
433+
):
434+
for afile in object_values(mail, ("ImioDmsFile",)):
427435
doc_annot = IAnnotations(afile).get("documentgenerator", {})
428436
# if not a generated odt (or needing mailing) or already done, we pass
429437
if doc_annot.get("need_mailing", True) is True or doc_annot.get("cleaned_download") is True:
430438
continue
431-
helper_view = getMultiAdapter((mail, mail.REQUEST), name='document_generation_helper_view')
439+
helper_view = getMultiAdapter((mail, mail.REQUEST), name="document_generation_helper_view")
432440
helper_view.pod_template = doc_annot.get("template_uid")
433441
helper_view.output_format = "odt"
434-
gen_context = {"context": mail, "portal": api.portal.get(), "view": helper_view,
435-
"render_download_barcode": True}
436-
new_file_content = convert_odt(afile.file, fmt='odt', gen_context=gen_context)
442+
gen_context = {
443+
"context": mail,
444+
"portal": api.portal.get(),
445+
"view": helper_view,
446+
"render_download_barcode": True,
447+
}
448+
new_file_content = convert_odt(afile.file, fmt="odt", gen_context=gen_context)
437449
afile.file = NamedBlobFile(new_file_content, filename=afile.file.filename)
438450
modified(afile, Attributes(ImioDmsFile, "file"))
439451
doc_annot["cleaned_download"] = True
@@ -466,7 +478,8 @@ def dmsoutgoingmail_transition(mail, event):
466478
type="error",
467479
)
468480
if seal_code and seal_email:
469-
ExternalSessionCreateView(mail, mail.REQUEST)(session_id=approval.session_id)
481+
for sid in approval.session_ids:
482+
ExternalSessionCreateView(mail, mail.REQUEST)(session_id=sid)
470483
else:
471484
# TODO check if to_sign and approved files have a pdf version
472485
pass
@@ -639,7 +652,7 @@ def task_transition(task, event):
639652

640653

641654
def _correct_to_sign(file_obj):
642-
""""Correct to_sign value following mimetype.
655+
""" "Correct to_sign value following mimetype.
643656
644657
:param file_obj: dmsommainfile or dmsappendixfile
645658
:return: True if to_sign has been changed
@@ -652,12 +665,7 @@ def _correct_to_sign(file_obj):
652665
file_obj.to_approve = False
653666
category_object = get_category_object(file_obj, file_obj.content_category)
654667
update_categorized_elements(
655-
file_obj.__parent__,
656-
file_obj,
657-
category_object,
658-
limited=True,
659-
sort=False,
660-
logging=True
668+
file_obj.__parent__, file_obj, category_object, limited=True, sort=False, logging=True
661669
)
662670
api.portal.show_message(
663671
message=_(
@@ -686,22 +694,19 @@ def _correct_to_approve(file_obj):
686694
new_value = False
687695
om_obj = file_obj.__parent__
688696
approval = OMApprovalAdapter(om_obj)
689-
if (orig_value and getattr(file_obj, "to_sign", False) and approval.approvers
690-
and not base_hasattr(file_obj, "conv_from_uid")
691-
and not getattr(file_obj, "need_mailing", False)):
697+
if (
698+
orig_value
699+
and getattr(file_obj, "to_sign", False)
700+
and approval.approvers
701+
and not base_hasattr(file_obj, "conv_from_uid")
702+
and not getattr(file_obj, "need_mailing", False)
703+
):
692704
new_value = True
693705
approval.add_file_to_approval(file_obj.UID())
694706
if orig_value != new_value: # only when passing from True to False normally
695707
file_obj.to_approve = new_value
696708
category_object = get_category_object(file_obj, file_obj.content_category)
697-
update_categorized_elements(
698-
om_obj,
699-
file_obj,
700-
category_object,
701-
limited=True,
702-
sort=False,
703-
logging=True
704-
)
709+
update_categorized_elements(om_obj, file_obj, category_object, limited=True, sort=False, logging=True)
705710

706711

707712
def i_annex_added(obj, event):
@@ -862,7 +867,7 @@ def imiodmsfile_added(obj, event):
862867

863868
def imiodmsfile_iconified_attr_changed(obj, event):
864869
"""When an iconified attribute is changed. Not used for the moment."""
865-
if event.attr_name == 'approved':
870+
if event.attr_name == "approved":
866871
if event.is_created:
867872
return
868873
fil = event.object # noqa F841
@@ -1344,10 +1349,13 @@ def organization_modified(obj, event):
13441349

13451350
def held_position_modified(obj, event):
13461351
if IPersonnelContact.providedBy(obj):
1347-
invalidate_cachekey_volatile_for('imio.dms.mail.vocabularies.OMSignersVocabulary')
1352+
invalidate_cachekey_volatile_for("imio.dms.mail.vocabularies.OMSignersVocabulary")
13481353
invalidate_cachekey_volatile_for("imio.dms.mail.vocabularies.SigningApprovingsVocabulary")
1349-
mod_attr = [at for at in getattr(event, "descriptions", []) if base_hasattr(at, "attributes")
1350-
and "IUsagesBehavior.usages" in at.attributes]
1354+
mod_attr = [
1355+
at
1356+
for at in getattr(event, "descriptions", [])
1357+
if base_hasattr(at, "attributes") and "IUsagesBehavior.usages" in at.attributes
1358+
]
13511359
if mod_attr:
13521360
update_approvers_settings()
13531361

@@ -1357,7 +1365,7 @@ def held_position_removed(obj, event):
13571365
# at site removal
13581366
if event.object.portal_type == "Plone Site":
13591367
return
1360-
invalidate_cachekey_volatile_for('imio.dms.mail.vocabularies.OMSignersVocabulary')
1368+
invalidate_cachekey_volatile_for("imio.dms.mail.vocabularies.OMSignersVocabulary")
13611369
invalidate_cachekey_volatile_for("imio.dms.mail.vocabularies.SigningApprovingsVocabulary")
13621370

13631371

0 commit comments

Comments
 (0)