11# -*- coding: utf-8 -*-
2+ from datetime import datetime
3+ from imio .dms .mail import _
24from imio .dms .mail .utils import add_mail_files_to_session
35from imio .dms .mail .utils import change_approval_user_status
46from imio .dms .mail .utils import get_approval_annot
7+ from imio .esign .utils import get_session_annotation
58from plone import api
69from Products .CMFPlone .utils import safe_unicode
710
@@ -40,14 +43,6 @@ def approve_file(self, mail=None, userid=None):
4043 type = "warning" ,
4144 )
4245 return self .REQUEST .RESPONSE .redirect (mail .absolute_url ())
43- # TODO is this useful ?
44- if approval ["users" ][userid ]["status" ] != "w" :
45- api .portal .show_message (
46- message = u"Current user {} has already approved the file." .format (userid ),
47- request = self .REQUEST ,
48- type = "warning" ,
49- )
50- return self .REQUEST .RESPONSE .redirect (mail .absolute_url ())
5146 f_uid = afile .UID ()
5247 if f_uid not in approval ["files" ]:
5348 api .portal .show_message (
@@ -68,6 +63,7 @@ def approve_file(self, mail=None, userid=None):
6863 # "awaiting" (w), "pending" (p), "approved" (a)
6964 # approve
7065 approval ["files" ][f_uid ][c_a ]["approved_by" ] = userid
66+ approval ["files" ][f_uid ][c_a ]["approved_on" ] = datetime .now ()
7167 approval ["files" ][f_uid ][c_a ]["status" ] = "a"
7268 """
7369 {
@@ -129,3 +125,36 @@ def approve_files(self, userid=None):
129125 for fil in self .get_files_to_sign ():
130126 approve_file (fil , mail = self , userid = userid )
131127 return self .REQUEST .RESPONSE .redirect (self .absolute_url ())
128+
129+
130+ def print_session_annotation (self ):
131+ """
132+ Print the session annotation for debug.
133+ """
134+ annot = get_session_annotation ()
135+ return str (annot )
136+
137+
138+ def add_to_session (self ):
139+ """
140+ Add the current file to the esign session.
141+ """
142+ if self .portal_type != "dmsoutgoingmail" :
143+ return
144+ mail = self
145+ ret , msg = add_mail_files_to_session (mail , approval = get_approval_annot (mail ))
146+ if not ret :
147+ api .portal .show_message (
148+ message = _ (u"There was an error while creating the signing session: ${msg} !" ,
149+ mapping = {"msg" : msg }),
150+ request = mail .REQUEST ,
151+ type = "error" ,
152+ )
153+ else :
154+ api .portal .show_message (
155+ message = _ (u"A signing session has been created: ${msg}." ,
156+ mapping = {"msg" : msg }),
157+ request = mail .REQUEST ,
158+ type = "info" ,
159+ )
160+ return self .REQUEST .RESPONSE .redirect (mail .absolute_url ())
0 commit comments