|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 |
|
3 | 3 | from AccessControl import Unauthorized |
| 4 | +from copy import deepcopy |
4 | 5 | from datetime import datetime |
5 | 6 | from datetime import timedelta |
6 | 7 | from imio.esign import _ |
|
12 | 13 | from imio.esign.config import get_registry_signing_users_email_content |
13 | 14 | from imio.esign.utils import create_external_session |
14 | 15 | from imio.esign.utils import get_session_annotation |
| 16 | +from imio.esign.utils import get_sessions_for |
15 | 17 | from imio.esign.utils import get_state_description |
16 | 18 | from imio.esign.utils import remove_session |
17 | 19 | from imio.helpers.content import uuidToObject |
@@ -206,23 +208,25 @@ def sessions_collection_uid(self): |
206 | 208 | def render(self): |
207 | 209 | """Render the viewlet.""" |
208 | 210 | if self.request.form.get("c1[]", None) == self.sessions_collection_uid: |
209 | | - if self.session: |
| 211 | + if self.sessions: |
210 | 212 | return self.index() |
211 | 213 | return self.sessions_listing_view(self.context, self.request).render_table() |
212 | 214 | return "" |
213 | 215 |
|
214 | 216 | @property |
215 | | - def session(self): |
216 | | - session = None |
| 217 | + def sessions(self): |
217 | 218 | 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 [] |
220 | 223 | sessions = get_session_annotation()["sessions"] |
221 | | - session = sessions.get(int(session_id)) |
| 224 | + session = sessions.get(session_id) |
222 | 225 | if not session: |
223 | | - return |
| 226 | + return [] |
| 227 | + session = deepcopy(session) |
224 | 228 | session["id"] = session_id |
225 | | - return session |
| 229 | + return [session] |
226 | 230 |
|
227 | 231 | def get_table_rows(self, column): |
228 | 232 | """Get the table rows following the column""" |
@@ -252,27 +256,22 @@ def get_state_description(self, state): |
252 | 256 |
|
253 | 257 |
|
254 | 258 | class ItemSessionInfoViewlet(FacetedSessionInfoViewlet): |
255 | | - """Show selected session info for an item.""" |
| 259 | + """Show session info for all sessions linked to a context item.""" |
256 | 260 |
|
257 | 261 | def available(self): |
258 | 262 | """Global availability of the viewlet.""" |
259 | 263 | return True |
260 | 264 |
|
261 | 265 | def render(self): |
262 | 266 | """Render the viewlet.""" |
263 | | - if self.session: |
| 267 | + if self.sessions: |
264 | 268 | return self.index() |
265 | 269 | return "" |
266 | 270 |
|
267 | 271 | @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()) |
276 | 275 |
|
277 | 276 |
|
278 | 277 | @implementer(IPublishTraverse) |
@@ -420,12 +419,17 @@ def filter_user(self, user_data): |
420 | 419 | portal_type="held_position", |
421 | 420 | userid=user_data["userid"], |
422 | 421 | ) |
423 | | - if not hps: |
424 | | - return False |
425 | 422 | for hp in hps: |
426 | 423 | hp_obj = hp.getObject() |
427 | 424 | if base_hasattr(hp_obj, "usages") and "signer" in hp_obj.usages: |
428 | 425 | 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 | + |
429 | 433 | return False |
430 | 434 |
|
431 | 435 | def get_users_data(self): |
@@ -515,7 +519,7 @@ def _get_selected_userids(self): |
515 | 519 | # Parse JSON array |
516 | 520 | try: |
517 | 521 | return json.loads(selected) |
518 | | - except (json.JSONDecodeError, ValueError, TypeError): |
| 522 | + except (ValueError, TypeError): |
519 | 523 | return [] |
520 | 524 |
|
521 | 525 | def _download_csv(self): |
|
0 commit comments