Skip to content

Commit ec51999

Browse files
committed
Refactor + tests WIP
1 parent 0f9337b commit ec51999

8 files changed

Lines changed: 251 additions & 156 deletions

File tree

imio/dms/mail/adapters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ def approve_file(self, afile, userid, values=None, transition=None, c_a=None):
16061606
self.annot["approval"][c_a][f_index]["approved_on"] = datetime.datetime.now()
16071607
self.annot["approval"][c_a][f_index]["approved_by"] = userid
16081608
self.annot["current_nb"] = self.calculate_current_nb()
1609-
pc = getToolByName(self.context, "portal_catalog")
1609+
pc = getToolByName(api.portal.get(), "portal_catalog")
16101610
if self.is_file_approved(f_uid):
16111611
afile.approved = True
16121612
if values is not None:

imio/dms/mail/configure.zcml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@
314314
class=".utils.OdmUtilsMethods"
315315
permission="zope2.View"
316316
allowed_attributes="
317-
duplicate
318317
get_object_from_relation
319318
get_om_folder
320319
highest_scan_id

imio/dms/mail/dmsmail.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -887,46 +887,6 @@ def wf_conditions(self):
887887
def has_mailing(self, document):
888888
return need_mailing_value(document=document)
889889

890-
def copy_dms_files(self, original_mail):
891-
"""Re-generate DMS files on self from templates used in original_mail."""
892-
mainfile_type = "dmsommainfile"
893-
dms_files = [sub for sub in original_mail.values() if sub.portal_type == mainfile_type]
894-
used_template_uids = set()
895-
# If no mail date, import it from source mail. Otherwise, the generated mails might be broken
896-
if dms_files and not self.mail_date:
897-
self.mail_date = original_mail.mail_date
898-
api.portal.show_message(
899-
translate(
900-
'The mail date was missing and has been updating following the source mail (${date}).',
901-
domain='imio.dms.mail',
902-
context=self.REQUEST,
903-
mapping={"date": self.mail_date.strftime("%d/%m/%Y")},
904-
),
905-
request=self.REQUEST,
906-
type='warn',
907-
)
908-
for dms_file in dms_files:
909-
annot = IAnnotations(dms_file).get('documentgenerator', {})
910-
if not annot:
911-
api.content.copy(source=dms_file, target=self)
912-
continue
913-
if not annot.get('template_uid') or annot.get('template_uid') in used_template_uids:
914-
continue
915-
document_generation_helper_view = getMultiAdapter(
916-
(self, self.REQUEST), name="document_generation_helper_view")
917-
requires_mailing = len(document_generation_helper_view.mailing_list()) > 1
918-
if requires_mailing and not annot.get('need_mailing'):
919-
continue
920-
template_uid = annot.get('template_uid')
921-
generation_view = getMultiAdapter((self, self.REQUEST), name="persistent-document-generation")
922-
pod_template = generation_view.get_pod_template(template_uid)
923-
if IMailingLoopTemplate.providedBy(pod_template):
924-
continue
925-
generation_view.pod_template = pod_template
926-
generation_view.output_format = 'odt'
927-
generation_view.generate_persistent_doc(pod_template, 'odt')
928-
used_template_uids.add(template_uid)
929-
930890

931891
class ImioDmsOutgoingMailWfConditionsAdapter(object):
932892
implements(IImioDmsOutgoingMailWfConditions)

imio/dms/mail/subscribers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ def dmsoutgoingmail_modified(mail, event):
480480
del annot['copy_dms_files_from']
481481
try:
482482
original_mail = uuidToObject(copy_dms_files_from, unrestricted=True)
483-
mail.copy_dms_files(original_mail)
483+
odm_utils = getMultiAdapter((mail, mail.REQUEST), name="odm-utils")
484+
odm_utils.copy_dms_files(original_mail)
484485
except Exception as e:
485486
logger.exception('An error occured when copying DMS files')
486487
api.portal.show_message(

imio/dms/mail/tests/test_adapters.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
from imio.dms.mail.adapters import TaskValidationCriterion
2727
from imio.dms.mail.browser.settings import IImioDmsMailConfig
2828
from imio.dms.mail.content.behaviors import ISigningBehavior
29+
from imio.dms.mail.Extensions.demo import activate_signing
2930
from imio.dms.mail.testing import DMSMAIL_INTEGRATION_TESTING
3031
from imio.dms.mail.testing import reset_dms_config
3132
from imio.dms.mail.utils import DummyView
3233
from imio.dms.mail.utils import set_dms_config
3334
from imio.dms.mail.utils import sub_create
34-
from imio.esign.config import set_registry_file_url
3535
from imio.esign.utils import get_session_annotation
3636
from imio.helpers.test_helpers import ImioTestHelpers
3737
from plone import api
@@ -470,11 +470,8 @@ class TestOMApprovalAdapter(unittest.TestCase, ImioTestHelpers):
470470
def setUp(self):
471471
self.portal = self.layer["portal"]
472472
self.pw = self.portal.portal_workflow
473+
activate_signing(self.portal)
473474
self.change_user("admin")
474-
self.portal.portal_setup.runImportStepFromProfile(
475-
"profile-imio.dms.mail:singles", "imiodmsmail-activate-esigning", run_dependencies=False
476-
)
477-
set_registry_file_url("https://downloads.files.com")
478475
# Create outgoing mail with two eSign signers and two files to approve
479476
intids = getUtility(IIntIds)
480477
self.pgof = self.portal["contacts"]["plonegroup-organization"]

imio/dms/mail/tests/test_dmsmail.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from plone.namedfile.file import NamedBlobFile
3232
from z3c.relationfield.relation import RelationValue
3333
from zc.relation.interfaces import ICatalog
34-
from zope.annotation.interfaces import IAnnotations
3534
from zope.component import getUtility
3635
from zope.interface import Invalid
3736
from zope.intid.interfaces import IIntIds
@@ -643,43 +642,3 @@ def test_AssignedUserValidator(self):
643642
self.assertRaises(Invalid, auv.validate, "agent1")
644643
# we check assigned_user requirement if the imail state will be changed
645644
# this test is done in im wfadaptation test
646-
647-
def test_ImioDmsOutgoingMail_copy_dms_files(self):
648-
"""Test ImioDmsOutgoingMail.copy_dms_files"""
649-
# Create fresh source and destination mails
650-
original = sub_create(self.portal["outgoing-mail"], "dmsoutgoingmail", datetime.now(), "test-orig-dms")
651-
pc = api.portal.get_tool("portal_catalog")
652-
653-
# No dmsommainfile on original → copy_dms_files is a no-op
654-
new_mail = sub_create(self.portal["outgoing-mail"], "dmsoutgoingmail", datetime.now(), "test-copy-dms-1")
655-
new_mail.mail_date = date.today()
656-
new_mail.copy_dms_files(original)
657-
self.assertEqual(len(pc(portal_type="dmsommainfile", path="/".join(new_mail.getPhysicalPath()))), 0)
658-
659-
# Add a dmsommainfile without documentgenerator annotation → direct copy
660-
new_mail2 = sub_create(self.portal["outgoing-mail"], "dmsoutgoingmail", datetime.now(), "test-copy-dms-2")
661-
new_mail2.mail_date = date.today()
662-
filename = u"Réponse salle.odt"
663-
with open("%s/batchimport/toprocess/outgoing-mail/%s" % (PRODUCT_DIR, filename), "rb") as fo:
664-
mainfile = createContentInContainer(
665-
original, "dmsommainfile", file=NamedBlobFile(fo.read(), filename=filename))
666-
self.assertNotIn("documentgenerator", IAnnotations(mainfile))
667-
new_mail2.copy_dms_files(original)
668-
self.assertEqual(len([s for s in new_mail2.values() if s.portal_type == "dmsommainfile"]), 1)
669-
670-
# Add a dmsommainfile generated from a template → regenerate the file on new_mail
671-
new_mail3 = sub_create(self.portal["outgoing-mail"], "dmsoutgoingmail", datetime.now(), "test-copy-dms-3")
672-
new_mail3.mail_date = date.today()
673-
dgv = getMultiAdapter((original, self.request), name="persistent-document-generation")
674-
template_uid = self.portal["templates"]["om"]["main"].UID()
675-
dgv(template_uid=template_uid, output_format='odt')
676-
new_mail3.copy_dms_files(original)
677-
self.assertEqual(len(pc(portal_type="dmsommainfile", path="/".join(new_mail3.getPhysicalPath()))), 1)
678-
679-
# mail_date missing on new_mail → gets copied from original (with warn message)
680-
new_mail4 = sub_create(self.portal["outgoing-mail"], "dmsoutgoingmail", datetime.now(), "test-copy-dms-4")
681-
original.mail_date = date(2024, 1, 15)
682-
self.assertIsNone(new_mail4.mail_date)
683-
new_mail4.copy_dms_files(original)
684-
self.assertEqual(new_mail4.mail_date, date(2024, 1, 15))
685-
self.assertEqual(len(pc(portal_type="dmsommainfile", path="/".join(new_mail4.getPhysicalPath()))), 1)

0 commit comments

Comments
 (0)