1.1 --- a/imiptools/handlers/person_outgoing.py Tue Mar 31 19:09:11 2015 +0200
1.2 +++ b/imiptools/handlers/person_outgoing.py Tue Mar 31 19:12:21 2015 +0200
1.3 @@ -20,28 +20,22 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 -from imiptools.data import get_window_end, uri_dict, uri_item, uri_values
1.8 +from imiptools.data import uri_dict, uri_item, uri_values
1.9 from imiptools.handlers import Handler
1.10
1.11 class PersonHandler(Handler):
1.12
1.13 "Handling mechanisms specific to people."
1.14
1.15 - def _get_identity(self, from_organiser=True):
1.16 + def set_identity(self, from_organiser=True):
1.17
1.18 """
1.19 - Get the identity of interest in a usable form for any unprocessed
1.20 - object.
1.21 + Set the current user for the current object. Return attributes for the
1.22 + user if the
1.23 """
1.24
1.25 - identity, attr = item = uri_item(self.obj.get_item(from_organiser and "ORGANIZER" or "ATTENDEE"))
1.26 -
1.27 - # Check for event using UID.
1.28 -
1.29 - if not self.have_new_object(identity):
1.30 - return None
1.31 -
1.32 - return item
1.33 + self.user, attr = uri_item(self.obj.get_item(from_organiser and "ORGANIZER" or "ATTENDEE"))
1.34 + return attr
1.35
1.36 def _record(self, from_organiser=True, update_freebusy=False):
1.37
1.38 @@ -51,71 +45,70 @@
1.39 free/busy information if 'update_freebusy' is set to a true value.
1.40 """
1.41
1.42 - item = self._get_identity(from_organiser)
1.43 - if not item:
1.44 + attr = self.set_identity(from_organiser)
1.45 +
1.46 + # Check for event using UID.
1.47 +
1.48 + if not self.have_new_object():
1.49 return False
1.50
1.51 - identity, attr = item
1.52 -
1.53 # Update the object.
1.54
1.55 if from_organiser:
1.56
1.57 # Set the complete event or an additional occurrence.
1.58
1.59 - self.store.set_event(identity, self.uid, self.recurrenceid, self.obj.to_node())
1.60 + self.store.set_event(self.user, self.uid, self.recurrenceid, self.obj.to_node())
1.61
1.62 # Remove additional recurrences if handling a complete event.
1.63
1.64 if not self.recurrenceid:
1.65 - self.store.remove_recurrences(identity, self.uid)
1.66 + self.store.remove_recurrences(self.user, self.uid)
1.67
1.68 else:
1.69 # Obtain valid attendees, merging their attendance with the stored
1.70 # object.
1.71
1.72 attendees = self.require_attendees(from_organiser)
1.73 - self.merge_attendance(attendees, identity)
1.74 + self.merge_attendance(attendees)
1.75
1.76 # Remove any associated request.
1.77
1.78 - self.store.dequeue_request(identity, self.uid, self.recurrenceid)
1.79 + self.store.dequeue_request(self.user, self.uid, self.recurrenceid)
1.80
1.81 # Update free/busy information.
1.82
1.83 if update_freebusy:
1.84
1.85 - freebusy = self.store.get_freebusy(identity)
1.86 -
1.87 - # Interpretation of periods can depend on the time zone.
1.88 -
1.89 - tzid = self.get_tzid(identity)
1.90 + freebusy = self.store.get_freebusy(self.user)
1.91
1.92 # Use the stored event in case the reply is incomplete, as is seen
1.93 # when Claws sends a REPLY for an object originally employing
1.94 # recurrence information.
1.95
1.96 - obj = self.get_object(identity)
1.97 + obj = self.get_object()
1.98 if not obj:
1.99 return False # although this should not happen
1.100
1.101 # If newer than any old version, discard old details from the
1.102 # free/busy record and check for suitability.
1.103
1.104 - periods = obj.get_periods_for_freebusy(tzid, get_window_end(tzid))
1.105 + # Interpretation of periods can depend on the time zone.
1.106 +
1.107 + periods = obj.get_periods_for_freebusy(self.get_tzid(), self.get_window_end())
1.108
1.109 self.update_freebusy_for_participant(freebusy, periods, attr,
1.110 - from_organiser and self.is_not_attendee(identity, obj))
1.111 + from_organiser and not self.is_attendee(self.user, obj))
1.112
1.113 # Remove either original recurrence or additional recurrence
1.114 # details depending on whether an additional recurrence or a
1.115 # complete event are being handled, respectively.
1.116
1.117 - self.remove_freebusy_for_recurrences(freebusy, self.store.get_recurrences(identity, self.uid))
1.118 - self.store.set_freebusy(identity, freebusy)
1.119 + self.remove_freebusy_for_recurrences(freebusy, self.store.get_recurrences(self.user, self.uid))
1.120 + self.store.set_freebusy(self.user, freebusy)
1.121
1.122 - if self.publisher:
1.123 - self.publisher.set_freebusy(identity, freebusy)
1.124 + if self.publisher and self.is_sharing():
1.125 + self.publisher.set_freebusy(self.user, freebusy)
1.126
1.127 return True
1.128
1.129 @@ -123,17 +116,18 @@
1.130
1.131 "Remove free/busy information for any unprocessed object."
1.132
1.133 - item = self._get_identity(from_organiser)
1.134 - if not item:
1.135 + self.set_identity(from_organiser)
1.136 +
1.137 + # Check for event using UID.
1.138 +
1.139 + if not self.have_new_object():
1.140 return False
1.141
1.142 - identity, attr = item
1.143 -
1.144 # Only cancel the event completely if all attendees are given.
1.145 # NOTE: Need to also check for recurrence identifiers and selective
1.146 # NOTE: cancellations.
1.147
1.148 - obj = self.get_object(identity)
1.149 + obj = self.get_object()
1.150 if not obj:
1.151 return False
1.152
1.153 @@ -142,7 +136,7 @@
1.154 given_attendees = set(uri_values(self.obj.get_values("ATTENDEE")))
1.155
1.156 if given_attendees == all_attendees:
1.157 - self.store.cancel_event(identity, self.uid, self.recurrenceid)
1.158 + self.store.cancel_event(self.user, self.uid, self.recurrenceid)
1.159
1.160 # Otherwise, remove the given attendees and update the event.
1.161
1.162 @@ -159,21 +153,21 @@
1.163
1.164 # Set the complete event if not an additional occurrence.
1.165
1.166 - self.store.set_event(identity, self.uid, self.recurrenceid, obj.to_node())
1.167 + self.store.set_event(self.user, self.uid, self.recurrenceid, obj.to_node())
1.168
1.169 # Remove any associated request.
1.170
1.171 - self.store.dequeue_request(identity, self.uid, self.recurrenceid)
1.172 + self.store.dequeue_request(self.user, self.uid, self.recurrenceid)
1.173
1.174 # Update free/busy information.
1.175
1.176 if update_freebusy:
1.177 - freebusy = self.store.get_freebusy(identity)
1.178 + freebusy = self.store.get_freebusy(self.user)
1.179 self.remove_from_freebusy(freebusy)
1.180 - self.store.set_freebusy(identity, freebusy)
1.181 + self.store.set_freebusy(self.user, freebusy)
1.182
1.183 - if self.publisher:
1.184 - self.publisher.set_freebusy(identity, freebusy)
1.185 + if self.publisher and self.is_sharing():
1.186 + self.publisher.set_freebusy(self.user, freebusy)
1.187
1.188 return True
1.189