# HG changeset patch # User Paul Boddie # Date 1422404222 -3600 # Node ID c6776371ecc82f256b42e23584f865b67a64852b # Parent 2527a2230686cf6f67e60cd7fd88ff0dadaa8857 Moved support code for free/busy publication into a separate class so that the person handler can use it without introducing a duplicate request method. Added free/busy publication upon receiving event invitations. diff -r 2527a2230686 -r c6776371ecc8 imiptools/handlers/common.py --- a/imiptools/handlers/common.py Wed Jan 28 01:04:24 2015 +0100 +++ b/imiptools/handlers/common.py Wed Jan 28 01:17:02 2015 +0100 @@ -21,22 +21,9 @@ from imiptools.content import to_part -class CommonFreebusy: - - "Common free/busy mix-in." - - def request(self): +class SupportFreebusy: - """ - Respond to a request by preparing a reply containing free/busy - information for each indicated attendee. - """ - - calendar = self.make_freebusy(from_organiser=False) - - # Return the reply. - - return [(True, to_part("REPLY", calendar))] + "Support for free/busy publishing and sharing." def make_freebusy_to_publish(self, from_organiser=True): @@ -110,4 +97,21 @@ return calendar +class CommonFreebusy(SupportFreebusy): + + "Common free/busy mix-in." + + def request(self): + + """ + Respond to a request by preparing a reply containing free/busy + information for each indicated attendee. + """ + + calendar = self.make_freebusy(from_organiser=False) + + # Return the reply. + + return [(True, to_part("REPLY", calendar))] + # vim: tabstop=4 expandtab shiftwidth=4 diff -r 2527a2230686 -r c6776371ecc8 imiptools/handlers/person.py --- a/imiptools/handlers/person.py Wed Jan 28 01:04:24 2015 +0100 +++ b/imiptools/handlers/person.py Wed Jan 28 01:17:02 2015 +0100 @@ -20,7 +20,7 @@ """ from imiptools.content import Handler, get_address, get_uri, to_part, uri_dict, uri_items -from imiptools.handlers.common import CommonFreebusy +from imiptools.handlers.common import CommonFreebusy, SupportFreebusy from imiptools.profile import Preferences from vCalendar import to_node @@ -124,7 +124,7 @@ for sender, sender_attr in uri_items(self.get_items(from_organiser and "ORGANIZER" or "ATTENDEE")): self.store.set_freebusy_for_other(get_uri(self.recipient), freebusy, sender) -class Event(PersonHandler): +class Event(PersonHandler, SupportFreebusy): "An event handler." @@ -179,7 +179,18 @@ "Hold requests and notify the recipient." self._record_and_deliver("VEVENT", from_organiser=True, queue=True) - return self.wrap("A request has been received.") + + # Produce free/busy information if configured to do so. + + preferences = Preferences(get_uri(self.recipient)) + if preferences.get("freebusy_sharing") == "share" and \ + preferences.get("freebusy_bundling") == "always": + + freebusy = self.make_freebusy_to_publish(from_organiser=False) + else: + freebusy = [] + + return self.wrap("A request has been received.") + freebusy class Freebusy(PersonHandler, CommonFreebusy):