~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/interfaces/person.py

[testfix][r=allenap][bug=871596][no-qa] Use pgbouncer 0.0.7 and storm
 0.19.0.99-lpwithnodatetime-r402.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
    Reference,
70
70
    )
71
71
from lazr.restful.interface import copy_field
 
72
from storm.expr import (
 
73
    And,
 
74
    Join,
 
75
    Select,
 
76
    Union,
 
77
    )
72
78
from zope.component import getUtility
73
79
from zope.formlib.form import NoInputData
74
80
from zope.interface import (
101
107
    IHasMugshot,
102
108
    IPrivacy,
103
109
    )
 
110
from canonical.launchpad.interfaces.lpstorm import IStore
104
111
from canonical.launchpad.interfaces.validation import validate_new_team_email
105
112
from canonical.launchpad.webapp.authorization import check_permission
106
113
from canonical.launchpad.webapp.interfaces import ILaunchpadApplication
522
529
 
523
530
 
524
531
def team_subscription_policy_can_transition(team, policy):
525
 
    """Can the team can change its subscription policy
 
532
    """Can the team can change its subscription policy?
526
533
 
527
534
    Returns True when the policy can change. or raises an error. OPEN teams
528
535
    cannot be members of MODERATED or RESTRICTED teams. OPEN teams
544
551
                raise TeamSubscriptionPolicyError(
545
552
                    "The team subscription policy cannot be %s because one "
546
553
                    "or more if its super teams are not open." % policy)
547
 
        # The team can be open if it has PPAs.
 
554
        # The team can not be open if it has PPAs.
548
555
        for ppa in team.ppas:
549
556
            if ppa.status != ArchiveStatus.DELETED:
550
557
                raise TeamSubscriptionPolicyError(
551
558
                    "The team subscription policy cannot be %s because it "
552
559
                    "has one or more active PPAs." % policy)
 
560
        # Circular imports.
 
561
        from lp.bugs.model.bug import Bug
 
562
        from lp.bugs.model.bugsubscription import BugSubscription
 
563
        from lp.bugs.model.bugtask import BugTask
 
564
        # The team cannot be open if it is subscribed to or assigned to
 
565
        # private bugs.
 
566
        private_bugs_involved = IStore(Bug).execute(Union(
 
567
            Select(
 
568
                Bug.id,
 
569
                tables=(
 
570
                    Bug,
 
571
                    Join(BugSubscription, BugSubscription.bug_id == Bug.id)),
 
572
                where=And(
 
573
                    Bug.private == True,
 
574
                    BugSubscription.person_id == team.id)),
 
575
            Select(
 
576
                Bug.id,
 
577
                tables=(
 
578
                    Bug,
 
579
                    Join(BugTask, BugTask.bugID == Bug.id)),
 
580
                where=And(Bug.private == True, BugTask.assignee == team.id)),
 
581
            limit=1))
 
582
        if private_bugs_involved.rowcount:
 
583
            raise TeamSubscriptionPolicyError(
 
584
                "The team subscription policy cannot be %s because it is "
 
585
                "subscribed to or assigned to one or more private "
 
586
                "bugs." % policy)
553
587
    elif team.subscriptionpolicy in OPEN_TEAM_POLICY:
554
588
        # The team can become MODERATED or RESTRICTED if its member teams
555
589
        # are not OPEN.