1.1 --- a/imiptools/handlers/scheduling/quota.py Sat Oct 08 23:45:25 2016 +0200
1.2 +++ b/imiptools/handlers/scheduling/quota.py Sun Oct 23 23:21:01 2016 +0200
1.3 @@ -81,17 +81,7 @@
1.4 """
1.5
1.6 quota, group = _get_quota_and_group(handler, args)
1.7 -
1.8 - # Update the journal entries.
1.9 -
1.10 - journal = handler.get_journal()
1.11 - entries = journal.get_entries_for_update(quota, group)
1.12 - handler.update_freebusy(entries, handler.user, False)
1.13 - journal.set_entries(quota, group, entries)
1.14 -
1.15 - # Store/update the object so that recurring events can be maintained.
1.16 -
1.17 - _update_object(handler, args)
1.18 + _add_to_quota(handler, quota, group, handler.user, False)
1.19
1.20 def remove_from_quota(handler, args):
1.21
1.22 @@ -101,26 +91,9 @@
1.23 """
1.24
1.25 quota, group = _get_quota_and_group(handler, args)
1.26 -
1.27 - # Update the journal entries.
1.28 -
1.29 - journal = handler.get_journal()
1.30 - entries = journal.get_entries_for_update(quota, group)
1.31 -
1.32 - # Remove only the entries associated with this recipient.
1.33 + _remove_from_quota(handler, quota, group, handler.user)
1.34
1.35 - removed = handler.remove_from_freebusy(entries)
1.36 - for p in removed:
1.37 - if p.attendee != handler.user:
1.38 - entries.insert_period(p)
1.39 -
1.40 - journal.set_entries(quota, group, entries)
1.41 -
1.42 - # Remove participation from the object to stop recurring event generation.
1.43 -
1.44 - _remove_object(handler, args)
1.45 -
1.46 -def _update_object(handler, args):
1.47 +def update_event(handler, args):
1.48
1.49 "Update a stored version of the current object of the given 'handler'."
1.50
1.51 @@ -145,7 +118,7 @@
1.52
1.53 journal.set_event(quota, handler.uid, handler.recurrenceid, obj.to_node())
1.54
1.55 -def _remove_object(handler, args):
1.56 +def remove_event(handler, args):
1.57
1.58 "Remove a stored version of the current object of the given 'handler'."
1.59
1.60 @@ -252,6 +225,53 @@
1.61 total += period.get_duration()
1.62 return total
1.63
1.64 +def _add_to_quota(handler, quota, user, participant, is_organiser):
1.65 +
1.66 + """
1.67 + Record details of the current object of the 'handler' in the applicable
1.68 + free/busy resource.
1.69 + """
1.70 +
1.71 + journal = handler.get_journal()
1.72 + freebusy = journal.get_entries_for_update(quota, user)
1.73 + handler.update_freebusy(freebusy, participant, is_organiser)
1.74 +
1.75 + # Remove original recurrence details replaced by additional
1.76 + # recurrences, as well as obsolete additional recurrences.
1.77 +
1.78 + handler.remove_freebusy_for_recurrences(freebusy, journal.get_recurrences(quota, handler.uid))
1.79 +
1.80 + # Update free/busy provider information if the event may recur indefinitely.
1.81 +
1.82 + if handler.possibly_recurring_indefinitely():
1.83 + journal.append_freebusy_provider(quota, handler.obj)
1.84 +
1.85 + journal.set_entries(quota, user, freebusy)
1.86 +
1.87 +def _remove_from_quota(handler, quota, user, participant):
1.88 +
1.89 + """
1.90 + Remove details of the current object of the 'handler' from the applicable
1.91 + free/busy resource.
1.92 + """
1.93 +
1.94 + journal = handler.get_journal()
1.95 + freebusy = journal.get_entries_for_update(quota, user)
1.96 +
1.97 + # Remove only the entries associated with this recipient.
1.98 +
1.99 + removed = handler.remove_from_freebusy(freebusy)
1.100 + for p in removed:
1.101 + if p.attendee != participant:
1.102 + freebusy.insert_period(p)
1.103 +
1.104 + # Update free/busy provider information if the event may recur indefinitely.
1.105 +
1.106 + if handler.possibly_recurring_indefinitely():
1.107 + journal.remove_freebusy_provider(quota, handler.obj)
1.108 +
1.109 + journal.set_entries(quota, user, freebusy)
1.110 +
1.111 # Collective free/busy maintenance.
1.112
1.113 def schedule_across_quota(handler, args):
1.114 @@ -281,11 +301,7 @@
1.115 """
1.116
1.117 quota, organiser = _get_quota_and_identity(handler, args)
1.118 -
1.119 - journal = handler.get_journal()
1.120 - freebusy = journal.get_entries_for_update(quota, organiser)
1.121 - handler.update_freebusy(freebusy, organiser, True)
1.122 - journal.set_entries(quota, organiser, freebusy)
1.123 + _add_to_quota(handler, quota, organiser, organiser, True)
1.124
1.125 def remove_from_quota_freebusy(handler, args):
1.126
1.127 @@ -295,11 +311,7 @@
1.128 """
1.129
1.130 quota, organiser = _get_quota_and_identity(handler, args)
1.131 -
1.132 - journal = handler.get_journal()
1.133 - freebusy = journal.get_entries_for_update(quota, organiser)
1.134 - handler.remove_from_freebusy(freebusy)
1.135 - journal.set_entries(quota, organiser, freebusy)
1.136 + _remove_from_quota(handler, quota, organiser, organiser)
1.137
1.138 def _get_quota_and_identity(handler, args):
1.139
1.140 @@ -428,37 +440,37 @@
1.141 # Registry of scheduling functions.
1.142
1.143 scheduling_functions = {
1.144 - "check_quota" : check_quota,
1.145 - "schedule_across_quota" : schedule_across_quota,
1.146 - "schedule_for_delegate" : schedule_for_delegate,
1.147 + "check_quota" : [check_quota],
1.148 + "schedule_across_quota" : [schedule_across_quota],
1.149 + "schedule_for_delegate" : [schedule_for_delegate],
1.150 }
1.151
1.152 # Registries of locking and unlocking functions.
1.153
1.154 locking_functions = {
1.155 - "check_quota" : lock_journal,
1.156 - "schedule_across_quota" : lock_journal,
1.157 - "schedule_for_delegate" : lock_journal,
1.158 + "check_quota" : [lock_journal],
1.159 + "schedule_across_quota" : [lock_journal],
1.160 + "schedule_for_delegate" : [lock_journal],
1.161 }
1.162
1.163 unlocking_functions = {
1.164 - "check_quota" : unlock_journal,
1.165 - "schedule_across_quota" : unlock_journal,
1.166 - "schedule_for_delegate" : unlock_journal,
1.167 + "check_quota" : [unlock_journal],
1.168 + "schedule_across_quota" : [unlock_journal],
1.169 + "schedule_for_delegate" : [unlock_journal],
1.170 }
1.171
1.172 # Registries of listener functions.
1.173
1.174 confirmation_functions = {
1.175 - "check_quota" : add_to_quota,
1.176 - "schedule_across_quota" : add_to_quota_freebusy,
1.177 - "schedule_for_delegate" : add_to_quota,
1.178 + "check_quota" : [add_to_quota, update_event],
1.179 + "schedule_across_quota" : [add_to_quota_freebusy, update_event],
1.180 + "schedule_for_delegate" : [add_to_quota, update_event],
1.181 }
1.182
1.183 retraction_functions = {
1.184 - "check_quota" : remove_from_quota,
1.185 - "schedule_across_quota" : remove_from_quota_freebusy,
1.186 - "schedule_for_delegate" : remove_from_quota,
1.187 + "check_quota" : [remove_from_quota, remove_event],
1.188 + "schedule_across_quota" : [remove_from_quota_freebusy, remove_event],
1.189 + "schedule_for_delegate" : [remove_from_quota, remove_event],
1.190 }
1.191
1.192 # vim: tabstop=4 expandtab shiftwidth=4