~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Changing Bug Task Status
========================

Restrictions
------------

There are a few simple rules around who can change the status of a
bug task.  There are three statuses that can only be set by either
the project registrant or the bug supervisor:

 * Won't Fix
 * Expired
 * Triaged

    >>> owner = factory.makePerson()
    >>> product = factory.makeProduct(owner=owner)
    >>> bugtask = factory.makeBugTask(target=product)
    >>> user = factory.makePerson()

    >>> from lp.bugs.interfaces.bugtask import BugTaskStatus
    >>> login_person(owner)
    >>> bugtask.transitionToStatus(BugTaskStatus.WONTFIX, owner)
    >>> print bugtask.status.title
    Won't Fix

Regular users of Launchpad cannot transition a bug task to any of
these statuses.

An additional restraint is added to Won't Fix.  Only the product
registrant or bug supervisor can change from this status to any
other status.

    >>> login_person(user)
    >>> bugtask.transitionToStatus(BugTaskStatus.CONFIRMED, user)
    Traceback (most recent call last):
    ...
    UserCannotEditBugTaskStatus...

This is fully tested in
lp.bugs.tests.test_bugtask_status.TestBugTaskStatusSetting.

Testing for Permission
----------------------

The method IBugTask.canTransitionToStatus comes in handy here. It
tells us if a transition to a status is permitted. It is *not* a
dry-run of IBugTask.transitionToStatus, but is good enough and fast
enough to be used by UI code, e.g. to display only those statuses to
which a user can transition a particular bugtask.

    >>> bugtask.canTransitionToStatus(BugTaskStatus.TRIAGED, owner)
    True
    >>> bugtask.canTransitionToStatus(BugTaskStatus.TRIAGED, user)
    False

This method is fully tested in
lp.bugs.tests.test_bugtask_status.TestCanTransitionToStatus.