diff --git a/teos/gatekeeper.py b/teos/gatekeeper.py index d0416a7..b333501 100644 --- a/teos/gatekeeper.py +++ b/teos/gatekeeper.py @@ -27,9 +27,9 @@ class UserInfo: self.available_slots = available_slots self.subscription_expiry = subscription_expiry - # FIXME: this list is currently never wiped if not appointments: - self.appointments = [] + # A dictionary of the form uuid:required_slots for each user appointment + self.appointments = {} else: self.appointments = appointments @@ -136,21 +136,20 @@ class Gatekeeper: except (InvalidParameter, InvalidKey, SignatureError): raise AuthenticationFailure("Wrong message or signature.") - def update_available_slots(self, user_id, new_appointment, old_appointment=None): + def add_update_appointment(self, user_id, uuid, appointment): """ - Updates (add/removes) slots from a user subscription. + Adds (or updates) an appointment to a user subscription. The user slots are updated accordingly. - Slots are removed if a new appointment is given, or an update is given with an appointment bigger than the - old one. + Slots are taken if a new appointment is given, or an update is given with an appointment bigger than the + existing one. - Slots are added if an update is given but the new appointment is smaller than the old one. + Slots are given back if an update is given but the new appointment is smaller than the existing one. Args: - user_id(:obj:`str`): the public key that identifies the user (33-bytes hex str). - new_appointment (:obj:`dict`): the summary of new appointment the user is requesting - to add. - old_appointment (:obj:`dict`): the summary old appointment the user wants to replace. - Optional. + user_id (:obj:`str`): the public key that identifies the user (33-bytes hex str). + uuid (:obj:`str`): the appointment uuid. + appointment (:obj:`ExtendedAppointment