# HG changeset patch # User Paul Boddie # Date 1443114845 -7200 # Node ID 2242ef8b2a39038422f4003c93882e3360ff92a7 # Parent 796a915569f6d85cfffbe7deadb0852d32e3ee10# Parent 79493ac5b434a2c27e68e2a193a9a6021bbeee23 Merged default branch changes. diff -r 796a915569f6 -r 2242ef8b2a39 imip_store.py --- a/imip_store.py Sat Sep 19 23:01:37 2015 +0200 +++ b/imip_store.py Thu Sep 24 19:14:05 2015 +0200 @@ -233,7 +233,7 @@ return all_events - def get_event_filename(self, user, uid, recurrenceid=None, dirname=None): + def get_event_filename(self, user, uid, recurrenceid=None, dirname=None, username=None): """ Get the filename providing the event for the given 'user' with the given @@ -245,9 +245,9 @@ """ if recurrenceid: - return self.get_recurrence_filename(user, uid, recurrenceid, dirname) + return self.get_recurrence_filename(user, uid, recurrenceid, dirname, username) else: - return self.get_complete_event_filename(user, uid, dirname) + return self.get_complete_event_filename(user, uid, dirname, username) def get_event(self, user, uid, recurrenceid=None): @@ -263,7 +263,7 @@ return filename and self._get_object(user, filename) - def get_complete_event_filename(self, user, uid, dirname=None): + def get_complete_event_filename(self, user, uid, dirname=None, username=None): """ Get the filename providing the event for the given 'user' with the given @@ -271,9 +271,12 @@ Where 'dirname' is specified, the given directory name is used as the base of the location within which any filename will reside. + + Where 'username' is specified, the event details will reside in a file + bearing that name within a directory having 'uid' as its name. """ - return self.get_object_in_store(user, dirname, "objects", uid) + return self.get_object_in_store(user, dirname, "objects", uid, username) def get_complete_event(self, user, uid): @@ -370,7 +373,7 @@ return [name for name in listdir(filename) if isfile(join(filename, name))] - def get_recurrence_filename(self, user, uid, recurrenceid, dirname=None): + def get_recurrence_filename(self, user, uid, recurrenceid, dirname=None, username=None): """ For the event of the given 'user' with the given 'uid', return the @@ -378,9 +381,12 @@ Where 'dirname' is specified, the given directory name is used as the base of the location within which any filename will reside. + + Where 'username' is specified, the event details will reside in a file + bearing that name within a directory having 'uid' as its name. """ - return self.get_object_in_store(user, dirname, "recurrences", uid, recurrenceid) + return self.get_object_in_store(user, dirname, "recurrences", uid, recurrenceid, username) def get_recurrence(self, user, uid, recurrenceid): @@ -733,7 +739,7 @@ type = request[2] if type == "COUNTER": - self.remove_counter(user, uid, recurrenceid) + self.remove_counters(user, uid, recurrenceid) else: result.append(request) @@ -755,40 +761,80 @@ return True return False - def get_counter(self, user, uid, recurrenceid=None): + def get_counters(self, user, uid, recurrenceid=None): """ - For the given 'user', return the counter-proposal for the given 'uid' - and optional 'recurrenceid'. + For the given 'user', return a mapping of counter-proposals from other + users to nodes representing those proposals for the given 'uid' and + optional 'recurrenceid'. """ filename = self.get_event_filename(user, uid, recurrenceid, "counters") if not filename: return False - return filename and self._get_object(user, filename) + counters = {} - def set_counter(self, user, node, uid, recurrenceid=None): + for other in listdir(filename): + counter_filename = self.get_event_filename(user, uid, recurrenceid, "counters", other) + counters[other] = self._get_object(user, counter_filename) + + return counters + + def get_counter(self, user, other, uid, recurrenceid=None): """ - For the given 'user', store the given 'node' for the given 'uid' and - 'recurrenceid' as a counter-proposal. + For the given 'user', return the counter-proposal from 'other' for the + given 'uid' and optional 'recurrenceid'. + """ + + filename = self.get_event_filename(user, uid, recurrenceid, "counters", other) + if not filename: + return False + + return self._get_object(user, filename) + + def set_counter(self, user, other, node, uid, recurrenceid=None): + + """ + For the given 'user', store a counter-proposal received from 'other' the + given 'node' representing that proposal for the given 'uid' and + 'recurrenceid'. + """ + + filename = self.get_event_filename(user, uid, recurrenceid, "counters", other) + if not filename: + return False + + return self._set_object(user, filename, node) + + def remove_counters(self, user, uid, recurrenceid=None): + + """ + For the given 'user', remove all counter-proposals associated with the + given 'uid' and 'recurrenceid'. """ filename = self.get_event_filename(user, uid, recurrenceid, "counters") if not filename: return False - return self._set_object(user, filename, node) + removed = False - def remove_counter(self, user, uid, recurrenceid=None): + for other in listdir(filename): + counter_filename = self.get_event_filename(user, uid, recurrenceid, "counters", other) + removed = removed or self._remove_object(counter_filename) + + return removed + + def remove_counter(self, user, other, uid, recurrenceid=None): """ - For the given 'user', remove any counter-proposal associated with the - given 'uid' and 'recurrenceid'. + For the given 'user', remove any counter-proposal from 'other' + associated with the given 'uid' and 'recurrenceid'. """ - filename = self.get_event_filename(user, uid, recurrenceid, "counters") + filename = self.get_event_filename(user, uid, recurrenceid, "counters", other) if not filename: return False diff -r 796a915569f6 -r 2242ef8b2a39 imiptools/handlers/person.py --- a/imiptools/handlers/person.py Sat Sep 19 23:01:37 2015 +0200 +++ b/imiptools/handlers/person.py Thu Sep 24 19:14:05 2015 +0200 @@ -99,7 +99,8 @@ # Queue any counter-proposal for perusal. - self.store.set_counter(self.user, self.obj.to_node(), self.uid, self.recurrenceid) + for attendee in attendees.keys(): + self.store.set_counter(self.user, attendee, self.obj.to_node(), self.uid, self.recurrenceid) self.store.queue_request(self.user, self.uid, self.recurrenceid, "COUNTER") return True diff -r 796a915569f6 -r 2242ef8b2a39 tests/test_resource_invitation_constraints.sh --- a/tests/test_resource_invitation_constraints.sh Sat Sep 19 23:01:37 2015 +0200 +++ b/tests/test_resource_invitation_constraints.sh Thu Sep 24 19:14:05 2015 +0200 @@ -90,7 +90,7 @@ && echo "Success" \ || echo "Failed" - grep -q 'DTSTART;TZID=Europe/Oslo.*:20141126T161500' "$STORE/$SENDER/counters/objects/event13@example.com" \ + grep -q 'DTSTART;TZID=Europe/Oslo.*:20141126T161500' "$STORE/$SENDER/counters/objects/event13@example.com/$USER" \ && echo "Success" \ || echo "Failed" @@ -157,7 +157,7 @@ && echo "Success" \ || echo "Failed" - [ ! -e "$STORE/$SENDER/counters/objects/event13@example.com" ] \ + [ ! -e "$STORE/$SENDER/counters/objects/event13@example.com/$USER" ] \ && echo "Success" \ || echo "Failed" @@ -200,7 +200,7 @@ && echo "Success" \ || echo "Failed" - [ ! -e "$STORE/$SENDER/counters/objects/event13@example.com" ] \ + [ ! -e "$STORE/$SENDER/counters/objects/event13@example.com/$USER" ] \ && echo "Success" \ || echo "Failed" diff -r 796a915569f6 -r 2242ef8b2a39 tests/test_resource_invitation_constraints_alternative.sh --- a/tests/test_resource_invitation_constraints_alternative.sh Sat Sep 19 23:01:37 2015 +0200 +++ b/tests/test_resource_invitation_constraints_alternative.sh Thu Sep 24 19:14:05 2015 +0200 @@ -92,7 +92,7 @@ && echo "Success" \ || echo "Failed" - grep -q 'DTSTART;TZID=Europe/Oslo.*:20141126T161500' "$STORE/$SENDER/counters/objects/event13@example.com" \ + grep -q 'DTSTART;TZID=Europe/Oslo.*:20141126T161500' "$STORE/$SENDER/counters/objects/event13@example.com/$USER" \ && echo "Success" \ || echo "Failed"