Changeset View
Changeset View
Standalone View
Standalone View
wallace/module_resources.py
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
from pykolab.xml import event_from_message | from pykolab.xml import event_from_message | ||||
from pykolab.xml import participant_status_label | from pykolab.xml import participant_status_label | ||||
from pykolab.itip import events_from_message | from pykolab.itip import events_from_message | ||||
from pykolab.itip import check_event_conflict | from pykolab.itip import check_event_conflict | ||||
from pykolab.translate import _ | from pykolab.translate import _ | ||||
# define some contstants used in the code below | # define some contstants used in the code below | ||||
COND_NOTIFY = 256 | COND_NOTIFY = 256 | ||||
ACT_MANUAL = 1 | ACT_MANUAL = 1 | ||||
ACT_ACCEPT = 2 | ACT_ACCEPT = 2 | ||||
ACT_REJECT = 8 | |||||
ACT_ACCEPT_AND_NOTIFY = ACT_ACCEPT + COND_NOTIFY | ACT_ACCEPT_AND_NOTIFY = ACT_ACCEPT + COND_NOTIFY | ||||
policy_name_map = { | policy_name_map = { | ||||
'ACT_MANUAL': ACT_MANUAL, | 'ACT_MANUAL': ACT_MANUAL, | ||||
'ACT_ACCEPT': ACT_ACCEPT, | 'ACT_ACCEPT': ACT_ACCEPT, | ||||
'ACT_REJECT': ACT_REJECT, | |||||
'ACT_ACCEPT_AND_NOTIFY': ACT_ACCEPT_AND_NOTIFY | 'ACT_ACCEPT_AND_NOTIFY': ACT_ACCEPT_AND_NOTIFY | ||||
} | } | ||||
log = pykolab.getLogger('pykolab.wallace') | log = pykolab.getLogger('pykolab.wallace') | ||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
mybasepath = '/var/spool/pykolab/wallace/resources/' | mybasepath = '/var/spool/pykolab/wallace/resources/' | ||||
▲ Show 20 Lines • Show All 279 Lines • ▼ Show 20 Lines | if done: | ||||
os.unlink(filepath) | os.unlink(filepath) | ||||
cleanup() | cleanup() | ||||
return | return | ||||
# do the magic for the receiving attendee | # do the magic for the receiving attendee | ||||
(available_resource, itip_event) = check_availability(itip_events, resource_dns, resources, receiving_attendee) | (available_resource, itip_event) = check_availability(itip_events, resource_dns, resources, receiving_attendee) | ||||
reject = False | |||||
resource = None | |||||
original_resource = None | |||||
# accept reservation | # accept reservation | ||||
if available_resource is not None: | if available_resource is not None: | ||||
if available_resource['mail'] in [a.get_email() for a in itip_event['xml'].get_attendees()]: | if available_resource['mail'] in [a.get_email() for a in itip_event['xml'].get_attendees()]: | ||||
log.debug(_("Accept invitation for individual resource %r / %r") % (available_resource['dn'], available_resource['mail']), level=8) | |||||
# check if reservation was delegated | # check if reservation was delegated | ||||
original_resource = None | |||||
if available_resource['mail'] != receiving_resource['mail'] and receiving_attendee.get_participant_status() == kolabformat.PartDelegated: | if available_resource['mail'] != receiving_resource['mail'] and receiving_attendee.get_participant_status() == kolabformat.PartDelegated: | ||||
original_resource = receiving_resource | original_resource = receiving_resource | ||||
accept_reservation_request(itip_event, available_resource, original_resource) | resource = available_resource | ||||
else: | else: | ||||
# This must have been a resource collection originally. | # This must have been a resource collection originally. | ||||
# We have inserted the reference to the original resource | # We have inserted the reference to the original resource | ||||
# record in 'memberof'. | # record in 'memberof'. | ||||
if available_resource.has_key('memberof'): | if available_resource.has_key('memberof'): | ||||
original_resource = resources[available_resource['memberof']] | original_resource = resources[available_resource['memberof']] | ||||
if original_resource['mail'] in [a.get_email() for a in itip_event['xml'].get_attendees()]: | if original_resource['mail'] in [a.get_email() for a in itip_event['xml'].get_attendees()]: | ||||
# | # | ||||
# Delegate: | # Delegate: | ||||
# - delegator: the original resource collection | # - delegator: the original resource collection | ||||
# - delegatee: the target resource | # - delegatee: the target resource | ||||
# | # | ||||
itip_event['xml'].delegate(original_resource['mail'], available_resource['mail'], available_resource['cn']) | itip_event['xml'].delegate(original_resource['mail'], available_resource['mail'], available_resource['cn']) | ||||
# set delegator to NON-PARTICIPANT and RSVP=FALSE | # set delegator to NON-PARTICIPANT and RSVP=FALSE | ||||
delegator = itip_event['xml'].get_attendee_by_email(original_resource['mail']) | delegator = itip_event['xml'].get_attendee_by_email(original_resource['mail']) | ||||
delegator.set_role(kolabformat.NonParticipant) | delegator.set_role(kolabformat.NonParticipant) | ||||
delegator.set_rsvp(False) | delegator.set_rsvp(False) | ||||
log.debug(_("Delegate invitation for resource collection %r to %r") % (original_resource['mail'], available_resource['mail']), level=8) | log.debug(_("Delegate invitation for resource collection %r to %r") % (original_resource['mail'], available_resource['mail']), level=8) | ||||
accept_reservation_request(itip_event, available_resource, original_resource) | resource = available_resource | ||||
# Look for ACT_REJECT policy | |||||
if resource is not None: | |||||
invitationpolicy = get_resource_invitationpolicy(resource) | |||||
log.debug(_("Apply invitation policies %r") % (invitationpolicy), level=9) | |||||
if invitationpolicy is not None: | |||||
for policy in invitationpolicy: | |||||
if policy & ACT_REJECT: | |||||
reject = True | |||||
break | |||||
# decline reservation | if resource is not None and not reject: | ||||
log.debug(_("Accept invitation for individual resource %r / %r") % (resource['dn'], resource['mail']), level=8) | |||||
accept_reservation_request(itip_event, resource, original_resource, False, invitationpolicy) | |||||
else: | else: | ||||
resource = resources[resource_dns[0]] # this is the receiving resource record | resource = resources[resource_dns[0]] # this is the receiving resource record | ||||
log.debug(_("Decline invitation for individual resource %r / %r") % (resource['dn'], resource['mail']), level=8) | |||||
decline_reservation_request(itip_event, resource) | decline_reservation_request(itip_event, resource) | ||||
cleanup() | cleanup() | ||||
os.unlink(filepath) | os.unlink(filepath) | ||||
def heartbeat(lastrun): | def heartbeat(lastrun): | ||||
▲ Show 20 Lines • Show All 362 Lines • ▼ Show 20 Lines | for num in reversed(data[0].split()): | ||||
continue | continue | ||||
if event and event.uid == uid: | if event and event.uid == uid: | ||||
return (event, master) | return (event, master) | ||||
return (event, master) | return (event, master) | ||||
def accept_reservation_request(itip_event, resource, delegator=None, confirmed=False): | def accept_reservation_request(itip_event, resource, delegator=None, confirmed=False, invitationpolicy=None): | ||||
""" | """ | ||||
Accepts the given iTip event by booking it into the resource's | Accepts the given iTip event by booking it into the resource's | ||||
calendar. Then set the attendee status of the given resource to | calendar. Then set the attendee status of the given resource to | ||||
ACCEPTED and sends an iTip reply message to the organizer. | ACCEPTED and sends an iTip reply message to the organizer. | ||||
""" | """ | ||||
owner = get_resource_owner(resource) | owner = get_resource_owner(resource) | ||||
confirmation_required = False | confirmation_required = False | ||||
if not confirmed and owner: | if not confirmed and owner: | ||||
if invitationpolicy is None: | |||||
invitationpolicy = get_resource_invitationpolicy(resource) | invitationpolicy = get_resource_invitationpolicy(resource) | ||||
log.debug(_("Apply invitation policies %r") % (invitationpolicy), level=9) | log.debug(_("Apply invitation policies %r") % (invitationpolicy), level=9) | ||||
if invitationpolicy is not None: | if invitationpolicy is not None: | ||||
for policy in invitationpolicy: | for policy in invitationpolicy: | ||||
if policy & ACT_MANUAL and owner['mail']: | if policy & ACT_MANUAL and owner['mail']: | ||||
confirmation_required = True | confirmation_required = True | ||||
break | break | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | elif resource.get('existing_events', []) and len(resource['existing_events']) > 0: | ||||
delete_resource_event(existing.uid, resource, existing._msguid) | delete_resource_event(existing.uid, resource, existing._msguid) | ||||
# delete old event referenced by itip_event (from owner confirmation) | # delete old event referenced by itip_event (from owner confirmation) | ||||
elif hasattr(itip_event['xml'], '_msguid'): | elif hasattr(itip_event['xml'], '_msguid'): | ||||
delete_resource_event(itip_event['xml'].uid, resource, itip_event['xml']._msguid) | delete_resource_event(itip_event['xml'].uid, resource, itip_event['xml']._msguid) | ||||
# send response and notification | # send response and notification | ||||
owner = get_resource_owner(resource) | owner = get_resource_owner(resource) | ||||
send_response(resource['mail'], itip_event, get_resource_owner(resource)) | send_response(resource['mail'], itip_event, owner) | ||||
if owner: | if owner: | ||||
send_owner_notification(resource, owner, itip_event, True) | send_owner_notification(resource, owner, itip_event, True) | ||||
def save_resource_event(itip_event, resource): | def save_resource_event(itip_event, resource): | ||||
""" | """ | ||||
Append the given event object to the resource's calendar | Append the given event object to the resource's calendar | ||||
▲ Show 20 Lines • Show All 585 Lines • Show Last 20 Lines |