~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/security.py

  • Committer: Curtis Hovey
  • Date: 2011-08-21 14:21:06 UTC
  • mto: This revision was merged to the branch mainline in revision 13745.
  • Revision ID: curtis.hovey@canonical.com-20110821142106-x93hajd6iguma8gx
Update test that was enforcing bad grammar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
__metaclass__ = type
7
7
__all__ = []
8
8
 
9
 
from zope.component import getUtility
10
 
 
11
 
from lp.bugs.interfaces.hasbug import IHasBug
12
 
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
 
9
from canonical.launchpad.interfaces.launchpad import IHasBug
 
10
from lp.services.messages.interfaces.message import IMessage
13
11
from lp.app.security import (
14
12
    AnonymousAuthorization,
15
13
    AuthorizationBase,
16
 
    DelegatedAuthorization,
17
14
    )
18
15
from lp.bugs.interfaces.bug import IBug
19
16
from lp.bugs.interfaces.bugattachment import IBugAttachment
20
17
from lp.bugs.interfaces.bugbranch import IBugBranch
 
18
from lp.bugs.interfaces.bugmessage import IBugMessage
21
19
from lp.bugs.interfaces.bugnomination import IBugNomination
22
20
from lp.bugs.interfaces.bugsubscription import IBugSubscription
23
21
from lp.bugs.interfaces.bugsubscriptionfilter import IBugSubscriptionFilter
24
 
from lp.bugs.interfaces.bugsupervisor import IHasBugSupervisor
25
 
from lp.bugs.interfaces.bugtask import IBugTaskDelete
26
22
from lp.bugs.interfaces.bugtracker import IBugTracker
27
23
from lp.bugs.interfaces.bugwatch import IBugWatch
28
24
from lp.bugs.interfaces.structuralsubscription import IStructuralSubscription
29
 
from lp.registry.interfaces.role import IHasOwner
30
 
from lp.services.messages.interfaces.message import IMessage
31
25
 
32
26
 
33
27
class EditBugNominationStatus(AuthorizationBase):
53
47
        return self.obj.bug.userCanView(user)
54
48
 
55
49
 
56
 
class DeleteBugTask(AuthorizationBase):
57
 
    permission = 'launchpad.Delete'
58
 
    usedfor = IBugTaskDelete
59
 
 
60
 
    def checkAuthenticated(self, user):
61
 
        """Check that a user may delete a bugtask.
62
 
 
63
 
        A user may delete a bugtask if:
64
 
         - project maintainer
65
 
         - task creator
66
 
         - bug supervisor
67
 
        """
68
 
        if user is None:
69
 
            return False
70
 
 
71
 
        # Admins can always delete bugtasks.
72
 
        if user.inTeam(getUtility(ILaunchpadCelebrities).admin):
73
 
            return True
74
 
 
75
 
        bugtask = self.obj
76
 
        owner = None
77
 
        if IHasOwner.providedBy(bugtask.pillar):
78
 
            owner = bugtask.pillar.owner
79
 
        bugsupervisor = None
80
 
        if IHasBugSupervisor.providedBy(bugtask.pillar):
81
 
            bugsupervisor = bugtask.pillar.bug_supervisor
82
 
        return (
83
 
            user.inTeam(owner) or
84
 
            user.inTeam(bugsupervisor) or
85
 
            user.inTeam(bugtask.owner))
86
 
 
87
 
 
88
 
class AdminDeleteBugTask(DeleteBugTask):
89
 
    """Launchpad admins can also delete bug tasks."""
90
 
    permission = 'launchpad.Admin'
91
 
 
92
 
 
93
50
class PublicToAllOrPrivateToExplicitSubscribersForBugTask(AuthorizationBase):
94
51
    permission = 'launchpad.View'
95
52
    usedfor = IHasBug
141
98
    def __init__(self, bug_branch):
142
99
        # The same permissions as for the BugBranch's bug should apply
143
100
        # to the BugBranch itself.
144
 
        super(EditBugBranch, self).__init__(bug_branch.bug)
145
 
 
146
 
 
147
 
class ViewBugAttachment(DelegatedAuthorization):
 
101
        EditPublicByLoggedInUserAndPrivateByExplicitSubscribers.__init__(
 
102
            self, bug_branch.bug)
 
103
 
 
104
 
 
105
class ViewBugAttachment(PublicToAllOrPrivateToExplicitSubscribersForBug):
148
106
    """Security adapter for viewing a bug attachment.
149
107
 
150
108
    If the user is authorized to view the bug, he's allowed to view the
154
112
    usedfor = IBugAttachment
155
113
 
156
114
    def __init__(self, bugattachment):
157
 
        super(ViewBugAttachment, self).__init__(
158
 
            bugattachment, bugattachment.bug)
159
 
 
160
 
 
161
 
class EditBugAttachment(DelegatedAuthorization):
 
115
        PublicToAllOrPrivateToExplicitSubscribersForBug.__init__(
 
116
            self, bugattachment.bug)
 
117
 
 
118
 
 
119
class EditBugAttachment(
 
120
    EditPublicByLoggedInUserAndPrivateByExplicitSubscribers):
162
121
    """Security adapter for editing a bug attachment.
163
122
 
164
123
    If the user is authorized to view the bug, he's allowed to edit the
168
127
    usedfor = IBugAttachment
169
128
 
170
129
    def __init__(self, bugattachment):
171
 
        super(EditBugAttachment, self).__init__(
172
 
            bugattachment, bugattachment.bug)
 
130
        EditPublicByLoggedInUserAndPrivateByExplicitSubscribers.__init__(
 
131
            self, bugattachment.bug)
173
132
 
174
133
 
175
134
class ViewBugSubscription(AnonymousAuthorization):
189
148
         - They are the owner of the team that owns the subscription.
190
149
         - They are an admin of the team that owns the subscription.
191
150
        """
192
 
        if self.obj.person.is_team:
 
151
        if self.obj.person.isTeam():
193
152
            return (
194
153
                self.obj.person.teamowner == user.person or
195
154
                user.person in self.obj.person.adminmembers)
202
161
    usedfor = IMessage
203
162
 
204
163
 
 
164
class SetBugCommentVisibility(AuthorizationBase):
 
165
    permission = 'launchpad.Admin'
 
166
    usedfor = IBug
 
167
 
 
168
    def checkAuthenticated(self, user):
 
169
        """Admins and registry admins can set bug comment visibility."""
 
170
        return (user.in_admin or user.in_registry_experts)
 
171
 
 
172
 
205
173
class ViewBugTracker(AnonymousAuthorization):
206
174
    """Anyone can view a bug tracker."""
207
175
    usedfor = IBugTracker