make Calendars shareable via CalDAV
authorCornelius Weiß <mail@corneliusweiss.de>
Tue, 25 Feb 2014 07:05:27 +0000 (08:05 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 4 Sep 2014 09:25:28 +0000 (11:25 +0200)
- fix grant resolving for containers user has no admin grant for

Change-Id: I9ee4d4aec4415bcdc5f7bbaa95c4b9e30067072d
Reviewed-on: http://gerrit.tine20.com/customers/367
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Frontend/WebDAV/ContainerTest.php
tine20/Calendar/Frontend/WebDAV/Container.php

index 67a169d..f42b61e 100644 (file)
@@ -81,9 +81,6 @@ class Calendar_Frontend_WebDAV_ContainerTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($this->objects['initialContainer']->name, $result);
     }
     
-    /**
-     * assert that name of folder is container name
-     */
     public function testGetOwner()
     {
         $container = new Calendar_Frontend_WebDAV_Container($this->objects['initialContainer']);
@@ -93,9 +90,6 @@ class Calendar_Frontend_WebDAV_ContainerTest extends PHPUnit_Framework_TestCase
         $this->assertEquals('principals/users/' . Tinebase_Core::getUser()->contact_id, $result);
     }
     
-    /**
-     * assert that name of folder is container name
-     */
     public function testGetACL()
     {
         $container = new Calendar_Frontend_WebDAV_Container($this->objects['initialContainer']);
@@ -107,9 +101,6 @@ class Calendar_Frontend_WebDAV_ContainerTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(6, count($result));
     }
     
-    /**
-     * assert that name of folder is container name
-     */
     public function testGetIdAsName()
     {
         $container = new Calendar_Frontend_WebDAV_Container($this->objects['initialContainer'], true);
@@ -306,6 +297,23 @@ class Calendar_Frontend_WebDAV_ContainerTest extends PHPUnit_Framework_TestCase
     }
     
     /**
+     * test Calendar_Frontend_WebDAV_Container::getShares for container user has no admin grant for
+     */
+    public function testGetSharesWithoutRights()
+    {
+        $jmcblack = array_value('jmcblack', Zend_Registry::get('personas'));
+        $jmcblacksCalId = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::DEFAULTCALENDAR, $jmcblack->getId());
+        $jmcblacksCal = Tinebase_Container::getInstance()->get($jmcblacksCalId);
+        
+        $container = new Calendar_Frontend_WebDAV_Container($jmcblacksCal);
+    
+        $shares = $container->getShares();
+    
+        $this->assertEquals(1, count($shares));
+        $this->assertTrue((bool)$shares[0]['readOnly']);
+    }
+    
+    /**
      * return vcalendar as string and replace organizers email address with emailaddess of current user
      * 
      * @param string $_filename  file to open
index afb2e99..43623ec 100644 (file)
@@ -262,7 +262,14 @@ class Calendar_Frontend_WebDAV_Container extends Tinebase_WebDav_Container_Abstr
     {
         $result = array();
         
-        foreach (Tinebase_Container::getInstance()->getGrantsOfContainer($this->_container) as $grant) {
+        try {
+            $grants = Tinebase_Container::getInstance()->getGrantsOfContainer($this->_container);
+        } catch (Tinebase_Exception_AccessDenied $e) {
+            // user has no right/grant to see all grants of this container
+            $grants = new Tinebase_Record_RecordSet('Tinebase_Model_Grants');
+            $grants->addRecord(Tinebase_Container::getInstance()->getGrantsOfAccount(Tinebase_Core::getUser(), $this->_container));
+        }
+        foreach ($grants as $grant) {
             
             switch ($grant->account_type) {
                 case 'anyone':