# HG changeset patch # User Paul Boddie # Date 1507992289 -7200 # Node ID 5b30a730b35c71618edb0cddaa55c81a31c443cc # Parent 3760b7487889f09d73d8921de6b44e12b7be4ad2# Parent a7f94e62243e19f495986f7e3c35f3a8f233acb7 Merged changes from the default branch. diff -r 3760b7487889 -r 5b30a730b35c imiptools/handlers/person.py --- a/imiptools/handlers/person.py Fri Oct 13 16:17:20 2017 +0200 +++ b/imiptools/handlers/person.py Sat Oct 14 16:44:49 2017 +0200 @@ -93,6 +93,11 @@ self.merge_attendance({attendee : attendees[attendee]}) + # Remove any previous counter-proposals for the event from the attendee. + # If a parent event is involved, remove all proposed recurrences. + + self.store.remove_counters(self.user, self.uid, self.recurrenceid, attendee) + # Queue any counter-proposal for perusal. self.store.set_counter(self.user, attendee, self.obj.to_node(), self.uid, self.recurrenceid) diff -r 3760b7487889 -r 5b30a730b35c imiptools/stores/common.py --- a/imiptools/stores/common.py Fri Oct 13 16:17:20 2017 +0200 +++ b/imiptools/stores/common.py Sat Oct 14 16:44:49 2017 +0200 @@ -512,11 +512,12 @@ pass - def remove_counters(self, user, uid, recurrenceid=None): + def remove_counters(self, user, uid, recurrenceid=None, attendee=None): """ For the given 'user', remove all counter-proposals associated with the - given 'uid' and 'recurrenceid'. + given 'uid' and 'recurrenceid'. If 'attendee' is specified, only objects + provided by this attendee will be removed. """ pass diff -r 3760b7487889 -r 5b30a730b35c imiptools/stores/database/common.py --- a/imiptools/stores/database/common.py Fri Oct 13 16:17:20 2017 +0200 +++ b/imiptools/stores/database/common.py Sat Oct 14 16:44:49 2017 +0200 @@ -735,11 +735,12 @@ self.cursor.execute(query, values) return True - def remove_counters(self, user, uid, recurrenceid=None): + def remove_counters(self, user, uid, recurrenceid=None, attendee=None): """ For the given 'user', remove all counter-proposals associated with the - given 'uid' and 'recurrenceid'. + given 'uid' and 'recurrenceid'. If 'attendee' is specified, only objects + provided by this attendee will be removed. """ table = self.get_event_table(recurrenceid, "counters") @@ -751,6 +752,10 @@ columns = ["store_user", "object_uid"] values = [user, uid] + if attendee: + columns.append("other") + values.append(attendee) + query, values = self.get_query( "delete from %(table)s :condition" % { "table" : table diff -r 3760b7487889 -r 5b30a730b35c imiptools/stores/file.py --- a/imiptools/stores/file.py Fri Oct 13 16:17:20 2017 +0200 +++ b/imiptools/stores/file.py Sat Oct 14 16:44:49 2017 +0200 @@ -608,11 +608,27 @@ return self._set_object(user, filename, node) - def remove_counters(self, user, uid, recurrenceid=None): + def remove_counters(self, user, uid, recurrenceid=None, attendee=None): """ For the given 'user', remove all counter-proposals associated with the - given 'uid' and 'recurrenceid'. + given 'uid' and 'recurrenceid'. If a parent event is specified, all + recurrence counter-proposals will be removed. If 'attendee' is + specified, only objects provided by this attendee will be removed. + """ + + self._remove_counters(user, uid, recurrenceid, attendee) + + if not recurrenceid: + for recurrenceid in self.get_counter_recurrences(user, uid): + self._remove_counters(user, uid, recurrenceid, attendee) + + def _remove_counters(self, user, uid, recurrenceid=None, attendee=None): + + """ + For the given 'user', remove all counter-proposals associated with the + given 'uid' and 'recurrenceid'. If 'attendee' is specified, only objects + provided by this attendee will be removed. """ filename = self.get_event_filename(user, uid, recurrenceid, "counters") @@ -622,8 +638,12 @@ removed = False for other in listdir(filename): - counter_filename = self.get_event_filename(user, uid, recurrenceid, "counters", other) - removed = removed or self._remove_object(counter_filename) + if not attendee or other == attendee: + counter_filename = self.get_event_filename(user, uid, recurrenceid, "counters", other) + removed = removed or self._remove_object(counter_filename) + + if not listdir(filename): + self._remove_collection(filename) return removed