Skip to content

Commit 15fac18

Browse files
committed
Simplified get_signers that now returns name, function, held_position, userid and email and must ensure that everything is correct or will raise ValueError in case something goes wrong (no userid, same userid for several signer, same email for several signers, ...)
Added ISignable.get_observers
1 parent 31a0af6 commit 15fac18

File tree

2 files changed

+28
-42
lines changed

2 files changed

+28
-42
lines changed

src/imio/esign/adapters.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,20 @@ def get_session(self, session_id=None):
5454
class ISignable(Interface):
5555
def get_signers(self):
5656
"""
57-
List signers for that item.
58-
returns a list of dict with keys: name, function, held_position
59-
Must make sure a valid userid if linked to the held_position.person
57+
List signers for that element.
58+
returns a list of dict with keys:
59+
name, function, held_position, userid and email
60+
Ensure a valid userid is linked to the held_position.person and a
61+
unique email is used for every signers
62+
Raise ValueError in case an error occurs.
6063
"""
6164

6265
def get_files_uids(self):
6366
"""
6467
List of file uids to sign.
6568
"""
69+
70+
def get_observers(self):
71+
"""
72+
List of observers for that element.
73+
"""

src/imio/esign/browser/actions.py

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,51 +39,29 @@ def index(self):
3939
)
4040
self._finished()
4141

42-
def _get_signers(self, show_message=True):
43-
"""Get the list of held_positions to be used as signer.
44-
45-
:return: list of signer infos with "held_position", "name" and "function"
46-
"""
47-
res = []
48-
for signer_info in ISignable(self.context).get_signers():
49-
if not signer_info["held_position"]:
50-
if show_message is True:
51-
api.portal.show_message(
52-
_(
53-
"Problem with certified signatories, make sure a held position "
54-
'is selected for each signatory (check "${name}/${function}")!',
55-
mapping={"name": signer_info["name"], "function": signer_info["function"]},
56-
),
57-
request=self.request,
58-
type="warning",
59-
)
60-
return []
61-
res.append(signer_info)
62-
return res
63-
6442
def get_signers(self):
65-
"""List of signers, should not be overrided, rely on self._get_signers.
43+
"""Get the list of held_positions to be used as signer.
6644
67-
:return: list of signer infos (userid, email, fullname, position)
45+
:return: list of signer infos with "held_position", "name",
46+
"function", "userid" and "email"
6847
"""
69-
res = []
70-
signer_infos = self._get_signers()
71-
# signers is a list of held_positions
72-
for signer_info in signer_infos:
73-
# get email from user
74-
hp = signer_info["held_position"]
75-
signer_person = hp.get_person()
76-
userid = signer_person.userid
77-
user = api.user.get(userid)
78-
email = user.getProperty("email")
79-
person_title = signer_info["name"] or signer_person.get_title(include_person_title=False)
80-
hp_label = signer_info["function"] or hp.label or u""
81-
res.append((userid, email, person_title, hp_label))
82-
return tuple(res)
48+
try:
49+
signers = ISignable(self.context).get_signers()
50+
except ValueError, msg:
51+
signers = []
52+
api.portal.show_message(
53+
_(
54+
"Problem getting signers: \"${error}\")!",
55+
mapping={"error": msg},
56+
),
57+
request=self.request,
58+
type="warning",
59+
)
60+
return signers
8361

8462
def get_observers(self):
8563
"""List of observers."""
86-
return ()
64+
return ISignable(self.context).get_observers()
8765

8866
def get_context_uid(self):
8967
""" """

0 commit comments

Comments
 (0)