def matches(self, event): if event.realm != 'ticket': return if event.category not in ('created', 'changed', 'attachment added', 'attachment deleted'): return updaters = [ row[0] for row in self.env.db_query( """ SELECT DISTINCT author FROM ticket_change WHERE ticket=%s """, (event.target.id, )) ] matcher = RecipientMatcher(self.env) klass = self.__class__.__name__ sids = set() for previous_updater in updaters: if previous_updater == event.author: continue recipient = matcher.match_recipient(previous_updater) if not recipient: continue sid, auth, addr = recipient # Default subscription for s in self.default_subscriptions(): yield s[0], s[1], sid, auth, addr, s[2], s[3], s[4] if sid: sids.add((sid, auth)) for s in Subscription.find_by_sids_and_class(self.env, sids, klass): yield s.subscription_tuple()
def matches(self, event): if event.realm != 'ticket': return if event.category not in ('created', 'changed', 'attachment added', 'attachment deleted'): return # CC field is stored as comma-separated string. Parse to set. chrome = Chrome(self.env) to_set = lambda cc: set(chrome.cc_list(cc)) cc_set = to_set(event.target['cc'] or '') # Harvest previous CC field if 'fields' in event.changes and 'cc' in event.changes['fields']: cc_set.update(to_set(event.changes['fields']['cc']['old'])) matcher = RecipientMatcher(self.env) klass = self.__class__.__name__ sids = set() for cc in cc_set: recipient = matcher.match_recipient(cc) if not recipient: continue sid, auth, addr = recipient # Default subscription for s in self.default_subscriptions(): yield s[0], s[1], sid, auth, addr, s[2], s[3], s[4] if sid: sids.add((sid, auth)) for s in Subscription.find_by_sids_and_class(self.env, sids, klass): yield s.subscription_tuple()
def _ticket_change_subscribers(subscriber, candidates): if not candidates: return if not isinstance(candidates, (list, set, tuple)): candidates = [candidates] # Get members of permission groups groups = PermissionSystem(subscriber.env).get_groups_dict() for cc in set(candidates): if cc in groups: candidates.remove(cc) candidates.update(groups[cc]) matcher = RecipientMatcher(subscriber.env) klass = subscriber.__class__.__name__ sids = set() for candidate in candidates: recipient = matcher.match_recipient(candidate) if not recipient: continue sid, auth, addr = recipient # Default subscription for s in subscriber.default_subscriptions(): yield s[0], s[1], sid, auth, addr, s[2], s[3], s[4] if sid: sids.add((sid, auth)) for s in Subscription.find_by_sids_and_class(subscriber.env, sids, klass): yield s.subscription_tuple()
def matches(self, event): if event.realm != 'ticket': return if event.category not in ('created', 'changed', 'attachment added', 'attachment deleted'): return ticket = event.target owners = [ticket['owner']] # Harvest previous owner if 'fields' in event.changes and 'owner' in event.changes['fields']: owners.append(event.changes['fields']['owner']['old']) matcher = RecipientMatcher(self.env) klass = self.__class__.__name__ sids = set() for owner in owners: recipient = matcher.match_recipient(owner) if not recipient: continue sid, auth, addr = recipient # Default subscription for s in self.default_subscriptions(): yield s[0], s[1], sid, auth, addr, s[2], s[3], s[4] if sid: sids.add((sid, auth)) for s in Subscription.find_by_sids_and_class(self.env, sids, klass): yield s.subscription_tuple()
def matches(self, event): if event.realm != 'ticket': return if event.category not in ('created', 'changed', 'attachment added', 'attachment deleted'): return # CC field is stored as comma-separated string. Parse to set. chrome = Chrome(self.env) to_set = lambda cc: set(chrome.cc_list(cc)) cc_set = to_set(event.target['cc'] or '') # Harvest previous CC field if 'fields' in event.changes and 'cc' in event.changes['fields']: cc_set.update(to_set(event.changes['fields']['cc']['old'])) matcher = RecipientMatcher(self.env) klass = self.__class__.__name__ sids = set() for cc in cc_set: recipient = matcher.match_recipient(cc) if not recipient: continue sid, auth, addr = recipient # Default subscription for s in self.default_subscriptions(): yield (s[0], s[1], sid, auth, addr, s[2], s[3], s[4]) if sid: sids.add((sid,auth)) for s in Subscription.find_by_sids_and_class(self.env, sids, klass): yield s.subscription_tuple()
def matches(self, event): if event.realm != 'ticket': return if event.category not in ('created', 'changed', 'attachment added', 'attachment deleted'): return updaters = [row[0] for row in self.env.db_query(""" SELECT DISTINCT author FROM ticket_change WHERE ticket=%s """, (event.target.id, ))] matcher = RecipientMatcher(self.env) klass = self.__class__.__name__ sids = set() for previous_updater in updaters: if previous_updater == event.author: continue recipient = matcher.match_recipient(previous_updater) if not recipient: continue sid, auth, addr = recipient # Default subscription for s in self.default_subscriptions(): yield (s[0], s[1], sid, auth, addr, s[2], s[3], s[4]) if sid: sids.add((sid,auth)) for s in Subscription.find_by_sids_and_class(self.env, sids, klass): yield s.subscription_tuple()
def matches(self, event): if event.realm != 'ticket': return if event.category not in ('created', 'changed', 'attachment added', 'attachment deleted'): return ticket = event.target owners = [ticket['owner']] # Harvest previous owner if 'fields' in event.changes and 'owner' in event.changes['fields']: owners.append(event.changes['fields']['owner']['old']) matcher = RecipientMatcher(self.env) klass = self.__class__.__name__ sids = set() for owner in owners: recipient = matcher.match_recipient(owner) if not recipient: continue sid, auth, addr = recipient # Default subscription for s in self.default_subscriptions(): yield (s[0], s[1], sid, auth, addr, s[2], s[3], s[4]) if sid: sids.add((sid,auth)) for s in Subscription.find_by_sids_and_class(self.env, sids, klass): yield s.subscription_tuple()
def matches(self, event): if event.realm != 'ticket': return if event.category == 'batchmodify': for ticket_event in event.get_ticket_change_events(self.env): for m in self.matches(ticket_event): yield m return if event.category not in ('created', 'changed', 'attachment added', 'attachment deleted'): return ticket = event.target matcher = RecipientMatcher(self.env) recipient = matcher.match_recipient(ticket['reporter']) if not recipient: return sid, auth, addr = recipient # Default subscription for s in self.default_subscriptions(): yield (s[0], s[1], sid, auth, addr, s[2], s[3], s[4]) if sid: klass = self.__class__.__name__ for s in Subscription.find_by_sids_and_class( self.env, ((sid, auth), ), klass): yield s.subscription_tuple()
def test_find_by_sids_and_class(self): self._insert_rows() sids = [('joe', True), ('jes', True), ('jan', True), ('jim', True)] items = Subscription.find_by_sids_and_class(self.env, sids, 'IrcSubscriber3') self.assertEqual(['joe', 'jim'], self._props(items, 'sid')) self.assertEqual([1] * 2, self._props(items, 'authenticated')) self.assertEqual(['irc'] * 2, self._props(items, 'distributor')) self.assertEqual(['text/plain', 'text/html'], self._props(items, 'format')) self.assertEqual([3, 3], self._props(items, 'priority')) self.assertEqual(['never', 'always'], self._props(items, 'adverb')) self.assertEqual(['IrcSubscriber3', 'IrcSubscriber3'], self._props(items, 'class'))
def _ticket_change_subscribers(subscriber, candidates): if not candidates: return if not isinstance(candidates, (list, set, tuple)): candidates = [candidates] matcher = RecipientMatcher(subscriber.env) klass = subscriber.__class__.__name__ sids = set() for candidate in candidates: recipient = matcher.match_recipient(candidate) if not recipient: continue sid, auth, addr = recipient # Default subscription for s in subscriber.default_subscriptions(): yield s[0], s[1], sid, auth, addr, s[2], s[3], s[4] if sid: sids.add((sid, auth)) for s in Subscription.find_by_sids_and_class(subscriber.env, sids, klass): yield s.subscription_tuple()
def matches(self, event): if event.realm != 'ticket': return if event.category not in ('created', 'changed', 'attachment added', 'attachment deleted'): return matcher = RecipientMatcher(self.env) recipient = matcher.match_recipient(event.author) if not recipient: return sid, auth, addr = recipient # Default subscription for s in self.default_subscriptions(): yield s[0], s[1], sid, auth, addr, s[2], s[3], s[4] if sid: klass = self.__class__.__name__ for s in Subscription.find_by_sids_and_class( self.env, ((sid, auth), ), klass): yield s.subscription_tuple()
def matches(self, event): if event.realm != 'ticket': return if event.category not in ('created', 'changed', 'attachment added', 'attachment deleted'): return matcher = RecipientMatcher(self.env) recipient = matcher.match_recipient(event.author) if not recipient: return sid, auth, addr = recipient # Default subscription for s in self.default_subscriptions(): yield (s[0], s[1], sid, auth, addr, s[2], s[3], s[4]) if sid: klass = self.__class__.__name__ for s in Subscription.find_by_sids_and_class(self.env, ((sid,auth),), klass): yield s.subscription_tuple()