Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions imio/dms/mail/browser/actionspanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def assignable_users(self):

def sortTransitions(self, lst):
"""Sort transitions following transitions list order"""
lst.sort(lambda x, y: cmp(self.tr_order.get(x["id"], 99), self.tr_order.get(y["id"], 99)))
lst.sort(lambda x, y: cmp(self.tr_order.get(x["id"], 99), self.tr_order.get(y["id"], 99))) # noqa F821

@ram.cache(actionspanelview_cachekey)
def DmsIMActionsPanelView__call__(
Expand Down Expand Up @@ -183,14 +183,15 @@ def __init__(self, context, request):
# self.ACCEPTABLE_ACTIONS = ['copy', 'paste', 'delete']
self.ACCEPTABLE_ACTIONS = ["delete"]
self.SECTIONS_TO_RENDER += (
"render_duplicate_button",
"render_create_from_template_button",
"render_create_new_message",
"render_send_email",
)

def sortTransitions(self, lst):
"""Sort transitions following transitions list order"""
lst.sort(lambda x, y: cmp(self.tr_order[x["id"]], self.tr_order[y["id"]]))
lst.sort(lambda x, y: cmp(self.tr_order[x["id"]], self.tr_order[y["id"]])) # noqa F821

def may_create_from_template(self):
"""
Expand All @@ -207,6 +208,17 @@ def render_create_from_template_button(self):
return ViewPageTemplateFile("templates/actions_panel_create_from_template.pt")(self)
return ""

def may_duplicate(self):
"""Method that check if special 'duplicate' action has to be displayed."""
if self.member.has_permission("Add portal content", self.portal["outgoing-mail"]):
return True
return False

def render_duplicate_button(self):
if self.may_duplicate():
return ViewPageTemplateFile("templates/actions_panel_duplicate.pt")(self)
return ""

def may_create_new_message(self):
if (
self.context.is_email()
Expand Down Expand Up @@ -296,7 +308,7 @@ def __init__(self, context, request):

def sortTransitions(self, lst):
"""Sort transitions following transitions list order"""
lst.sort(lambda x, y: cmp(self.tr_order[x["id"]], self.tr_order[y["id"]]))
lst.sort(lambda x, y: cmp(self.tr_order[x["id"]], self.tr_order[y["id"]])) # noqa F821

@ram.cache(actionspanelview_cachekey)
def DmsTaskActionsPanelView__call__(
Expand Down
7 changes: 7 additions & 0 deletions imio/dms/mail/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
class=".views.CreateFromTemplateForm"
/>

<browser:page
name="om-duplicate"
for="imio.dms.mail.dmsmail.IImioDmsOutgoingMail"
permission="zope2.View"
class=".views.OMDuplicateForm"
/>

<browser:page
name="imiodmsmail-settings"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
Expand Down
29 changes: 29 additions & 0 deletions imio/dms/mail/browser/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ class IStateSetSchema(IRuleSchema):
# ]
# )

omail_duplicate_fields = SimpleVocabulary(
[
SimpleTerm(value=u"category", title=_(u"Keep classification category")),
SimpleTerm(value=u"folder", title=_(u"Keep classification folder")),
SimpleTerm(value=u"reply_to", title=_(u"Keep reply_to mails")),
SimpleTerm(value=u"dms_files", title=_(u"Keep DMS files")),
SimpleTerm(value=u"annexes", title=_(u"Keep annexes")),
SimpleTerm(value=u"link_to_duplicated", title=_(u"Link to duplicated mail")),
]
)

oemail_sender_email_values = SimpleVocabulary(
[
SimpleTerm(value=u"agent_email", title=_(u"Sender held position email is used")),
Expand Down Expand Up @@ -451,6 +462,8 @@ class IImioDmsMailConfig(model.Schema):
"omail_fullname_used_form",
"omail_send_modes",
"omail_post_mailing",
"omail_duplicate_display_fields",
"omail_duplicate_true_default_values",
"omail_fields",
"omail_group_encoder",
],
Expand Down Expand Up @@ -505,6 +518,22 @@ class IImioDmsMailConfig(model.Schema):
default=True,
)

omail_duplicate_display_fields = schema.List(
title=_(u"Fields to display when duplicating an outgoing mail"),
required=False,
value_type=schema.Choice(vocabulary=omail_duplicate_fields),
default=[u"category", u"folder", u"reply_to", u"dms_files", u"annexes", u"link_to_duplicated"],
)
# widget("omail_duplicate_display_fields", CheckBoxFieldWidget, multiple="multiple", size=5)

omail_duplicate_true_default_values = schema.List(
title=_(u"Default values to True when duplicating an outgoing mail"),
description=_(u"If checked, the default value will be True."),
required=False,
value_type=schema.Choice(vocabulary=omail_duplicate_fields),
default=[u"category", u"folder", u"annexes"],
)

omail_fields = schema.List(
title=_(u"${type} fields display", mapping={"type": _("Outgoing mail")}),
description=_(u"Configure this carefully. You can order with arrows."),
Expand Down
3 changes: 3 additions & 0 deletions imio/dms/mail/browser/static/copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions imio/dms/mail/browser/templates/actions_panel_duplicate.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<td class="noPadding" i18n:domain="imio.dms.mail">
<a tal:attributes="href string:${context/absolute_url}/@@om-duplicate"
target="_parent"
class="overlay"
tal:define="dummy view/saveHasActions;">
<input tal:condition="not:view/useIcons" type="button" value="Duplicate" class="apButton apButtonAction apButtonAction_duplicate" i18n:attributes="value" />
<img tal:condition="view/useIcons" i18n:attributes="title" title="Duplicate outgoing mail" tal:attributes="src string: ${view/portal_url}/++resource++imio.dms.mail/copy.svg;"/>
</a>
</td>
<td class="noPadding">
66 changes: 66 additions & 0 deletions imio/dms/mail/browser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from imio.dms.mail import _
from imio.dms.mail import _tr
from imio.dms.mail import PMH_ENABLED
from imio.dms.mail.browser.settings import IImioDmsMailConfig
from imio.dms.mail.browser.settings import omail_duplicate_fields
from imio.dms.mail.browser.table import CKTemplatesTable
from imio.dms.mail.browser.table import PersonnelTable
from imio.dms.mail.dmsfile import IImioDmsFile
Expand All @@ -19,11 +21,16 @@
from imio.helpers.fancytree.views import BaseRenderFancyTree
from imio.helpers.workflow import do_transitions
from imio.helpers.xhtml import object_link
from imio.pyutils.utils import safe_encode
from plone import api
from Products.CMFPlone.utils import safe_unicode
from Products.Five import BrowserView
from Products.PageTemplates.Expressions import SecureModuleImporter
from unidecode import unidecode # unidecode_expect_nonascii not yet available in used version
from z3c.form import button
from z3c.form.field import Fields
from z3c.form.form import Form
from zope import schema
from zope.annotation import IAnnotations
from zope.component import getMultiAdapter
from zope.i18n import translate
Expand Down Expand Up @@ -70,6 +77,65 @@ def redirect_url(self, uid):
return "{}/persistent-document-generation?{}".format(url, "&".join(params))


class OMDuplicateForm(Form):

"""Duplicate an outgoing mail."""
label = _(u"Duplicate mail")
ignoreContext = True

def update(self):
"""Handle fields."""
om_fields = api.portal.get_registry_record("omail_fields", IImioDmsMailConfig, [])
om_fields = [dic["field_name"] for dic in om_fields]
matching = {u"category": "IClassificationFolder.classification_categories",
u"folder": "IClassificationFolder.classification_folders",
u"reply_to": "reply_to",
u"link_to_duplicated": "reply_to"}
to_show = api.portal.get_registry_record("omail_duplicate_display_fields", IImioDmsMailConfig, [])
to_true = api.portal.get_registry_record("omail_duplicate_true_default_values", IImioDmsMailConfig, [])
for term in omail_duplicate_fields:
if ((term.value in matching and matching[term.value] not in om_fields) or
(term.value not in to_show and term.value not in to_true)):
continue
self.fields += Fields(
schema.Bool(
__name__=safe_encode(term.value),
title=term.title,
default=term.value in to_true,
))
super(OMDuplicateForm, self).update()

def updateWidgets(self, prefix=None):
super(OMDuplicateForm, self).updateWidgets()

# we hide fields not to show
to_show = api.portal.get_registry_record("omail_duplicate_display_fields", IImioDmsMailConfig, [])
for term in omail_duplicate_fields:
if term.value not in to_show:
self.widgets[term.value].mode = "hidden"

@button.buttonAndHandler(_('Duplicate'), name='duplicate')
def handleApply(self, action):
data, errors = self.extractData()

if errors:
self.status = self.formErrorsMessage
return

# Duplicate the mail
odm_utils = getMultiAdapter((self.context, self.request), name="odm-utils")
duplicated_mail = odm_utils.duplicate(
keep_category=data.get('category', False),
keep_folder=data.get('folder', False),
keep_reply_to=data.get('reply_to', False),
keep_dms_files=data.get('dms_files', False),
keep_annexes=data.get('annexes', False),
link_to_duplicated=data.get('link_to_duplicated', False),
)

self.request.response.redirect(duplicated_mail.absolute_url()+"/edit")


def parse_query(text):
"""Copied from plone.app.vocabularies.catalog.parse_query but cleaned."""
for char in "?-+*()":
Expand Down
4 changes: 4 additions & 0 deletions imio/dms/mail/skins/imio_dms_mail/imiodmsmail.css.dtml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ dl.portletWidgetCollection div.portlet_add_icons a {
background-image: url('&dtml-portal_url;/++resource++imio.dms.mail/models_icon.png');
}

.apButtonAction_duplicate {
background-image: url('&dtml-portal_url;/++resource++imio.dms.mail/copy.svg');
}

.apButtonAction_sendemail {
background-image: url('&dtml-portal_url;/++resource++imio.dms.mail/send_email.svg');
background-size: 18px 18px;
Expand Down
11 changes: 11 additions & 0 deletions imio/dms/mail/subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
# from zope.component.interfaces import ComponentLookupError
from zope.annotation import IAnnotations
from zope.component import getAdapter
from zope.component import getMultiAdapter
from zope.component import getSiteManager
from zope.component import getUtility
from zope.component import queryUtility
Expand Down Expand Up @@ -384,6 +385,16 @@ def dmsoutgoingmail_transition(mail, event):
mail.portal_catalog.reindexObject(mail, idxs=("in_out_date",), update_metadata=0)


def dmsoutgoingmail_modified(mail, event):
annot = IAnnotations(mail).get('imio.dms.mail', {})
copy_dms_files_from = annot.get('copy_dms_files_from')
if copy_dms_files_from:
del annot['copy_dms_files_from']
original_mail = uuidToObject(copy_dms_files_from, unrestricted=True)
odm_utils = getMultiAdapter((mail, mail.REQUEST), name="odm-utils")
odm_utils.copy_dms_files(original_mail)


def dv_handle_file_creation(obj, event):
"""Intermediate function to avoid converting some files in documentviewer"""
if obj.portal_type in DV_AVOIDED_TYPES:
Expand Down
6 changes: 6 additions & 0 deletions imio/dms/mail/subscribers.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
handler=".subscribers.dmsoutgoingmail_transition"
/>

<subscriber
for="imio.dms.mail.dmsmail.IImioDmsOutgoingMail
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".subscribers.dmsoutgoingmail_modified"
/>

<!-- Various -->
<subscriber
for="plone.dexterity.interfaces.IDexterityContent
Expand Down
Loading