Skip to content

Commit 1d7c988

Browse files
committed
Added esign annotation admin view
1 parent 7bae93a commit 1d7c988

File tree

5 files changed

+134
-0
lines changed

5 files changed

+134
-0
lines changed

imio/dms/mail/browser/actionspanel.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from imio.actionspanel.browser.views import ActionsPanelView
44
from imio.dms.mail.dmsmail import filter_dmsincomingmail_assigned_users
55
from imio.helpers.cache import get_plone_groups_for_user
6+
from imio.helpers.security import check_zope_admin
67
from plone import api
78
from plone.memoize import ram
89
from Products.CMFPlone.interfaces import IHideFromBreadcrumbs
@@ -159,12 +160,14 @@ class DmsActionsPanelViewlet(ActionsPanelViewlet):
159160

160161

161162
class SigningFieldsetActionsPanelView(ActionsPanelView):
163+
"""Actions panel for sining actions located in outgoing mail singing fieldset"""
162164

163165
_fieldset = "signing"
164166

165167
def __init__(self, context, request):
166168
super(SigningFieldsetActionsPanelView, self).__init__(context, request)
167169
self.ACCEPTABLE_ACTIONS = ["edit", "approvals"]
170+
self.SECTIONS_TO_RENDER += ("renderSigningAnnotationInfo",)
168171

169172
@property
170173
def fieldset(self):
@@ -175,6 +178,11 @@ def renderEdit(self):
175178
return ViewPageTemplateFile("templates/fieldset_actions_panel_edit.pt")(self)
176179
return ""
177180

181+
def renderSigningAnnotationInfo(self):
182+
if check_zope_admin():
183+
return ViewPageTemplateFile("templates/fieldset_actions_panel_signing_annotation_info.pt")(self)
184+
return ""
185+
178186
@ram.cache(actionspanelview_cachekey)
179187
def SigningFieldsetActionsPanelView__call__(
180188
self,

imio/dms/mail/browser/configure.zcml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@
5555
permission="cmf.ModifyPortalContent"
5656
/>
5757

58+
<browser:page
59+
for="imio.dms.mail.dmsmail.IImioDmsOutgoingMail"
60+
name="signing-annotation-info"
61+
class=".views.SigningAnnotationInfoView"
62+
permission="cmf.ManagePortal"
63+
/>
64+
5865
<browser:page
5966
for="imio.dms.mail.dmsmail.IImioDmsOutgoingMail"
6067
name="render_email_signature"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<td class="noPadding" tal:define="dummy view/saveHasActions;
2+
useIcons view/useIcons;">
3+
<tal:comment replace="nothing">Icon</tal:comment>
4+
<a tal:condition="useIcons"
5+
tal:attributes="href string:${context/absolute_url}/@@signing-annotation-info;
6+
target python: view.kwargs.get('edit_action_target', '_blank');"
7+
title="Annotation info (Zope admin only)">
8+
<img tal:attributes="src string:${view/portal_url}/search_icon.png" title="Annotation info" />
9+
</a>
10+
<tal:comment replace="nothing">Button</tal:comment>
11+
<form tal:condition="not: useIcons"
12+
tal:attributes="action string:${context/absolute_url}/@@signing-annotation-info;">
13+
<input type="submit" value="Annotation info"
14+
class="apButton apButtonAction"/>
15+
</form>
16+
</td>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
2+
xmlns:tal="http://xml.zope.org/namespaces/tal"
3+
xmlns:metal="http://xml.zope.org/namespaces/metal"
4+
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
5+
metal:use-macro="context/main_template/macros/master"
6+
i18n:domain="imio.dms.mail">
7+
<body>
8+
<metal:bodytext fill-slot="main">
9+
<h1>Signing annotation info</h1>
10+
<div id="content-core">
11+
12+
<h2>idm.approval annotation</h2>
13+
<pre style="background: #f5f5f5; color: #333; padding: 1em; overflow: auto;"
14+
tal:content="structure view/approval_annot_html" />
15+
16+
<tal:esign condition="view/esign_session">
17+
<h2 tal:content="string:imio.esign session (id: ${view/esign_session_id})"></h2>
18+
<pre style="background: #f5f5f5; color: #333; padding: 1em; overflow: auto;"
19+
tal:content="structure view/esign_session_html" />
20+
</tal:esign>
21+
22+
</div>
23+
</metal:bodytext>
24+
</body>
25+
</html>

imio/dms/mail/browser/views.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from AccessControl import getSecurityManager
3+
from AccessControl import Unauthorized
34
from Acquisition import aq_inner
45
from collective.ckeditortemplates.cktemplate import ICKTemplate
56
from datetime import datetime
@@ -15,17 +16,20 @@
1516
from imio.dms.mail.interfaces import IPersonnelContact
1617
from imio.dms.mail.utils import current_user_groups_ids
1718
from imio.dms.mail.utils import get_dms_config
19+
from imio.dms.mail.utils import persistent_to_native
1820
from imio.esign import manage_session_perm
1921
from imio.esign.browser.views import ExternalSessionCreateView
2022
from imio.esign.browser.views import SessionsListingView
2123
from imio.esign.config import get_registry_enabled
24+
from imio.esign.utils import get_session_annotation
2225
from imio.helpers.content import richtextval
2326
from imio.helpers.content import uuidToObject
2427
from imio.helpers.emailer import add_attachment
2528
from imio.helpers.emailer import create_html_email
2629
from imio.helpers.emailer import get_mail_host
2730
from imio.helpers.emailer import send_email
2831
from imio.helpers.fancytree.views import BaseRenderFancyTree
32+
from imio.helpers.security import check_zope_admin
2933
from imio.helpers.workflow import do_transitions
3034
from imio.helpers.xhtml import object_link
3135
from plone import api
@@ -48,6 +52,7 @@
4852
from zope.pagetemplate.pagetemplate import PageTemplate
4953

5054
import json
55+
import pprint
5156

5257

5358
class CreateFromTemplateForm(BaseRenderFancyTree):
@@ -643,3 +648,76 @@ def get_link_url(item):
643648
result = sorted(result, key=lambda x: x['id'] == "plus")
644649

645650
return result
651+
652+
653+
class SigningAnnotationInfoView(BrowserView):
654+
"""Admin-only view displaying idm.approval and imio.esign session annotations for an outgoing mail."""
655+
656+
index = ViewPageTemplateFile("templates/signing_annotation_info.pt")
657+
658+
def __call__(self):
659+
if not check_zope_admin():
660+
raise Unauthorized
661+
return self.index()
662+
663+
def _uid_to_link(self, uid):
664+
"""Return an HTML link for an object UID, or the UID if not found."""
665+
obj = uuidToObject(uid, unrestricted=True)
666+
if obj is None:
667+
return u"<span title='not found'>{}</span>".format(safe_unicode(uid))
668+
url = obj.absolute_url()
669+
title = safe_unicode(getattr(obj, 'title', '') or uid)
670+
path = u"/".join(obj.getPhysicalPath())
671+
return u"<a href='{}' title='{}'>{}</a>".format(url, path, title)
672+
673+
def _render_value(self, value, indent=u""):
674+
"""Render a value, replacing UIDs with links where possible."""
675+
inner = indent + u" "
676+
if isinstance(value, dict):
677+
if not value:
678+
return u"{}"
679+
lines = [u"{"]
680+
for k, v in sorted(value.items()):
681+
lines.append(u"{}{!r}: {},".format(inner, k, self._render_value(v, inner)))
682+
lines.append(u"{}}}".format(indent))
683+
return u"\n".join(lines)
684+
elif isinstance(value, (list, tuple)):
685+
if not value:
686+
return u"[]"
687+
lines = [u"["]
688+
for item in value:
689+
lines.append(u"{}{},".format(inner, self._render_value(item, inner)))
690+
lines.append(u"{}]".format(indent))
691+
return u"\n".join(lines)
692+
elif isinstance(value, basestring) and len(value) == 32 and value.isalnum():
693+
# Looks like a UUID
694+
return self._uid_to_link(value)
695+
else:
696+
return safe_unicode(pprint.pformat(value))
697+
698+
@property
699+
def approval_annot_html(self):
700+
approval = IOMApproval(self.context)
701+
native = persistent_to_native(approval.annot)
702+
return self._render_value(native)
703+
704+
@property
705+
def esign_session_id(self):
706+
approval = IOMApproval(self.context)
707+
return approval.annot.get("session_id")
708+
709+
@property
710+
def esign_session(self):
711+
session_id = self.esign_session_id
712+
if session_id is None:
713+
return None
714+
annot = get_session_annotation()
715+
return annot["sessions"].get(session_id)
716+
717+
@property
718+
def esign_session_html(self):
719+
session = self.esign_session
720+
if session is None:
721+
return u""
722+
native = persistent_to_native(session)
723+
return self._render_value(native)

0 commit comments

Comments
 (0)