]> source.dussan.org Git - nextcloud-server.git/commitdiff
Return null when requesting tags for null user
authorVincent Petry <pvince81@owncloud.com>
Wed, 25 Feb 2015 16:20:26 +0000 (17:20 +0100)
committerVincent Petry <pvince81@owncloud.com>
Wed, 25 Feb 2015 16:20:26 +0000 (17:20 +0100)
The TagManager->load() now returns null if the user is not authenticated
instead of failing with an error.

lib/private/tagmanager.php
tests/lib/tags.php

index 9bc461f25eb2ba68c3de9acb10a8c6f504a8558d..1c7ace114691cf87b02969c2e605f090011e2d4e 100644 (file)
@@ -65,6 +65,11 @@ class TagManager implements \OCP\ITagManager {
        */
        public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) {
                if (is_null($userId)) {
+                       $user = $this->userSession->getUser();
+                       if ($user === null) {
+                               // nothing we can do without a user
+                               return null;
+                       }
                        $userId = $this->userSession->getUser()->getUId();
                }
                return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared);
index 547cd302d5dc58da5ccc7140d8e1561521529332..a50855c88f306662f765a8c1c0daf3418d1e739a 100644 (file)
@@ -62,6 +62,16 @@ class Test_Tags extends \Test\TestCase {
                parent::tearDown();
        }
 
+       public function testTagManagerWithoutUserReturnsNull() {
+               $this->userSession = $this->getMock('\OCP\IUserSession');
+               $this->userSession
+                       ->expects($this->any())
+                       ->method('getUser')
+                       ->will($this->returnValue(null));
+               $this->tagMgr = new OC\TagManager($this->tagMapper, $this->userSession);
+               $this->assertNull($this->tagMgr->load($this->objectType));
+       }
+
        public function testInstantiateWithDefaults() {
                $defaultTags = array('Friends', 'Family', 'Work', 'Other');