# HG changeset patch # User Paul Boddie # Date 1463091776 -7200 # Node ID d674245140c305c5f8f62e8b97b84a22e56f3a29 # Parent 6bc9f39224a9c51c94f60a7ba04a95052184c811 Added some support for recognising multiple delegators and delegates. diff -r 6bc9f39224a9 -r d674245140c3 imiptools/data.py --- a/imiptools/data.py Thu May 12 23:15:18 2016 +0200 +++ b/imiptools/data.py Fri May 13 00:22:56 2016 +0200 @@ -973,22 +973,35 @@ """ Using the 'attendee_map', check the attributes for the given 'attendee' provided as 'attendee_attr', following the delegation chain back to the - delegator and forward again to yield the delegate identity. Return - whether this identity is the given 'attendee', providing the delegator - identity; otherwise return None. + delegators and forward again to yield the delegate identities in each + case. Pictorially... + + attendee -> DELEGATED-FROM -> delegator + ? <- DELEGATED-TO <--- + + Return whether 'attendee' was identified as a delegate by providing the + identity of any delegators referencing the attendee. """ + delegators = [] + # The recipient should have a reference to the delegator. delegated_from = attendee_attr and attendee_attr.get("DELEGATED-FROM") - delegated_from = delegated_from and delegated_from[0] - delegator = delegated_from and attendee_map.get(delegated_from) + if delegated_from: + + # Examine all delegators. + + for delegator in delegated_from: + delegator_attr = attendee_map.get(delegator) - # The delegator should have a reference to the recipient. + # The delegator should have a reference to the recipient. - delegated_to = delegator and delegator.get("DELEGATED-TO") - delegated_to = delegated_to and delegated_to[0] - return delegated_to == attendee and delegated_from or None + delegated_to = delegator_attr and delegator_attr.get("DELEGATED-TO") + if delegated_to and attendee in delegated_to: + delegators.append(delegator) + + return delegators def get_periods(obj, tzid, end=None, inclusive=False): diff -r 6bc9f39224a9 -r d674245140c3 imiptools/handlers/resource.py --- a/imiptools/handlers/resource.py Thu May 12 23:15:18 2016 +0200 +++ b/imiptools/handlers/resource.py Fri May 13 00:22:56 2016 +0200 @@ -90,7 +90,7 @@ "Attempt to schedule the current object for the current user." attendee_attr = uri_dict(self.obj.get_value_map("ATTENDEE"))[self.user] - delegate = None + delegates = None # Attempt to schedule the event. @@ -124,7 +124,7 @@ if scheduled == "ACCEPTED": self.confirm_scheduling() - # For delegated proposals, prepare a request to the delegate in + # For delegated proposals, prepare a request to the delegates in # addition to the usual response. elif scheduled == "DELEGATED": @@ -134,8 +134,7 @@ # The recipient will have indicated the delegate whose details # will have been added to the object. - delegated_to = attendee_attr["DELEGATED-TO"] - delegate = delegated_to and delegated_to[0] + delegates = attendee_attr["DELEGATED-TO"] # For countered proposals, record the offer in the resource's # free/busy collection. @@ -169,21 +168,23 @@ self.update_sender(attendee_attr) attendees = [(self.user, attendee_attr)] - # Add the delegate if delegating (RFC 5546 being inconsistent here since + # Add delegates if delegating (RFC 5546 being inconsistent here since # it provides an example reply to the organiser without the delegate). - if delegate: - delegate_attr = uri_dict(self.obj.get_value_map("ATTENDEE"))[delegate] - attendees.append((delegate, delegate_attr)) + if delegates: + for delegate in delegates: + delegate_attr = uri_dict(self.obj.get_value_map("ATTENDEE"))[delegate] + attendees.append((delegate, delegate_attr)) # Reply to the delegator in addition to the organiser if replying to a # delegation request. - delegator = self.is_delegation() - if delegator: - delegator_attr = uri_dict(self.obj.get_value_map("ATTENDEE"))[delegator] - attendees.append((delegator, delegator_attr)) - recipients.append(get_address(delegator)) + delegators = self.is_delegation() + if delegators: + for delegator in delegators: + delegator_attr = uri_dict(self.obj.get_value_map("ATTENDEE"))[delegator] + attendees.append((delegator, delegator_attr)) + recipients.append(get_address(delegator)) # Prepare the response for the organiser plus any delegator. @@ -191,11 +192,11 @@ self.update_dtstamp() self.add_result(method, recipients, self.object_to_part(method, self.obj)) - # If delegating, send a request to the delegate. + # If delegating, send a request to the delegates. - if delegate: + if delegates: method = "REQUEST" - self.add_result(method, [get_address(delegate)], self.object_to_part(method, self.obj)) + self.add_result(method, map(get_address, delegates), self.object_to_part(method, self.obj)) def _cancel_for_attendee(self):