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