2 commits - plugins/calendar plugins/kolab_delegation

Aleksander Machniak machniak at kolabsys.com
Tue Dec 4 20:10:37 CET 2012


 plugins/calendar/calendar.php                         |   24 +---
 plugins/calendar/drivers/calendar_driver.php          |   12 +-
 plugins/calendar/drivers/database/database_driver.php |   49 ++++++++-
 plugins/calendar/drivers/kolab/kolab_driver.php       |   91 ++++++++++++------
 plugins/kolab_delegation/kolab_delegation.php         |   25 +++-
 plugins/kolab_delegation/kolab_delegation_engine.php  |    4 
 6 files changed, 142 insertions(+), 63 deletions(-)

New commits:
commit f0ef421c0071c997a1513e5f67aeac4a040daf1b
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Tue Dec 4 20:10:04 2012 +0100

    Fix Invitations can not be accepted when calendars are shared with certain rights (#1406)

diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php
index e344c40..24d929a 100644
--- a/plugins/calendar/calendar.php
+++ b/plugins/calendar/calendar.php
@@ -234,7 +234,7 @@ class calendar extends rcube_plugin
   public function get_default_calendar($writeable = false)
   {
     $default_id = $this->rc->config->get('calendar_default_calendar');
-    $calendars = $this->driver->list_calendars();
+    $calendars = $this->driver->list_calendars(false, true);
     $calendar = $calendars[$default_id] ?: null;
     if (!$calendar || ($writeable && $calendar['readonly'])) {
       foreach ($calendars as $cal) {
@@ -402,9 +402,8 @@ class calendar extends rcube_plugin
       // default calendar selection
       $field_id = 'rcmfd_default_calendar';
       $select_cal = new html_select(array('name' => '_default_calendar', 'id' => $field_id, 'is_escaped' => true));
-      foreach ((array)$this->driver->list_calendars() as $id => $prop) {
-        if (!$prop['readonly'])
-          $select_cal->add($prop['name'], strval($id));
+      foreach ((array)$this->driver->list_calendars(false, true) as $id => $prop) {
+        $select_cal->add($prop['name'], strval($id));
         if ($prop['default'])
           $default_calendar = $id;
       }
@@ -705,7 +704,7 @@ class calendar extends rcube_plugin
         $status = $event['fallback'];
         $html = html::div('rsvp-status', $status != 'CANCELLED' ? $this->gettext('acceptinvitation') : '');
         $this->load_driver();
-        if ($existing = $this->driver->get_event($event, true)) {
+        if ($existing = $this->driver->get_event($event, true, false, true)) {
           $emails = $this->get_user_emails();
           foreach ($existing['attendees'] as $i => $attendee) {
             if ($attendee['email'] && in_array($attendee['email'], $emails)) {
@@ -716,7 +715,7 @@ class calendar extends rcube_plugin
         }
         else {
           // get a list of writeable calendars
-          $calendars = $this->driver->list_calendars();
+          $calendars = $this->driver->list_calendars(false, true);
           $calendar_select = new html_select(array('name' => 'calendar', 'id' => 'calendar-saveto', 'is_escaped' => true));
           $numcals = 0;
           foreach ($calendars as $calendar) {
@@ -949,7 +948,7 @@ class calendar extends rcube_plugin
     if (!$start) $start = mktime(0, 0, 0, 1, date('n'), date('Y')-1);
     if (!$end) $end = mktime(0, 0, 0, 31, 12, date('Y')+10);
     $calid = $calname = get_input_value('source', RCUBE_INPUT_GET);
-    $calendars = $this->driver->list_calendars();
+    $calendars = $this->driver->list_calendars(true);
     
     if ($calendars[$calid]) {
       $calname = $calendars[$calid]['name'] ? $calendars[$calid]['name'] : $calid;
@@ -1163,12 +1162,8 @@ class calendar extends rcube_plugin
   {
     $num = $_REQUEST['_num'] ? intval($_REQUEST['_num']) : 100;
     $cats = array_keys($this->driver->list_categories());
-    $cals = array();
-    foreach ($this->driver->list_calendars() as $cid => $cal) {
-      if ($cal['active'])
-        $cals[$cid] = $cal;
-    }
-    
+    $cals = $this->driver->list_calendars(true);
+
     while ($count++ < $num) {
       $start = round((time() + rand(-2600, 2600) * 1000) / 300) * 300;
       $duration = round(rand(30, 360) / 30) * 30 * 60;
@@ -1789,7 +1784,7 @@ class calendar extends rcube_plugin
     if (!empty($events) && ($event = $events[$index])) {
       // find writeable calendar to store event
       $cal_id = !empty($_REQUEST['_calendar']) ? get_input_value('_calendar', RCUBE_INPUT_POST) : null;
-      $calendars = $this->driver->list_calendars();
+      $calendars = $this->driver->list_calendars(false, true);
       $calendar = $calendars[$cal_id] ?: $this->get_default_calendar(true);
 
       // update my attendee status according to submitted method
@@ -1852,6 +1847,7 @@ class calendar extends rcube_plugin
           // import the (newer) event
           else if ($event['sequence'] >= $existing['sequence'] || $event['changed'] >= $existing['changed']) {
             $event['id'] = $existing['id'];
+            $event['calendar'] = $existing['calendar'];
             $success = $this->driver->edit_event($event);
           }
           else if (!empty($status)) {
diff --git a/plugins/calendar/drivers/calendar_driver.php b/plugins/calendar/drivers/calendar_driver.php
index 15183e9..a0d0c52 100644
--- a/plugins/calendar/drivers/calendar_driver.php
+++ b/plugins/calendar/drivers/calendar_driver.php
@@ -92,8 +92,13 @@ abstract class calendar_driver
 
   /**
    * Get a list of available calendars from this source
+   *
+   * @param bool $active   Return only active calendars
+   * @param bool $personal Return only personal calendars
+   *
+   * @return array List of calendars
    */
-  abstract function list_calendars();
+  abstract function list_calendars($active = false, $personal = false);
 
   /**
    * Create a new calendar assigned to the current user
@@ -208,9 +213,12 @@ abstract class calendar_driver
    *        id: Event identifier
    *  calendar: Calendar identifier (optional)
    * @param boolean If true, only writeable calendars shall be searched
+   * @param boolean If true, only active calendars shall be searched
+   * @param boolean If true, only personal calendars shall be searched
+   *
    * @return array Event object as hash array
    */
-  abstract function get_event($event, $writeable = null);
+  abstract function get_event($event, $writeable = false, $active = false, $personal = false);
 
   /**
    * Get events from source.
diff --git a/plugins/calendar/drivers/database/database_driver.php b/plugins/calendar/drivers/database/database_driver.php
index 1f26446..733aa2c 100644
--- a/plugins/calendar/drivers/database/database_driver.php
+++ b/plugins/calendar/drivers/database/database_driver.php
@@ -103,18 +103,36 @@ class database_driver extends calendar_driver
 
   /**
    * Get a list of available calendars from this source
+   *
+   * @param bool $active   Return only active calendars
+   * @param bool $personal Return only personal calendars
+   *
+   * @return array List of calendars
    */
-  public function list_calendars()
+  public function list_calendars($active = false, $personal = false)
   {
     // attempt to create a default calendar for this user
     if (empty($this->calendars)) {
       if ($this->create_calendar(array('name' => 'Default', 'color' => 'cc0000')))
         $this->_read_calendars();
     }
-    
-    return $this->calendars;
+
+    $calendars = $this->calendars;
+
+    // filter active calendars
+    if ($active) {
+      foreach ($calendars as $idx => $cal) {
+        if (!$cal['active']) {
+          unset($calendars[$idx]);
+        }
+      }
+    }
+
+    // 'personal' is unsupported in this driver
+
+    return $calendars;
   }
-  
+
   /**
    * Create a new calendar assigned to the current user
    *
@@ -651,23 +669,38 @@ class database_driver extends calendar_driver
   /**
    * Return data of a specific event
    * @param mixed  Hash array with event properties or event UID
-   * @param boolean Only search in writeable calendars (currently ignored)
+   * @param boolean Only search in writeable calendars (ignored)
+   * @param boolean Only search in active calendars
+   * @param boolean Only search in personal calendars (ignored)
    * @return array Hash array with event properties
    */
-  public function get_event($event, $writeable = null)
+  public function get_event($event, $writeable = false, $active = false, $personal = false)
   {
     $id = is_array($event) ? ($event['id'] ? $event['id'] : $event['uid']) : $event;
     $col = is_array($event) && is_numeric($id) ? 'event_id' : 'uid';
 
     if ($this->cache[$id])
       return $this->cache[$id];
-    
+
+    if ($active) {
+      $calendars = $this->calendars;
+      foreach ($calendars as $idx => $cal) {
+        if (!$cal['active']) {
+          unset($calendars[$idx]);
+        }
+      }
+      $cals = join(',', $calendars);
+    }
+    else {
+      $cals = $this->calendar_ids;
+    }
+
     $result = $this->rc->db->query(sprintf(
       "SELECT e.*, COUNT(a.attachment_id) AS _attachments FROM " . $this->db_events . " AS e
        LEFT JOIN " . $this->db_attachments . " AS a ON (a.event_id = e.event_id OR a.event_id = e.recurrence_id)
        WHERE e.calendar_id IN (%s)
        AND e.$col=?",
-       $this->calendar_ids
+       $cals
       ),
       $id);
 
diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index 9392ddc..c9cc7e7 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -96,8 +96,13 @@ class kolab_driver extends calendar_driver
 
   /**
    * Get a list of available calendars from this source
+   *
+   * @param bool $active   Return only active calendars
+   * @param bool $personal Return only personal calendars
+   *
+   * @return array List of calendars
    */
-  public function list_calendars()
+  public function list_calendars($active = false, $personal = false)
   {
     // attempt to create a default calendar for this user
     if (!$this->has_writeable) {
@@ -107,24 +112,23 @@ class kolab_driver extends calendar_driver
       }
     }
 
-    $calendars = $names = array();
-
-    foreach ($this->calendars as $id => $cal) {
-      if ($cal->ready) {
-        $name = kolab_storage::folder_displayname($cal->get_name(), $names);
-
-        $calendars[$cal->id] = array(
-          'id'       => $cal->id,
-          'name'     => $name,
-          'editname' => $cal->get_foldername(),
-          'color'    => $cal->get_color(),
-          'readonly' => $cal->readonly,
-          'showalarms' => $cal->alarms,
-          'class_name' => $cal->get_namespace(),
-          'default'  => $cal->storage->default,
-          'active'   => $cal->storage->is_subscribed(kolab_storage::SERVERSIDE_SUBSCRIPTION),
-        );
-      }
+    $calendars = $this->filter_calendars(false, $active, $personal);
+    $names     = array();
+
+    foreach ($calendars as $id => $cal) {
+      $name = kolab_storage::folder_displayname($cal->get_name(), $names);
+
+      $calendars[$id] = array(
+        'id'       => $cal->id,
+        'name'     => $name,
+        'editname' => $cal->get_foldername(),
+        'color'    => $cal->get_color(),
+        'readonly' => $cal->readonly,
+        'showalarms' => $cal->alarms,
+        'class_name' => $cal->get_namespace(),
+        'default'  => $cal->storage->default,
+        'active'   => $cal->storage->is_subscribed(),
+      );
     }
 
     return $calendars;
@@ -132,6 +136,37 @@ class kolab_driver extends calendar_driver
 
 
   /**
+   * Get list of calendars according to specified filters
+   *
+   * @param bool $writable Return only writeable calendars
+   * @param bool $active   Return only active calendars
+   * @param bool $personal Return only personal calendars
+   *
+   * @return array List of calendars
+   */
+  protected function filter_calendars($writable = false, $active = false, $personal = false)
+  {
+    $calendars = array();
+    foreach ($this->calendars as $cal) {
+      if (!$cal->ready) {
+        continue;
+      }
+      if ($writeable && $cal->readonly) {
+        continue;
+      }
+      if ($active && !$cal->storage->is_subscribed()) {
+        continue;
+      }
+      if ($personal && $cal->get_namespace() != 'personal') {
+        continue;
+      }
+      $calendars[$cal->id] = $cal;
+    }
+
+    return $calendars;
+  }
+
+  /**
    * Create a new calendar assigned to the current user
    *
    * @param array Hash array with calendar properties
@@ -252,7 +287,7 @@ class kolab_driver extends calendar_driver
    * @see calendar_driver::get_event()
    * @return array Hash array with event properties, false if not found
    */
-  public function get_event($event, $writeable = null)
+  public function get_event($event, $writeable = false, $active = false, $personal = false)
   {
     if (is_array($event)) {
       $id = $event['id'] ? $event['id'] : $event['uid'];
@@ -261,16 +296,16 @@ class kolab_driver extends calendar_driver
     else {
       $id = $event;
     }
-    
-    if ($cal && ($storage = $this->calendars[$cal])) {
-      return $storage->get_event($id);
+
+    if ($cal) {
+      if ($storage = $this->calendars[$cal]) {
+        return $storage->get_event($id);
+      }
     }
     // iterate over all calendar folders and search for the event ID
-    else if (!$cal) {
-      foreach ($this->calendars as $storage) {
-        if ($writeable && $storage->readonly)
-          continue;
-        if ($result = $storage->get_event($id)) {
+    else {
+      foreach ($this->filter_calendars($writeable, $active, $personal) as $calendar) {
+        if ($result = $calendar->get_event($id)) {
           return $result;
         }
       }


commit cda4c47325851acd0d8e4cfe370f89406c1a67cc
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Tue Dec 4 20:08:14 2012 +0100

    Implemented kolab_delegation_purge_identities setting

diff --git a/plugins/kolab_delegation/kolab_delegation.php b/plugins/kolab_delegation/kolab_delegation.php
index a3902af..07be816 100644
--- a/plugins/kolab_delegation/kolab_delegation.php
+++ b/plugins/kolab_delegation/kolab_delegation.php
@@ -88,16 +88,12 @@ class kolab_delegation extends rcube_plugin
         //       or alias email if 'kolab_delegation_purge_identities' is set.
 
         $engine     = $this->engine();
-        $delegators = $engine->list_delegators();
-
-        if (empty($delegators)) {
-            return $args;
-        }
-
         $storage    = $this->rc->get_storage();
+        $delegators = $engine->list_delegators();
         $other_ns   = $storage->get_namespace('other');
         $folders    = $storage->list_folders();
         $identities = $this->rc->user->list_identities();
+        $emails     = array();
 
         // convert identities to simpler format for faster access
         foreach ($identities as $idx => $ident) {
@@ -110,16 +106,17 @@ class kolab_delegation extends rcube_plugin
 //                    'html_signature' => $ident['html_signature'],
                 );
             }
-            $identities[$idx] = $ident['email'];
+            $emails[$ident['identity_id']] = $ident['email'];
         }
 
         // for every delegator...
         foreach ($delegators as $delegator) {
-            $email_arr = (array)$delegator['email'];
-            $diff      = array_intersect($identities, $email_arr);
+            $email_arr = $delegator['email'];
+            $diff      = array_intersect($emails, $email_arr);
 
             // identity with delegator's email already exist, do nothing
             if (count($diff)) {
+                $emails = array_diff($emails, $email_arr);
                 continue;
             }
 
@@ -146,6 +143,16 @@ class kolab_delegation extends rcube_plugin
             }
         }
 
+        // remove identities that "do not belong" to user nor delegators
+        if ($this->rc->config->get('kolab_delegation_purge_identities')) {
+            $user = $engine->user(true);
+            $emails = array_diff($emails, $user['email']);
+
+            foreach (array_keys($emails) as $idx) {
+                $this->rc->user->delete_identity($idx);
+            }
+        }
+
         return $args;
     }
 
diff --git a/plugins/kolab_delegation/kolab_delegation_engine.php b/plugins/kolab_delegation/kolab_delegation_engine.php
index e6c2ed7..b86ee1f 100644
--- a/plugins/kolab_delegation/kolab_delegation_engine.php
+++ b/plugins/kolab_delegation/kolab_delegation_engine.php
@@ -450,7 +450,7 @@ class kolab_delegation_engine
      *
      * @return array User data
      */
-    public function user()
+    public function user($parsed = false)
     {
         if (!isset($this->cache['user'])) {
             $ldap = $this->ldap();
@@ -465,7 +465,7 @@ class kolab_delegation_engine
             $this->cache['user'] = $ldap->get_record($this->ldap_dn, true);
         }
 
-        return $this->cache['user'];
+        return $parsed ? $this->parse_ldap_record($this->cache['user']) : $this->cache['user'];
     }
 
     /**





More information about the commits mailing list