Skip to content

Commit f9cef7c

Browse files
committed
Merge remote-tracking branch 'origin/main' into PARAF-359_file_added_to_same_session_again
2 parents 9eefa2e + 76b0cbd commit f9cef7c

File tree

7 files changed

+468
-47
lines changed

7 files changed

+468
-47
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Changelog
2929
[chris-adam]
3030
- Added external watchers for esign sessions.
3131
[chris-adam, sgeulette]
32+
- Added possibility to have elements of the same context to belong to different sessions.
33+
[chris-adam]
3234
- Manage file added again to same session, data is updated.
3335
[gbastien]
3436

src/imio/esign/browser/templates/macros.pt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<tr metal:define-macro="session_id" i18n:domain="imio.esign">
22
<td class="table_widget_label"><label i18n:translate="">Session ID</label></td>
33
<td class="table_widget_value" tal:define="can_link python:view.can_display_sessions_listing_link()">
4-
<span tal:condition="not: can_link" tal:content="python: session['id']">25452</span>
4+
<span tal:condition="not: can_link" tal:content="python: session_id">25452</span>
55
<a tal:condition="can_link" href="#" target="_blank"
6-
tal:content="python: session['id']"
7-
tal:attributes="href python:'{}#{}'.format(view.session_listing_url, session['id'])">25452 - College</a>
6+
tal:content="python: session_id"
7+
tal:attributes="href python:'{}#{}'.format(view.session_listing_url, session_id)">25452 - College</a>
88
</td>
99
</tr>
1010
<tr metal:define-macro="state" i18n:domain="imio.esign">
@@ -40,7 +40,7 @@
4040
<tr metal:define-macro="signers" i18n:domain="imio.esign">
4141
<td class="table_widget_label"><label i18n:translate="">Signers</label></td>
4242
<td class="table_widget_value">
43-
<table id="context_viewlet_signers_table" class="no-border no-style-table listing"
43+
<table class="context_viewlet_signers_table no-border no-style-table listing"
4444
tal:define="signers python:session.get('signers', [])">
4545
<thead>
4646
<tr>

src/imio/esign/browser/templates/session_info.pt

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,37 @@
1212
</div>
1313
<div id="collapsible-session-info"
1414
tal:attributes="class python: view.collapsible_content_css_default()">
15-
<div class="collapsible-inner-content session-info-container"
16-
tal:define="template python: context.unrestrictedTraverse('@@esign-macros').index;
17-
session python: view.session">
18-
<div class="session-info-column">
19-
<table id="context_viewlet_session_table" class="no-style-table table-view-widgets">
20-
<tbody>
21-
<tal:block tal:repeat="macro_name python:view.get_table_rows(1)">
22-
<metal:render_cell use-macro="python: template.macros[macro_name]" />
23-
</tal:block>
24-
</tbody>
25-
</table>
26-
</div>
15+
<tal:loop repeat="session_infos python:view.sessions.items()">
16+
<div class="collapsible-inner-content session-info-container"
17+
tal:attributes="class python:'collapsible-inner-content session-info-container ' + classOddEven"
18+
tal:define="oddrow repeat/session_infos/odd;
19+
classOddEven python: oddrow and 'even' or 'odd';
20+
template python: context.unrestrictedTraverse('@@esign-macros').index">
21+
<tal:session_defines define="session_id python: session_infos[0];
22+
session python: session_infos[1]">
23+
<div class="session-info-column">
24+
<table tal:attributes="id string:context_viewlet_session_table_${session_id}" class="no-style-table table-view-widgets">
25+
<tbody>
26+
<tal:block tal:repeat="macro_name python:view.get_table_rows(1)">
27+
<metal:render_cell use-macro="python: template.macros[macro_name]" />
28+
</tal:block>
29+
</tbody>
30+
</table>
31+
</div>
2732

28-
<div class="session-info-column">
29-
<table id="context_viewlet_session_signers" class="no-style-table table-view-widgets">
30-
<tbody>
31-
<tal:block tal:repeat="macro_name python:view.get_table_rows(2)">
32-
<metal:render_cell use-macro="python: template.macros[macro_name]" />
33-
</tal:block>
34-
</tbody>
35-
</table>
33+
<div class="session-info-column">
34+
<table tal:attributes="id string:context_viewlet_session_signers_${session_id}" class="no-style-table table-view-widgets">
35+
<tbody>
36+
<tal:block tal:repeat="macro_name python:view.get_table_rows(2)">
37+
<metal:render_cell use-macro="python: template.macros[macro_name]" />
38+
</tal:block>
39+
</tbody>
40+
</table>
41+
</div>
42+
</tal:session_defines>
3643
</div>
37-
<script>$('table#context_viewlet_signers_table').each(setoddeven);</script>
38-
</div>
44+
</tal:loop>
45+
<script>$('table.context_viewlet_signers_table').each(setoddeven);</script>
3946
</div>
4047
</div>
4148

src/imio/esign/browser/views.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
from AccessControl import Unauthorized
4+
from copy import deepcopy
45
from datetime import datetime
56
from datetime import timedelta
67
from imio.esign import _
@@ -12,6 +13,7 @@
1213
from imio.esign.config import get_registry_signing_users_email_content
1314
from imio.esign.utils import create_external_session
1415
from imio.esign.utils import get_session_annotation
16+
from imio.esign.utils import get_sessions_for
1517
from imio.esign.utils import get_state_description
1618
from imio.esign.utils import remove_session
1719
from imio.helpers.content import uuidToObject
@@ -206,23 +208,25 @@ def sessions_collection_uid(self):
206208
def render(self):
207209
"""Render the viewlet."""
208210
if self.request.form.get("c1[]", None) == self.sessions_collection_uid:
209-
if self.session:
211+
if self.sessions:
210212
return self.index()
211213
return self.sessions_listing_view(self.context, self.request).render_table()
212214
return ""
213215

214216
@property
215-
def session(self):
216-
session = None
217+
def sessions(self):
217218
session_id = self.request.form.get("esign_session_id[]", None)
218-
if not session_id:
219-
return
219+
try:
220+
session_id = int(session_id)
221+
except (TypeError, ValueError):
222+
return []
220223
sessions = get_session_annotation()["sessions"]
221-
session = sessions.get(int(session_id))
224+
session = sessions.get(session_id)
222225
if not session:
223-
return
226+
return []
227+
session = deepcopy(session)
224228
session["id"] = session_id
225-
return session
229+
return [session]
226230

227231
def get_table_rows(self, column):
228232
"""Get the table rows following the column"""
@@ -252,27 +256,22 @@ def get_state_description(self, state):
252256

253257

254258
class ItemSessionInfoViewlet(FacetedSessionInfoViewlet):
255-
"""Show selected session info for an item."""
259+
"""Show session info for all sessions linked to a context item."""
256260

257261
def available(self):
258262
"""Global availability of the viewlet."""
259263
return True
260264

261265
def render(self):
262266
"""Render the viewlet."""
263-
if self.session:
267+
if self.sessions:
264268
return self.index()
265269
return ""
266270

267271
@property
268-
def session(self):
269-
annot = get_session_annotation()
270-
for f_uid in annot["c_uids"].get(self.context.UID(), []):
271-
if f_uid in annot["uids"]:
272-
session = annot["sessions"].get(annot["uids"][f_uid], {})
273-
session["id"] = annot["uids"][f_uid]
274-
return session
275-
return {}
272+
def sessions(self):
273+
"""Return all sessions that contain files from this context."""
274+
return get_sessions_for(self.context.UID())
276275

277276

278277
@implementer(IPublishTraverse)
@@ -420,12 +419,17 @@ def filter_user(self, user_data):
420419
portal_type="held_position",
421420
userid=user_data["userid"],
422421
)
423-
if not hps:
424-
return False
425422
for hp in hps:
426423
hp_obj = hp.getObject()
427424
if base_hasattr(hp_obj, "usages") and "signer" in hp_obj.usages:
428425
return True
426+
427+
user_obj = api.user.get(userid=user_data["userid"])
428+
if user_obj:
429+
for group in api.group.get_groups(user=user_obj):
430+
if group.getId().endswith("watchers"):
431+
return True
432+
429433
return False
430434

431435
def get_users_data(self):
@@ -515,7 +519,7 @@ def _get_selected_userids(self):
515519
# Parse JSON array
516520
try:
517521
return json.loads(selected)
518-
except (json.JSONDecodeError, ValueError, TypeError):
522+
except (ValueError, TypeError):
519523
return []
520524

521525
def _download_csv(self):

0 commit comments

Comments
 (0)