# HG changeset patch # User Paul Boddie # Date 1442080739 -7200 # Node ID f3d6831fcc21ae1cecb7e2a734874846046763e8 # Parent 575ed0737946c27eef0f974dd9d5fcc9216b66e3 Ensure user initialisation before invoking each handler method. diff -r 575ed0737946 -r f3d6831fcc21 imiptools/client.py --- a/imiptools/client.py Sat Sep 12 18:15:26 2015 +0200 +++ b/imiptools/client.py Sat Sep 12 19:58:59 2015 +0200 @@ -37,6 +37,7 @@ "Common handler and manager methods." default_window_size = 100 + organiser_methods = "ADD", "CANCEL", "DECLINECOUNTER", "PUBLISH", "REQUEST" def __init__(self, user, messenger=None, store=None, publisher=None, preferences_dir=None): @@ -279,6 +280,17 @@ self.sequence = obj and self.obj.get_value("SEQUENCE") self.dtstamp = obj and self.obj.get_value("DTSTAMP") + def set_identity(self, method): + + """ + Set the current user for the current object in the context of the given + 'method'. It is usually set when initialising the handler, using the + recipient details, but outgoing messages do not reference the recipient + in this way. + """ + + pass + def is_usable(self, method=None): "Return whether the current object is usable with the given 'method'." diff -r 575ed0737946 -r f3d6831fcc21 imiptools/content.py --- a/imiptools/content.py Sat Sep 12 18:15:26 2015 +0200 +++ b/imiptools/content.py Sat Sep 12 19:58:59 2015 +0200 @@ -69,6 +69,8 @@ # Dispatch to a handler and obtain any response. handler.set_object(Object({name : item})) + handler.set_identity(method) + if handler.is_usable(method): methods[method](handler)() diff -r 575ed0737946 -r f3d6831fcc21 imiptools/handlers/person_outgoing.py --- a/imiptools/handlers/person_outgoing.py Sat Sep 12 18:15:26 2015 +0200 +++ b/imiptools/handlers/person_outgoing.py Sat Sep 12 19:58:59 2015 +0200 @@ -21,7 +21,7 @@ """ from imiptools.client import Client -from imiptools.data import uri_dict, uri_item, uri_values +from imiptools.data import get_uri, uri_dict, uri_values from imiptools.handlers import Handler from imiptools.handlers.common import CommonEvent @@ -29,21 +29,23 @@ "Handling mechanisms specific to people." - def set_identity(self, from_organiser=True): + def set_identity(self, method): """ - Set the current user for the current object. It is usually set when - initialising the handler, using the recipient details, but outgoing - messages do not reference the recipient in this way. + Set the current user for the current object in the context of the given + 'method'. It is usually set when initialising the handler, using the + recipient details, but outgoing messages do not reference the recipient + in this way. """ - self.user, attr = uri_item(self.obj.get_item(from_organiser and "ORGANIZER" or "ATTENDEE")) + if self.obj: + from_organiser = method in self.organiser_methods + self.user = get_uri(self.obj.get_value(from_organiser and "ORGANIZER" or "ATTENDEE")) def _add(self): "Add a recurrence for the current object." - self.set_identity() if not Client.is_participating(self): return False @@ -81,7 +83,6 @@ from an organiser if 'from_organiser' is set to a true value. """ - self.set_identity(from_organiser) if not Client.is_participating(self): return False @@ -128,7 +129,6 @@ from an organiser if 'from_organiser' is set to a true value. """ - self.set_identity(True) if not Client.is_participating(self): return False