[sobjects] Do not generate notifications on state change when coming from 'outdated' state

Closes #5230287.

authorDenis Laxalde <denis.laxalde@logilab.fr>
changeseta2376a41e407
branchdefault
phasepublic
hiddenno
parent revision#8bc8b8ca16ab Add a Tox config
child revision#655ee937d6a4 [view] Add view that show diff (content and commit message) between the current revision of a patch and an obsolete one.
files modified by this revision
sobjects.py
test/unittest_hooks.py
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1429283907 -7200
# Fri Apr 17 17:18:27 2015 +0200
# Node ID a2376a41e407dba7e40c7ae770c717605654a56e
# Parent 8bc8b8ca16abdc18ea4746dfc36abf842803bc63
[sobjects] Do not generate notifications on state change when coming from 'outdated' state

Closes #5230287.

diff --git a/sobjects.py b/sobjects.py
@@ -50,16 +50,34 @@
1          entity = self.cw_rset.get_entity(0, 0)
2          patch = entity.email_export(size=MAX_PATCH_SIZE)
3          return super(PatchAddedView, self).context(content=patch, **kwargs)
4 
5 
6 +class is_in_state_not_from(is_in_state):
7 +    """Like `cubicweb.predicates.is_in_state` filtering on the previous state
8 +    using `not_from` parameter.
9 +    """
10 +    def __init__(self, *expected, **kwargs):
11 +        super(is_in_state_not_from, self).__init__(*expected)
12 +        self.not_from = kwargs.get('not_from', ())
13 +
14 +    def _score(self, adapted):
15 +        score = super(is_in_state_not_from, self)._score(adapted)
16 +        if score:
17 +            trinfo = adapted.latest_trinfo()
18 +            if trinfo.previous_state.name in self.not_from:
19 +                return 0
20 +        return score
21 +
22 +
23  class PatchStatusChangeView(StatusChangeMixIn, NotificationView):
24 -    __select__ = is_instance('Patch') & is_in_state('pending-review',
25 -                                                    'in-progress',
26 -                                                    'reviewed',
27 -                                                    'applied',
28 -                                                    'rejected')
29 +    __select__ = is_instance('Patch') & is_in_state_not_from('pending-review',
30 +                                                             'in-progress',
31 +                                                             'reviewed',
32 +                                                             'applied',
33 +                                                             'rejected',
34 +                                                             not_from='outdated')
35 
36      content = StatusChangeMixIn.content + '''
37  %(reviewer)s
38 
39  %(patch)s
diff --git a/test/unittest_hooks.py b/test/unittest_hooks.py
@@ -711,10 +711,29 @@
40                  'victor@ratax.es',
41                  u'\n'.join([u'', u'needs work!\n\n\n',
42                              u'url: {}#navcontentbottom{}'.format(
43                                  rev.absolute_url(), point.eid)]))
44 
45 +    def test_no_notification_from_outdated(self):
46 +        with self.admin_access.client_cnx() as cnx:
47 +            rql = 'Any R ORDERBY R DESC WHERE R is Revision'
48 +            rev = cnx.execute(rql).get_entity(1, 0)
49 +            assert rev.description == 'Add more elephants children'
50 +            patch = rev.reverse_patch_revision[0]
51 +            assert patch.patch_name == 'Add more elephants children'
52 +            patch.cw_adapt_to('IWorkflowable').fire_transition('ask review')
53 +            cnx.commit()
54 +            patch.cw_adapt_to('IWorkflowable').fire_transition('obsolete')
55 +            cnx.commit()
56 +            patch.cw_clear_all_caches()
57 +            iwf = patch.cw_adapt_to('IWorkflowable')
58 +            self.assertEqual(iwf.state, 'outdated')
59 +            MAILBOX[:] = []
60 +            patch.cw_adapt_to('IWorkflowable').fire_transition('ask review')
61 +            cnx.commit()
62 +            self.assertEqual(MAILBOX, [])
63 +
64      def test_reviewer_email(self):
65          with self.admin_access.client_cnx() as cnx:
66              rql = 'Any R ORDERBY R DESC WHERE R is Revision'
67              rev = cnx.execute(rql).get_entity(1, 0)
68              assert rev.description == 'Add more elephants children'