Skip to content

Commit 13c936d

Browse files
committed
Add duplicate action for outgoing mails WIP
1 parent 9e10366 commit 13c936d

File tree

11 files changed

+589
-42
lines changed

11 files changed

+589
-42
lines changed

imio/dms/mail/browser/actionspanel.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def __init__(self, context, request):
184184
self.ACCEPTABLE_ACTIONS = ["delete"]
185185
self.SECTIONS_TO_RENDER += (
186186
"render_create_from_template_button",
187+
"render_duplicate_button",
187188
"render_create_new_message",
188189
"render_send_email",
189190
)
@@ -207,6 +208,18 @@ def render_create_from_template_button(self):
207208
return ViewPageTemplateFile("templates/actions_panel_create_from_template.pt")(self)
208209
return ""
209210

211+
def may_duplicate(self):
212+
"""
213+
Method that check if special 'duplicate' action has to be displayed.
214+
"""
215+
# TODO define permissions for duplicate
216+
return True
217+
218+
def render_duplicate_button(self):
219+
if self.may_duplicate():
220+
return ViewPageTemplateFile("templates/actions_panel_duplicate.pt")(self)
221+
return ""
222+
210223
def may_create_new_message(self):
211224
if (
212225
self.context.is_email()

imio/dms/mail/browser/configure.zcml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
class=".views.CreateFromTemplateForm"
1919
/>
2020

21+
<browser:page
22+
name="duplicate"
23+
for="imio.dms.mail.dmsmail.IImioDmsOutgoingMail"
24+
permission="zope2.View"
25+
class=".views.DuplicateForm"
26+
/>
27+
2128
<browser:page
2229
name="imiodmsmail-settings"
2330
for="Products.CMFPlone.interfaces.IPloneSiteRoot"

imio/dms/mail/browser/settings.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ class IImioDmsMailConfig(model.Schema):
453453
"omail_post_mailing",
454454
"omail_fields",
455455
"omail_group_encoder",
456+
"omail_duplicate_default_keep_category",
457+
"omail_duplicate_default_keep_folder",
458+
"omail_duplicate_default_keep_linked_mails",
459+
"omail_duplicate_default_keep_dms_files",
460+
"omail_duplicate_default_keep_annexes",
461+
"omail_duplicate_default_link_to_original",
456462
],
457463
)
458464

@@ -533,6 +539,33 @@ class IImioDmsMailConfig(model.Schema):
533539
default=False,
534540
)
535541

542+
# the duplicate-form default fields
543+
# TODO hide these next two field if not enabled ?
544+
omail_duplicate_default_keep_category = schema.Bool(
545+
title=_(u"Default value when duplicating an outgoing mail for 'Keep classification category'"),
546+
default=True,
547+
)
548+
omail_duplicate_default_keep_folder = schema.Bool(
549+
title=_(u"Default value when duplicating an outgoing mail for 'Keep classification folder'"),
550+
default=True,
551+
)
552+
omail_duplicate_default_keep_linked_mails = schema.Bool(
553+
title=_(u"Default value when duplicating an outgoing mail for 'Keep linked mails'"),
554+
default=True,
555+
)
556+
omail_duplicate_default_keep_dms_files = schema.Bool(
557+
title=_(u"Default value when duplicating an outgoing mail for 'Keep DMS files'"),
558+
default=True,
559+
)
560+
omail_duplicate_default_keep_annexes = schema.Bool(
561+
title=_(u"Default value when duplicating an outgoing mail for 'Keep annexes'"),
562+
default=True,
563+
)
564+
omail_duplicate_default_link_to_original = schema.Bool(
565+
title=_(u"Default value when duplicating an outgoing mail for 'Link to original'"),
566+
default=True,
567+
)
568+
536569
# FIELDSET OEM
537570
model.fieldset(
538571
"outgoing_email",
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<td class="noPadding" i18n:domain="imio.dms.mail">
2+
<a tal:attributes="href string:${context/absolute_url}/@@duplicate"
3+
target="_parent"
4+
class="overlay"
5+
tal:define="dummy view/saveHasActions;">
6+
<input tal:condition="not:view/useIcons" type="button" value="Duplicate" class="apButton apButtonAction apButtonAction_duplicate" i18n:attributes="value" />
7+
<img tal:condition="view/useIcons" i18n:attributes="title" title="Dupliquer" tal:attributes="src string: ${view/portal_url}/++resource++imio.dms.mail/copy.svg;"/>
8+
</a>
9+
</td>
10+
<td class="noPadding">

imio/dms/mail/browser/views.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# -*- coding: utf-8 -*-
22
from AccessControl import getSecurityManager
33
from collective.ckeditortemplates.cktemplate import ICKTemplate
4+
from collective.dms.basecontent.dmsfile import IDmsAppendixFile
5+
from collective.dms.mailcontent.dmsmail import internalReferenceOutgoingMailDefaultValue
46
from datetime import datetime
7+
from DateTime import DateTime
58
from eea.faceted.vocabularies.autocomplete import IAutocompleteSuggest
69
from imio.dms.mail import _
710
from imio.dms.mail import _tr
811
from imio.dms.mail import PMH_ENABLED
12+
from imio.dms.mail.browser.settings import IImioDmsMailConfig
913
from imio.dms.mail.browser.table import CKTemplatesTable
1014
from imio.dms.mail.browser.table import PersonnelTable
1115
from imio.dms.mail.dmsfile import IImioDmsFile
@@ -20,14 +24,23 @@
2024
from imio.helpers.workflow import do_transitions
2125
from imio.helpers.xhtml import object_link
2226
from plone import api
27+
from plone.supermodel import model
28+
from Products.CMFCore.utils import getToolByName
2329
from Products.CMFPlone.utils import safe_unicode
2430
from Products.Five import BrowserView
2531
from Products.PageTemplates.Expressions import SecureModuleImporter
2632
from unidecode import unidecode # unidecode_expect_nonascii not yet available in used version
33+
from z3c.form import button
34+
from z3c.form.field import Fields
35+
from z3c.form.form import Form
36+
from z3c.relationfield import RelationValue
37+
from zope import schema
2738
from zope.annotation import IAnnotations
2839
from zope.component import getMultiAdapter
40+
from zope.component import getUtility
2941
from zope.i18n import translate
3042
from zope.interface import implements
43+
from zope.intid.interfaces import IIntIds
3144
from zope.lifecycleevent import modified
3245
from zope.pagetemplate.pagetemplate import PageTemplate
3346

@@ -70,6 +83,117 @@ def redirect_url(self, uid):
7083
return "{}/persistent-document-generation?{}".format(url, "&".join(params))
7184

7285

86+
class IDuplicateFormSchema(model.Schema):
87+
88+
keep_category = schema.Bool(
89+
title=_(u"Keep classification category"),
90+
description=u'',
91+
default=True,
92+
)
93+
94+
keep_folder = schema.Bool(
95+
title=_(u"Keep classification folder"),
96+
description=u'',
97+
default=True,
98+
)
99+
100+
keep_linked_mails = schema.Bool(
101+
title=_(u"Keep linked mails"),
102+
description=u'',
103+
default=True,
104+
)
105+
106+
keep_dms_files = schema.Bool(
107+
title=_(u"Keep DMS files"),
108+
description=u'',
109+
default=True,
110+
)
111+
112+
keep_annexes = schema.Bool(
113+
title=_(u"Keep annexes"),
114+
description=u'',
115+
default=True,
116+
)
117+
118+
link_to_original = schema.Bool(
119+
title=_(u"Link to original"),
120+
description=u'',
121+
default=True,
122+
)
123+
124+
125+
class DuplicateForm(Form):
126+
127+
"""Duplicate an outgoing mail."""
128+
label = _(u"Duplicate mail")
129+
fields = Fields(IDuplicateFormSchema)
130+
ignoreContext = True
131+
132+
@button.buttonAndHandler(_('Duplicate'), name='duplicate')
133+
def handleApply(self, action):
134+
data, errors = self.extractData()
135+
136+
if errors:
137+
self.status = self.formErrorsMessage
138+
return
139+
140+
# Duplicate the mail
141+
parent = self.context.aq_parent
142+
clipboard = parent.manage_copyObjects([self.context.getId()])
143+
result = parent.manage_pasteObjects(clipboard)
144+
duplicated_mail = parent[result[0]['new_id']]
145+
duplicated_mail.creation_date = DateTime()
146+
duplicated_mail.reindexObject(idxs=['created'])
147+
duplicated_mail.internal_reference_no = internalReferenceOutgoingMailDefaultValue(self)
148+
duplicated_mail.due_date = None
149+
duplicated_mail.outgoing_date = None
150+
duplicated_mail.mail_date = None
151+
152+
if not data['keep_category']:
153+
duplicated_mail.classification_categories = None
154+
155+
if not data['keep_folder']:
156+
duplicated_mail.classification_folders = None
157+
158+
if not data['keep_linked_mails']:
159+
duplicated_mail.reply_to = None
160+
161+
if not data['keep_dms_files']:
162+
dms_files = [sub_content.getId() for sub_content in duplicated_mail.values() if IImioDmsFile.providedBy(sub_content)]
163+
if dms_files:
164+
duplicated_mail.manage_delObjects(dms_files)
165+
166+
if not data['keep_annexes']:
167+
annexes = [sub_content.getId() for sub_content in duplicated_mail.values() if IDmsAppendixFile.providedBy(sub_content)]
168+
if annexes:
169+
duplicated_mail.manage_delObjects(annexes)
170+
171+
if data['link_to_original']:
172+
intids = getUtility(IIntIds)
173+
rel_id = intids.getId(self.context)
174+
if duplicated_mail.reply_to is None:
175+
duplicated_mail.reply_to = []
176+
duplicated_mail.reply_to.append(RelationValue(rel_id))
177+
178+
self.request.response.redirect(duplicated_mail.absolute_url()+"/edit")
179+
180+
def updateWidgets(self):
181+
super(DuplicateForm, self).updateWidgets()
182+
self.widgets["keep_category"].value = ['selected'] if api.portal.get_registry_record("omail_duplicate_default_keep_category", IImioDmsMailConfig, True) else []
183+
self.widgets["keep_folder"].value = ['selected'] if api.portal.get_registry_record("omail_duplicate_default_keep_folder", IImioDmsMailConfig, True) else []
184+
self.widgets["keep_linked_mails"].value = ['selected'] if api.portal.get_registry_record("omail_duplicate_default_keep_linked_mails", IImioDmsMailConfig, True) else []
185+
self.widgets["keep_dms_files"].value = ['selected'] if api.portal.get_registry_record("omail_duplicate_default_keep_dms_files", IImioDmsMailConfig, True) else []
186+
self.widgets["keep_annexes"].value = ['selected'] if api.portal.get_registry_record("omail_duplicate_default_keep_annexes", IImioDmsMailConfig, True) else []
187+
self.widgets["link_to_original"].value = ['selected'] if api.portal.get_registry_record("omail_duplicate_default_link_to_original", IImioDmsMailConfig, True) else []
188+
189+
navtree_props = getToolByName(api.portal.get(), 'portal_properties').navtree_properties
190+
excluded_types = navtree_props.getProperty('metaTypesNotToList', ())
191+
if 'ClassificationContainer' in excluded_types:
192+
self.widgets["keep_category"].mode = "hidden"
193+
if 'ClassificationFolders' in excluded_types:
194+
self.widgets["keep_folder"].mode = "hidden"
195+
196+
73197
def parse_query(text):
74198
"""Copied from plone.app.vocabularies.catalog.parse_query but cleaned."""
75199
for char in "?-+*()":

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,3 +1330,60 @@ msgstr "Templates"
13301330
#: ./browser/viewlets.py:107
13311331
msgid "zip_code"
13321332
msgstr ""
1333+
1334+
#: ./browser/settings.py:556
1335+
msgid "Default value when duplicating an outgoing mail for 'Keep DMS files'"
1336+
msgstr ""
1337+
1338+
#: ./browser/settings.py:560
1339+
msgid "Default value when duplicating an outgoing mail for 'Keep annexes'"
1340+
msgstr ""
1341+
1342+
#: ./browser/settings.py:544
1343+
msgid "Default value when duplicating an outgoing mail for 'Keep classification category'"
1344+
msgstr ""
1345+
1346+
#: ./browser/settings.py:548
1347+
msgid "Default value when duplicating an outgoing mail for 'Keep classification folder'"
1348+
msgstr ""
1349+
1350+
#: ./browser/settings.py:552
1351+
msgid "Default value when duplicating an outgoing mail for 'Keep linked mails'"
1352+
msgstr ""
1353+
1354+
#: ./browser/settings.py:564
1355+
msgid "Default value when duplicating an outgoing mail for 'Link to original'"
1356+
msgstr ""
1357+
1358+
#: ./browser/views.py:108
1359+
msgid "Keep DMS files"
1360+
msgstr ""
1361+
1362+
#: ./browser/views.py:115
1363+
msgid "Keep annexes"
1364+
msgstr ""
1365+
1366+
#: ./browser/views.py:87
1367+
msgid "Keep classification category"
1368+
msgstr ""
1369+
1370+
#: ./browser/views.py:94
1371+
msgid "Keep classification folder"
1372+
msgstr ""
1373+
1374+
#: ./browser/views.py:101
1375+
msgid "Keep linked mails"
1376+
msgstr ""
1377+
1378+
#: ./browser/views.py:122
1379+
msgid "Link to original"
1380+
msgstr ""
1381+
1382+
#: ./browser/templates/actions_panel_duplicate.pt:6
1383+
#: ./browser/views.py:136
1384+
msgid "Duplicate"
1385+
msgstr ""
1386+
1387+
#: ./browser/views.py:132
1388+
msgid "Duplicate mail"
1389+
msgstr ""

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,3 +1332,60 @@ msgstr "Modèles"
13321332
#: ./browser/viewlets.py:107
13331333
msgid "zip_code"
13341334
msgstr "Code postal"
1335+
1336+
#: ./browser/settings.py:556
1337+
msgid "Default value when duplicating an outgoing mail for 'Keep DMS files'"
1338+
msgstr "Valeur par défaut pour le champ 'Garder les fichiers GED' lorsqu'on duplique un courrier sortant"
1339+
1340+
#: ./browser/settings.py:560
1341+
msgid "Default value when duplicating an outgoing mail for 'Keep annexes'"
1342+
msgstr "Valeur par défaut pour le champ 'Garder les annexes' lorsqu'on duplique un courrier sortant"
1343+
1344+
#: ./browser/settings.py:544
1345+
msgid "Default value when duplicating an outgoing mail for 'Keep classification category'"
1346+
msgstr "Valeur par défaut pour le champ 'Garder les catégories' lorsqu'on duplique un courrier sortant"
1347+
1348+
#: ./browser/settings.py:548
1349+
msgid "Default value when duplicating an outgoing mail for 'Keep classification folder'"
1350+
msgstr "Valeur par défaut pour le champ 'Garder les dossiers' lorsqu'on duplique un courrier sortant"
1351+
1352+
#: ./browser/settings.py:552
1353+
msgid "Default value when duplicating an outgoing mail for 'Keep linked mails'"
1354+
msgstr "Valeur par défaut pour le champ 'Garder les courriers liés' lorsqu'on duplique un courrier sortant"
1355+
1356+
#: ./browser/settings.py:564
1357+
msgid "Default value when duplicating an outgoing mail for 'Link to original'"
1358+
msgstr "Valeur par défaut pour le champ 'Lier le courrier dupliqué à l'original' lorsqu'on duplique un courrier sortant"
1359+
1360+
#: ./browser/views.py:108
1361+
msgid "Keep DMS files"
1362+
msgstr "Garder les fichiers GED"
1363+
1364+
#: ./browser/views.py:115
1365+
msgid "Keep annexes"
1366+
msgstr "Garder les annexes"
1367+
1368+
#: ./browser/views.py:87
1369+
msgid "Keep classification category"
1370+
msgstr "Garder les catégories"
1371+
1372+
#: ./browser/views.py:94
1373+
msgid "Keep classification folder"
1374+
msgstr "Garder les dossiers"
1375+
1376+
#: ./browser/views.py:101
1377+
msgid "Keep linked mails"
1378+
msgstr "Garder les courriers liés"
1379+
1380+
#: ./browser/views.py:122
1381+
msgid "Link to original"
1382+
msgstr "Lier le courrier dupliqué à l'original"
1383+
1384+
#: ./browser/templates/actions_panel_duplicate.pt:6
1385+
#: ./browser/views.py:136
1386+
msgid "Duplicate"
1387+
msgstr "Dupliquer"
1388+
1389+
#: ./browser/views.py:132
1390+
msgid "Duplicate mail"
1391+
msgstr "Dupliquer le courrier"

0 commit comments

Comments
 (0)