Commit 950a8d03 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

fix(hooks/notification)!: BREAKING CHANGE correctly initialize operation with event attribute

parent 12fcef038237
...@@ -27,7 +27,7 @@ from cubicweb.server import hook ...@@ -27,7 +27,7 @@ from cubicweb.server import hook
from cubicweb.sobjects.supervising import SupervisionMailOp from cubicweb.sobjects.supervising import SupervisionMailOp
def notify_on_commit(cnx, view, viewargs=None): def notify_on_commit(cnx, view, event, viewargs=None):
"""register a notification view (see """register a notification view (see
:class:`~cubicweb.sobjects.notification.NotificationView`) to be sent at :class:`~cubicweb.sobjects.notification.NotificationView`) to be sent at
post-commit time, ie only if the transaction has succeeded. post-commit time, ie only if the transaction has succeeded.
...@@ -37,7 +37,7 @@ def notify_on_commit(cnx, view, viewargs=None): ...@@ -37,7 +37,7 @@ def notify_on_commit(cnx, view, viewargs=None):
""" """
if viewargs is None: if viewargs is None:
viewargs = {} viewargs = {}
notif_op = _RenderAndSendNotificationOp.get_instance(cnx) notif_op = _RenderAndSendNotificationOp.get_instance(cnx, event=event)
notif_op.add_data((view, viewargs)) notif_op.add_data((view, viewargs))
...@@ -114,7 +114,7 @@ class StatusChangeHook(NotificationHook): ...@@ -114,7 +114,7 @@ class StatusChangeHook(NotificationHook):
viewargs = {'comment': comment, viewargs = {'comment': comment,
'previous_state': entity.previous_state.name, 'previous_state': entity.previous_state.name,
'current_state': entity.new_state.name} 'current_state': entity.new_state.name}
notify_on_commit(self._cw, view, viewargs=viewargs) notify_on_commit(self._cw, view, event=self.event, viewargs=viewargs)
class RelationChangeHook(NotificationHook): class RelationChangeHook(NotificationHook):
__regid__ = 'notifyrelationchange' __regid__ = 'notifyrelationchange'
...@@ -130,7 +130,7 @@ class RelationChangeHook(NotificationHook): ...@@ -130,7 +130,7 @@ class RelationChangeHook(NotificationHook):
rset=rset, row=0) rset=rset, row=0)
if view is None: if view is None:
return return
notify_on_commit(self._cw, view) notify_on_commit(self._cw, view, event=self.event)
class EntityChangeHook(NotificationHook): class EntityChangeHook(NotificationHook):
...@@ -145,7 +145,7 @@ class EntityChangeHook(NotificationHook): ...@@ -145,7 +145,7 @@ class EntityChangeHook(NotificationHook):
view = self.select_view('notif_%s' % self.event, rset=rset, row=0) view = self.select_view('notif_%s' % self.event, rset=rset, row=0)
if view is None: if view is None:
return return
notify_on_commit(self._cw, view) notify_on_commit(self._cw, view, event=self.event)
class EntityUpdatedNotificationOp(hook.SingleLastOperation): class EntityUpdatedNotificationOp(hook.SingleLastOperation):
...@@ -158,7 +158,7 @@ class EntityUpdatedNotificationOp(hook.SingleLastOperation): ...@@ -158,7 +158,7 @@ class EntityUpdatedNotificationOp(hook.SingleLastOperation):
view = cnx.vreg['views'].select('notif_entity_updated', cnx, view = cnx.vreg['views'].select('notif_entity_updated', cnx,
rset=cnx.eid_rset(eid), rset=cnx.eid_rset(eid),
row=0) row=0)
notify_on_commit(self.cnx, view, notify_on_commit(self.cnx, view, event=self.event,
viewargs={'changes': cnx.transaction_data['changes'][eid]}) viewargs={'changes': cnx.transaction_data['changes'][eid]})
......
...@@ -17,8 +17,8 @@ notification: ...@@ -17,8 +17,8 @@ notification:
* write a hook for event that should trigger this notification, select the view * write a hook for event that should trigger this notification, select the view
(without rendering it), and give it to (without rendering it), and give it to
:func:`cubicweb.hooks.notification.notify_on_commit` so that the notification :func:`cubicweb.hooks.notification.notify_on_commit` with the event type as a
will be sent if the transaction succeed. string so that the notification will be sent if the transaction succeed.
.. XXX explain recipient finder and provide example .. XXX explain recipient finder and provide example
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment