0009934: can't save shared tag with anyoneAccountDisabled
authorPhilipp Schüle <p.schuele@metaways.de>
Fri, 23 May 2014 09:17:38 +0000 (11:17 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 23 May 2014 09:36:49 +0000 (11:36 +0200)
* we need to ignore acl when fetching shared tag in admin area

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

Change-Id: I51b60dda1285efec3fa949cf803d0e8f6339234a
Reviewed-on: http://gerrit.tine20.com/customers/682
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Admin/JsonTest.php
tine20/Admin/Controller/Tags.php
tine20/Tinebase/Tags.php

index 22d69c5..5aea9a8 100644 (file)
@@ -4,16 +4,11 @@
  * 
  * @package     Admin
  * @license     http://www.gnu.org/licenses/agpl.html
- * @copyright   Copyright (c) 2008-2013 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2008-2014 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Philipp Schüle <p.schuele@metaways.de>
  */
 
 /**
- * Test helper
- */
-require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
-
-/**
  * Test class for Tinebase_Admin json frontend
  */
 class Admin_JsonTest extends TestCase
@@ -79,6 +74,12 @@ class Admin_JsonTest extends TestCase
         ));
     }
     
+    protected function tearDown()
+    {
+        parent::tearDown();
+        Tinebase_Config::getInstance()->set(Tinebase_Config::ANYONE_ACCOUNT_DISABLED, false);
+    }
+    
     /**
      * try to save group data
      * 
@@ -816,6 +817,29 @@ class Admin_JsonTest extends TestCase
     }
     
     /**
+     * testSaveTagWithoutAnyone
+     * 
+     * @see 0009934: can't save shared tag with anyoneAccountDisabled
+     */
+    public function testSaveTagWithoutAnyone()
+    {
+        Tinebase_Config::getInstance()->set(Tinebase_Config::ANYONE_ACCOUNT_DISABLED, true);
+        
+        $defaultUserGroup = Tinebase_Group::getInstance()->getDefaultGroup();
+        $tagData = $this->_getTagData();
+        $tagData['rights'] = array(array(
+            'account_id' => $defaultUserGroup->getId(),
+            'account_type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP,
+            'view_right' => true,
+            'use_right' => true
+        ));
+        $this->objects['tag'] = $this->_json->saveTag($tagData);
+        
+        $this->assertEquals('supertag', $this->objects['tag']['name']);
+        $this->assertEquals(1, count($this->objects['tag']['rights']));
+    }
+    
+    /**
      * test searchContainers
      */
     public function testSearchContainers()
index 08eccd6..c3abaad 100644 (file)
@@ -101,7 +101,7 @@ class Admin_Controller_Tags extends Tinebase_Controller_Record_Abstract
      */
     public function get($_tagId)
     {
-        $fullTag = parent::get($_tagId);
+        $fullTag = Tinebase_Tags::getInstance()->getFullTagById($_tagId, /* ignoreAcl = */ true);
         
         $fullTag->rights =  Tinebase_Tags::getInstance()->getRights($_tagId);
         $fullTag->contexts = Tinebase_Tags::getInstance()->getContexts($_tagId);
index d710975..c1f9eda 100644 (file)
@@ -5,7 +5,7 @@
  * @package     Tinebase
  * @subpackage  Tags
  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
- * @copyright   Copyright (c) 2008-2012 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2008-2014 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Cornelius Weiss <c.weiss@metaways.de>
  *
  * @todo        this should implement Tinebase_Backend_Sql_Interface or use standard sql backend + refactor this
@@ -171,19 +171,31 @@ class Tinebase_Tags
      */
     public function get($_id, $_getDeleted = FALSE)
     {
-        $tagId = ($_id instanceof Tinebase_Model_Tag) ? $_id->getId() : $_id;
-
-        $tag = Tinebase_Tags::getInstance()->getTagsById($tagId);
-
-        if (count($tag) == 0) {
-            throw new Tinebase_Exception_NotFound("Tag $_id not found or insufficient rights.");
-        }
-
-        $fullTag = new Tinebase_Model_FullTag($tag[0]->toArray(), true);
-
+        $fullTag = $this->getFullTagById($_id);
         return $fullTag;
     }
-
+    
+    /**
+     * get full tag by id
+     * 
+     * @param string|Tinebase_Model_Tag $id
+     * @param string $ignoreAcl
+     * @throws Tinebase_Exception_NotFound
+     * @return Tinebase_Model_FullTag
+     */
+    public function getFullTagById($id, $ignoreAcl = false)
+    {
+        $tagId = ($id instanceof Tinebase_Model_Tag) ? $id->getId() : $id;
+        
+        $tags = Tinebase_Tags::getInstance()->getTagsById($tagId, Tinebase_Model_TagRight::VIEW_RIGHT, $ignoreAcl);
+        
+        if (count($tags) == 0) {
+            throw new Tinebase_Exception_NotFound("Tag $id not found or insufficient rights.");
+        }
+        
+        return new Tinebase_Model_FullTag($tags[0]->toArray(), true);
+    }
+    
     /**
      * Returns (bare) tags identified by its id(s)
      *