diff --git a/hooks.py b/hooks.py index 51f55a77be208a4c24dce1431c7d8ee10a20fba3_aG9va3MucHk=..1d783e846e875c74d8d33df7f15490c0c8806aa0_aG9va3MucHk= 100644 --- a/hooks.py +++ b/hooks.py @@ -1,3 +1,3 @@ -from cubicweb.selectors import implements -from cubicweb.sobjects.notification import ContentAddedView +from cubicweb.selectors import implements, score_entity +from cubicweb.sobjects.notification import NotificationView, StatusChangeMixIn @@ -3,7 +3,9 @@ -class BlogEntryAddedView(ContentAddedView): - """get notified from new blogs""" - __select__ = implements('BlogEntry',) +class BlogEntryPublishedView(StatusChangeMixIn, NotificationView): + """get notified from published blogs""" + __select__ = (implements('BlogEntry',) + & score_entity(lambda x: x.latest_trinfo().new_state.name == 'published') + ) content_attr = 'content' def subject(self): diff --git a/migration/1.7.2_Any.py b/migration/1.7.2_Any.py new file mode 100644 index 0000000000000000000000000000000000000000..1d783e846e875c74d8d33df7f15490c0c8806aa0_bWlncmF0aW9uLzEuNy4yX0FueS5weQ== --- /dev/null +++ b/migration/1.7.2_Any.py @@ -0,0 +1,1 @@ +sync_schema_props_perm('BlogEntry') diff --git a/test/unittest_blog.py b/test/unittest_blog.py index 51f55a77be208a4c24dce1431c7d8ee10a20fba3_dGVzdC91bml0dGVzdF9ibG9nLnB5..1d783e846e875c74d8d33df7f15490c0c8806aa0_dGVzdC91bml0dGVzdF9ibG9nLnB5 100644 --- a/test/unittest_blog.py +++ b/test/unittest_blog.py @@ -21,6 +21,9 @@ self.execute('SET E entry_of B WHERE B eid %(beid)s, E eid %(eeid)s' % {'beid' :cubicweb_blog.eid, 'eeid' : blog_entry_2.eid}) self.assertEquals(len(MAILBOX), 0) self.commit() - self.assertEquals(len(MAILBOX), 2) + self.assertEquals(len(MAILBOX), 0) + blog_entry_1.fire_transition('publish') + self.commit() + self.assertEquals(len(MAILBOX), 1) mail = MAILBOX[0] self.assertEquals(mail.subject, '[data] hop') @@ -25,5 +28,8 @@ mail = MAILBOX[0] self.assertEquals(mail.subject, '[data] hop') + blog_entry_2.fire_transition('publish') + self.commit() + self.assertEquals(len(MAILBOX), 2) mail = MAILBOX[1] self.assertEquals(mail.subject, '[data] yes')