~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/model/personroles.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-12-14 00:03:36 UTC
  • mfrom: (14494.2.3 private-traversal-2)
  • Revision ID: launchpad@pqm.canonical.com-20111214000336-xrnjofa8o4koipmm
[rs=sinzui][no-qa] restore the test and webapp changes that remove
        the assumptions that any attribute can be access on an IPerson.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
    getUtility,
12
12
    )
13
13
from zope.interface import implements
 
14
from zope.security.proxy import removeSecurityProxy
14
15
 
15
16
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
16
17
from lp.bugs.interfaces.bugsupervisor import IHasBugSupervisor
29
30
    def __init__(self, person):
30
31
        self.person = person
31
32
        self._celebrities = getUtility(ILaunchpadCelebrities)
32
 
        self.inTeam = self.person.inTeam
 
33
        # Use an unproxied inTeam() method for security checks.
 
34
        self.inTeam = removeSecurityProxy(self.person).inTeam
33
35
 
34
36
    def __getattr__(self, name):
35
37
        """Handle all in_* attributes."""
39
41
            raise AttributeError(errortext)
40
42
        attribute = name[len(prefix):]
41
43
        try:
42
 
            return self.person.inTeam(getattr(self._celebrities, attribute))
 
44
            return self.inTeam(getattr(self._celebrities, attribute))
43
45
        except AttributeError:
44
46
            raise AttributeError(errortext)
45
47
 
49
51
 
50
52
    def isOwner(self, obj):
51
53
        """See IPersonRoles."""
52
 
        return self.person.inTeam(obj.owner)
 
54
        return self.inTeam(obj.owner)
53
55
 
54
56
    def isBugSupervisor(self, obj):
55
57
        """See IPersonRoles."""
56
58
        return (IHasBugSupervisor.providedBy(obj)
57
 
                and self.person.inTeam(obj.bug_supervisor))
 
59
                and self.inTeam(obj.bug_supervisor))
58
60
 
59
61
    def isSecurityContact(self, obj):
60
62
        """See IPersonRoles."""
61
63
        return (IHasSecurityContact.providedBy(obj)
62
 
                and self.person.inTeam(obj.security_contact))
 
64
                and self.inTeam(obj.security_contact))
63
65
 
64
66
    def isDriver(self, obj):
65
67
        """See IPersonRoles."""
66
 
        return self.person.inTeam(obj.driver)
 
68
        return self.inTeam(obj.driver)
67
69
 
68
70
    def isOneOfDrivers(self, obj):
69
71
        """See IPersonRoles."""
70
72
        if not IHasDrivers.providedBy(obj):
71
73
            return self.isDriver(obj)
72
74
        for driver in obj.drivers:
73
 
            if self.person.inTeam(driver):
 
75
            if self.inTeam(driver):
74
76
                return True
75
77
        return False
76
78
 
78
80
        """See IPersonRoles."""
79
81
        for attr in attributes:
80
82
            role = getattr(obj, attr)
81
 
            if self.person.inTeam(role):
 
83
            if self.inTeam(role):
82
84
                return True
83
85
        return False