Skip to content

Commit 2225014

Browse files
committed
Added possiblity to add custom data when creating session
Fixed delete session action Make ItemSessionInfoViewlet inherits from FacetedSessionInfoViewlet Added utils.get_session_info
1 parent ef77ab7 commit 2225014

File tree

7 files changed

+68
-30
lines changed

7 files changed

+68
-30
lines changed

src/imio/esign/adapters.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def get_watchers(self):
7777

7878
def get_discriminators(self):
7979
"""
80-
List of watchers email for that element.
80+
List of discriminators for that element to associate it to an available session.
8181
"""
8282
return []
83+
84+
def get_create_session_custom_data(self):
85+
"""
86+
Dict of custom data that will be stored on session at creation time.
87+
"""
88+
return {}

src/imio/esign/browser/configure.zcml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
for="eea.facetednavigation.subtypes.interfaces.IFacetedNavigable"
7272
manager="collective.eeafaceted.z3ctable.interfaces.ITopAboveNavManager"
7373
name="esign-faceted-session-info"
74-
template="templates/faceted_session_info.pt"
74+
template="templates/session_info.pt"
7575
class=".views.FacetedSessionInfoViewlet"
7676
permission="zope2.View"
7777
/>
@@ -81,7 +81,7 @@
8181
manager="plone.app.layout.viewlets.interfaces.IBelowContentTitle"
8282
view="plone.app.layout.globals.interfaces.IViewView"
8383
name="esign-item-session-info"
84-
template="templates/faceted_session_info.pt"
84+
template="templates/session_info.pt"
8585
class=".views.ItemSessionInfoViewlet"
8686
permission="imio.esign.ManageSessions"
8787
/-->

src/imio/esign/browser/table.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
from eea.facetednavigation.interfaces import IFacetedNavigable
23
from DateTime import DateTime
34
from imio.esign import _
45
from imio.esign import manage_session_perm
@@ -14,10 +15,18 @@ class IdColumn(Column):
1415
weight = 10
1516
cssClasses = {"th": "th_header_sessions_id"}
1617

18+
def renderHeadCell(self):
19+
"""
20+
Override to add JS that will the "No results" link when displayed in faceted dashboard.
21+
"""
22+
res = super(IdColumn, self).renderHeadCell()
23+
if IFacetedNavigable.providedBy(self.context):
24+
res += "<script>$('div.table_faceted_results').hide();</script>"
25+
return res
26+
1727
def renderCell(self, item):
1828
# this will hide the "No results" link when displayed in faceted dashboard
19-
return "<script>$('div.table_faceted_results').hide();</script>" \
20-
"<span id='{0}'>{0}</span>".format(str(item.get("id")))
29+
return "<span id='{0}'>{0}</span>".format(str(item.get("id")))
2130

2231

2332
def external_session_link(session, title=None):
@@ -104,7 +113,7 @@ def renderCell(self, item):
104113
u"onclick=\"toggleDetails('collapsible-session-files_{0}', "
105114
u"toggle_parent_active=true, parent_tag=null, "
106115
u"load_view='@@esign-session-files?session_id={0}', "
107-
u"base_url='{1}');\"> <a href='#'>{2}</a></div>"
116+
u"base_url='{1}');\"> {2}</div>"
108117
u'<div id="collapsible-session-files_{0}" class="collapsible-content" style="display: none;">'
109118
u'<div class="collapsible-inner-content">'
110119
u'<img src="{1}/spinner_small.gif" />'
@@ -126,12 +135,11 @@ def renderCell(self, item):
126135
session_id = item.get("id")
127136
dashboard_link = self.table.view.get_dashboard_link({"id": session_id})
128137
sessions_url = self.table.view.get_sessions_url()
129-
if not sessions_url.endswith("/"):
130-
sessions_url += "/"
138+
#if not sessions_url.endswith("/"):
139+
# sessions_url += "/"
131140
admin_buttons = u"""
132141
<img title="{delete}" onclick="javascript:confirmDeleteObject(base_url='{sessions_url}', object_uid=null, this,
133-
msgName=null, view_name='@@esign-session-delete?esign_session_id={session_id}');
134-
window.location.reload();" style="cursor:pointer" src="delete_icon.png">
142+
msgName=null, view_name='@@esign-session-delete?esign_session_id={session_id}', redirect=null);" style="cursor:pointer" src="delete_icon.png">
135143
""".format(
136144
delete=translate(_("Delete session"), context=self.request),
137145
sessions_url=sessions_url,
File renamed without changes.

src/imio/esign/browser/views.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ def __call__(self, session_id=None):
161161
class FacetedSessionInfoViewlet(ViewletBase):
162162
"""Show selected session info inside faceted results."""
163163

164-
index = ViewPageTemplateFile("templates/faceted_session_info.pt")
165164
sessions_listing_view = SessionsListingView # to be overridden in subclass
166165

167166
def available(self):
@@ -195,24 +194,26 @@ def session(self):
195194
session["id"] = session_id
196195
return session
197196

197+
def get_table_rows(self, column):
198+
"""Get the table rows following the column"""
199+
return {1: ["session_id", "state", "update_date", "sealed"],
200+
2: ["external_link", "signers"]}.get(column, [])
201+
198202
def ext_session_link(self, session):
199203
return external_session_link(session)
200204

205+
@property
206+
def session_listing_url(self):
207+
return api.portal.get().absolute_url() + "/sessions/@@esign-sessions-listing"
201208

202-
class ItemSessionInfoViewlet(ViewletBase):
203-
"""Show selected session info for an item."""
204209

205-
index = ViewPageTemplateFile("templates/faceted_session_info.pt")
210+
class ItemSessionInfoViewlet(FacetedSessionInfoViewlet):
211+
"""Show selected session info for an item."""
206212

207213
def available(self):
208214
"""Global availability of the viewlet."""
209215
return True
210216

211-
def get_table_rows(self, column):
212-
"""Get the table rows following the column"""
213-
return {1: ["session_id", "state", "update_date", "sealed"],
214-
2: ["external_link", "signers"]}.get(column, [])
215-
216217
def render(self):
217218
"""Render the viewlet."""
218219
if self.session:
@@ -229,14 +230,6 @@ def session(self):
229230
return session
230231
return {}
231232

232-
@property
233-
def session_listing_url(self):
234-
return api.portal.get().absolute_url() + "/@@esign-sessions-listing"
235-
236-
def ext_session_link(self, session):
237-
return external_session_link(session)
238-
# TODO clean up css
239-
240233

241234
@implementer(IPublishTraverse)
242235
class DownloadFileView(BrowserView):

src/imio/esign/tests/test_utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from imio.esign.utils import get_file_download_url
88
from imio.esign.utils import get_max_download_date
99
from imio.esign.utils import get_session_annotation
10+
from imio.esign.utils import get_session_info
1011
from imio.esign.utils import remove_context_from_session
1112
from imio.esign.utils import remove_files_from_session
1213
from imio.esign.utils import remove_session
@@ -298,6 +299,20 @@ def test_remove_session(self):
298299
self.assertEqual(len(annot["c_uids"]), 2)
299300
self.assertEqual(len(annot["sessions"]), 1)
300301

302+
def test_get_session_info(self):
303+
"""Test getting info about a given session id."""
304+
annot = get_session_annotation()
305+
self.assertEqual(len(annot["sessions"]), 0)
306+
self.assertIsNone(get_session_info(0))
307+
self.assertIsNone(get_session_info(1))
308+
self.assertIsNone(get_session_info(2))
309+
signers = [
310+
("user1", "user1@sign.com", "User 1", "Position 1"),
311+
("user2", "user2@sign.com", "User 2", "Position 2"),
312+
]
313+
sid, session = add_files_to_session(signers, (self.uids[0], self.uids[1]))
314+
self.assertEqual(get_session_info(sid), session)
315+
301316
def test_get_file_download_url(self):
302317
"""Test generating file download URL from UID."""
303318
uid = "f40682caafc045b4b81973bd82ea9ab6"

src/imio/esign/utils.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
def add_files_to_session(
33-
signers, files_uids, seal=None, acroform=True, session_id=None, title=None, discriminators=(), watchers=()
33+
signers, files_uids, seal=None, acroform=True, session_id=None, title=None, discriminators=(), watchers=(), create_session_custom_data={}
3434
):
3535
"""Add files to a session with the given signers.
3636
@@ -42,6 +42,7 @@ def add_files_to_session(
4242
:param title: optional string for session title. If it contains {sign_id} or {session_id} it will be replaced
4343
:param discriminators: optional list of string discriminators to use for session discrimination
4444
:param watchers: optional list of external esign session watchers emails (used only when creating a new session)
45+
:param create_session_custom_data: optional custom dict of custom session data
4546
:return: session_id, session
4647
"""
4748
annot = get_session_annotation()
@@ -56,7 +57,8 @@ def add_files_to_session(
5657
if not session:
5758
session_id, session = create_session(
5859
signers, seal, acroform=acroform, title=title or "", annot=annot, discriminators=discriminators,
59-
watchers=watchers
60+
watchers=watchers,
61+
create_session_custom_data=create_session_custom_data,
6062
)
6163
existing_files = [path.splitext(f["filename"])[0] for f in session["files"]]
6264
for uid in files_uids:
@@ -170,7 +172,7 @@ def create_external_session(session_id, b64_cred=None, esign_root_url=None):
170172
return ret
171173

172174

173-
def create_session(signers, seal=False, acroform=True, title=None, annot=None, discriminators=(), watchers=()):
175+
def create_session(signers, seal=False, acroform=True, title=None, annot=None, discriminators=(), watchers=(), create_session_custom_data={}):
174176
"""Create a session with the given signers and seal.
175177
176178
:param signers: a list of signers, each is a quartet with userid, email, fullname and position text
@@ -180,6 +182,7 @@ def create_session(signers, seal=False, acroform=True, title=None, annot=None, d
180182
:param annot: esign annotation, if not provided it will be fetched
181183
:param discriminators: optional list of string discriminators
182184
:param watchers: optional list of external esign session watchers emails
185+
:param create_session_custom_data: optional custom dict of custom session data
183186
:return: session id and session information
184187
"""
185188
if not annot:
@@ -208,6 +211,8 @@ def create_session(signers, seal=False, acroform=True, title=None, annot=None, d
208211
"title": title,
209212
"returns": PersistentList(),
210213
})
214+
for k, v in create_session_custom_data.items():
215+
sessions[session_id][k] = v
211216
return session_id, sessions[session_id]
212217

213218

@@ -300,6 +305,17 @@ def get_session_annotation(portal=None):
300305
return annotations["imio.esign"]
301306

302307

308+
def get_session_info(session_id, portal=None):
309+
"""Return a session info for a given numbering.
310+
311+
:param session_id: the session id to return
312+
:param portal: portal if necessary to get the session annotation
313+
"""
314+
annot = get_session_annotation(portal=portal)
315+
if session_id in annot['sessions']:
316+
return annot['sessions'][session_id]
317+
318+
303319
def remove_context_from_session(context_uids):
304320
"""Remove all files from a session that are linked to the given context UIDs.
305321

0 commit comments

Comments
 (0)