591
def query_structural_subscriptions(
592
what, bug, bugtasks, level, exclude=None):
593
"""Query into structural subscriptions for a given bug.
595
:param what: The fields to fetch. Choose from `Person`,
596
`StructuralSubscription`, `BugSubscriptionFilter`, or a combo.
597
:param bug: An `IBug`
598
:param bugtasks: An iterable of `IBugTask`.
599
:param level: A level from `BugNotificationLevel`.
600
:param exclude: `Person`s to exclude (e.g. direct subscribers).
603
_get_structural_subscription_filter_id_query(
604
bug, bugtasks, level, exclude))
605
if not filter_id_query:
606
return EmptyResultSet()
607
from lp.registry.model.person import Person # Circular.
608
source = IStore(StructuralSubscription).using(
609
StructuralSubscription,
610
Join(BugSubscriptionFilter,
611
BugSubscriptionFilter.structural_subscription_id ==
612
StructuralSubscription.id),
614
Person.id == StructuralSubscription.subscriberID))
616
BugSubscriptionFilter.id, filter_id_query)
617
return source.find(what, conditions)
591
620
def get_structural_subscribers(
592
621
bug_or_bugtask, recipients, level, direct_subscribers=None):
593
622
"""Return subscribers for bug or bugtask at level.
596
:param recipients: a BugNotificationRecipients object or None.
598
:param level: a level from lp.bugs.enum.BugNotificationLevel.
599
:param direct_subscribers: a collection of Person objects who are
600
directly subscribed to the bug.
624
:param bug_or_bugtask: An `IBug` or `IBugTask`.
625
:param recipients: A `BugNotificationRecipients` object or
626
`None`, which will be populated if provided.
627
:param level: A level from `BugNotificationLevel`.
628
:param exclude: `Person`s to exclude (e.g. direct subscribers).
630
from lp.registry.model.person import Person # Circular.
602
Excludes structural subscriptions for people who are directly subscribed
604
632
if IBug.providedBy(bug_or_bugtask):
605
633
bug = bug_or_bugtask
606
634
bugtasks = bug.bugtasks
609
637
bugtasks = [bug_or_bugtask]
611
639
raise ValueError('First argument must be bug or bugtask')
613
_get_structural_subscription_filter_id_query(
614
bug, bugtasks, level, direct_subscribers))
615
if not filter_id_query:
616
return EmptyResultSet()
617
# This is here because of a circular import.
618
from lp.registry.model.person import Person
619
source = IStore(StructuralSubscription).using(
620
StructuralSubscription,
621
Join(BugSubscriptionFilter,
622
BugSubscriptionFilter.structural_subscription_id ==
623
StructuralSubscription.id),
625
Person.id == StructuralSubscription.subscriberID),
627
641
if recipients is None:
630
In(BugSubscriptionFilter.id,
631
filter_id_query)).config(distinct=True).order_by()
642
subscribers = query_structural_subscriptions(
643
Person, bug, bugtasks, level, direct_subscribers)
644
subscribers.config(distinct=True)
645
return subscribers.order_by()
647
results = query_structural_subscriptions(
648
(Person, StructuralSubscription, BugSubscriptionFilter),
649
bug, bugtasks, level, direct_subscribers)
634
query_results = source.find(
635
(Person, StructuralSubscription, BugSubscriptionFilter),
636
In(BugSubscriptionFilter.id, filter_id_query))
637
for person, subscription, filter in query_results:
651
for person, subscription, filter in results:
639
652
if person not in recipients:
640
653
subscribers.append(person)
641
654
recipients.addStructuralSubscriber(