paul@108 | 1 | #!/usr/bin/env python |
paul@108 | 2 | |
paul@108 | 3 | """ |
paul@108 | 4 | Common handler functionality for different entities. |
paul@108 | 5 | """ |
paul@108 | 6 | |
paul@108 | 7 | from imiptools.content import to_part |
paul@108 | 8 | |
paul@108 | 9 | class CommonFreebusy: |
paul@108 | 10 | |
paul@108 | 11 | "Common free/busy mix-in." |
paul@108 | 12 | |
paul@108 | 13 | def request(self): |
paul@108 | 14 | |
paul@108 | 15 | """ |
paul@108 | 16 | Respond to a request by preparing a reply containing free/busy |
paul@108 | 17 | information for each indicated attendee. |
paul@108 | 18 | """ |
paul@108 | 19 | |
paul@108 | 20 | oa = self.require_organiser_and_attendees() |
paul@108 | 21 | if not oa: |
paul@108 | 22 | return None |
paul@108 | 23 | |
paul@108 | 24 | (organiser, organiser_attr), attendees = organiser_item, attendees = oa |
paul@108 | 25 | |
paul@108 | 26 | # Validate the organiser, ignoring spoofed requests. |
paul@108 | 27 | |
paul@108 | 28 | if not self.validate_identities([organiser_item]): |
paul@108 | 29 | return None |
paul@108 | 30 | |
paul@108 | 31 | # Construct an appropriate fragment. |
paul@108 | 32 | |
paul@108 | 33 | calendar = [] |
paul@108 | 34 | cwrite = calendar.append |
paul@108 | 35 | |
paul@108 | 36 | # Get the details for each attendee. |
paul@108 | 37 | |
paul@108 | 38 | for attendee, attendee_attr in attendees.items(): |
paul@108 | 39 | freebusy = self.store.get_freebusy(attendee) |
paul@108 | 40 | |
paul@108 | 41 | record = [] |
paul@108 | 42 | rwrite = record.append |
paul@108 | 43 | |
paul@108 | 44 | rwrite(("ORGANIZER", organiser_attr, organiser)) |
paul@108 | 45 | rwrite(("ATTENDEE", attendee_attr, attendee)) |
paul@108 | 46 | rwrite(("UID", {}, self.uid)) |
paul@108 | 47 | |
paul@108 | 48 | if freebusy: |
paul@108 | 49 | for start, end, uid in freebusy: |
paul@109 | 50 | rwrite(("FREEBUSY", {"FBTYPE" : "BUSY"}, "/".join([start, end]))) |
paul@108 | 51 | |
paul@108 | 52 | cwrite(("VFREEBUSY", {}, record)) |
paul@108 | 53 | |
paul@108 | 54 | # Return the reply. |
paul@108 | 55 | |
paul@108 | 56 | return "REPLY", to_part("REPLY", calendar) |
paul@108 | 57 | |
paul@108 | 58 | # vim: tabstop=4 expandtab shiftwidth=4 |