author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 25 Jan 2010 19:13:17 +0100 | |
changeset 4337 | 27ea69e2cfea |
parent 4252 | 6c4f109c2b03 |
child 4719 | aaed3f813ef8 |
permissions | -rw-r--r-- |
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2818
diff
changeset
|
1 |
"""some views to handle notification on data changes |
0 | 2 |
|
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1723
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
2101
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
9 |
_ = unicode |
0 | 10 |
|
11 |
from itertools import repeat |
|
12 |
||
13 |
from logilab.common.textutils import normalize_text |
|
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
14 |
from logilab.common.deprecation import class_renamed, deprecated |
0 | 15 |
|
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2818
diff
changeset
|
16 |
from cubicweb.selectors import yes |
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
17 |
from cubicweb.view import Component |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
18 |
from cubicweb.mail import NotificationView, SkipEmail |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
19 |
from cubicweb.server.hook import SendMailOp |
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
20 |
|
0 | 21 |
|
22 |
class RecipientsFinder(Component): |
|
23 |
"""this component is responsible to find recipients of a notification |
|
24 |
||
25 |
by default user's with their email set are notified if any, else the default |
|
26 |
email addresses specified in the configuration are used |
|
27 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
28 |
__regid__ = 'recipients_finder' |
781
323656dd85a9
fix import, use non_final_entity instead of implements('Any')
sylvain.thenault@logilab.fr
parents:
761
diff
changeset
|
29 |
__select__ = yes() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
30 |
user_rql = ('Any X,E,A WHERE X is CWUser, X in_state S, S name "activated",' |
0 | 31 |
'X primary_email E, E address A') |
1477 | 32 |
|
0 | 33 |
def recipients(self): |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
34 |
mode = self._cw.vreg.config['default-recipients-mode'] |
0 | 35 |
if mode == 'users': |
36 |
# use unsafe execute else we may don't have the right to see users |
|
37 |
# to notify... |
|
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
38 |
execute = self._cw.unsafe_execute |
0 | 39 |
dests = [(u.get_email(), u.property_value('ui.language')) |
40 |
for u in execute(self.user_rql, build_descr=True, propagate=True).entities()] |
|
41 |
elif mode == 'default-dest-addrs': |
|
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
42 |
lang = self._cw.vreg.property_value('ui.language') |
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
43 |
dests = zip(self._cw.vreg.config['default-dest-addrs'], repeat(lang)) |
0 | 44 |
else: # mode == 'none' |
45 |
dests = [] |
|
46 |
return dests |
|
47 |
||
1477 | 48 |
|
0 | 49 |
# abstract or deactivated notification views and mixin ######################## |
50 |
||
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
51 |
class NotificationView(NotificationView): |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
52 |
"""overriden to delay actual sending of mails to a commit operation by |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
53 |
default |
0 | 54 |
""" |
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
55 |
def send_on_commit(self, recipients, msg): |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
56 |
SendMailOp(self._cw, recipients=recipients, msg=msg) |
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
57 |
send = send_on_commit |
0 | 58 |
|
59 |
||
60 |
class StatusChangeMixIn(object): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
61 |
__regid__ = 'notif_status_change' |
0 | 62 |
msgid_timestamp = True |
63 |
message = _('status changed') |
|
64 |
content = _(""" |
|
65 |
%(user)s changed status from <%(previous_state)s> to <%(current_state)s> for entity |
|
66 |
'%(title)s' |
|
67 |
||
68 |
%(comment)s |
|
69 |
||
70 |
url: %(url)s |
|
71 |
""") |
|
72 |
||
73 |
||
738
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
74 |
############################################################################### |
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
75 |
# Actual notification views. # |
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
76 |
# # |
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
77 |
# disable them at the recipients_finder level if you don't want them # |
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
78 |
############################################################################### |
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
79 |
|
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
80 |
# XXX should be based on dc_title/dc_description, no? |
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
81 |
|
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
82 |
class ContentAddedView(NotificationView): |
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
83 |
"""abstract class for notification on entity/relation |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
84 |
|
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
85 |
all you have to do by default is : |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
86 |
* set id and __select__ attributes to match desired events and entity types |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
87 |
* set a content attribute to define the content of the email (unless you |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
88 |
override call) |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
89 |
""" |
738
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
90 |
__abstract__ = True |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
91 |
__regid__ = 'notif_after_add_entity' |
0 | 92 |
msgid_timestamp = False |
93 |
message = _('new') |
|
94 |
content = """ |
|
95 |
%(title)s |
|
96 |
||
97 |
%(content)s |
|
98 |
||
99 |
url: %(url)s |
|
100 |
""" |
|
101 |
||
102 |
def context(self, **kwargs): |
|
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
103 |
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
0 | 104 |
content = entity.printable_value(self.content_attr, format='text/plain') |
105 |
if content: |
|
3004
09ab5e93a02c
[notification] fix #103822, don't try to wrap text/rest to 80 characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2879
diff
changeset
|
106 |
contentformat = getattr(entity, self.content_attr + '_format', |
09ab5e93a02c
[notification] fix #103822, don't try to wrap text/rest to 80 characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2879
diff
changeset
|
107 |
'text/rest') |
09ab5e93a02c
[notification] fix #103822, don't try to wrap text/rest to 80 characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2879
diff
changeset
|
108 |
# XXX don't try to wrap rest until we've a proper transformation (see |
09ab5e93a02c
[notification] fix #103822, don't try to wrap text/rest to 80 characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2879
diff
changeset
|
109 |
# #103822) |
09ab5e93a02c
[notification] fix #103822, don't try to wrap text/rest to 80 characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2879
diff
changeset
|
110 |
if contentformat != 'text/rest': |
09ab5e93a02c
[notification] fix #103822, don't try to wrap text/rest to 80 characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2879
diff
changeset
|
111 |
content = normalize_text(content, 80) |
761 | 112 |
return super(ContentAddedView, self).context(content=content, **kwargs) |
1477 | 113 |
|
0 | 114 |
def subject(self): |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
115 |
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
116 |
return u'%s #%s (%s)' % (self._cw.__('New %s' % entity.e_schema), |
3110
757d36162235
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3051
diff
changeset
|
117 |
entity.eid, self.user_data['login']) |
0 | 118 |
|
3525
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
119 |
|
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
120 |
def format_value(value): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
121 |
if isinstance(value, unicode): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
122 |
return u'"%s"' % value |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
123 |
return value |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
124 |
|
3536 | 125 |
|
3525
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
126 |
class EntityUpdatedNotificationView(NotificationView): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
127 |
"""abstract class for notification on entity/relation |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
128 |
|
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
129 |
all you have to do by default is : |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
130 |
* set id and __select__ attributes to match desired events and entity types |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
131 |
* set a content attribute to define the content of the email (unless you |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
132 |
override call) |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
133 |
""" |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
134 |
__abstract__ = True |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
135 |
id = 'notif_entity_updated' |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
136 |
msgid_timestamp = False |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
137 |
message = _('updated') |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
138 |
no_detailed_change_attrs = () |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
139 |
content = """ |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
140 |
Properties have been updated by %(user)s: |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
141 |
|
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
142 |
%(changes)s |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
143 |
|
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
144 |
url: %(url)s |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
145 |
""" |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
146 |
|
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
147 |
def context(self, **kwargs): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
148 |
context = super(EntityUpdatedNotificationView, self).context(**kwargs) |
4230
6514a76eaa5c
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
149 |
changes = self._cw.transaction_data['changes'][self.cw_rset[0][0]] |
6514a76eaa5c
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
150 |
_ = self._cw._ |
3525
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
151 |
formatted_changes = [] |
4230
6514a76eaa5c
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
152 |
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
3525
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
153 |
for attr, oldvalue, newvalue in sorted(changes): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
154 |
# check current user has permission to see the attribute |
4230
6514a76eaa5c
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
155 |
rschema = self._cw.vreg.schema[attr] |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3580
diff
changeset
|
156 |
if rschema.final: |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
157 |
rdef = entity.e_schema.rdef(rschema) |
4230
6514a76eaa5c
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
158 |
if not rdef.has_perm(self._cw, 'read', eid=self.cw_rset[0][0]): |
3525
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
159 |
continue |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
160 |
# XXX suppose it's a subject relation... |
4230
6514a76eaa5c
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
161 |
elif not rschema.has_perm(self._cw, 'read', fromeid=self.cw_rset[0][0]): # XXX toeid |
3525
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
162 |
continue |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
163 |
if attr in self.no_detailed_change_attrs: |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
164 |
msg = _('%s updated') % _(attr) |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
165 |
elif oldvalue not in (None, ''): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
166 |
msg = _('%(attr)s updated from %(oldvalue)s to %(newvalue)s') % { |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
167 |
'attr': _(attr), |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
168 |
'oldvalue': format_value(oldvalue), |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
169 |
'newvalue': format_value(newvalue)} |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
170 |
else: |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
171 |
msg = _('%(attr)s set to %(newvalue)s') % { |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
172 |
'attr': _(attr), 'newvalue': format_value(newvalue)} |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
173 |
formatted_changes.append('* ' + msg) |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
174 |
if not formatted_changes: |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
175 |
# current user isn't allowed to see changes, skip this notification |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
176 |
raise SkipEmail() |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
177 |
context['changes'] = '\n'.join(formatted_changes) |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
178 |
return context |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
179 |
|
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
180 |
def subject(self): |
4230
6514a76eaa5c
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
181 |
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
6514a76eaa5c
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
182 |
return u'%s #%s (%s)' % (self._cw.__('Updated %s' % entity.e_schema), |
3525
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
183 |
entity.eid, self.user_data['login']) |
3536 | 184 |
|
185 |
||
2880 | 186 |
from logilab.common.deprecation import class_renamed, class_moved, deprecated |
187 |
from cubicweb.hooks.notification import RenderAndSendNotificationView |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
188 |
from cubicweb.mail import parse_message_id |
2880 | 189 |
|
738
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
190 |
NormalizedTextView = class_renamed('NormalizedTextView', ContentAddedView) |
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2818
diff
changeset
|
191 |
RenderAndSendNotificationView = class_moved(RenderAndSendNotificationView) |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
192 |
parse_message_id = deprecated('parse_message_id is now defined in cubicweb.mail')(parse_message_id) |
3083
3084bc9ccc64
wrong merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3072
diff
changeset
|
193 |