Skip to content

Commit c04ef48

Browse files
authored
Merge pull request #41 from IMIO/imio_annex
imio.annex integration
2 parents 5f27897 + 2ad5a59 commit c04ef48

File tree

21 files changed

+615
-15
lines changed

21 files changed

+615
-15
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Changelog
1818
[sgeulette]
1919
- Used session from imio.esign.
2020
[sgeulette]
21+
- Added 'imio.annex' and iconified categories to dms files and dms appendix files.
22+
[sgeulette, chris-adam]
2123

2224
3.0 (2021-09-30)
2325
----------------

imio/dms/mail/Extensions/demo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,3 +535,13 @@ def activate_signing(self):
535535
)
536536

537537
return portal.REQUEST.response.redirect(portal.absolute_url())
538+
539+
540+
def disable_resources_debug_mode(self):
541+
portal = self
542+
css_tool = portal.portal_css
543+
js_tool = portal.portal_javascripts
544+
if getattr(css_tool, 'getDebugMode', None):
545+
css_tool.setDebugMode(False)
546+
if getattr(js_tool, 'getDebugMode', None):
547+
js_tool.setDebugMode(False)

imio/dms/mail/adapters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,7 @@ def config(self):
11421142
if annot["approval"] != 99 and annot["users"][userid]["order"] > annot["approval"]:
11431143
continue # only users that can approve have visibility
11441144
def_roles = ["Reader"]
1145+
# TODO add a specific role and permission to manage approval ?
11451146
if annot["users"][userid].get("editor"):
11461147
def_roles.append("Editor")
11471148
roles[userid] = tuple(def_roles)

imio/dms/mail/browser/configure.zcml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@
6161
permission="cmf.ModifyPortalContent"
6262
/>
6363

64+
<browser:page
65+
for="imio.dms.mail.dmsfile.IImioDmsFile"
66+
name="iconified-approved"
67+
layer="collective.iconifiedcategory.interfaces.ICollectiveIconifiedCategoryLayer"
68+
class=".iconified_category.ApprovedChangeView"
69+
permission="zope2.View"
70+
/>
71+
6472
<browser:page
6573
for="imio.dms.mail.interfaces.IPersonnelFolder"
6674
name="personnel-listing"
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
collective.iconifiedcategory overrided views
4+
"""
5+
from collective.iconifiedcategory.browser.actionview import ApprovedChangeView as BaseApprovedChangeView
6+
from collective.iconifiedcategory.browser.tabview import ApprovedColumn as BaseApprovedColumn
7+
from imio.dms.mail.utils import add_file_to_approval
8+
from imio.dms.mail.utils import approve_file
9+
from imio.dms.mail.utils import can_approve
10+
from imio.dms.mail.utils import get_approval_annot
11+
from imio.dms.mail.utils import is_file_approved
12+
from imio.dms.mail.utils import logger # noqa F401
13+
from imio.dms.mail.utils import remove_file_from_approval
14+
from plone import api
15+
from zope.i18n import translate
16+
17+
18+
"""
19+
{
20+
'approval': 1,
21+
'files': {'4115fb4c265647ca82d85285504973b8': {1: {'status': 'p'}, 2: {'status': 'w'}}},
22+
'numbers': {
23+
1: {'status': 'p', 'signer': ('dirg', '[email protected]', u'Maxime DG', u'Directeur G\xe9n\xe9ral'),
24+
'users': ['dirg']},
25+
2: {'status': 'w', 'signer': ('bourgmestre', '[email protected]', u'Paul BM', u'Bourgmestre'),
26+
'users': ['bourgmestre', 'chef']}},
27+
'session_id': None,
28+
'users': {'bourgmestre': {'status': 'w', 'editor': False, 'name': u'Monsieur Paul BM', 'order': 2},
29+
'chef': {'status': 'w', 'editor': False, 'name': u'Monsieur Michel Chef', 'order': 2},
30+
'dirg': {'status': 'w', 'editor': True, 'name': u'Monsieur Maxime DG', 'order': 1}},
31+
}
32+
""" # noqa
33+
34+
35+
class ApprovedColumn(BaseApprovedColumn):
36+
37+
the_object = True
38+
39+
def __init__(self, context, request, table):
40+
super(ApprovedColumn, self).__init__(context, request, table)
41+
# self.context is the mail here
42+
self.a_a = get_approval_annot(self.context)
43+
self.msg = u""
44+
45+
def alt(self, content):
46+
return translate(
47+
self.msg,
48+
context=self.table.request,
49+
domain='collective.iconifiedcategory',
50+
)
51+
52+
def css_class(self, content):
53+
av = self.get_action_view(content)
54+
editable = self.is_editable(content) and " editable" or ""
55+
# when deactivated, anyone see a grey icon
56+
if av.p_state not in ("to_approve", "to_be_signed", "signed", "sent"):
57+
if self.is_deactivated(content):
58+
if editable:
59+
self.msg = u"Deactivated for approval (click to activate)"
60+
return " deactivated editable"
61+
else:
62+
self.msg = u"Deactivated for approval"
63+
return " deactivated"
64+
elif editable:
65+
self.msg = u"Activated for approval (click to deactivate)"
66+
return editable
67+
else:
68+
self.msg = u"Activated for approval"
69+
return ""
70+
# when to_approve, the red icon (no class) is shown if :
71+
# * no approval at all
72+
# * but the current approver see a green icon when he just approved
73+
elif av.p_state == "to_approve":
74+
if can_approve(self.a_a, av.userid, av.uid):
75+
if self.a_a["files"][content.UID][self.a_a["approval"]]["status"] == "a":
76+
self.msg = u"Already approved (click to change)"
77+
return " active{}".format(editable)
78+
self.msg = u"Waiting for your approval (click to approve)"
79+
return editable
80+
else:
81+
self.msg = u"Waiting for approval but you can't approve (now)"
82+
# after a first approval, we show a partially or totally approved icon even for a previously or future approver
83+
if content["approved"]: # all approved
84+
self.msg = u"Totally approved"
85+
return " totally-approved"
86+
elif is_file_approved(self.a_a, content.UID, totally=False):
87+
self.msg = u"Partially approved. Still waiting for other approval(s)"
88+
return " partially-approved"
89+
return ""
90+
91+
def get_url(self, content):
92+
av = self.get_action_view(content)
93+
# after to_approve state, no one can click on the icon
94+
if av.p_state in ("to_be_signed", "signed", "sent"):
95+
return "#"
96+
# when to_approve, only an approver can click on the icon
97+
if av.p_state == "to_approve" and not can_approve(self.a_a, av.userid, av.uid):
98+
return "#"
99+
return '{url}/@@{action}'.format(
100+
url=content.getURL(),
101+
action=self.get_action_view_name(content),
102+
)
103+
104+
105+
class ApprovedChangeView(BaseApprovedChangeView):
106+
permission = "View"
107+
108+
def __init__(self, context, request):
109+
super(ApprovedChangeView, self).__init__(context, request)
110+
self.parent = self.context.__parent__
111+
self.p_state = api.content.get_state(self.parent)
112+
self.a_a = get_approval_annot(self.parent)
113+
self.reload = False
114+
self.user_id = None
115+
self.uid = self.context.UID()
116+
self.msg = u""
117+
118+
@property
119+
def userid(self):
120+
if self.user_id is None:
121+
self.user_id = api.user.get_current().getId()
122+
return self.user_id
123+
124+
def _get_next_values(self, old_values):
125+
""" """
126+
values = {}
127+
status = 0
128+
# logger.info("Before annot change: %s", self.a_a)
129+
# logger.info("Before values change: %s", old_values)
130+
if self.p_state == "to_approve":
131+
# in to_approve state, only an approver can approve or not
132+
if can_approve(self.a_a, self.userid, self.uid):
133+
if self.a_a["files"][self.uid][self.a_a["approval"]]["status"] == "a":
134+
status = 0
135+
self.msg = u"Already approved (click to change)"
136+
# TODO TO BE HANDLED
137+
else:
138+
self.msg = u"Waiting for your approval (click to approve)"
139+
# the status is changed (if totally approved) in sub method
140+
# must we pass self to update self.msg: no need for now because we reload in all cases !!
141+
ret, self.reload = approve_file(self.a_a, self.parent, self.context, self.userid, values=values,
142+
transition="propose_to_be_signed")
143+
status = int(ret)
144+
elif self.p_state not in ("to_be_signed", "signed", "sent"):
145+
# before to_approve state, we can only enable or disable to_approve
146+
if old_values['to_approve'] is False:
147+
values['to_approve'] = True
148+
values['approved'] = False
149+
status = 0
150+
add_file_to_approval(self.a_a, self.uid)
151+
self.msg = u"Activated for approval (click to deactivate)"
152+
else:
153+
values['to_approve'] = False
154+
values['approved'] = False
155+
status = -1
156+
remove_file_from_approval(self.a_a, self.uid)
157+
self.msg = u"Deactivated for approval (click to activate)"
158+
self.reload = False
159+
else:
160+
# cannot be in after to_approve state because get_url column method ?
161+
logger.warn("IN else of approved change view ???")
162+
# logger.info("After annot change: %s, ", self.a_a)
163+
# logger.info("After values change: %s, %s", status, values)
164+
return status, values
165+
166+
def _may_set_values(self, values, ):
167+
if self.p_state in ("to_be_signed", "signed", "sent"):
168+
return False
169+
return super(ApprovedChangeView, self)._may_set_values(values)
170+
171+
def set_values(self, values):
172+
old_values = self.get_current_values()
173+
status, values = self._get_next_values(old_values)
174+
super(BaseApprovedChangeView, self).set_values(values)
175+
return status, self.msg
176+
177+
def __call__(self):
178+
# TODO ajouter un comparatif de date afin de voir si on agit bien sur qlq chose à jour...
179+
json_resp = super(ApprovedChangeView, self).__call__()
180+
if self.reload and json_resp.rstrip().endswith("}"):
181+
# logger.info("RELOAD TRUE")
182+
json_resp = json_resp.rstrip()[:-1] + ',"reload": true}'
183+
return json_resp

imio/dms/mail/browser/viewlets.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,7 @@ class ImioFacetedSessionInfoViewlet(FacetedSessionInfoViewlet):
162162

163163
@property
164164
def sessions_collection_uid(self):
165-
return api.portal.get()["outgoing-mail"]["mail-searches"]["in_esign_sessions"].UID()
165+
om_searches_folder = api.portal.get()["outgoing-mail"]["mail-searches"]
166+
if "in_esign_sessions" not in om_searches_folder:
167+
return None
168+
return om_searches_folder["in_esign_sessions"].UID()

imio/dms/mail/columns.zcml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@
185185
name="dms.extedit"
186186
/>
187187

188+
<adapter
189+
name="approved-column"
190+
for="imio.dms.mail.dmsmail.IImioDmsOutgoingMail
191+
zope.interface.Interface
192+
collective.dms.basecontent.browser.listing.VersionsTable"
193+
provides="z3c.table.interfaces.IColumn"
194+
factory=".browser.iconified_category.ApprovedColumn"
195+
/>
196+
188197
<adapter
189198
for="imio.dms.mail.dmsmail.IImioDmsIncomingMail
190199
zope.interface.Interface

imio/dms/mail/dmsmail.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ class ImioDmsOutgoingMail(DmsOutgoingMail):
731731

732732
def get_files_to_sign(self):
733733
"""Returns the list of ImioDmsFile objects to sign"""
734+
# TODO to be removed
734735
# get ordered files
735736
files = reversed([f for f in object_values(self, ["ImioDmsFile"])
736737
if f.file and f.file.contentType == "application/vnd.oasis.opendocument.text"])

0 commit comments

Comments
 (0)