Implement CalDAV DELETE.
authorJan Schneider <jan@horde.org>
Mon, 9 Aug 2010 18:43:41 +0000 (20:43 +0200)
committerJan Schneider <jan@horde.org>
Tue, 10 Aug 2010 23:28:28 +0000 (01:28 +0200)
kronolith/delete.php
kronolith/lib/Driver/Ical.php
kronolith/templates/delete/delete.inc
kronolith/templates/delete/one.inc

index fd7178e..5e0c9b9 100644 (file)
@@ -19,7 +19,7 @@ if (Kronolith::showAjaxView()) {
 if (Kronolith_Resource::isResourceCalendar($c = Horde_Util::getFormData('calendar'))) {
     $driver = 'Resource';
 } else {
-    $driver = null;
+    $driver = Horde_Util::getFormData('type');
 }
 
 $kronolith_driver = Kronolith::getDriver($driver, $c);
@@ -35,11 +35,16 @@ if ($eventID = Horde_Util::getFormData('eventID')) {
         $url->redirect();
     }
     if ($driver != 'Resource') {
-        $share = $kronolith_shares->getShare($event->calendar);
-        if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE, $event->creator)) {
-            $notification->push(_("You do not have permission to delete this event."), 'horde.warning');
-        } else {
+        if ($driver == 'remote') {
+            /* The remote server is doing the permission checks for us. */
             $have_perms = true;
+        } else {
+            $share = $kronolith_shares->getShare($event->calendar);
+            if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE, $event->creator)) {
+                $notification->push(_("You do not have permission to delete this event."), 'horde.warning');
+            } else {
+                $have_perms = true;
+            }
         }
     } else {
         if (!$registry->isAdmin()) {
index bf227a3..a73cfef 100644 (file)
@@ -381,6 +381,41 @@ class Kronolith_Driver_Ical extends Kronolith_Driver
     }
 
     /**
+     * Deletes an event.
+     *
+     * @param string $eventId  The ID of the event to delete.
+     * @param boolean $silent  Don't send notifications, used when deleting
+     *                         events in bulk from maintenance tasks.
+     *
+     * @throws Kronolith_Exception
+     * @throws Horde_Exception_NotFound
+     * @throws Horde_Mime_Exception
+     */
+    public function deleteEvent($eventId, $silent = false)
+    {
+        if (!$this->isCalDAV()) {
+            throw new Kronolith_Exception(_("Deleting events is not supported with this remote calendar."));
+        }
+
+        if (preg_match('/(.*)-(\d+)$/', $eventId, $matches)) {
+            throw new Kronolith_Exception(_("Cannot delete exceptions (yet)."));
+        }
+
+        $url = trim($this->_getUrl(), '/') . '/' . $eventId;
+        try {
+            $response = $this->_getClient()->delete($url);
+        } catch (Horde_Http_Exception $e) {
+            Horde::logMessage($e, 'INFO');
+            throw new Kronolith_Exception($e);
+        }
+        if (!in_array($response->code, array(200, 202, 204))) {
+            Horde::logMessage(sprintf('Failed to delete event from remote calendar: url = "%s", status = %s',
+                                      $url, $response->code), 'INFO');
+            throw new Kronolith_Exception(_("The event could not be deleted from the remote server."));
+        }
+    }
+
+    /**
      * Fetches a remote calendar into the session and return the data.
      *
      * @param boolean $cache  Whether to return data from the session cache.
index 9d5a85a..c402e37 100644 (file)
@@ -12,6 +12,7 @@ if (empty($url)) {
 <input type="hidden" name="url" value="<?php echo htmlspecialchars($url) ?>" />
 <input type="hidden" name="eventID" value="<?php echo htmlspecialchars($this->event->id) ?>" />
 <input type="hidden" name="calendar" value="<?php echo htmlspecialchars($this->event->calendar) ?>" />
+<input type="hidden" name="type" value="<?php echo htmlspecialchars($this->event->calendarType) ?>" />
 
 <table class="striped" cellspacing="0">
 <tr><td class="warning"><?php echo _("This is a recurring event. Delete the current event only, this<br />occurrence and all future occurences, or all occurences?") ?></td></tr>
index 4da64a6..85900dd 100644 (file)
@@ -12,6 +12,7 @@ if (empty($url)) {
 <input type="hidden" name="url" value="<?php echo htmlspecialchars($url) ?>" />
 <input type="hidden" name="eventID" value="<?php echo htmlspecialchars($this->event->id) ?>" />
 <input type="hidden" name="calendar" value="<?php echo htmlspecialchars(Horde_Util::getFormData('calendar')) ?>" />
+<input type="hidden" name="type" value="<?php echo htmlspecialchars($this->event->calendarType) ?>" />
 
 <div class="headerbox">
 <?php if (!empty($this->event->attendees)): ?>