~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

[r=wgrant][rollback=13154] Revert r13154. It breaks bugs with
 duplicate team subscriptions. Or something.

Show diffs side-by-side

added added

removed removed

Lines of Context:
967
967
        See the comment in getDirectSubscribers for a description of the
968
968
        recipients argument.
969
969
        """
970
 
        if self.private:
971
 
            # We short-circuit for private bugs, since actually
972
 
            # returning something non-empty here causes things to break
973
 
            # in fun and interesting ways (see bug 780248).
974
 
            return []
975
 
 
976
970
        if level is None:
977
971
            level = BugNotificationLevel.LIFECYCLE
978
972
        info = self.getSubscriptionInfo(level)
979
973
 
980
974
        if recipients is not None:
981
 
            # Pre-load duplicates
 
975
            # Pre-load duplicate bugs.
982
976
            list(self.duplicates)
983
977
            for subscription in info.duplicate_only_subscriptions:
984
978
                recipients.addDupeSubscriber(
985
979
                    subscription.person, subscription.bug)
986
 
            for subscription in info.structural_subscriptions_from_duplicates:
987
 
                recipients.addDupeSubscriber(
988
 
                    subscription.subscriber)
989
980
 
990
 
        unified_subscribers = (
991
 
            info.duplicate_only_subscriptions.subscribers.union(
992
 
                info.structural_subscriptions_from_duplicates.subscribers))
993
 
        return unified_subscribers.sorted
 
981
        return info.duplicate_only_subscriptions.subscribers.sorted
994
982
 
995
983
    def getSubscribersForPerson(self, person):
996
984
        """See `IBug."""
1055
1043
                                     include_master_dupe_subscribers=False):
1056
1044
        """See `IBug`."""
1057
1045
        recipients = BugNotificationRecipients(duplicateof=duplicateof)
1058
 
        # Call getDirectSubscribers to update the recipients list with direct
1059
 
        # subscribers.  The results of the method call are not used.
1060
1046
        self.getDirectSubscribers(recipients, level=level)
1061
1047
        if self.private:
1062
1048
            assert self.getIndirectSubscribers() == [], (
1063
1049
                "Indirect subscribers found on private bug. "
1064
1050
                "A private bug should never have implicit subscribers!")
1065
1051
        else:
1066
 
            # Call getIndirectSubscribers to update the recipients list with direct
1067
 
            # subscribers.  The results of the method call are not used.
1068
1052
            self.getIndirectSubscribers(recipients, level=level)
1069
1053
            if include_master_dupe_subscribers and self.duplicateof:
1070
1054
                # This bug is a public duplicate of another bug, so include
1931
1915
 
1932
1916
    def personIsAlsoNotifiedSubscriber(self, person):
1933
1917
        """See `IBug`."""
1934
 
        # This is here to avoid circular imports.
1935
 
        from lp.bugs.mail.bugnotificationrecipients import (
1936
 
            BugNotificationRecipients,
1937
 
            )
1938
 
 
1939
 
        def check_person_in_team(person, list_of_people):
1940
 
            """Is the person in one of the teams?
1941
 
 
1942
 
            Given a person and a list of people/teams, see if the person
1943
 
            belongs to one of the teams.
1944
 
            """
1945
 
            for subscriber in list_of_people:
1946
 
                if subscriber.is_team and person.inTeam(subscriber):
1947
 
                    return True
1948
 
            return False
1949
 
 
1950
1918
        # We have to use getAlsoNotifiedSubscribers() here and iterate
1951
1919
        # over what it returns because "also notified subscribers" is
1952
1920
        # actually a composite of bug contacts, structural subscribers
1957
1925
            return True
1958
1926
        # Otherwise check to see if the person is a member of any of the
1959
1927
        # subscribed teams.
1960
 
        if check_person_in_team(person, also_notified_subscribers):
1961
 
            return True
1962
 
 
1963
 
        direct_subscribers = self.getDirectSubscribers()
1964
 
        if check_person_in_team(person, direct_subscribers):
1965
 
            return True
1966
 
        duplicate_subscribers = self.getSubscribersFromDuplicates(
1967
 
            recipients=BugNotificationRecipients())
1968
 
        if check_person_in_team(person, duplicate_subscribers):
1969
 
            return True
 
1928
        for subscriber in also_notified_subscribers:
 
1929
            if subscriber.is_team and person.inTeam(subscriber):
 
1930
                return True
1970
1931
        return False
1971
1932
 
1972
1933
    def personIsSubscribedToDuplicate(self, person):
2330
2291
        return get_structural_subscriptions_for_bug(self.bug)
2331
2292
 
2332
2293
    @cachedproperty
2333
 
    @freeze(StructuralSubscriptionSet)
2334
 
    def structural_subscriptions_from_duplicates(self):
2335
 
        """Structural subscriptions from the bug's duplicates."""
2336
 
        self.duplicate_subscriptions.subscribers # Pre-load subscribers.
2337
 
        higher_precedence = (
2338
 
            self.direct_subscriptions.subscribers.union(
2339
 
                self.also_notified_subscribers))
2340
 
        all_duplicate_structural_subscriptions = list()
2341
 
        for duplicate in self.bug.duplicates:
2342
 
            duplicate_struct_subs = get_structural_subscriptions_for_bug(
2343
 
                duplicate)
2344
 
            all_duplicate_structural_subscriptions += duplicate_struct_subs
2345
 
        return (
2346
 
            subscription for subscription in
2347
 
                all_duplicate_structural_subscriptions
2348
 
                if subscription.subscriber not in higher_precedence)
2349
 
 
2350
 
    @cachedproperty
2351
2294
    @freeze(BugSubscriberSet)
2352
2295
    def all_assignees(self):
2353
2296
        """Assignees of the bug's tasks."""