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