Skip to content

Commit

Permalink
Send ITIP_CANCEL to attendess that were removed when using Dav.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Jun 8, 2016
1 parent d3125a7 commit 1d1d17b
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion kronolith/lib/Icalendar/Handler/Dav.php
Expand Up @@ -50,6 +50,14 @@ class Kronolith_Icalendar_Handler_Dav extends Kronolith_Icalendar_Handler_Base
*/
protected $_noItips = array();

/**
* List of attendess that have been previously invited. Used to detect if
* attendees are removed and to send ITIP_CANCEL to these attendees.
*
* @var Kronolith_Attendee_List
*/
protected $_oldAttendees;

/**
*
* @param Horde_Icalendar $iCal The iCalendar data.
Expand Down Expand Up @@ -86,6 +94,8 @@ protected function _preSave($component)

// Ensure we start with a fresh state.
$this->_existingEvent = null;
$this->_oldAttendees = new Kronolith_Attendee_List();
$this->_noItips = array();

// Get the internal id of the existing copy of the event, if it exists.
try {
Expand Down Expand Up @@ -121,6 +131,9 @@ protected function _preSave($component)
$this->_existingEvent->loadHistory();
$modified = $this->_existingEvent->modified
?: $this->_existingEvent->created;

// Get list of existing attendees.
$this->_oldAttendees = $this->_existingEvent->attendees;
} catch (Horde_Exception_NotFound $e) {
$this->_existingEvent = null;
}
Expand Down Expand Up @@ -165,6 +178,8 @@ protected function _preSave($component)

protected function _postSave(Kronolith_Event $event)
{
global $registry;

if (!$this->_dav->getInternalObjectId($this->_params['object'], $this->_calendar)) {
$this->_dav->addObjectMap($event->id, $this->_params['object'], $this->_calendar);
}
Expand All @@ -176,11 +191,37 @@ protected function _postSave(Kronolith_Event $event)
}
$event_copy = clone($event);
$event_copy->attendees = $event->attendees->without($this->_noItips);
$notification = new Horde_Notification_Handler(new Horde_Notification_Storage_Object());
Kronolith::sendITipNotifications(
$event_copy,
new Horde_Notification_Handler(new Horde_Notification_Storage_Object()),
$notification,
$type
);

// Send ITIP_CANCEL to any attendee that was removed, but only if this
// is the ORGANZIER's copy of the event.
if (empty($event->organizer) ||
($registry->getAuth() == $event->creator &&
Kronolith::isUserEmail($event->creator, $event->organizer))) {

$removed_attendees = new Kronolith_Attendee_List();
foreach ($this->_oldAttendees as $old_attendee) {
if (!$event->attendees->has($old_attendee)) {
$removed_attendees->add($old_attendee);
}
}
if (count($removed_attendees)) {
$cancelEvent = clone $event;
Kronolith::sendITipNotifications(
$cancelEvent,
$notification,
Kronolith::ITIP_CANCEL,
null,
null,
$removed_attendees
);
}
}
}

}

0 comments on commit 1d1d17b

Please sign in to comment.