paul@441 | 1 | #!/usr/bin/env python |
paul@441 | 2 | |
paul@441 | 3 | """ |
paul@441 | 4 | Common calendar client utilities. |
paul@441 | 5 | |
paul@441 | 6 | Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk> |
paul@441 | 7 | |
paul@441 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@441 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@441 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@441 | 11 | version. |
paul@441 | 12 | |
paul@441 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@441 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@441 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@441 | 16 | details. |
paul@441 | 17 | |
paul@441 | 18 | You should have received a copy of the GNU General Public License along with |
paul@441 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@441 | 20 | """ |
paul@441 | 21 | |
paul@740 | 22 | from datetime import datetime, timedelta |
paul@749 | 23 | from imiptools import config |
paul@606 | 24 | from imiptools.data import Object, get_address, get_uri, get_window_end, \ |
paul@606 | 25 | is_new_object, make_freebusy, to_part, \ |
paul@818 | 26 | uri_dict, uri_items, uri_parts, uri_values |
paul@669 | 27 | from imiptools.dates import check_permitted_values, format_datetime, get_default_timezone, \ |
paul@809 | 28 | get_duration, get_timestamp |
paul@606 | 29 | from imiptools.period import can_schedule, remove_period, \ |
paul@606 | 30 | remove_additional_periods, remove_affected_period, \ |
paul@606 | 31 | update_freebusy |
paul@443 | 32 | from imiptools.profile import Preferences |
paul@604 | 33 | import imip_store |
paul@441 | 34 | |
paul@443 | 35 | class Client: |
paul@443 | 36 | |
paul@443 | 37 | "Common handler and manager methods." |
paul@443 | 38 | |
paul@467 | 39 | default_window_size = 100 |
paul@729 | 40 | organiser_methods = "ADD", "CANCEL", "DECLINECOUNTER", "PUBLISH", "REQUEST" |
paul@467 | 41 | |
paul@639 | 42 | def __init__(self, user, messenger=None, store=None, publisher=None, preferences_dir=None): |
paul@728 | 43 | |
paul@728 | 44 | """ |
paul@728 | 45 | Initialise a calendar client with the current 'user', plus any |
paul@728 | 46 | 'messenger', 'store' and 'publisher' objects, indicating any specific |
paul@728 | 47 | 'preferences_dir'. |
paul@728 | 48 | """ |
paul@728 | 49 | |
paul@443 | 50 | self.user = user |
paul@601 | 51 | self.messenger = messenger |
paul@604 | 52 | self.store = store or imip_store.FileStore() |
paul@604 | 53 | |
paul@604 | 54 | try: |
paul@604 | 55 | self.publisher = publisher or imip_store.FilePublisher() |
paul@604 | 56 | except OSError: |
paul@604 | 57 | self.publisher = None |
paul@604 | 58 | |
paul@639 | 59 | self.preferences_dir = preferences_dir |
paul@443 | 60 | self.preferences = None |
paul@443 | 61 | |
paul@730 | 62 | # Store-related methods. |
paul@730 | 63 | |
paul@730 | 64 | def acquire_lock(self): |
paul@730 | 65 | self.store.acquire_lock(self.user) |
paul@730 | 66 | |
paul@730 | 67 | def release_lock(self): |
paul@730 | 68 | self.store.release_lock(self.user) |
paul@730 | 69 | |
paul@730 | 70 | # Preferences-related methods. |
paul@730 | 71 | |
paul@443 | 72 | def get_preferences(self): |
paul@467 | 73 | if not self.preferences and self.user: |
paul@639 | 74 | self.preferences = Preferences(self.user, self.preferences_dir) |
paul@443 | 75 | return self.preferences |
paul@443 | 76 | |
paul@791 | 77 | def get_user_attributes(self): |
paul@791 | 78 | prefs = self.get_preferences() |
paul@791 | 79 | return prefs and prefs.get_all(["CN"]) or {} |
paul@791 | 80 | |
paul@443 | 81 | def get_tzid(self): |
paul@443 | 82 | prefs = self.get_preferences() |
paul@467 | 83 | return prefs and prefs.get("TZID") or get_default_timezone() |
paul@443 | 84 | |
paul@443 | 85 | def get_window_size(self): |
paul@443 | 86 | prefs = self.get_preferences() |
paul@443 | 87 | try: |
paul@467 | 88 | return prefs and int(prefs.get("window_size")) or self.default_window_size |
paul@443 | 89 | except (TypeError, ValueError): |
paul@467 | 90 | return self.default_window_size |
paul@443 | 91 | |
paul@443 | 92 | def get_window_end(self): |
paul@443 | 93 | return get_window_end(self.get_tzid(), self.get_window_size()) |
paul@443 | 94 | |
paul@667 | 95 | def is_participating(self): |
paul@748 | 96 | |
paul@748 | 97 | "Return participation in the calendar system." |
paul@748 | 98 | |
paul@667 | 99 | prefs = self.get_preferences() |
paul@749 | 100 | return prefs and prefs.get("participating", config.PARTICIPATING_DEFAULT) != "no" or False |
paul@667 | 101 | |
paul@443 | 102 | def is_sharing(self): |
paul@748 | 103 | |
paul@748 | 104 | "Return whether free/busy information is being generally shared." |
paul@748 | 105 | |
paul@467 | 106 | prefs = self.get_preferences() |
paul@749 | 107 | return prefs and prefs.get("freebusy_sharing", config.SHARING_DEFAULT) == "share" or False |
paul@443 | 108 | |
paul@443 | 109 | def is_bundling(self): |
paul@748 | 110 | |
paul@748 | 111 | "Return whether free/busy information is being bundled in messages." |
paul@748 | 112 | |
paul@467 | 113 | prefs = self.get_preferences() |
paul@749 | 114 | return prefs and prefs.get("freebusy_bundling", config.BUNDLING_DEFAULT) == "always" or False |
paul@467 | 115 | |
paul@467 | 116 | def is_notifying(self): |
paul@748 | 117 | |
paul@748 | 118 | "Return whether recipients are notified about free/busy payloads." |
paul@748 | 119 | |
paul@467 | 120 | prefs = self.get_preferences() |
paul@749 | 121 | return prefs and prefs.get("freebusy_messages", config.NOTIFYING_DEFAULT) == "notify" or False |
paul@443 | 122 | |
paul@748 | 123 | def is_publishing(self): |
paul@748 | 124 | |
paul@748 | 125 | "Return whether free/busy information is being published as Web resources." |
paul@748 | 126 | |
paul@748 | 127 | prefs = self.get_preferences() |
paul@749 | 128 | return prefs and prefs.get("freebusy_publishing", config.PUBLISHING_DEFAULT) == "publish" or False |
paul@748 | 129 | |
paul@688 | 130 | def is_refreshing(self): |
paul@748 | 131 | |
paul@748 | 132 | "Return whether a recipient supports requests to refresh event details." |
paul@748 | 133 | |
paul@688 | 134 | prefs = self.get_preferences() |
paul@749 | 135 | return prefs and prefs.get("event_refreshing", config.REFRESHING_DEFAULT) == "always" or False |
paul@688 | 136 | |
paul@734 | 137 | def allow_add(self): |
paul@734 | 138 | return self.get_add_method_response() in ("add", "refresh") |
paul@734 | 139 | |
paul@734 | 140 | def get_add_method_response(self): |
paul@728 | 141 | prefs = self.get_preferences() |
paul@749 | 142 | return prefs and prefs.get("add_method_response", config.ADD_RESPONSE_DEFAULT) or "refresh" |
paul@734 | 143 | |
paul@740 | 144 | def get_offer_period(self): |
paul@740 | 145 | |
paul@759 | 146 | "Decode a specification in the iCalendar duration format." |
paul@740 | 147 | |
paul@740 | 148 | prefs = self.get_preferences() |
paul@749 | 149 | duration = prefs and prefs.get("freebusy_offers", config.FREEBUSY_OFFER_DEFAULT) |
paul@740 | 150 | |
paul@759 | 151 | # NOTE: Should probably report an error somehow if None. |
paul@740 | 152 | |
paul@759 | 153 | return duration and get_duration(duration) or None |
paul@740 | 154 | |
paul@734 | 155 | def get_organiser_replacement(self): |
paul@734 | 156 | prefs = self.get_preferences() |
paul@749 | 157 | return prefs and prefs.get("organiser_replacement", config.ORGANISER_REPLACEMENT_DEFAULT) or "attendee" |
paul@728 | 158 | |
paul@668 | 159 | def have_manager(self): |
paul@749 | 160 | return config.MANAGER_INTERFACE |
paul@668 | 161 | |
paul@669 | 162 | def get_permitted_values(self): |
paul@655 | 163 | |
paul@655 | 164 | """ |
paul@655 | 165 | Decode a specification of one of the following forms... |
paul@655 | 166 | |
paul@655 | 167 | <minute values> |
paul@655 | 168 | <hour values>:<minute values> |
paul@655 | 169 | <hour values>:<minute values>:<second values> |
paul@655 | 170 | |
paul@655 | 171 | ...with each list of values being comma-separated. |
paul@655 | 172 | """ |
paul@655 | 173 | |
paul@655 | 174 | prefs = self.get_preferences() |
paul@669 | 175 | permitted_values = prefs and prefs.get("permitted_times") |
paul@669 | 176 | if permitted_values: |
paul@655 | 177 | try: |
paul@655 | 178 | l = [] |
paul@669 | 179 | for component in permitted_values.split(":")[:3]: |
paul@655 | 180 | if component: |
paul@655 | 181 | l.append(map(int, component.split(","))) |
paul@655 | 182 | else: |
paul@655 | 183 | l.append(None) |
paul@655 | 184 | |
paul@655 | 185 | # NOTE: Should probably report an error somehow. |
paul@655 | 186 | |
paul@655 | 187 | except ValueError: |
paul@655 | 188 | return None |
paul@655 | 189 | else: |
paul@655 | 190 | l = (len(l) < 2 and [None] or []) + l + (len(l) < 3 and [None] or []) |
paul@655 | 191 | return l |
paul@655 | 192 | else: |
paul@655 | 193 | return None |
paul@655 | 194 | |
paul@581 | 195 | # Common operations on calendar data. |
paul@581 | 196 | |
paul@584 | 197 | def update_sender(self, attr): |
paul@584 | 198 | |
paul@584 | 199 | "Update the SENT-BY attribute of the 'attr' sender metadata." |
paul@584 | 200 | |
paul@584 | 201 | if self.messenger and self.messenger.sender != get_address(self.user): |
paul@584 | 202 | attr["SENT-BY"] = get_uri(self.messenger.sender) |
paul@584 | 203 | |
paul@847 | 204 | def get_sending_attendee(self): |
paul@847 | 205 | |
paul@847 | 206 | "Return the attendee who sent the current object." |
paul@847 | 207 | |
paul@847 | 208 | calendar_uri = get_uri(config.MESSAGE_SENDER) |
paul@847 | 209 | for attendee, attendee_attr in uri_items(self.obj.get_items("ATTENDEE")): |
paul@847 | 210 | if attendee_attr.get("SENT-BY") == calendar_uri: |
paul@847 | 211 | return get_uri(attendee) |
paul@847 | 212 | return None |
paul@847 | 213 | |
paul@606 | 214 | def get_periods(self, obj): |
paul@606 | 215 | |
paul@606 | 216 | """ |
paul@606 | 217 | Return periods for the given 'obj'. Interpretation of periods can depend |
paul@606 | 218 | on the time zone, which is obtained for the current user. |
paul@606 | 219 | """ |
paul@606 | 220 | |
paul@606 | 221 | return obj.get_periods(self.get_tzid(), self.get_window_end()) |
paul@606 | 222 | |
paul@606 | 223 | # Store operations. |
paul@606 | 224 | |
paul@766 | 225 | def get_stored_object(self, uid, recurrenceid, section=None, username=None): |
paul@606 | 226 | |
paul@606 | 227 | """ |
paul@606 | 228 | Return the stored object for the current user, with the given 'uid' and |
paul@766 | 229 | 'recurrenceid' from the given 'section' and for the given 'username' (if |
paul@766 | 230 | specified), or from the standard object collection otherwise. |
paul@606 | 231 | """ |
paul@606 | 232 | |
paul@755 | 233 | if section == "counters": |
paul@766 | 234 | fragment = self.store.get_counter(self.user, username, uid, recurrenceid) |
paul@755 | 235 | else: |
paul@755 | 236 | fragment = self.store.get_event(self.user, uid, recurrenceid) |
paul@606 | 237 | return fragment and Object(fragment) |
paul@606 | 238 | |
paul@604 | 239 | # Free/busy operations. |
paul@604 | 240 | |
paul@606 | 241 | def get_freebusy_part(self, freebusy=None): |
paul@604 | 242 | |
paul@604 | 243 | """ |
paul@606 | 244 | Return a message part containing free/busy information for the user, |
paul@606 | 245 | either specified as 'freebusy' or obtained from the store directly. |
paul@604 | 246 | """ |
paul@604 | 247 | |
paul@604 | 248 | if self.is_sharing() and self.is_bundling(): |
paul@604 | 249 | |
paul@604 | 250 | # Invent a unique identifier. |
paul@604 | 251 | |
paul@604 | 252 | utcnow = get_timestamp() |
paul@604 | 253 | uid = "imip-agent-%s-%s" % (utcnow, get_address(self.user)) |
paul@604 | 254 | |
paul@606 | 255 | freebusy = freebusy or self.store.get_freebusy(self.user) |
paul@604 | 256 | |
paul@604 | 257 | user_attr = {} |
paul@604 | 258 | self.update_sender(user_attr) |
paul@604 | 259 | return to_part("PUBLISH", [make_freebusy(freebusy, uid, self.user, user_attr)]) |
paul@604 | 260 | |
paul@604 | 261 | return None |
paul@604 | 262 | |
paul@740 | 263 | def update_freebusy(self, freebusy, periods, transp, uid, recurrenceid, summary, organiser, expires=None): |
paul@606 | 264 | |
paul@606 | 265 | """ |
paul@606 | 266 | Update the 'freebusy' collection with the given 'periods', indicating a |
paul@606 | 267 | 'transp' status, explicit 'uid' and 'recurrenceid' to indicate either a |
paul@606 | 268 | recurrence or the parent event. The 'summary' and 'organiser' must also |
paul@606 | 269 | be provided. |
paul@740 | 270 | |
paul@740 | 271 | An optional 'expires' datetime string can be provided to tag a free/busy |
paul@740 | 272 | offer. |
paul@606 | 273 | """ |
paul@606 | 274 | |
paul@740 | 275 | update_freebusy(freebusy, periods, transp, uid, recurrenceid, summary, organiser, expires) |
paul@606 | 276 | |
paul@601 | 277 | class ClientForObject(Client): |
paul@601 | 278 | |
paul@601 | 279 | "A client maintaining a specific object." |
paul@601 | 280 | |
paul@639 | 281 | def __init__(self, obj, user, messenger=None, store=None, publisher=None, preferences_dir=None): |
paul@639 | 282 | Client.__init__(self, user, messenger, store, publisher, preferences_dir) |
paul@601 | 283 | self.set_object(obj) |
paul@601 | 284 | |
paul@601 | 285 | def set_object(self, obj): |
paul@606 | 286 | |
paul@606 | 287 | "Set the current object to 'obj', obtaining metadata details." |
paul@606 | 288 | |
paul@601 | 289 | self.obj = obj |
paul@601 | 290 | self.uid = obj and self.obj.get_uid() |
paul@601 | 291 | self.recurrenceid = obj and self.obj.get_recurrenceid() |
paul@601 | 292 | self.sequence = obj and self.obj.get_value("SEQUENCE") |
paul@601 | 293 | self.dtstamp = obj and self.obj.get_value("DTSTAMP") |
paul@601 | 294 | |
paul@729 | 295 | def set_identity(self, method): |
paul@729 | 296 | |
paul@729 | 297 | """ |
paul@729 | 298 | Set the current user for the current object in the context of the given |
paul@729 | 299 | 'method'. It is usually set when initialising the handler, using the |
paul@729 | 300 | recipient details, but outgoing messages do not reference the recipient |
paul@729 | 301 | in this way. |
paul@729 | 302 | """ |
paul@729 | 303 | |
paul@729 | 304 | pass |
paul@729 | 305 | |
paul@727 | 306 | def is_usable(self, method=None): |
paul@720 | 307 | |
paul@727 | 308 | "Return whether the current object is usable with the given 'method'." |
paul@720 | 309 | |
paul@720 | 310 | return True |
paul@720 | 311 | |
paul@818 | 312 | def is_organiser(self): |
paul@818 | 313 | |
paul@818 | 314 | """ |
paul@818 | 315 | Return whether the current user is the organiser in the current object. |
paul@818 | 316 | """ |
paul@818 | 317 | |
paul@818 | 318 | return get_uri(self.obj.get_value("ORGANIZER")) == self.user |
paul@818 | 319 | |
paul@604 | 320 | # Object update methods. |
paul@601 | 321 | |
paul@676 | 322 | def update_recurrenceid(self): |
paul@676 | 323 | |
paul@676 | 324 | """ |
paul@676 | 325 | Update the RECURRENCE-ID in the current object, initialising it from |
paul@676 | 326 | DTSTART. |
paul@676 | 327 | """ |
paul@676 | 328 | |
paul@680 | 329 | self.obj["RECURRENCE-ID"] = [self.obj.get_item("DTSTART")] |
paul@676 | 330 | self.recurrenceid = self.obj.get_recurrenceid() |
paul@676 | 331 | |
paul@809 | 332 | def update_dtstamp(self, obj=None): |
paul@601 | 333 | |
paul@809 | 334 | "Update the DTSTAMP in the current object or any given object 'obj'." |
paul@809 | 335 | |
paul@809 | 336 | obj = obj or self.obj |
paul@809 | 337 | self.dtstamp = obj.update_dtstamp() |
paul@601 | 338 | |
paul@809 | 339 | def update_sequence(self, increment=False, obj=None): |
paul@601 | 340 | |
paul@809 | 341 | "Update the SEQUENCE in the current object or any given object 'obj'." |
paul@601 | 342 | |
paul@809 | 343 | obj = obj or self.obj |
paul@809 | 344 | obj.update_sequence(increment) |
paul@601 | 345 | |
paul@606 | 346 | def merge_attendance(self, attendees): |
paul@606 | 347 | |
paul@606 | 348 | """ |
paul@606 | 349 | Merge attendance from the current object's 'attendees' into the version |
paul@606 | 350 | stored for the current user. |
paul@606 | 351 | """ |
paul@606 | 352 | |
paul@606 | 353 | obj = self.get_stored_object_version() |
paul@606 | 354 | |
paul@739 | 355 | if not obj or not self.have_new_object(): |
paul@606 | 356 | return False |
paul@606 | 357 | |
paul@606 | 358 | # Get attendee details in a usable form. |
paul@606 | 359 | |
paul@606 | 360 | attendee_map = uri_dict(obj.get_value_map("ATTENDEE")) |
paul@606 | 361 | |
paul@606 | 362 | for attendee, attendee_attr in attendees.items(): |
paul@606 | 363 | |
paul@836 | 364 | # Update attendance in the loaded object for any recognised |
paul@836 | 365 | # attendees. |
paul@606 | 366 | |
paul@836 | 367 | if attendee_map.has_key(attendee): |
paul@836 | 368 | attendee_map[attendee] = attendee_attr |
paul@606 | 369 | |
paul@606 | 370 | # Set the new details and store the object. |
paul@606 | 371 | |
paul@606 | 372 | obj["ATTENDEE"] = attendee_map.items() |
paul@606 | 373 | |
paul@744 | 374 | # Set a specific recurrence or the complete event if not an additional |
paul@744 | 375 | # occurrence. |
paul@606 | 376 | |
paul@829 | 377 | return self.store.set_event(self.user, self.uid, self.recurrenceid, obj.to_node()) |
paul@606 | 378 | |
paul@818 | 379 | def update_attendees(self, attendees, removed): |
paul@818 | 380 | |
paul@818 | 381 | """ |
paul@818 | 382 | Update the attendees in the current object with the given 'attendees' |
paul@818 | 383 | and 'removed' attendee lists. |
paul@818 | 384 | |
paul@818 | 385 | A tuple is returned containing two items: a list of the attendees whose |
paul@818 | 386 | attendance is being proposed (in a counter-proposal), a list of the |
paul@818 | 387 | attendees whose attendance should be cancelled. |
paul@818 | 388 | """ |
paul@818 | 389 | |
paul@818 | 390 | to_cancel = [] |
paul@818 | 391 | |
paul@818 | 392 | existing_attendees = uri_items(self.obj.get_items("ATTENDEE") or []) |
paul@818 | 393 | existing_attendees_map = dict(existing_attendees) |
paul@818 | 394 | |
paul@818 | 395 | # Added attendees are those from the supplied collection not already |
paul@818 | 396 | # present in the object. |
paul@818 | 397 | |
paul@818 | 398 | added = set(uri_values(attendees)).difference([uri for uri, attr in existing_attendees]) |
paul@818 | 399 | |
paul@818 | 400 | # NOTE: When countering, no removals will occur, but additions might. |
paul@818 | 401 | |
paul@818 | 402 | if added or removed: |
paul@818 | 403 | |
paul@818 | 404 | # The organiser can remove existing attendees. |
paul@818 | 405 | |
paul@818 | 406 | if removed and self.is_organiser(): |
paul@818 | 407 | remaining = [] |
paul@818 | 408 | |
paul@818 | 409 | for attendee, attendee_attr in existing_attendees: |
paul@818 | 410 | if attendee in removed: |
paul@818 | 411 | |
paul@818 | 412 | # Only when an event has not been published can |
paul@818 | 413 | # attendees be silently removed. |
paul@818 | 414 | |
paul@818 | 415 | if obj.is_shared(): |
paul@818 | 416 | to_cancel.append((attendee, attendee_attr)) |
paul@818 | 417 | else: |
paul@818 | 418 | remaining.append((attendee, attendee_attr)) |
paul@818 | 419 | |
paul@818 | 420 | existing_attendees = remaining |
paul@818 | 421 | |
paul@818 | 422 | # Attendees (when countering) must only include the current user and |
paul@818 | 423 | # any added attendees. |
paul@818 | 424 | |
paul@818 | 425 | elif not self.is_organiser(): |
paul@818 | 426 | existing_attendees = [] |
paul@818 | 427 | |
paul@818 | 428 | # Both organisers and attendees (when countering) can add attendees. |
paul@818 | 429 | |
paul@818 | 430 | if added: |
paul@818 | 431 | |
paul@818 | 432 | # Obtain a mapping from URIs to name details. |
paul@818 | 433 | |
paul@818 | 434 | attendee_map = dict([(attendee_uri, cn) for cn, attendee_uri in uri_parts(attendees)]) |
paul@818 | 435 | |
paul@818 | 436 | for attendee in added: |
paul@818 | 437 | attendee = attendee.strip() |
paul@818 | 438 | if attendee: |
paul@818 | 439 | cn = attendee_map.get(attendee) |
paul@818 | 440 | attendee_attr = {"CN" : cn} or {} |
paul@818 | 441 | |
paul@818 | 442 | # Only the organiser can reset the participation attributes. |
paul@818 | 443 | |
paul@818 | 444 | if self.is_organiser(): |
paul@818 | 445 | attendee_attr.update({"PARTSTAT" : "NEEDS-ACTION", "RSVP" : "TRUE"}) |
paul@818 | 446 | |
paul@818 | 447 | existing_attendees.append((attendee, attendee_attr)) |
paul@818 | 448 | |
paul@818 | 449 | # Attendees (when countering) must only include the current user and |
paul@818 | 450 | # any added attendees. |
paul@818 | 451 | |
paul@818 | 452 | if not self.is_organiser() and self.user not in existing_attendees: |
paul@818 | 453 | user_attr = self.get_user_attributes() |
paul@818 | 454 | user_attr.update(existing_attendees_map.get(self.user) or {}) |
paul@818 | 455 | existing_attendees.append((self.user, user_attr)) |
paul@818 | 456 | |
paul@818 | 457 | self.obj["ATTENDEE"] = existing_attendees |
paul@818 | 458 | |
paul@818 | 459 | return added, to_cancel |
paul@818 | 460 | |
paul@818 | 461 | def update_participation(self, partstat=None): |
paul@818 | 462 | |
paul@818 | 463 | """ |
paul@818 | 464 | Update the participation in the current object of the user with the |
paul@818 | 465 | given 'partstat'. |
paul@818 | 466 | """ |
paul@818 | 467 | |
paul@818 | 468 | attendee_attr = uri_dict(self.obj.get_value_map("ATTENDEE")).get(self.user) |
paul@818 | 469 | if not attendee_attr: |
paul@818 | 470 | return None |
paul@818 | 471 | if partstat: |
paul@818 | 472 | attendee_attr["PARTSTAT"] = partstat |
paul@818 | 473 | if attendee_attr.has_key("RSVP"): |
paul@818 | 474 | del attendee_attr["RSVP"] |
paul@818 | 475 | self.update_sender(attendee_attr) |
paul@818 | 476 | return attendee_attr |
paul@818 | 477 | |
paul@606 | 478 | # Object-related tests. |
paul@606 | 479 | |
paul@728 | 480 | def is_recognised_organiser(self, organiser): |
paul@728 | 481 | |
paul@728 | 482 | """ |
paul@728 | 483 | Return whether the given 'organiser' is recognised from |
paul@728 | 484 | previously-received details. If no stored details exist, True is |
paul@728 | 485 | returned. |
paul@728 | 486 | """ |
paul@728 | 487 | |
paul@728 | 488 | obj = self.get_stored_object_version() |
paul@728 | 489 | if obj: |
paul@728 | 490 | stored_organiser = get_uri(obj.get_value("ORGANIZER")) |
paul@728 | 491 | return stored_organiser == organiser |
paul@728 | 492 | else: |
paul@728 | 493 | return True |
paul@728 | 494 | |
paul@728 | 495 | def is_recognised_attendee(self, attendee): |
paul@728 | 496 | |
paul@728 | 497 | """ |
paul@728 | 498 | Return whether the given 'attendee' is recognised from |
paul@728 | 499 | previously-received details. If no stored details exist, True is |
paul@728 | 500 | returned. |
paul@728 | 501 | """ |
paul@728 | 502 | |
paul@728 | 503 | obj = self.get_stored_object_version() |
paul@728 | 504 | if obj: |
paul@728 | 505 | stored_attendees = uri_dict(obj.get_value_map("ATTENDEE")) |
paul@728 | 506 | return stored_attendees.has_key(attendee) |
paul@728 | 507 | else: |
paul@728 | 508 | return True |
paul@728 | 509 | |
paul@694 | 510 | def get_attendance(self, user=None, obj=None): |
paul@606 | 511 | |
paul@606 | 512 | """ |
paul@606 | 513 | Return the attendance attributes for 'user', or the current user if |
paul@606 | 514 | 'user' is not specified. |
paul@606 | 515 | """ |
paul@606 | 516 | |
paul@694 | 517 | attendees = uri_dict((obj or self.obj).get_value_map("ATTENDEE")) |
paul@697 | 518 | return attendees.get(user or self.user) |
paul@606 | 519 | |
paul@694 | 520 | def is_participating(self, user, as_organiser=False, obj=None): |
paul@609 | 521 | |
paul@609 | 522 | """ |
paul@609 | 523 | Return whether, subject to the 'user' indicating an identity and the |
paul@609 | 524 | 'as_organiser' status of that identity, the user concerned is actually |
paul@609 | 525 | participating in the current object event. |
paul@609 | 526 | """ |
paul@609 | 527 | |
paul@697 | 528 | # Use any attendee property information for an organiser, not the |
paul@697 | 529 | # organiser property attributes. |
paul@697 | 530 | |
paul@694 | 531 | attr = self.get_attendance(user, obj=obj) |
paul@697 | 532 | return as_organiser or attr is not None and not attr or attr and attr.get("PARTSTAT") != "DECLINED" |
paul@609 | 533 | |
paul@609 | 534 | def get_overriding_transparency(self, user, as_organiser=False): |
paul@609 | 535 | |
paul@609 | 536 | """ |
paul@609 | 537 | Return the overriding transparency to be associated with the free/busy |
paul@609 | 538 | records for an event, subject to the 'user' indicating an identity and |
paul@609 | 539 | the 'as_organiser' status of that identity. |
paul@609 | 540 | |
paul@609 | 541 | Where an identity is only an organiser and not attending, "ORG" is |
paul@609 | 542 | returned. Otherwise, no overriding transparency is defined and None is |
paul@609 | 543 | returned. |
paul@609 | 544 | """ |
paul@609 | 545 | |
paul@609 | 546 | attr = self.get_attendance(user) |
paul@609 | 547 | return as_organiser and not (attr and attr.get("PARTSTAT")) and "ORG" or None |
paul@609 | 548 | |
paul@606 | 549 | def can_schedule(self, freebusy, periods): |
paul@606 | 550 | |
paul@606 | 551 | """ |
paul@606 | 552 | Indicate whether within 'freebusy' the given 'periods' can be scheduled. |
paul@606 | 553 | """ |
paul@606 | 554 | |
paul@606 | 555 | return can_schedule(freebusy, periods, self.uid, self.recurrenceid) |
paul@606 | 556 | |
paul@739 | 557 | def have_new_object(self, strict=True): |
paul@606 | 558 | |
paul@606 | 559 | """ |
paul@739 | 560 | Return whether the current object is new to the current user. |
paul@739 | 561 | |
paul@739 | 562 | If 'strict' is specified and is a false value, the DTSTAMP test will be |
paul@739 | 563 | ignored. This is useful in handling responses from attendees from |
paul@739 | 564 | clients (like Claws Mail) that erase time information from DTSTAMP and |
paul@739 | 565 | make it invalid. |
paul@606 | 566 | """ |
paul@606 | 567 | |
paul@739 | 568 | obj = self.get_stored_object_version() |
paul@606 | 569 | |
paul@606 | 570 | # If found, compare SEQUENCE and potentially DTSTAMP. |
paul@606 | 571 | |
paul@606 | 572 | if obj: |
paul@606 | 573 | sequence = obj.get_value("SEQUENCE") |
paul@606 | 574 | dtstamp = obj.get_value("DTSTAMP") |
paul@606 | 575 | |
paul@606 | 576 | # If the request refers to an older version of the object, ignore |
paul@606 | 577 | # it. |
paul@606 | 578 | |
paul@682 | 579 | return is_new_object(sequence, self.sequence, dtstamp, self.dtstamp, not strict) |
paul@606 | 580 | |
paul@606 | 581 | return True |
paul@606 | 582 | |
paul@672 | 583 | def possibly_recurring_indefinitely(self): |
paul@672 | 584 | |
paul@672 | 585 | "Return whether the object recurs indefinitely." |
paul@672 | 586 | |
paul@672 | 587 | # Obtain the stored object to make sure that recurrence information |
paul@672 | 588 | # is not being ignored. This might happen if a client sends a |
paul@672 | 589 | # cancellation without the complete set of properties, for instance. |
paul@672 | 590 | |
paul@672 | 591 | return self.obj.possibly_recurring_indefinitely() or \ |
paul@672 | 592 | self.get_stored_object_version() and \ |
paul@672 | 593 | self.get_stored_object_version().possibly_recurring_indefinitely() |
paul@672 | 594 | |
paul@655 | 595 | # Constraint application on event periods. |
paul@655 | 596 | |
paul@655 | 597 | def check_object(self): |
paul@655 | 598 | |
paul@655 | 599 | "Check the object against any scheduling constraints." |
paul@655 | 600 | |
paul@669 | 601 | permitted_values = self.get_permitted_values() |
paul@669 | 602 | if not permitted_values: |
paul@655 | 603 | return None |
paul@655 | 604 | |
paul@655 | 605 | invalid = [] |
paul@655 | 606 | |
paul@660 | 607 | for period in self.obj.get_periods(self.get_tzid()): |
paul@655 | 608 | start = period.get_start() |
paul@655 | 609 | end = period.get_end() |
paul@669 | 610 | start_errors = check_permitted_values(start, permitted_values) |
paul@669 | 611 | end_errors = check_permitted_values(end, permitted_values) |
paul@656 | 612 | if start_errors or end_errors: |
paul@656 | 613 | invalid.append((period.origin, start_errors, end_errors)) |
paul@655 | 614 | |
paul@655 | 615 | return invalid |
paul@655 | 616 | |
paul@660 | 617 | def correct_object(self): |
paul@655 | 618 | |
paul@660 | 619 | "Correct the object according to any scheduling constraints." |
paul@655 | 620 | |
paul@669 | 621 | permitted_values = self.get_permitted_values() |
paul@669 | 622 | return permitted_values and self.obj.correct_object(self.get_tzid(), permitted_values) |
paul@655 | 623 | |
paul@606 | 624 | # Object retrieval. |
paul@606 | 625 | |
paul@606 | 626 | def get_stored_object_version(self): |
paul@606 | 627 | |
paul@606 | 628 | """ |
paul@606 | 629 | Return the stored object to which the current object refers for the |
paul@606 | 630 | current user. |
paul@606 | 631 | """ |
paul@606 | 632 | |
paul@606 | 633 | return self.get_stored_object(self.uid, self.recurrenceid) |
paul@606 | 634 | |
paul@704 | 635 | def get_definitive_object(self, as_organiser): |
paul@606 | 636 | |
paul@606 | 637 | """ |
paul@606 | 638 | Return an object considered definitive for the current transaction, |
paul@704 | 639 | using 'as_organiser' to select the current transaction's object if |
paul@704 | 640 | false, or selecting a stored object if true. |
paul@606 | 641 | """ |
paul@606 | 642 | |
paul@704 | 643 | return not as_organiser and self.obj or self.get_stored_object_version() |
paul@606 | 644 | |
paul@606 | 645 | def get_parent_object(self): |
paul@606 | 646 | |
paul@606 | 647 | """ |
paul@606 | 648 | Return the parent object to which the current object refers for the |
paul@606 | 649 | current user. |
paul@606 | 650 | """ |
paul@606 | 651 | |
paul@606 | 652 | return self.recurrenceid and self.get_stored_object(self.uid, None) or None |
paul@606 | 653 | |
paul@606 | 654 | # Convenience methods for modifying free/busy collections. |
paul@606 | 655 | |
paul@606 | 656 | def get_recurrence_start_point(self, recurrenceid): |
paul@606 | 657 | |
paul@606 | 658 | "Get 'recurrenceid' in a form suitable for matching free/busy entries." |
paul@606 | 659 | |
paul@627 | 660 | return self.obj.get_recurrence_start_point(recurrenceid, self.get_tzid()) |
paul@606 | 661 | |
paul@606 | 662 | def remove_from_freebusy(self, freebusy): |
paul@606 | 663 | |
paul@606 | 664 | "Remove this event from the given 'freebusy' collection." |
paul@606 | 665 | |
paul@606 | 666 | if not remove_period(freebusy, self.uid, self.recurrenceid) and self.recurrenceid: |
paul@606 | 667 | remove_affected_period(freebusy, self.uid, self.get_recurrence_start_point(self.recurrenceid)) |
paul@606 | 668 | |
paul@606 | 669 | def remove_freebusy_for_recurrences(self, freebusy, recurrenceids=None): |
paul@606 | 670 | |
paul@606 | 671 | """ |
paul@606 | 672 | Remove from 'freebusy' any original recurrence from parent free/busy |
paul@606 | 673 | details for the current object, if the current object is a specific |
paul@606 | 674 | additional recurrence. Otherwise, remove all additional recurrence |
paul@606 | 675 | information corresponding to 'recurrenceids', or if omitted, all |
paul@606 | 676 | recurrences. |
paul@606 | 677 | """ |
paul@606 | 678 | |
paul@606 | 679 | if self.recurrenceid: |
paul@606 | 680 | recurrenceid = self.get_recurrence_start_point(self.recurrenceid) |
paul@606 | 681 | remove_affected_period(freebusy, self.uid, recurrenceid) |
paul@606 | 682 | else: |
paul@606 | 683 | # Remove obsolete recurrence periods. |
paul@606 | 684 | |
paul@606 | 685 | remove_additional_periods(freebusy, self.uid, recurrenceids) |
paul@606 | 686 | |
paul@606 | 687 | # Remove original periods affected by additional recurrences. |
paul@606 | 688 | |
paul@606 | 689 | if recurrenceids: |
paul@606 | 690 | for recurrenceid in recurrenceids: |
paul@606 | 691 | recurrenceid = self.get_recurrence_start_point(recurrenceid) |
paul@606 | 692 | remove_affected_period(freebusy, self.uid, recurrenceid) |
paul@606 | 693 | |
paul@740 | 694 | def update_freebusy(self, freebusy, user, as_organiser, offer=False): |
paul@606 | 695 | |
paul@606 | 696 | """ |
paul@606 | 697 | Update the 'freebusy' collection for this event with the periods and |
paul@606 | 698 | transparency associated with the current object, subject to the 'user' |
paul@606 | 699 | identity and the attendance details provided for them, indicating |
paul@704 | 700 | whether the update is being done 'as_organiser' (for the organiser of |
paul@676 | 701 | an event) or not. |
paul@740 | 702 | |
paul@740 | 703 | If 'offer' is set to a true value, any free/busy updates will be tagged |
paul@740 | 704 | with an expiry time. |
paul@606 | 705 | """ |
paul@606 | 706 | |
paul@606 | 707 | # Obtain the stored object if the current object is not issued by the |
paul@606 | 708 | # organiser. Attendees do not have the opportunity to redefine the |
paul@606 | 709 | # periods. |
paul@606 | 710 | |
paul@704 | 711 | obj = self.get_definitive_object(as_organiser) |
paul@606 | 712 | if not obj: |
paul@606 | 713 | return |
paul@606 | 714 | |
paul@606 | 715 | # Obtain the affected periods. |
paul@606 | 716 | |
paul@606 | 717 | periods = self.get_periods(obj) |
paul@606 | 718 | |
paul@606 | 719 | # Define an overriding transparency, the indicated event transparency, |
paul@606 | 720 | # or the default transparency for the free/busy entry. |
paul@606 | 721 | |
paul@704 | 722 | transp = self.get_overriding_transparency(user, as_organiser) or \ |
paul@606 | 723 | obj.get_value("TRANSP") or \ |
paul@606 | 724 | "OPAQUE" |
paul@606 | 725 | |
paul@740 | 726 | # Calculate any expiry time. If no offer period is defined, do not |
paul@740 | 727 | # record the offer periods. |
paul@740 | 728 | |
paul@740 | 729 | if offer: |
paul@740 | 730 | offer_period = self.get_offer_period() |
paul@740 | 731 | if offer_period: |
paul@759 | 732 | expires = get_timestamp(offer_period) |
paul@740 | 733 | else: |
paul@740 | 734 | return |
paul@740 | 735 | else: |
paul@740 | 736 | expires = None |
paul@740 | 737 | |
paul@606 | 738 | # Perform the low-level update. |
paul@606 | 739 | |
paul@606 | 740 | Client.update_freebusy(self, freebusy, periods, transp, |
paul@606 | 741 | self.uid, self.recurrenceid, |
paul@606 | 742 | obj.get_value("SUMMARY"), |
paul@740 | 743 | obj.get_value("ORGANIZER"), |
paul@740 | 744 | expires) |
paul@606 | 745 | |
paul@606 | 746 | def update_freebusy_for_participant(self, freebusy, user, for_organiser=False, |
paul@740 | 747 | updating_other=False, offer=False): |
paul@606 | 748 | |
paul@606 | 749 | """ |
paul@695 | 750 | Update the 'freebusy' collection for the given 'user', indicating |
paul@695 | 751 | whether the update is 'for_organiser' (being done for the organiser of |
paul@695 | 752 | an event) or not, and whether it is 'updating_other' (meaning another |
paul@695 | 753 | user's details). |
paul@740 | 754 | |
paul@740 | 755 | If 'offer' is set to a true value, any free/busy updates will be tagged |
paul@740 | 756 | with an expiry time. |
paul@606 | 757 | """ |
paul@606 | 758 | |
paul@606 | 759 | # Record in the free/busy details unless a non-participating attendee. |
paul@697 | 760 | # Remove periods for non-participating attendees. |
paul@606 | 761 | |
paul@744 | 762 | if offer or self.is_participating(user, for_organiser and not updating_other): |
paul@704 | 763 | self.update_freebusy(freebusy, user, |
paul@704 | 764 | for_organiser and not updating_other or |
paul@740 | 765 | not for_organiser and updating_other, |
paul@740 | 766 | offer |
paul@704 | 767 | ) |
paul@606 | 768 | else: |
paul@606 | 769 | self.remove_from_freebusy(freebusy) |
paul@606 | 770 | |
paul@697 | 771 | def remove_freebusy_for_participant(self, freebusy, user, for_organiser=False, |
paul@697 | 772 | updating_other=False): |
paul@697 | 773 | |
paul@697 | 774 | """ |
paul@697 | 775 | Remove details from the 'freebusy' collection for the given 'user', |
paul@697 | 776 | indicating whether the modification is 'for_organiser' (being done for |
paul@697 | 777 | the organiser of an event) or not, and whether it is 'updating_other' |
paul@697 | 778 | (meaning another user's details). |
paul@697 | 779 | """ |
paul@697 | 780 | |
paul@697 | 781 | # Remove from the free/busy details if a specified attendee. |
paul@697 | 782 | |
paul@697 | 783 | if self.is_participating(user, for_organiser and not updating_other): |
paul@697 | 784 | self.remove_from_freebusy(freebusy) |
paul@697 | 785 | |
paul@606 | 786 | # Convenience methods for updating stored free/busy information received |
paul@606 | 787 | # from other users. |
paul@606 | 788 | |
paul@697 | 789 | def update_freebusy_from_participant(self, user, for_organiser, fn=None): |
paul@606 | 790 | |
paul@606 | 791 | """ |
paul@606 | 792 | For the current user, record the free/busy information for another |
paul@606 | 793 | 'user', indicating whether the update is 'for_organiser' or not, thus |
paul@606 | 794 | maintaining a separate record of their free/busy details. |
paul@606 | 795 | """ |
paul@606 | 796 | |
paul@697 | 797 | fn = fn or self.update_freebusy_for_participant |
paul@697 | 798 | |
paul@606 | 799 | # A user does not store free/busy information for themself as another |
paul@606 | 800 | # party. |
paul@606 | 801 | |
paul@606 | 802 | if user == self.user: |
paul@606 | 803 | return |
paul@606 | 804 | |
paul@730 | 805 | self.acquire_lock() |
paul@702 | 806 | try: |
paul@730 | 807 | freebusy = self.store.get_freebusy_for_other(self.user, user) |
paul@702 | 808 | fn(freebusy, user, for_organiser, True) |
paul@702 | 809 | |
paul@702 | 810 | # Tidy up any obsolete recurrences. |
paul@606 | 811 | |
paul@702 | 812 | self.remove_freebusy_for_recurrences(freebusy, self.store.get_recurrences(self.user, self.uid)) |
paul@730 | 813 | self.store.set_freebusy_for_other(self.user, freebusy, user) |
paul@606 | 814 | |
paul@702 | 815 | finally: |
paul@730 | 816 | self.release_lock() |
paul@606 | 817 | |
paul@606 | 818 | def update_freebusy_from_organiser(self, organiser): |
paul@606 | 819 | |
paul@606 | 820 | "For the current user, record free/busy information from 'organiser'." |
paul@606 | 821 | |
paul@606 | 822 | self.update_freebusy_from_participant(organiser, True) |
paul@606 | 823 | |
paul@606 | 824 | def update_freebusy_from_attendees(self, attendees): |
paul@606 | 825 | |
paul@606 | 826 | "For the current user, record free/busy information from 'attendees'." |
paul@606 | 827 | |
paul@836 | 828 | obj = self.get_stored_object_version() |
paul@836 | 829 | |
paul@836 | 830 | if not obj or not self.have_new_object(): |
paul@836 | 831 | return |
paul@836 | 832 | |
paul@836 | 833 | # Filter out unrecognised attendees. |
paul@836 | 834 | |
paul@836 | 835 | attendees = set(attendees).intersection(uri_values(obj.get_values("ATTENDEE"))) |
paul@836 | 836 | |
paul@836 | 837 | for attendee in attendees: |
paul@606 | 838 | self.update_freebusy_from_participant(attendee, False) |
paul@606 | 839 | |
paul@697 | 840 | def remove_freebusy_from_organiser(self, organiser): |
paul@697 | 841 | |
paul@697 | 842 | "For the current user, remove free/busy information from 'organiser'." |
paul@697 | 843 | |
paul@697 | 844 | self.update_freebusy_from_participant(organiser, True, self.remove_freebusy_for_participant) |
paul@697 | 845 | |
paul@697 | 846 | def remove_freebusy_from_attendees(self, attendees): |
paul@697 | 847 | |
paul@697 | 848 | "For the current user, remove free/busy information from 'attendees'." |
paul@697 | 849 | |
paul@697 | 850 | for attendee in attendees.keys(): |
paul@697 | 851 | self.update_freebusy_from_participant(attendee, False, self.remove_freebusy_for_participant) |
paul@697 | 852 | |
paul@756 | 853 | # Convenience methods for updating free/busy details at the event level. |
paul@756 | 854 | |
paul@756 | 855 | def update_event_in_freebusy(self, for_organiser=True): |
paul@756 | 856 | |
paul@756 | 857 | """ |
paul@756 | 858 | Update free/busy information when handling an object, doing so for the |
paul@756 | 859 | organiser of an event if 'for_organiser' is set to a true value. |
paul@756 | 860 | """ |
paul@756 | 861 | |
paul@756 | 862 | freebusy = self.store.get_freebusy(self.user) |
paul@756 | 863 | |
paul@756 | 864 | # Obtain the attendance attributes for this user, if available. |
paul@756 | 865 | |
paul@756 | 866 | self.update_freebusy_for_participant(freebusy, self.user, for_organiser) |
paul@756 | 867 | |
paul@756 | 868 | # Remove original recurrence details replaced by additional |
paul@756 | 869 | # recurrences, as well as obsolete additional recurrences. |
paul@756 | 870 | |
paul@756 | 871 | self.remove_freebusy_for_recurrences(freebusy, self.store.get_recurrences(self.user, self.uid)) |
paul@756 | 872 | self.store.set_freebusy(self.user, freebusy) |
paul@756 | 873 | |
paul@756 | 874 | if self.publisher and self.is_sharing() and self.is_publishing(): |
paul@756 | 875 | self.publisher.set_freebusy(self.user, freebusy) |
paul@756 | 876 | |
paul@756 | 877 | # Update free/busy provider information if the event may recur |
paul@756 | 878 | # indefinitely. |
paul@756 | 879 | |
paul@756 | 880 | if self.possibly_recurring_indefinitely(): |
paul@756 | 881 | self.store.append_freebusy_provider(self.user, self.obj) |
paul@756 | 882 | |
paul@756 | 883 | return True |
paul@756 | 884 | |
paul@756 | 885 | def remove_event_from_freebusy(self): |
paul@756 | 886 | |
paul@756 | 887 | "Remove free/busy information when handling an object." |
paul@756 | 888 | |
paul@756 | 889 | freebusy = self.store.get_freebusy(self.user) |
paul@756 | 890 | |
paul@756 | 891 | self.remove_from_freebusy(freebusy) |
paul@756 | 892 | self.remove_freebusy_for_recurrences(freebusy) |
paul@756 | 893 | self.store.set_freebusy(self.user, freebusy) |
paul@756 | 894 | |
paul@756 | 895 | if self.publisher and self.is_sharing() and self.is_publishing(): |
paul@756 | 896 | self.publisher.set_freebusy(self.user, freebusy) |
paul@756 | 897 | |
paul@756 | 898 | # Update free/busy provider information if the event may recur |
paul@756 | 899 | # indefinitely. |
paul@756 | 900 | |
paul@756 | 901 | if self.possibly_recurring_indefinitely(): |
paul@756 | 902 | self.store.remove_freebusy_provider(self.user, self.obj) |
paul@756 | 903 | |
paul@756 | 904 | def update_event_in_freebusy_offers(self): |
paul@756 | 905 | |
paul@756 | 906 | "Update free/busy offers when handling an object." |
paul@756 | 907 | |
paul@756 | 908 | freebusy = self.store.get_freebusy_offers(self.user) |
paul@756 | 909 | |
paul@756 | 910 | # Obtain the attendance attributes for this user, if available. |
paul@756 | 911 | |
paul@756 | 912 | self.update_freebusy_for_participant(freebusy, self.user, offer=True) |
paul@756 | 913 | |
paul@756 | 914 | # Remove original recurrence details replaced by additional |
paul@756 | 915 | # recurrences, as well as obsolete additional recurrences. |
paul@756 | 916 | |
paul@756 | 917 | self.remove_freebusy_for_recurrences(freebusy, self.store.get_recurrences(self.user, self.uid)) |
paul@756 | 918 | self.store.set_freebusy_offers(self.user, freebusy) |
paul@756 | 919 | |
paul@756 | 920 | return True |
paul@756 | 921 | |
paul@756 | 922 | def remove_event_from_freebusy_offers(self): |
paul@756 | 923 | |
paul@756 | 924 | "Remove free/busy offers when handling an object." |
paul@756 | 925 | |
paul@756 | 926 | freebusy = self.store.get_freebusy_offers(self.user) |
paul@756 | 927 | |
paul@756 | 928 | self.remove_from_freebusy(freebusy) |
paul@756 | 929 | self.remove_freebusy_for_recurrences(freebusy) |
paul@756 | 930 | self.store.set_freebusy_offers(self.user, freebusy) |
paul@756 | 931 | |
paul@756 | 932 | return True |
paul@756 | 933 | |
paul@809 | 934 | # Convenience methods for removing counter-proposals and updating the |
paul@809 | 935 | # request queue. |
paul@809 | 936 | |
paul@813 | 937 | def remove_request(self): |
paul@813 | 938 | return self.store.dequeue_request(self.user, self.uid, self.recurrenceid) |
paul@813 | 939 | |
paul@813 | 940 | def remove_event(self): |
paul@813 | 941 | return self.store.remove_event(self.user, self.uid, self.recurrenceid) |
paul@813 | 942 | |
paul@809 | 943 | def remove_counter(self, attendee): |
paul@809 | 944 | self.remove_counters([attendee]) |
paul@809 | 945 | |
paul@809 | 946 | def remove_counters(self, attendees): |
paul@809 | 947 | for attendee in attendees: |
paul@809 | 948 | self.store.remove_counter(self.user, attendee, self.uid, self.recurrenceid) |
paul@809 | 949 | |
paul@809 | 950 | if not self.store.get_counters(self.user, self.uid, self.recurrenceid): |
paul@809 | 951 | self.store.dequeue_request(self.user, self.uid, self.recurrenceid) |
paul@809 | 952 | |
paul@441 | 953 | # vim: tabstop=4 expandtab shiftwidth=4 |