0011024: don't show external imip events in shared calendars
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 7 May 2015 13:49:07 +0000 (15:49 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 13 May 2015 13:47:20 +0000 (15:47 +0200)
* do not ignore acl when fetching shared containers in Calendar
* fixes some typos and improves formatting

https://forge.tine20.org/view.php?id=11024

Change-Id: I81c1f6224622a0734266a8a8e4c38d675321b39e
Reviewed-on: http://gerrit.tine20.com/customers/1915
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Frontend/iMIPTest.php
tine20/Calendar/Controller/Event.php
tine20/Calendar/Model/CalendarFilter.php
tine20/Tinebase/Container.php
tine20/Tinebase/Model/Filter/Container.php

index 61aaae2..84f9bd3 100644 (file)
@@ -4,7 +4,7 @@
  * 
  * @package     Calendar
  * @license     http://www.gnu.org/licenses/agpl.html
- * @copyright   Copyright (c) 2011-2014 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2011-2015 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Philipp Schüle <p.schuele@metaways.de>
  * 
  * @todo        add tests testInvitationCancel and testOrganizerSendBy
@@ -123,6 +123,26 @@ class Calendar_Frontend_iMIPTest extends TestCase
     }
 
     /**
+     * testSearchSharedCalendarsForExternalEvents
+     *
+     * @see 0011024: don't show external imip events in shared calendars
+     */
+    public function testSearchSharedCalendarsForExternalEvents()
+    {
+        $iMIP = $this->testExternalInvitationRequestAutoProcess();
+        $this->_iMIPFrontendMock->process($iMIP, Calendar_Model_Attender::STATUS_ACCEPTED);
+        $this->_eventIdsToDelete[] = $iMIP->event->getId();
+
+        $filter = new Calendar_Model_EventFilter(array(
+            array('field' => 'container_id', 'operator' => 'equals', 'value' => '/shared')
+        ));
+        $eventsInShared = Calendar_Controller_Event::getInstance()->search($filter);
+
+        $this->assertFalse(in_array($iMIP->event->getId(), $eventsInShared->getArrayOfIds()),
+            'found event in shared calendar: ' . print_r($iMIP->event->toArray(), true));
+    }
+
+    /**
     * testSupportedPrecondition
     */
     public function testUnsupportedPrecondition()
index c0b6a81..da39029 100644 (file)
@@ -1496,7 +1496,7 @@ class Calendar_Controller_Event extends Tinebase_Controller_Record_Abstract impl
             }
             
             if (! $container instanceof Tinebase_Model_Container || $container->type == Tinebase_Model_Container::TYPE_PERSONAL) {
-                // move into spechial (external users) container
+                // move into special (external users) container
                 $container = Calendar_Controller::getInstance()->getInvitationContainer($_record->resolveOrganizer());
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
                     . ' Setting container_id to ' . $container->getId() . ' for external organizer ' . $_record->organizer->email);
index 5009814..b8eb38e 100644 (file)
@@ -5,7 +5,7 @@
  * @package     Calendar
  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
  * @author      Cornelius Weiss <c.weiss@metaways.de>
- * @copyright   Copyright (c) 2009 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2009-2015 Metaways Infosystems GmbH (http://www.metaways.de)
  */
 
 /**
@@ -26,7 +26,7 @@ class Calendar_Model_CalendarFilter extends Tinebase_Model_Filter_Container
 {
     
     /**
-     * @var array One of theese grants must be given
+     * @var array One of these grants must be given
      */
     protected $_requiredGrants = NULL;
     
@@ -92,10 +92,10 @@ class Calendar_Model_CalendarFilter extends Tinebase_Model_Filter_Container
      */
     public function getRelatedAttendeeFilter()
     {
-        // allways set currentaccount
+        // always set current account
         $userIds = array(Tinebase_Core::getUser()->getId());
         
-        // rip users from pathes
+        // rip users from paths
         foreach ((array) $this->getValue() as $value) {
             if (preg_match("/^\/personal\/([0-9a-z_\-]+)/i", $value, $matches)) {
                 // transform current user 
@@ -117,4 +117,20 @@ class Calendar_Model_CalendarFilter extends Tinebase_Model_Filter_Container
         $attenderFilter = new Calendar_Model_AttenderFilter('attender', 'in', $attendeeFilterData);
         return $attenderFilter;
     }
+
+    /**
+     * fetch shared containers
+     *
+     * NOTE: this is needed because we don't want external organizers events to be visible if 'shared' node is requested
+     *
+     * @param $currentAccount
+     * @param $appName
+     * @return mixed
+     */
+    protected function _getSharedContainer($currentAccount, $appName)
+    {
+        return Tinebase_Container::getInstance()->getSharedContainer($currentAccount, $appName, array(
+            Tinebase_Model_Grants::GRANT_READ
+        ))->getId();
+    }
 }
index cf548a3..6d7a79b 100644 (file)
@@ -805,7 +805,8 @@ class Tinebase_Container extends Tinebase_Backend_Sql_Abstract
         $this->saveInClassCache(__FUNCTION__, $classCacheId, $containers);
         
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ 
-            . ' Found ' . count($containers) . ' shared container(s) in application ' . $application->name);
+            . ' Found ' . count($containers) . ' shared container(s) in application ' . $application->name
+            . ' with grant(s): ' . implode(',', (array)$grant));
         
         return $containers;
     }
index 0316146..3c0e5bb 100644 (file)
@@ -219,7 +219,8 @@ class Tinebase_Model_Filter_Container extends Tinebase_Model_Filter_Abstract imp
     protected function _resolve()
     {
         if ($this->_isResolved) {
-            //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' already resolved');
+            if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ .
+                ' already resolved');
             return;
         }
         
@@ -231,6 +232,9 @@ class Tinebase_Model_Filter_Container extends Tinebase_Model_Filter_Abstract imp
         foreach((array)$this->_value as $path) {
             $this->_containerIds = array_merge($this->_containerIds, $this->_resolvePath($path));
         }
+
+        if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ .
+            ' resolved ids: ' . print_r($this->_containerIds, true));
         
         $this->_containerIds = array_unique($this->_containerIds);
         
@@ -279,10 +283,14 @@ class Tinebase_Model_Filter_Container extends Tinebase_Model_Filter_Abstract imp
         $appName = $this->_options['applicationName'];
         
         switch ($_node) {
-            case 'all':        return Tinebase_Container::getInstance()->getContainerByACL($currentAccount, $appName, $this->_requiredGrants, TRUE, $this->_options['ignoreAcl']);
-            case 'personal':   return Tinebase_Container::getInstance()->getPersonalContainer($currentAccount, $appName, $_ownerId, $this->_requiredGrants, $this->_options['ignoreAcl'])->getId();
-            case 'shared':     return Tinebase_Container::getInstance()->getSharedContainer($currentAccount, $appName, $this->_requiredGrants, $this->_options['ignoreAcl'])->getId();
-            case Tinebase_Model_Container::TYPE_OTHERUSERS: return Tinebase_Container::getInstance()->getOtherUsersContainer($currentAccount, $appName, $this->_requiredGrants, $this->_options['ignoreAcl'])->getId();
+            case 'all':        return Tinebase_Container::getInstance()->getContainerByACL($currentAccount,
+                $appName, $this->_requiredGrants, TRUE, $this->_options['ignoreAcl']);
+            case 'personal':   return Tinebase_Container::getInstance()->getPersonalContainer($currentAccount,
+                $appName, $_ownerId, $this->_requiredGrants, $this->_options['ignoreAcl'])->getId();
+            case 'shared':     return $this->_getSharedContainer($currentAccount, $appName);
+            case Tinebase_Model_Container::TYPE_OTHERUSERS:
+                return Tinebase_Container::getInstance()->getOtherUsersContainer($currentAccount, $appName,
+                    $this->_requiredGrants, $this->_options['ignoreAcl'])->getId();
             case 'internal':
                 // @todo remove legacy code
                 if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ 
@@ -294,6 +302,19 @@ class Tinebase_Model_Filter_Container extends Tinebase_Model_Filter_Abstract imp
         
         return $ids;
     }
+
+    /**
+     * fetch shared containers
+     *
+     * @param $currentAccount
+     * @param $appName
+     * @return mixed
+     */
+    protected function _getSharedContainer($currentAccount, $appName)
+    {
+        return Tinebase_Container::getInstance()->getSharedContainer($currentAccount, $appName, $this->_requiredGrants,
+            $this->_options['ignoreAcl'])->getId();
+    }
     
     /**
      * converts given *Node params to a path