Skip to content

Commit 3e49ec0

Browse files
committed
Add duplicate action for outgoing mails WIP
1 parent 9e10366 commit 3e49ec0

File tree

11 files changed

+581
-42
lines changed

11 files changed

+581
-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: 32 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,32 @@ class IImioDmsMailConfig(model.Schema):
533539
default=False,
534540
)
535541

542+
# the duplicate-form default fields
543+
omail_duplicate_default_keep_category = schema.Bool(
544+
title=_(u"Default value when duplicating an outgoing mail for 'Keep classification category'"),
545+
default=True,
546+
)
547+
omail_duplicate_default_keep_folder = schema.Bool(
548+
title=_(u"Default value when duplicating an outgoing mail for 'Keep classification folder'"),
549+
default=True,
550+
)
551+
omail_duplicate_default_keep_linked_mails = schema.Bool(
552+
title=_(u"Default value when duplicating an outgoing mail for 'Keep linked mails'"),
553+
default=True,
554+
)
555+
omail_duplicate_default_keep_dms_files = schema.Bool(
556+
title=_(u"Default value when duplicating an outgoing mail for 'Keep DMS files'"),
557+
default=True,
558+
)
559+
omail_duplicate_default_keep_annexes = schema.Bool(
560+
title=_(u"Default value when duplicating an outgoing mail for 'Keep annexes'"),
561+
default=True,
562+
)
563+
omail_duplicate_default_link_to_original = schema.Bool(
564+
title=_(u"Default value when duplicating an outgoing mail for 'Link to original'"),
565+
default=True,
566+
)
567+
536568
# FIELDSET OEM
537569
model.fieldset(
538570
"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: 117 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,22 @@
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
2328
from Products.CMFPlone.utils import safe_unicode
2429
from Products.Five import BrowserView
2530
from Products.PageTemplates.Expressions import SecureModuleImporter
2631
from unidecode import unidecode # unidecode_expect_nonascii not yet available in used version
32+
from z3c.form import button
33+
from z3c.form.field import Fields
34+
from z3c.form.form import Form
35+
from z3c.relationfield import RelationValue
36+
from zope import schema
2737
from zope.annotation import IAnnotations
2838
from zope.component import getMultiAdapter
39+
from zope.component import getUtility
2940
from zope.i18n import translate
3041
from zope.interface import implements
42+
from zope.intid.interfaces import IIntIds
3143
from zope.lifecycleevent import modified
3244
from zope.pagetemplate.pagetemplate import PageTemplate
3345

@@ -70,6 +82,111 @@ def redirect_url(self, uid):
7082
return "{}/persistent-document-generation?{}".format(url, "&".join(params))
7183

7284

85+
class IDuplicateFormSchema(model.Schema):
86+
87+
keep_category = schema.Bool(
88+
title=_(u"Keep classification category"),
89+
description=u'',
90+
default=True,
91+
)
92+
93+
keep_folder = schema.Bool(
94+
title=_(u"Keep classification folder"),
95+
description=u'',
96+
default=True,
97+
)
98+
99+
keep_linked_mails = schema.Bool(
100+
title=_(u"Keep linked mails"),
101+
description=u'',
102+
default=True,
103+
)
104+
105+
keep_dms_files = schema.Bool(
106+
title=_(u"Keep DMS files"),
107+
description=u'',
108+
default=True,
109+
)
110+
111+
keep_annexes = schema.Bool(
112+
title=_(u"Keep annexes"),
113+
description=u'',
114+
default=True,
115+
)
116+
117+
link_to_original = schema.Bool(
118+
title=_(u"Link to original"),
119+
description=u'',
120+
default=True,
121+
)
122+
123+
124+
class DuplicateForm(Form):
125+
126+
"""Duplicate an outgoing mail."""
127+
label = _(u"Duplicate mail")
128+
fields = Fields(IDuplicateFormSchema)
129+
ignoreContext = True
130+
131+
@button.buttonAndHandler(_('Duplicate'), name='duplicate')
132+
def handleApply(self, action):
133+
data, errors = self.extractData()
134+
135+
if errors:
136+
self.status = self.formErrorsMessage
137+
return
138+
139+
# Duplicate the mail
140+
parent = self.context.aq_parent
141+
clipboard = parent.manage_copyObjects([self.context.getId()])
142+
result = parent.manage_pasteObjects(clipboard)
143+
duplicated_mail = parent[result[0]['new_id']]
144+
duplicated_mail.creation_date = DateTime()
145+
duplicated_mail.reindexObject(idxs=['created'])
146+
duplicated_mail.internal_reference_no = internalReferenceOutgoingMailDefaultValue(self)
147+
duplicated_mail.due_date = None
148+
duplicated_mail.outgoing_date = None
149+
duplicated_mail.mail_date = None
150+
151+
# TODO hide category and folder fields if not enabled
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+
73190
def parse_query(text):
74191
"""Copied from plone.app.vocabularies.catalog.parse_query but cleaned."""
75192
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éfault 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éfault 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éfault 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éfault 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éfault pour le champ 'Garder les courrier 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éfault 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 courrier 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)