# HG changeset patch # User Paul Boddie # Date 1441555142 -7200 # Node ID 12405ca6dc58898980b25f2ea4d05bf37b567a2b # Parent eac447470d3d14f8d5cf9bec272c5186c644f1e0 Made the is_participating method more generally applicable and logical. Introduced separate methods for removing periods from free/busy collections associated with other users. Fixed various tests with regard to organiser participation. Simplified the outgoing handler slightly. diff -r eac447470d3d -r 12405ca6dc58 imiptools/client.py --- a/imiptools/client.py Sun Sep 06 02:17:33 2015 +0200 +++ b/imiptools/client.py Sun Sep 06 17:59:02 2015 +0200 @@ -339,7 +339,7 @@ """ attendees = uri_dict((obj or self.obj).get_value_map("ATTENDEE")) - return attendees.get(user or self.user) or {} + return attendees.get(user or self.user) def is_participating(self, user, as_organiser=False, obj=None): @@ -349,8 +349,11 @@ participating in the current object event. """ + # Use any attendee property information for an organiser, not the + # organiser property attributes. + attr = self.get_attendance(user, obj=obj) - return as_organiser or not attr or attr.get("PARTSTAT") != "DECLINED" + return as_organiser or attr is not None and not attr or attr and attr.get("PARTSTAT") != "DECLINED" def get_overriding_transparency(self, user, as_organiser=False): @@ -567,18 +570,32 @@ """ # Record in the free/busy details unless a non-participating attendee. - # Use any attendee property information for an organiser, not the - # organiser property attributes. + # Remove periods for non-participating attendees. if self.is_participating(user, for_organiser and not updating_other): self.update_freebusy(freebusy, user, for_organiser) else: self.remove_from_freebusy(freebusy) + def remove_freebusy_for_participant(self, freebusy, user, for_organiser=False, + updating_other=False): + + """ + Remove details from the 'freebusy' collection for the given 'user', + indicating whether the modification is 'for_organiser' (being done for + the organiser of an event) or not, and whether it is 'updating_other' + (meaning another user's details). + """ + + # Remove from the free/busy details if a specified attendee. + + if self.is_participating(user, for_organiser and not updating_other): + self.remove_from_freebusy(freebusy) + # Convenience methods for updating stored free/busy information received # from other users. - def update_freebusy_from_participant(self, user, for_organiser): + def update_freebusy_from_participant(self, user, for_organiser, fn=None): """ For the current user, record the free/busy information for another @@ -586,6 +603,8 @@ maintaining a separate record of their free/busy details. """ + fn = fn or self.update_freebusy_for_participant + # A user does not store free/busy information for themself as another # party. @@ -593,7 +612,7 @@ return freebusy = self.store.get_freebusy_for_other(self.user, user) - self.update_freebusy_for_participant(freebusy, user, for_organiser, True) + fn(freebusy, user, for_organiser, True) # Tidy up any obsolete recurrences. @@ -613,4 +632,17 @@ for attendee in attendees.keys(): self.update_freebusy_from_participant(attendee, False) + def remove_freebusy_from_organiser(self, organiser): + + "For the current user, remove free/busy information from 'organiser'." + + self.update_freebusy_from_participant(organiser, True, self.remove_freebusy_for_participant) + + def remove_freebusy_from_attendees(self, attendees): + + "For the current user, remove free/busy information from 'attendees'." + + for attendee in attendees.keys(): + self.update_freebusy_from_participant(attendee, False, self.remove_freebusy_for_participant) + # vim: tabstop=4 expandtab shiftwidth=4 diff -r eac447470d3d -r 12405ca6dc58 imiptools/handlers/person.py --- a/imiptools/handlers/person.py Sun Sep 06 02:17:33 2015 +0200 +++ b/imiptools/handlers/person.py Sun Sep 06 17:59:02 2015 +0200 @@ -91,14 +91,6 @@ if not self.have_new_object() or not self.is_attendee(self.user): return False - # Indicate the organiser's implicit attendance if mentioned in the - # cancellation message. - - if cancel: - obj_attendees = uri_dict(self.obj.get_value_map("ATTENDEE")) - if obj_attendees.has_key(organiser): - obj_attendees[organiser]["PARTSTAT"] = "DECLINED" - # Remove additional recurrences if handling a complete event. if not self.recurrenceid: @@ -112,7 +104,7 @@ # Cancel complete events or particular occurrences in recurring # events. - elif cancel: + if cancel: self.store.cancel_event(self.user, self.uid, self.recurrenceid) # Remove any associated request. @@ -125,9 +117,12 @@ self.remove_event_from_freebusy() - # Update the recipient's record of the organiser's schedule. + # Update the recipient's record of the organiser's schedule. - self.update_freebusy_from_organiser(organiser) + self.remove_freebusy_from_organiser(organiser) + + else: + self.update_freebusy_from_organiser(organiser) # Set the complete event or an additional occurrence. diff -r eac447470d3d -r 12405ca6dc58 imiptools/handlers/person_outgoing.py --- a/imiptools/handlers/person_outgoing.py Sun Sep 06 02:17:33 2015 +0200 +++ b/imiptools/handlers/person_outgoing.py Sun Sep 06 17:59:02 2015 +0200 @@ -116,14 +116,14 @@ return True - def _remove(self, from_organiser=True): + def _remove(self): """ Remove details from the current object given a message originating from an organiser if 'from_organiser' is set to a true value. """ - self.set_identity(from_organiser) + self.set_identity(True) # Check for event using UID. @@ -146,6 +146,10 @@ given_attendees = set(uri_values(self.obj.get_values("ATTENDEE"))) cancel_entire_event = not all_attendees.difference(given_attendees) + # Update the recipient's record of the organiser's schedule. + + self.remove_freebusy_from_organiser(self.obj.get_value("ORGANIZER")) + # Otherwise, remove the given attendees and update the event. if not cancel_entire_event and obj: @@ -196,7 +200,7 @@ "Remove an event or a recurrence." - self._remove(True) + self._remove() def counter(self): diff -r eac447470d3d -r 12405ca6dc58 tests/templates/event-request-person-recurring-day-floating.txt --- a/tests/templates/event-request-person-recurring-day-floating.txt Sun Sep 06 02:17:33 2015 +0200 +++ b/tests/templates/event-request-person-recurring-day-floating.txt Sun Sep 06 17:59:02 2015 +0200 @@ -9,7 +9,7 @@ MIME-Version: 1.0 Content-Transfer-Encoding: 7bit -This message contains an event. +This message contains an event. Note that the organiser is not attending! --===============0047278175== MIME-Version: 1.0 Content-Transfer-Encoding: 7bit diff -r eac447470d3d -r 12405ca6dc58 tests/templates/event-request-person-recurring-reschedule-instance.txt --- a/tests/templates/event-request-person-recurring-reschedule-instance.txt Sun Sep 06 02:17:33 2015 +0200 +++ b/tests/templates/event-request-person-recurring-reschedule-instance.txt Sun Sep 06 17:59:02 2015 +0200 @@ -22,6 +22,7 @@ BEGIN:VEVENT ORGANIZER:mailto:paul.boddie@example.com ATTENDEE;RSVP=TRUE:mailto:vincent.vole@example.com +ATTENDEE;RSVP=TRUE:mailto:paul.boddie@example.com DTSTAMP:20141009T182500Z DTSTART;TZID=Europe/Oslo:20141011T100000 DTEND;TZID=Europe/Oslo:20141011T110000 diff -r eac447470d3d -r 12405ca6dc58 tests/templates/event-request-person-recurring.txt --- a/tests/templates/event-request-person-recurring.txt Sun Sep 06 02:17:33 2015 +0200 +++ b/tests/templates/event-request-person-recurring.txt Sun Sep 06 17:59:02 2015 +0200 @@ -9,7 +9,7 @@ MIME-Version: 1.0 Content-Transfer-Encoding: 7bit -This message contains an event. Note that the organiser is not attending! +This message contains an event. --===============0047278175== MIME-Version: 1.0 @@ -23,6 +23,7 @@ BEGIN:VEVENT ORGANIZER:mailto:paul.boddie@example.com ATTENDEE;RSVP=TRUE:mailto:vincent.vole@example.com +ATTENDEE;RSVP=TRUE:mailto:paul.boddie@example.com DTSTAMP:20141009T182400Z DTSTART;TZID=Europe/Oslo:20141010T100000 DTEND;TZID=Europe/Oslo:20141010T110000 diff -r eac447470d3d -r 12405ca6dc58 tests/test_person_invitation_recurring.sh --- a/tests/test_person_invitation_recurring.sh Sun Sep 06 02:17:33 2015 +0200 +++ b/tests/test_person_invitation_recurring.sh Sun Sep 06 17:59:02 2015 +0200 @@ -270,7 +270,9 @@ && echo "Success" \ || echo "Failed" - grep -q "^20141211T220000Z${TAB}20141212T220000Z" "$FBOTHERFILE" \ +# (The organiser is not attending.) + + ! grep -q "^20141211T220000Z${TAB}20141212T220000Z" "$FBOTHERFILE" \ && echo "Success" \ || echo "Failed"