products/CPSSubscriptions

changeset 1057:387470868ff8 CPS-3.5

#2049: extraction method
author Georges Racinet on ishtar.racinet.fr <georges@racinet.fr>
date Tue, 27 Sep 2011 15:57:20 +0200
parents 3ac6cd0a5b23
children 207d647993db
files SubscriptionsTool.py
diffstat 1 files changed, 52 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/SubscriptionsTool.py
     1.2 +++ b/SubscriptionsTool.py
     1.3 @@ -946,6 +946,58 @@
     1.4  
     1.5          return recipients
     1.6  
     1.7 +    security.declarePublic("getDetailedRecipientsFor")
     1.8 +    def getDetailedRecipientsFor(self, obj, infos={}):
     1.9 +        """Compute all the recipients of all events for given object
    1.10 +
    1.11 +        object can be a container as well
    1.12 +
    1.13 +        The returned structure is a dict with three keys:
    1.14 +          - members
    1.15 +          - groups
    1.16 +          - other
    1.17 +
    1.18 +        Values are themselves dicts whose keys are ids in corresponding
    1.19 +        directories and values the list of events for which the recipient
    1.20 +        is notified.
    1.21 +        """
    1.22 +
    1.23 +        members = {}
    1.24 +        groups = {}
    1.25 +        other = {}
    1.26 +        recipients = dict(members=members, groups=groups, other=other)
    1.27 +
    1.28 +        def record(category, recipient, event):
    1.29 +            """Record that a recipient of category is notified for event_type.
    1.30 +
    1.31 +            Category is one of our three dicts
    1.32 +            """
    1.33 +            category.setdefault(recipient, []).append(event)
    1.34 +
    1.35 +        expand_groups = not self.use_group_emails
    1.36 +
    1.37 +        for event in self.getEventsFromContext(context=obj):
    1.38 +            for subscription in self.getSubscriptionsFor(event, obj, infos):
    1.39 +                for rule in subscription.getRecipientsRules():
    1.40 +                    rrecs = rule.getRecipients(event, obj, infos,
    1.41 +                                               expand_groups=expand_groups)
    1.42 +
    1.43 +                    if expand_groups: # uniformity
    1.44 +                        rrecs = (rrecs, {})
    1.45 +                    elif not isinstance(rrecs, tuple) or len(rrecs) != 2:
    1.46 +                        logger.error("getRecipients of %r with expand_groups="
    1.47 +                                     "False should return two dicts, got %r "
    1.48 +                                     "instead (skipping).", rule, rrecs)
    1.49 +
    1.50 +                    for category, recs in zip((members, groups), rrecs):
    1.51 +                        for address, rid in recs.items():
    1.52 +                            if rid:
    1.53 +                                record(category, rid, event)
    1.54 +                            else:
    1.55 +                                record(other, address, event)
    1.56 +
    1.57 +        return recipients
    1.58 +
    1.59      #############################################################
    1.60  
    1.61      def _makeEltDict(self, ob, subscription):