~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/browser/bugsubscription.py

  • Committer: j.c.sackett
  • Date: 2011-11-02 21:42:28 UTC
  • mto: This revision was merged to the branch mainline in revision 14287.
  • Revision ID: jonathan.sackett@canonical.com-20111102214228-jw911ikpjyfwxf0k
Added validate method to block subscriptions for open/delegated teams.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
from lp.bugs.model.structuralsubscription import (
54
54
    get_structural_subscriptions_for_bug,
55
55
    )
 
56
from lp.registry.interfaces.person import TeamSubscriptionPolicy
56
57
from lp.services.propertycache import cachedproperty
57
58
 
58
59
 
68
69
        super(BugSubscriptionAddView, self).setUpFields()
69
70
        self.form_fields['person'].for_input = True
70
71
 
 
72
    def validate(self, data):
 
73
        '''Validation hook.
 
74
        Ensures that open and delegated teams aren't allowed to be subscribed
 
75
        to private bugs.
 
76
        '''
 
77
        person = data['person']
 
78
        if person.isTeam() and self.context.bug.private:
 
79
            bad_types = (
 
80
                TeamSubscriptionPolicy.OPEN,
 
81
                TeamSubscriptionPolicy.DELEGATED
 
82
                )
 
83
            if person.subscriptionpolicy in bad_types: 
 
84
                error_msg = ("Open and delegated teams cannot be subscribed "
 
85
                    "to private bugs.")
 
86
                self.setFieldError('person', error_msg)
 
87
 
71
88
    @action('Subscribe user', name='add')
72
89
    def add_action(self, action, data):
73
90
        person = data['person']