1 #!/usr/bin/env python 2 3 """ 4 Common calendar client utilities. 5 6 Copyright (C) 2014, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk> 7 8 This program is free software; you can redistribute it and/or modify it under 9 the terms of the GNU General Public License as published by the Free Software 10 Foundation; either version 3 of the License, or (at your option) any later 11 version. 12 13 This program is distributed in the hope that it will be useful, but WITHOUT 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 details. 17 18 You should have received a copy of the GNU General Public License along with 19 this program. If not, see <http://www.gnu.org/licenses/>. 20 """ 21 22 from collections import OrderedDict 23 from datetime import datetime, timedelta 24 from imiptools.config import settings 25 from imiptools.data import check_delegation, get_address, \ 26 get_recurrence_periods, \ 27 get_sender_identities, get_uri, \ 28 get_window_end, is_new_object, make_freebusy, \ 29 make_uid, new_object, to_part, \ 30 update_attendees_with_delegates, \ 31 uri_dict, uri_item, uri_items, uri_parts, uri_values 32 from imiptools.dates import check_permitted_values, format_datetime, \ 33 get_datetime, get_default_timezone, \ 34 get_duration, get_time, get_timestamp, \ 35 to_datetime 36 from imiptools.i18n import get_translator 37 from imiptools.freebusy import SupportAttendee, SupportExpires 38 from imiptools.profile import Preferences 39 from imiptools.stores import get_store, get_publisher, get_journal 40 41 class Client: 42 43 "Common handler and manager methods." 44 45 default_window_size = 100 46 organiser_methods = "ADD", "CANCEL", "DECLINECOUNTER", "PUBLISH", "REQUEST" 47 48 def __init__(self, user, messenger=None, store=None, publisher=None, journal=None, 49 preferences_dir=None): 50 51 """ 52 Initialise a calendar client with the current 'user', plus any 53 'messenger', 'store', 'publisher' and 'journal' objects, indicating any 54 specific 'preferences_dir'. 55 """ 56 57 self.user = user 58 self.messenger = messenger 59 self.store = store or get_store(settings["STORE_TYPE"], settings["STORE_DIR"]) 60 self.journal = journal or get_journal(settings["STORE_TYPE"], settings["JOURNAL_DIR"]) 61 62 try: 63 self.publisher = publisher or get_publisher(settings["PUBLISH_DIR"]) 64 except OSError: 65 self.publisher = None 66 67 self.preferences_dir = preferences_dir 68 self.preferences = None 69 70 # Localise the messenger. 71 72 if self.messenger: 73 self.messenger.gettext = self.get_translator() 74 75 def get_store(self): 76 return self.store 77 78 def get_publisher(self): 79 return self.publisher 80 81 def get_journal(self): 82 return self.journal 83 84 # Store-related methods. 85 86 def acquire_lock(self): 87 self.store.acquire_lock(self.user) 88 89 def release_lock(self): 90 self.store.release_lock(self.user) 91 92 # Preferences-related methods. 93 94 def get_preferences(self): 95 if not self.preferences and self.user: 96 self.preferences = Preferences(self.user, self.preferences_dir) 97 return self.preferences 98 99 def get_locale(self): 100 prefs = self.get_preferences() 101 return prefs and prefs.get("LANG", "en", True) or "en" 102 103 def get_translator(self): 104 return get_translator([self.get_locale()]) 105 106 def get_user_attributes(self): 107 prefs = self.get_preferences() 108 return prefs and prefs.get_all(["CN"]) or {} 109 110 def get_tzid(self): 111 prefs = self.get_preferences() 112 return prefs and prefs.get("TZID") or get_default_timezone() 113 114 def get_window_size(self): 115 116 "Return the period window size as an integer." 117 118 prefs = self.get_preferences() 119 try: 120 return prefs and int(prefs.get("window_size")) or self.default_window_size 121 except (TypeError, ValueError): 122 return self.default_window_size 123 124 def get_window_start(self): 125 126 "Return the period window start as a datetime." 127 128 prefs = self.get_preferences() 129 tzid = self.get_tzid() 130 start = prefs and get_datetime(prefs.get("window_start"), {"TZID" : tzid}) 131 return isinstance(start, datetime) and start or start and to_datetime(start, tzid) 132 133 def get_window_end(self, size=None, start=None): 134 135 "Return the period window end as a datetime." 136 137 tzid = self.get_tzid() 138 return get_window_end(tzid, size or self.get_window_size(), 139 start or self.get_window_start()) 140 141 def is_participating(self): 142 143 "Return participation in the calendar system." 144 145 prefs = self.get_preferences() 146 return prefs and prefs.get("participating", settings["PARTICIPATING_DEFAULT"]) != "no" or False 147 148 def is_sharing(self): 149 150 "Return whether free/busy information is being generally shared." 151 152 prefs = self.get_preferences() 153 return prefs and prefs.get("freebusy_sharing", settings["SHARING_DEFAULT"]) == "share" or False 154 155 def is_bundling(self): 156 157 "Return whether free/busy information is being bundled in messages." 158 159 prefs = self.get_preferences() 160 return prefs and prefs.get("freebusy_bundling", settings["BUNDLING_DEFAULT"]) == "always" or False 161 162 def is_notifying(self): 163 164 "Return whether recipients are notified about free/busy payloads." 165 166 prefs = self.get_preferences() 167 return prefs and prefs.get("freebusy_messages", settings["NOTIFYING_DEFAULT"]) == "notify" or False 168 169 def is_publishing(self): 170 171 "Return whether free/busy information is being published as Web resources." 172 173 prefs = self.get_preferences() 174 return prefs and prefs.get("freebusy_publishing", settings["PUBLISHING_DEFAULT"]) == "publish" or False 175 176 def is_refreshing(self): 177 178 "Return whether a recipient supports requests to refresh event details." 179 180 prefs = self.get_preferences() 181 return prefs and prefs.get("event_refreshing", settings["REFRESHING_DEFAULT"]) == "always" or False 182 183 def allow_add(self): 184 return self.get_add_method_response() in ("add", "refresh") 185 186 def get_add_method_response(self): 187 prefs = self.get_preferences() 188 return prefs and prefs.get("add_method_response", settings["ADD_RESPONSE_DEFAULT"]) or "refresh" 189 190 def get_offer_period(self): 191 192 "Decode a specification in the iCalendar duration format." 193 194 prefs = self.get_preferences() 195 duration = prefs and prefs.get("freebusy_offers", settings["FREEBUSY_OFFER_DEFAULT"]) 196 197 # NOTE: Should probably report an error somehow if None. 198 199 return duration and get_duration(duration) or None 200 201 def get_organiser_replacement(self): 202 prefs = self.get_preferences() 203 return prefs and prefs.get("organiser_replacement", settings["ORGANISER_REPLACEMENT_DEFAULT"]) or "attendee" 204 205 def have_manager(self): 206 return settings["MANAGER_INTERFACE"] 207 208 def get_permitted_values(self): 209 210 """ 211 Decode a specification of one of the following forms... 212 213 <minute values> 214 <hour values>:<minute values> 215 <hour values>:<minute values>:<second values> 216 217 ...with each list of values being comma-separated. 218 """ 219 220 prefs = self.get_preferences() 221 permitted_values = prefs and prefs.get("permitted_times") 222 if permitted_values: 223 try: 224 l = [] 225 for component in permitted_values.split(":")[:3]: 226 if component: 227 l.append(map(int, component.split(","))) 228 else: 229 l.append(None) 230 231 # NOTE: Should probably report an error somehow. 232 233 except ValueError: 234 return None 235 else: 236 l = (len(l) < 2 and [None] or []) + l + (len(l) < 3 and [None] or []) 237 return l 238 else: 239 return None 240 241 # Common operations on calendar data. 242 243 def update_sender_attr(self, attr): 244 245 "Update the SENT-BY attribute of the 'attr' sender metadata." 246 247 if self.messenger: 248 if self.messenger.sender != get_address(self.user): 249 attr["SENT-BY"] = get_uri(self.messenger.sender) 250 elif attr.has_key("SENT-BY"): 251 del attr["SENT-BY"] 252 253 def get_periods(self, obj, explicit_only=False, future_only=False): 254 255 """ 256 Return periods for the given 'obj'. 257 258 If 'explicit_only' is set to a true value, only explicit periods will be 259 returned, not rule-based periods. 260 261 If 'future_only' is set to a true value, only future periods will be 262 returned, not all periods defined by an event starting in the past. 263 """ 264 265 return obj.get_periods( 266 start=(future_only and self.get_window_start() or None), 267 end=(not explicit_only and self.get_window_end() or None)) 268 269 def get_updated_periods(self, obj, explicit_only=False, future_only=False): 270 271 """ 272 Return the periods provided by 'obj' and associated recurrence 273 instances. Each original period is returned in a tuple with a 274 corresponding updated period which may be the same or which may be None 275 if the period is cancelled. A list of these tuples is returned. 276 277 If 'explicit_only' is set to a true value, only explicit periods will be 278 returned, not rule-based periods. 279 280 If 'future_only' is set to a true value, only future periods will be 281 returned, not all periods defined by an event starting in the past. 282 """ 283 284 self.store.update_event_from_recurrences(self.user, obj) 285 286 return obj.get_updated_periods( 287 start=(future_only and self.get_window_start() or None), 288 end=(not explicit_only and self.get_window_end() or None)) 289 290 def get_main_period(self, obj): 291 292 "Return the main period defined by 'obj'." 293 294 return obj.get_main_period() 295 296 def get_recurrence_periods(self, obj): 297 298 "Return recurrence periods defined by 'obj'." 299 300 return get_recurrence_periods(Client.get_periods(self, obj)) 301 302 # Store operations. 303 304 def get_stored_object(self, uid, recurrenceid, section=None, username=None): 305 306 """ 307 Return the stored object for the current user, with the given 'uid' and 308 'recurrenceid' from the given 'section' and for the given 'username' (if 309 specified), or from the standard object collection otherwise. 310 """ 311 312 if section == "counters": 313 obj = self.store.get_counter(self.user, username, uid, recurrenceid) 314 else: 315 obj = self.store.get_event(self.user, uid, recurrenceid, section) 316 317 # Set the fallback time zone. 318 319 if obj: 320 obj.set_tzid(self.get_tzid()) 321 322 return obj 323 324 # Free/busy operations. 325 326 def get_freebusy_part(self, freebusy=None): 327 328 """ 329 Return a message part containing free/busy information for the user, 330 either specified as 'freebusy' or obtained from the store directly. 331 """ 332 333 if self.is_sharing() and self.is_bundling(): 334 335 # Invent a unique identifier. 336 337 uid = make_uid(self.user) 338 339 freebusy = freebusy or self.store.get_freebusy(self.user) 340 341 user_attr = {} 342 self.update_sender_attr(user_attr) 343 return self.to_part("PUBLISH", [make_freebusy(freebusy, uid, self.user, user_attr)]) 344 345 return None 346 347 def update_freebusy(self, freebusy, periods, transp, uid, recurrenceid, summary, organiser, expires=None): 348 349 """ 350 Update the 'freebusy' collection with the given 'periods', indicating a 351 'transp' status, explicit 'uid' and 'recurrenceid' to indicate either a 352 recurrence or the parent event. The 'summary' and 'organiser' must also 353 be provided. 354 355 An optional 'expires' datetime string can be provided to tag a free/busy 356 offer. 357 """ 358 359 # Add specific attendee information for certain collections. 360 361 if isinstance(freebusy, SupportAttendee): 362 freebusy.update_freebusy(periods, transp, uid, recurrenceid, summary, organiser, self.user) 363 364 # Add expiry datetime for certain collections. 365 366 elif isinstance(freebusy, SupportExpires): 367 freebusy.update_freebusy(periods, transp, uid, recurrenceid, summary, organiser, expires) 368 369 # Provide only the essential attributes for other collections. 370 371 else: 372 freebusy.update_freebusy(periods, transp, uid, recurrenceid, summary, organiser) 373 374 # Preparation of content. 375 376 def to_part(self, method, fragments): 377 378 "Return an encoded MIME part for the given 'method' and 'fragments'." 379 380 return to_part(method, fragments, line_length=settings["CALENDAR_LINE_LENGTH"]) 381 382 def object_to_part(self, method, obj): 383 384 "Return an encoded MIME part for the given 'method' and 'obj'." 385 386 return obj.to_part(method, line_length=settings["CALENDAR_LINE_LENGTH"]) 387 388 # Preparation of messages communicating the state of events. 389 390 def get_message_parts(self, obj, method, attendee=None): 391 392 """ 393 Return a tuple containing a list of methods and a list of message parts, 394 with the parts collectively describing the given object 'obj' and its 395 recurrences, using 'method' as the means of publishing details (with 396 CANCEL being used to retract or remove details). 397 398 If 'attendee' is indicated, the attendee's participation will be taken 399 into account when generating the description. 400 """ 401 402 # Assume that the outcome will be composed of requests and 403 # cancellations. It would not seem completely bizarre to produce 404 # publishing messages if a refresh message was unprovoked. 405 406 responses = [] 407 methods = set() 408 409 # Get the parent event, add SENT-BY details to the organiser. 410 411 if not attendee or self.is_participating(attendee, obj=obj): 412 self.update_sender(obj) 413 responses.append(self.object_to_part(method, obj)) 414 methods.add(method) 415 416 # Get recurrences for parent events. 417 418 if not self.recurrenceid: 419 420 # Collect active and cancelled recurrences. 421 422 for rl, section, rmethod in [ 423 (self.store.get_active_recurrences(self.user, self.uid), None, method), 424 (self.store.get_cancelled_recurrences(self.user, self.uid), "cancellations", "CANCEL"), 425 ]: 426 427 for recurrenceid in rl: 428 429 # Get the recurrence, add SENT-BY details to the organiser. 430 431 obj = self.get_stored_object(self.uid, recurrenceid, section) 432 433 if not attendee or self.is_participating(attendee, obj=obj): 434 self.update_sender(obj) 435 responses.append(self.object_to_part(rmethod, obj)) 436 methods.add(rmethod) 437 438 return methods, responses 439 440 class ClientForObject(Client): 441 442 "A client maintaining a specific object." 443 444 def __init__(self, obj, user, messenger=None, store=None, publisher=None, 445 journal=None, preferences_dir=None): 446 Client.__init__(self, user, messenger, store, publisher, journal, preferences_dir) 447 self.set_object(obj) 448 449 def set_object(self, obj): 450 451 "Set the current object to 'obj', obtaining metadata details." 452 453 self.obj = obj 454 self.uid = obj and self.obj.get_uid() 455 self.recurrenceid = obj and self.obj.get_recurrenceid() 456 self.sequence = obj and self.obj.get_value("SEQUENCE") 457 self.dtstamp = obj and self.obj.get_value("DTSTAMP") 458 459 # Set the fallback time zone. 460 461 if obj: 462 self.obj.set_tzid(self.get_tzid()) 463 464 def new_object(self, objtype): 465 466 "Initialise a new object for the client with the given 'objtype'." 467 468 self.set_object(new_object(objtype, self.user, self.get_user_attributes(), self.get_tzid())) 469 return self.obj 470 471 def load_object(self, uid, recurrenceid): 472 473 "Load the object with the given 'uid' and 'recurrenceid'." 474 475 self.set_object(self.get_stored_object(uid, recurrenceid)) 476 477 def set_identity(self, method): 478 479 """ 480 Set the current user for the current object in the context of the given 481 'method'. It is usually set when initialising the handler, using the 482 recipient details, but outgoing messages do not reference the recipient 483 in this way. 484 """ 485 486 pass 487 488 def is_usable(self, method=None): 489 490 "Return whether the current object is usable with the given 'method'." 491 492 return True 493 494 def is_attendee(self): 495 496 "Return whether the current user is an attendee in the current object." 497 498 return self.obj.get_value_map("ATTENDEE").has_key(self.user) 499 500 def is_organiser(self): 501 502 """ 503 Return whether the current user is the organiser in the current object. 504 """ 505 506 return get_uri(self.obj.get_value("ORGANIZER")) == self.user 507 508 def is_recurrence(self): 509 510 "Return whether the current object is a recurrence of its parent." 511 512 parent = self.get_parent_object() 513 return parent and parent.has_recurrence(self.obj.get_recurrenceid()) 514 515 def get_recurrences(self, uid=None): 516 517 "Return the current object's recurrence identifiers." 518 519 return self.store.get_recurrences(self.user, uid or self.uid) 520 521 def get_periods(self, obj=None, explicit_only=False, future_only=False): 522 523 "Return the periods provided by the current object." 524 525 return Client.get_periods(self, obj or self.obj, explicit_only, future_only) 526 527 def get_updated_periods(self, obj=None): 528 529 """ 530 Return the periods provided by the current object and associated 531 recurrence instances. 532 """ 533 534 return Client.get_updated_periods(self, obj or self.obj) 535 536 def get_main_period(self, obj=None): 537 538 "Return the main period defined by the current object." 539 540 return Client.get_main_period(self, obj or self.obj) 541 542 def get_recurrence_periods(self, obj=None): 543 544 "Return the recurrence periods defined by the current object." 545 546 return Client.get_recurrence_periods(self, obj or self.obj) 547 548 # Common operations on calendar data. 549 550 def update_sender(self, obj=None): 551 552 """ 553 Update sender details in 'obj', or the current object if not indicated, 554 modifying the organiser attributes. 555 """ 556 557 obj = obj or self.obj 558 organiser, organiser_attr = uri_item(obj.get_item("ORGANIZER")) 559 self.update_sender_attr(organiser_attr) 560 561 def update_senders(self, obj=None): 562 563 """ 564 Update sender details in 'obj', or the current object if not indicated, 565 removing SENT-BY attributes for attendees other than the current user if 566 those attributes give the URI of the calendar system. 567 """ 568 569 obj = obj or self.obj 570 calendar_uri = self.messenger and get_uri(self.messenger.sender) 571 572 for attendee, attendee_attr in uri_items(obj.get_items("ATTENDEE") or []): 573 574 # Fix up the SENT-BY attribute for this user. 575 576 if attendee == self.user: 577 self.update_sender_attr(attendee_attr) 578 579 # Remove any conflicting SENT-BY attributes for other users. 580 581 elif attendee_attr.get("SENT-BY") == calendar_uri: 582 del attendee_attr["SENT-BY"] 583 584 def get_sending_attendee(self): 585 586 "Return the attendee who sent the current object." 587 588 # Search for the sender of the message or the calendar system address. 589 590 senders = set(uri_values(self.senders or self.messenger and [self.messenger.sender] or [])) 591 592 if senders: 593 594 # Obtain a mapping from sender URI to attendee URI, where the sender 595 # is taken from the SENT-BY attribute if present, or from the 596 # attendee value otherwise. 597 598 sent_by = get_sender_identities(uri_dict(self.obj.get_value_map("ATTENDEE"))) 599 600 # Obtain the attendee for the first sender matching the SENT-BY or 601 # attendee value. 602 603 for sender in senders.intersection(sent_by.keys()): 604 return sent_by[sender][0] 605 606 return None 607 608 # Object update methods. 609 610 def update_recurrenceid(self): 611 612 """ 613 Update the RECURRENCE-ID in the current object, initialising it from 614 DTSTART. 615 """ 616 617 self.obj["RECURRENCE-ID"] = [self.obj.get_item("DTSTART")] 618 self.recurrenceid = self.obj.get_recurrenceid() 619 620 def update_dtstamp(self, obj=None): 621 622 "Update the DTSTAMP in the current object or any given object 'obj'." 623 624 obj = obj or self.obj 625 self.dtstamp = obj.update_dtstamp() 626 627 def update_sequence(self, obj=None): 628 629 "Update the SEQUENCE in the current object or any given object 'obj'." 630 631 obj = obj or self.obj 632 obj.update_sequence(self.is_organiser()) 633 634 def merge_attendance(self, attendees): 635 636 """ 637 Merge attendance from the current object's 'attendees' into the version 638 stored for the current user. 639 """ 640 641 obj = self.get_stored_object_version() 642 643 if not obj or not self.have_new_object(): 644 return False 645 646 # Get attendee details in a usable form. 647 648 stored_attendees = uri_dict(obj.get_value_map("ATTENDEE")) 649 650 for attendee, attendee_attr in attendees.items(): 651 652 # Update attendance in the loaded object for any recognised 653 # attendees. 654 655 if stored_attendees.has_key(attendee): 656 stored_attendees[attendee] = attendee_attr 657 658 update_attendees_with_delegates(stored_attendees, attendees) 659 660 # Set the new details and store the object. 661 662 obj["ATTENDEE"] = stored_attendees.items() 663 664 # Set a specific recurrence or the complete event if not an additional 665 # occurrence. 666 667 return self.store.set_event(self.user, self.uid, self.recurrenceid, obj.to_node()) 668 669 def update_attendees(self, to_invite, to_cancel, to_modify): 670 671 """ 672 Update the attendees in the current object with the given 'to_invite', 673 'to_cancel' and 'to_modify' attendee mappings. 674 """ 675 676 attendees = uri_items(self.obj.get_items("ATTENDEE") or []) 677 attendee_map = OrderedDict(attendees) 678 679 # Normalise the identities. 680 681 to_invite = uri_dict(to_invite) 682 to_cancel = uri_dict(to_cancel) 683 to_modify = uri_dict(to_modify) 684 685 if self.is_organiser(): 686 687 # Remove uninvited attendees. 688 689 for attendee in to_cancel.keys(): 690 if attendee_map.has_key(attendee): 691 del attendee_map[attendee] 692 693 # Attendees (when countering) must only include the current user and 694 # any added attendees. 695 696 else: 697 attr = attendee_map.get(self.user) or self.get_user_attributes() 698 attendee_map = {self.user : attr} 699 700 # Update modified attendees. 701 702 for attendee, attr in to_modify.items(): 703 existing_attr = attendee_map.get(attendee) 704 if existing_attr: 705 existing_attr.update(attr) 706 707 # Add newly-invited attendees, applicable for organisers and attendees 708 # (when countering). 709 710 for attendee, attr in to_invite.items(): 711 if not attendee_map.has_key(attendee): 712 713 # Only the organiser can reset the participation attributes. 714 715 if self.is_organiser() and attendee != self.user: 716 attr.update({"PARTSTAT" : "NEEDS-ACTION", "RSVP" : "TRUE"}) 717 718 attendee_map[attendee] = attr 719 720 self.obj["ATTENDEE"] = attendee_map.items() 721 722 def update_participation(self, partstat=None): 723 724 """ 725 Update the participation in the current object of the user with the 726 given 'partstat'. 727 """ 728 729 attendee_attr = uri_dict(self.obj.get_value_map("ATTENDEE")).get(self.user) 730 731 if not attendee_attr: 732 return None 733 734 # Set the participation and remove any request for response indicator. 735 736 if partstat: 737 attendee_attr["PARTSTAT"] = partstat 738 if attendee_attr.has_key("RSVP"): 739 del attendee_attr["RSVP"] 740 741 return attendee_attr 742 743 def update_event_version(self, changed=False): 744 745 """ 746 Update the event version information and details for sending. Where 747 'changed' is set to a true value for the attendee, the attendee list 748 will be processed and preserved; otherwise, the attendee replying will 749 be retained and the others removed from the object. 750 """ 751 752 if self.is_organiser(): 753 self.update_sender() 754 755 # Process attendee SENT-BY usage, timestamp and sequence details 756 # appropriately for the sender's role. 757 758 self.update_senders() 759 self.update_dtstamp() 760 self.update_sequence() 761 762 return True 763 764 def update_event_from_periods(self, to_set, to_exclude): 765 766 """ 767 Set the periods in any redefined event from the 'to_set' list, excluding 768 the main period if it appears in 'to_exclude'. 769 """ 770 771 if to_set: 772 self.obj.set_periods(to_set) 773 774 if to_exclude: 775 self.obj.update_exceptions(to_exclude, to_set or []) 776 777 # General message generation methods. 778 779 def get_recipients(self, obj=None): 780 781 """ 782 Return recipients for 'obj' (or the current object) dependent on the 783 current user's role. 784 """ 785 786 obj = obj or self.obj 787 788 organiser = get_uri(obj.get_value("ORGANIZER")) 789 attendees = uri_values(obj.get_values("ATTENDEE")) 790 791 # As organiser, send an invitation to attendees, excluding oneself if 792 # also attending. The updated event will be saved by the outgoing 793 # handler. 794 795 if self.is_organiser(): 796 return [get_address(attendee) for attendee in attendees if attendee != self.user] 797 else: 798 return [get_address(organiser)] 799 800 def attach_freebusy(self, parts): 801 802 """ 803 Since the outgoing handler updates this user's free/busy details, the 804 stored details will probably not have the updated details straight away, 805 so we update our copy for serialisation as the bundled free/busy object. 806 """ 807 808 freebusy = self.store.get_freebusy(self.user).copy() 809 self.update_freebusy(freebusy, self.user, self.is_organiser()) 810 811 # Bundle free/busy information if appropriate. 812 813 part = self.get_freebusy_part(freebusy) 814 if part: 815 parts.append(part) 816 817 def make_message(self, parts, recipients, bcc_sender=False): 818 819 """ 820 Send the given 'parts' to the appropriate 'recipients', also sending a 821 copy to the sender. 822 """ 823 824 if not self.messenger: 825 return None 826 827 # Update and attach bundled free/busy details. 828 829 self.attach_freebusy(parts) 830 831 if not bcc_sender: 832 return self.messenger.make_outgoing_message(parts, recipients) 833 else: 834 sender = get_address(self.user) 835 return self.messenger.make_outgoing_message(parts, recipients, outgoing_bcc=sender) 836 837 def send_message(self, message, recipients, bcc_sender=False): 838 839 """ 840 Send 'message' to 'recipients', explicitly specifying the sender as an 841 outgoing BCC recipient if 'bcc_sender' is set, since the generic 842 calendar user will be the actual sender. 843 """ 844 845 if not recipients and not bcc_sender or not self.messenger: 846 return 847 848 if not bcc_sender: 849 self.messenger.sendmail(recipients, message.as_string()) 850 else: 851 sender = get_address(self.user) 852 self.messenger.sendmail(recipients, message.as_string(), outgoing_bcc=sender) 853 854 def make_message_for_self(self, parts): 855 856 "Send 'message' to the current user." 857 858 if not self.messenger: 859 return None 860 861 sender = get_address(self.user) 862 return self.messenger.make_outgoing_message(parts, [sender]) 863 864 def send_message_to_self(self, message): 865 866 "Send 'message' to the current user." 867 868 if not self.messenger: 869 return 870 871 sender = get_address(self.user) 872 self.messenger.sendmail([sender], message.as_string()) 873 874 # Specific message generation methods. 875 876 def get_rescheduled_parts(self, periods, method): 877 878 """ 879 Return message parts describing rescheduled 'periods' affected by 'method'. 880 """ 881 882 rescheduled_parts = [] 883 884 if periods: 885 886 # Duplicate the core of the object without any period information. 887 888 obj = self.obj.copy() 889 obj.remove_all(["RRULE", "RDATE", "DTSTART", "DTEND", "DURATION"]) 890 891 for p in periods: 892 if not p.origin: 893 continue 894 895 # Set specific recurrence information. 896 897 obj.set_datetime("DTSTART", p.get_start()) 898 obj.set_datetime("DTEND", p.get_end()) 899 900 # Acquire the original recurrence identifier associated with 901 # this period. This may differ where the start of the period has 902 # changed. 903 904 dt, attr = p.get_recurrenceid_item() 905 obj["RECURRENCE-ID"] = [(format_datetime(dt), attr)] 906 907 rescheduled_parts.append(self.object_to_part(method, obj)) 908 909 return rescheduled_parts 910 911 def make_update_message(self, recipients, update_parent=False, 912 to_unschedule=None, to_reschedule=None, 913 all_unscheduled=None, all_rescheduled=None, 914 to_add=None): 915 916 """ 917 Prepare event updates from the organiser of an event for the given 918 'recipients', including the parent event if 'update_parent' is set to a 919 true value. 920 921 Additional parts are provided by the 'to_unschedule' and 'to_reschedule' 922 collections. Alternatively, where the parent event is being updated, the 923 'all_unscheduled' and 'all_rescheduled' period collections are included. 924 925 The 'to_add' period collection augments the existing periods. 926 """ 927 928 parts = [] 929 930 if update_parent: 931 parts.append(self.object_to_part("REQUEST", self.obj)) 932 unscheduled = all_unscheduled 933 rescheduled = all_rescheduled 934 else: 935 unscheduled = to_unschedule 936 rescheduled = to_reschedule 937 938 parts += self.get_rescheduled_parts(unscheduled, "CANCEL") 939 parts += self.get_rescheduled_parts(rescheduled, "REQUEST") 940 parts += self.get_rescheduled_parts(to_add, "ADD") 941 return self.make_message(parts, recipients) 942 943 def make_self_update_message(self, all_unscheduled=None, all_rescheduled=None, 944 to_add=None): 945 946 """ 947 Prepare event updates to be sent from the organiser of an event to 948 themself. 949 """ 950 951 parts = [self.object_to_part("PUBLISH", self.obj)] 952 parts += self.get_rescheduled_parts(all_unscheduled, "CANCEL") 953 parts += self.get_rescheduled_parts(all_rescheduled, "PUBLISH") 954 parts += self.get_rescheduled_parts(to_add, "ADD") 955 return self.make_message_for_self(parts) 956 957 def make_response_message(self, recipients, update_parent=False, 958 all_rescheduled=None, to_reschedule=None): 959 960 """ 961 Prepare a response to 'recipients', including the parent event if 962 'update_parent' is set to a true value, incorporating 'all_rescheduled' 963 periods, of which there may be indicated periods 'to_reschedule'. 964 """ 965 966 parts = [self.object_to_part(update_parent and "COUNTER" or "REPLY", self.obj)] 967 968 # Determine existing replaced periods that are not newly rescheduled. 969 970 rescheduled_unmodified = set(all_rescheduled or []).difference(to_reschedule or []) 971 972 if rescheduled_unmodified: 973 parts += self.get_rescheduled_parts(rescheduled_unmodified, update_parent and "COUNTER" or "REPLY") 974 975 # Suggest details for newly rescheduled periods. 976 977 if to_reschedule: 978 parts += self.get_rescheduled_parts(to_reschedule, "COUNTER") 979 980 return self.make_message(parts, recipients, bcc_sender=True) 981 982 def make_cancel_message(self, to_cancel=None): 983 984 """ 985 Prepare an event cancellation message involving the participants in the 986 'to_cancel' mapping. 987 """ 988 989 if not to_cancel: 990 return None 991 992 obj = self.obj.copy() 993 obj["ATTENDEE"] = to_cancel.items() 994 995 parts = [self.object_to_part("CANCEL", obj)] 996 return self.make_message(parts, to_cancel.keys()) 997 998 def make_cancel_message_for_self(self, obj): 999 1000 "Prepare an event cancellation for the current user." 1001 1002 parts = [self.object_to_part("CANCEL", obj)] 1003 return self.make_message_for_self(parts) 1004 1005 # Action methods. 1006 1007 def send_declined_counter_to_attendee(self, attendee): 1008 1009 "Send a declined counter-proposal to 'attendee'." 1010 1011 # Obtain the counter-proposal for the attendee. 1012 1013 obj = self.get_stored_object(self.uid, self.recurrenceid, "counters", attendee) 1014 if not obj: 1015 return 1016 1017 self.update_senders(obj) 1018 obj.update_dtstamp() 1019 obj.update_sequence() 1020 1021 parts = [self.object_to_part("DECLINECOUNTER", obj)] 1022 1023 # Create and send the response. 1024 1025 recipients = self.get_recipients(obj) 1026 message = self.make_message(parts, recipients, bcc_sender=True) 1027 self.send_message(message, recipients, bcc_sender=True) 1028 1029 def send_response_to_organiser(self, all_rescheduled=None, to_reschedule=None, 1030 changed=False): 1031 1032 """ 1033 Send a response to the organiser describing attendance and proposed 1034 amendments to the event. 1035 1036 If 'all_rescheduled' is specified, it provides details of separate 1037 recurrence instances for which a response needs to be generated. 1038 1039 If 'to_reschedule' provides rescheduled periods, these will be sent as 1040 counter-proposals. 1041 1042 If 'changed' is set to a true value, a counter-proposal will be sent for 1043 the entire event instead of a reply. 1044 """ 1045 1046 recipients = self.get_recipients() 1047 message = self.make_response_message(recipients, all_rescheduled, 1048 to_reschedule, changed) 1049 self.send_message(message, recipients, bcc_sender=True) 1050 1051 def send_update_to_recipients(self, to_unschedule=None, to_reschedule=None): 1052 1053 """ 1054 Send cancellations for each of the recurrences 'to_unschedule' along 1055 with modifications for each of the recurrences 'to_reschedule'. 1056 """ 1057 1058 recipients = self.get_recipients() 1059 message = self.make_update_message(recipients, to_unschedule, to_reschedule) 1060 self.send_message(message, recipients) 1061 1062 def send_publish_to_self(self, all_unscheduled=None, all_rescheduled=None): 1063 1064 """ 1065 Send published event details incorporating 'all_unscheduled' and 1066 'all_rescheduled' periods. 1067 """ 1068 1069 # Since the organiser can update the SEQUENCE but this can leave any 1070 # mail/calendar client lagging, issue a PUBLISH message to the 1071 # user's address. 1072 1073 recipients = self.get_recipients() 1074 message = self.make_self_update_message(all_unscheduled, all_rescheduled) 1075 self.send_message_to_self(message) 1076 1077 def send_cancel_to_recipients(self, to_cancel=None): 1078 1079 "Send a cancellation to all uninvited attendees in 'to_cancel'." 1080 1081 message = self.make_cancel_message(to_cancel) 1082 self.send_message(message, to_cancel.keys()) 1083 1084 def send_cancel_to_self(self): 1085 1086 "Issue a CANCEL message to the user's address." 1087 1088 message = self.make_cancel_message_for_self(self.obj) 1089 self.send_message_to_self(message) 1090 1091 # Object-related tests. 1092 1093 def is_recognised_organiser(self, organiser): 1094 1095 """ 1096 Return whether the given 'organiser' is recognised from 1097 previously-received details. If no stored details exist, True is 1098 returned. 1099 """ 1100 1101 obj = self.get_stored_object_version() 1102 if obj: 1103 stored_organiser = get_uri(obj.get_value("ORGANIZER")) 1104 return stored_organiser == organiser 1105 else: 1106 return True 1107 1108 def is_recognised_attendee(self, attendee): 1109 1110 """ 1111 Return whether the given 'attendee' is recognised from 1112 previously-received details. If no stored details exist, True is 1113 returned. 1114 """ 1115 1116 obj = self.get_stored_object_version() 1117 if obj: 1118 stored_attendees = uri_dict(obj.get_value_map("ATTENDEE")) 1119 return stored_attendees.has_key(attendee) 1120 else: 1121 return True 1122 1123 def get_attendance(self, user=None, obj=None): 1124 1125 """ 1126 Return the attendance attributes for 'user', or the current user if 1127 'user' is not specified. 1128 """ 1129 1130 attendees = uri_dict((obj or self.obj).get_value_map("ATTENDEE")) 1131 return attendees.get(user or self.user) 1132 1133 def is_participating(self, user, as_organiser=False, obj=None): 1134 1135 """ 1136 Return whether, subject to the 'user' indicating an identity and the 1137 'as_organiser' status of that identity, the user concerned is actually 1138 participating in the current object event. 1139 """ 1140 1141 # Use any attendee property information for an organiser, not the 1142 # organiser property attributes. 1143 1144 attr = self.get_attendance(user, obj) 1145 return as_organiser or attr is not None and not attr or \ 1146 attr and attr.get("PARTSTAT") not in ("DECLINED", "DELEGATED", "NEEDS-ACTION") 1147 1148 def has_indicated_attendance(self, user=None, obj=None): 1149 1150 """ 1151 Return whether the given 'user' (or the current user if not specified) 1152 has indicated attendance in the given 'obj' (or the current object if 1153 not specified). 1154 """ 1155 1156 attr = self.get_attendance(user, obj) 1157 return attr and attr.get("PARTSTAT") not in (None, "NEEDS-ACTION") 1158 1159 def get_overriding_transparency(self, user, as_organiser=False): 1160 1161 """ 1162 Return the overriding transparency to be associated with the free/busy 1163 records for an event, subject to the 'user' indicating an identity and 1164 the 'as_organiser' status of that identity. 1165 1166 Where an identity is only an organiser and not attending, "ORG" is 1167 returned. Otherwise, no overriding transparency is defined and None is 1168 returned. 1169 """ 1170 1171 attr = self.get_attendance(user) 1172 return as_organiser and not (attr and attr.get("PARTSTAT")) and "ORG" or None 1173 1174 def can_schedule(self, freebusy, periods): 1175 1176 """ 1177 Indicate whether within 'freebusy' the given 'periods' can be scheduled. 1178 """ 1179 1180 return freebusy.can_schedule(periods, self.uid, self.recurrenceid) 1181 1182 def have_new_object(self, strict=True): 1183 1184 """ 1185 Return whether the current object is new to the current user. 1186 1187 If 'strict' is specified and is a false value, the DTSTAMP test will be 1188 ignored. This is useful in handling responses from attendees from 1189 clients (like Claws Mail) that erase time information from DTSTAMP and 1190 make it invalid. 1191 """ 1192 1193 obj = self.get_stored_object_version() 1194 1195 # If found, compare SEQUENCE and potentially DTSTAMP. 1196 1197 if obj: 1198 sequence = obj.get_value("SEQUENCE") 1199 dtstamp = obj.get_value("DTSTAMP") 1200 1201 # If the request refers to an older version of the object, ignore 1202 # it. 1203 1204 return is_new_object(sequence, self.sequence, dtstamp, self.dtstamp, not strict) 1205 1206 return True 1207 1208 def possibly_recurring_indefinitely(self): 1209 1210 "Return whether the object recurs indefinitely." 1211 1212 # Obtain the stored object to make sure that recurrence information 1213 # is not being ignored. This might happen if a client sends a 1214 # cancellation without the complete set of properties, for instance. 1215 1216 return self.obj.possibly_recurring_indefinitely() or \ 1217 self.get_stored_object_version() and \ 1218 self.get_stored_object_version().possibly_recurring_indefinitely() 1219 1220 # Constraint application on event periods. 1221 1222 def check_object(self): 1223 1224 "Check the object against any scheduling constraints." 1225 1226 permitted_values = self.get_permitted_values() 1227 if not permitted_values: 1228 return None 1229 1230 invalid = [] 1231 1232 for period in self.obj.get_periods(): 1233 errors = period.check_permitted(permitted_values) 1234 if errors: 1235 start_errors, end_errors = errors 1236 invalid.append((period.origin, start_errors, end_errors)) 1237 1238 return invalid 1239 1240 def correct_object(self): 1241 1242 "Correct the object according to any scheduling constraints." 1243 1244 permitted_values = self.get_permitted_values() 1245 return permitted_values and self.obj.correct_object(permitted_values) 1246 1247 def correct_period(self, period): 1248 1249 "Correct 'period' according to any scheduling constraints." 1250 1251 permitted_values = self.get_permitted_values() 1252 if not permitted_values: 1253 return period 1254 else: 1255 return period.get_corrected(permitted_values) 1256 1257 # Object retrieval. 1258 1259 def get_stored_object_version(self): 1260 1261 """ 1262 Return the stored object to which the current object refers for the 1263 current user. 1264 """ 1265 1266 return self.get_stored_object(self.uid, self.recurrenceid) 1267 1268 def get_definitive_object(self, as_organiser): 1269 1270 """ 1271 Return an object considered definitive for the current transaction, 1272 using 'as_organiser' to select the current transaction's object if 1273 false, or selecting a stored object if true. 1274 """ 1275 1276 return not as_organiser and self.obj or self.get_stored_object_version() 1277 1278 def get_parent_object(self): 1279 1280 """ 1281 Return the parent object to which the current object refers for the 1282 current user. 1283 """ 1284 1285 return self.recurrenceid and self.get_stored_object(self.uid, None) or None 1286 1287 # Convenience methods for modifying free/busy collections. 1288 1289 def get_recurrence_start_point(self, recurrenceid): 1290 1291 "Get 'recurrenceid' in a form suitable for matching free/busy entries." 1292 1293 return self.obj.get_recurrence_start_point(recurrenceid) 1294 1295 def remove_from_freebusy(self, freebusy, participant=None): 1296 1297 """ 1298 Remove this event from the given 'freebusy' collection. If 'participant' 1299 is specified, only remove this event if the participant is attending. 1300 """ 1301 1302 removed = freebusy.remove_event_periods(self.uid, self.recurrenceid, participant) 1303 if not removed and self.recurrenceid: 1304 return freebusy.remove_affected_period(self.uid, self.get_recurrence_start_point(self.recurrenceid), participant) 1305 else: 1306 return removed 1307 1308 def remove_freebusy_for_recurrences(self, freebusy, recurrenceids=None): 1309 1310 """ 1311 Remove from 'freebusy' any original recurrence from parent free/busy 1312 details for the current object, if the current object is a specific 1313 additional recurrence. Otherwise, remove all additional recurrence 1314 information corresponding to 'recurrenceids', or if omitted, all 1315 recurrences. 1316 """ 1317 1318 if self.recurrenceid: 1319 recurrenceid = self.get_recurrence_start_point(self.recurrenceid) 1320 freebusy.remove_affected_period(self.uid, recurrenceid) 1321 else: 1322 # Remove obsolete recurrence periods. 1323 1324 freebusy.remove_additional_periods(self.uid, recurrenceids) 1325 1326 # Remove original periods affected by additional recurrences. 1327 1328 if recurrenceids: 1329 for recurrenceid in recurrenceids: 1330 recurrenceid = self.get_recurrence_start_point(recurrenceid) 1331 freebusy.remove_affected_period(self.uid, recurrenceid) 1332 1333 def update_freebusy(self, freebusy, user, as_organiser, offer=False): 1334 1335 """ 1336 Update the 'freebusy' collection for this event with the periods and 1337 transparency associated with the current object, subject to the 'user' 1338 identity and the attendance details provided for them, indicating 1339 whether the update is being done 'as_organiser' (for the organiser of 1340 an event) or not. 1341 1342 If 'offer' is set to a true value, any free/busy updates will be tagged 1343 with an expiry time. 1344 """ 1345 1346 # Obtain the stored object if the current object is not issued by the 1347 # organiser. Attendees do not have the opportunity to redefine the 1348 # periods. 1349 1350 obj = self.get_definitive_object(as_organiser) 1351 if not obj: 1352 return 1353 1354 # Obtain the affected periods. 1355 1356 periods = self.get_periods(obj, future_only=True) 1357 1358 # Define an overriding transparency, the indicated event transparency, 1359 # or the default transparency for the free/busy entry. 1360 1361 transp = self.get_overriding_transparency(user, as_organiser) or \ 1362 obj.get_value("TRANSP") or \ 1363 "OPAQUE" 1364 1365 # Calculate any expiry time. If no offer period is defined, do not 1366 # record the offer periods. 1367 1368 if offer: 1369 offer_period = self.get_offer_period() 1370 if offer_period: 1371 expires = get_timestamp(offer_period) 1372 else: 1373 return 1374 else: 1375 expires = None 1376 1377 # Perform the low-level update. 1378 1379 Client.update_freebusy(self, freebusy, periods, transp, 1380 self.uid, self.recurrenceid, 1381 obj.get_value("SUMMARY"), 1382 get_uri(obj.get_value("ORGANIZER")), 1383 expires) 1384 1385 def update_freebusy_for_participant(self, freebusy, user, for_organiser=False, 1386 updating_other=False, offer=False): 1387 1388 """ 1389 Update the 'freebusy' collection for the given 'user', indicating 1390 whether the update is 'for_organiser' (being done for the organiser of 1391 an event) or not, and whether it is 'updating_other' (meaning another 1392 user's details). 1393 1394 If 'offer' is set to a true value, any free/busy updates will be tagged 1395 with an expiry time. 1396 """ 1397 1398 # Record in the free/busy details unless a non-participating attendee. 1399 # Remove periods for non-participating attendees. 1400 1401 if offer or self.is_participating(user, for_organiser and not updating_other): 1402 self.update_freebusy(freebusy, user, 1403 for_organiser and not updating_other or 1404 not for_organiser and updating_other, 1405 offer 1406 ) 1407 else: 1408 self.remove_from_freebusy(freebusy) 1409 1410 def remove_freebusy_for_participant(self, freebusy, user, for_organiser=False, 1411 updating_other=False): 1412 1413 """ 1414 Remove details from the 'freebusy' collection for the given 'user', 1415 indicating whether the modification is 'for_organiser' (being done for 1416 the organiser of an event) or not, and whether it is 'updating_other' 1417 (meaning another user's details). 1418 """ 1419 1420 # Remove from the free/busy details if a specified attendee. 1421 1422 if self.is_participating(user, for_organiser and not updating_other): 1423 self.remove_from_freebusy(freebusy) 1424 1425 # Convenience methods for updating stored free/busy information received 1426 # from other users. 1427 1428 def update_freebusy_from_participant(self, user, for_organiser, fn=None): 1429 1430 """ 1431 For the current user, record the free/busy information for another 1432 'user', indicating whether the update is 'for_organiser' or not, thus 1433 maintaining a separate record of their free/busy details. 1434 """ 1435 1436 fn = fn or self.update_freebusy_for_participant 1437 1438 # A user does not store free/busy information for themself as another 1439 # party. 1440 1441 if user == self.user: 1442 return 1443 1444 self.acquire_lock() 1445 try: 1446 freebusy = self.store.get_freebusy_for_other_for_update(self.user, user) 1447 fn(freebusy, user, for_organiser, True) 1448 1449 # Tidy up any obsolete recurrences. 1450 1451 self.remove_freebusy_for_recurrences(freebusy, self.get_recurrences()) 1452 self.store.set_freebusy_for_other(self.user, freebusy, user) 1453 1454 finally: 1455 self.release_lock() 1456 1457 def update_freebusy_from_organiser(self, organiser): 1458 1459 "For the current user, record free/busy information from 'organiser'." 1460 1461 self.update_freebusy_from_participant(organiser, True) 1462 1463 def update_freebusy_from_attendees(self, attendees): 1464 1465 "For the current user, record free/busy information from 'attendees'." 1466 1467 obj = self.get_stored_object_version() 1468 1469 if not obj or not self.have_new_object(): 1470 return False 1471 1472 # Filter out unrecognised attendees. 1473 1474 attendees = set(attendees).intersection(uri_values(obj.get_values("ATTENDEE"))) 1475 1476 for attendee in attendees: 1477 self.update_freebusy_from_participant(attendee, False) 1478 1479 return True 1480 1481 def remove_freebusy_from_organiser(self, organiser): 1482 1483 "For the current user, remove free/busy information from 'organiser'." 1484 1485 self.update_freebusy_from_participant(organiser, True, self.remove_freebusy_for_participant) 1486 1487 def remove_freebusy_from_attendees(self, attendees): 1488 1489 "For the current user, remove free/busy information from 'attendees'." 1490 1491 for attendee in attendees.keys(): 1492 self.update_freebusy_from_participant(attendee, False, self.remove_freebusy_for_participant) 1493 1494 # Convenience methods for updating free/busy details at the event level. 1495 1496 def update_event_in_freebusy(self, for_organiser=True): 1497 1498 """ 1499 Update free/busy information when handling an object, doing so for the 1500 organiser of an event if 'for_organiser' is set to a true value. 1501 """ 1502 1503 freebusy = self.store.get_freebusy_for_update(self.user) 1504 1505 # Obtain the attendance attributes for this user, if available. 1506 1507 self.update_freebusy_for_participant(freebusy, self.user, for_organiser) 1508 1509 # Remove original recurrence details replaced by additional 1510 # recurrences, as well as obsolete additional recurrences. 1511 1512 self.remove_freebusy_for_recurrences(freebusy, self.get_recurrences()) 1513 self.store.set_freebusy(self.user, freebusy) 1514 1515 if self.publisher and self.is_sharing() and self.is_publishing(): 1516 self.publisher.set_freebusy(self.user, freebusy) 1517 1518 # Update free/busy provider information if the event may recur 1519 # indefinitely. 1520 1521 if self.possibly_recurring_indefinitely(): 1522 self.store.append_freebusy_provider(self.user, self.obj) 1523 1524 return True 1525 1526 def remove_event_from_freebusy(self): 1527 1528 "Remove free/busy information when handling an object." 1529 1530 freebusy = self.store.get_freebusy_for_update(self.user) 1531 1532 self.remove_from_freebusy(freebusy) 1533 self.remove_freebusy_for_recurrences(freebusy) 1534 self.store.set_freebusy(self.user, freebusy) 1535 1536 if self.publisher and self.is_sharing() and self.is_publishing(): 1537 self.publisher.set_freebusy(self.user, freebusy) 1538 1539 # Update free/busy provider information if the event may recur 1540 # indefinitely. 1541 1542 if self.possibly_recurring_indefinitely(): 1543 self.store.remove_freebusy_provider(self.user, self.obj) 1544 1545 def update_event_in_freebusy_offers(self): 1546 1547 "Update free/busy offers when handling an object." 1548 1549 freebusy = self.store.get_freebusy_offers_for_update(self.user) 1550 1551 # Obtain the attendance attributes for this user, if available. 1552 1553 self.update_freebusy_for_participant(freebusy, self.user, offer=True) 1554 1555 # Remove original recurrence details replaced by additional 1556 # recurrences, as well as obsolete additional recurrences. 1557 1558 self.remove_freebusy_for_recurrences(freebusy, self.get_recurrences()) 1559 self.store.set_freebusy_offers(self.user, freebusy) 1560 1561 return True 1562 1563 def remove_event_from_freebusy_offers(self): 1564 1565 "Remove free/busy offers when handling an object." 1566 1567 freebusy = self.store.get_freebusy_offers_for_update(self.user) 1568 1569 self.remove_from_freebusy(freebusy) 1570 self.remove_freebusy_for_recurrences(freebusy) 1571 self.store.set_freebusy_offers(self.user, freebusy) 1572 1573 return True 1574 1575 # Convenience methods for removing counter-proposals and updating the 1576 # request queue. 1577 1578 def remove_request(self): 1579 return self.store.dequeue_request(self.user, self.uid, self.recurrenceid) 1580 1581 def remove_event(self): 1582 return self.store.remove_event(self.user, self.uid, self.recurrenceid) 1583 1584 def remove_counter(self, attendee): 1585 self.remove_counters([attendee]) 1586 1587 def remove_counters(self, attendees): 1588 for attendee in attendees: 1589 self.store.remove_counter(self.user, attendee, self.uid, self.recurrenceid) 1590 1591 if not self.store.get_counters(self.user, self.uid, self.recurrenceid): 1592 self.store.dequeue_request(self.user, self.uid, self.recurrenceid) 1593 1594 # vim: tabstop=4 expandtab shiftwidth=4