~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/model/bug.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-10-29 10:51:28 UTC
  • mfrom: (14205.1.8 bug-882902)
  • Revision ID: launchpad@pqm.canonical.com-20111029105128-78uf7u6mgwou7yiu
[r=bac][bug=882902] Bug.userCanView's duplicated visibility logic is
        replaced with a call to get_bug_privacy_filter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
190
190
    )
191
191
from lp.registry.interfaces.product import IProduct
192
192
from lp.registry.interfaces.productseries import IProductSeries
193
 
from lp.registry.interfaces.role import IPersonRoles
194
193
from lp.registry.interfaces.series import SeriesStatus
195
194
from lp.registry.interfaces.sourcepackage import ISourcePackage
196
195
from lp.registry.model.person import (
2090
2089
        authenticated users.  It is also called in other contexts where the
2091
2090
        user may be anonymous.
2092
2091
 
 
2092
        Most logic is delegated to the query provided by
 
2093
        get_bug_privacy_filter, but some short-circuits and caching are
 
2094
        reimplemented here.
 
2095
 
2093
2096
        If bug privacy rights are changed here, corresponding changes need
2094
2097
        to be made to the queries which screen for privacy.  See
2095
2098
        Bug.searchAsUser and BugTask.get_bug_privacy_filter_with_decorator.
2104
2107
        if user.id in self._known_viewers:
2105
2108
            return True
2106
2109
 
2107
 
        elif IPersonRoles(user).in_admin:
2108
 
            # Admins can view all bugs.
 
2110
        filter = get_bug_privacy_filter(user)
 
2111
        store = Store.of(self)
 
2112
        store.flush()
 
2113
        if (not filter or
 
2114
            not store.find(Bug, Bug.id == self.id, filter).is_empty()):
 
2115
            self._known_viewers.add(user.id)
2109
2116
            return True
2110
 
        else:
2111
 
            # At this point we know the bug is private and the user is
2112
 
            # unprivileged.
2113
 
 
2114
 
            # Assignees to bugtasks can see the private bug.
2115
 
            for bugtask in self.bugtasks:
2116
 
                if user.inTeam(bugtask.assignee):
2117
 
                    self._known_viewers.add(user.id)
2118
 
                    return True
2119
 
            # Explicit subscribers may also view it.
2120
 
            for subscription in self.subscriptions:
2121
 
                if user.inTeam(subscription.person):
2122
 
                    self._known_viewers.add(user.id)
2123
 
                    return True
2124
 
            # Pillar owners can view it. Note that this is contentious and
2125
 
            # possibly incorrect: see bug 702429.
2126
 
            for pillar_owner in [bt.pillar.owner for bt in self.bugtasks]:
2127
 
                if user.inTeam(pillar_owner):
2128
 
                    self._known_viewers.add(user.id)
2129
 
                    return True
2130
2117
        return False
2131
2118
 
2132
2119
    def linkHWSubmission(self, submission):