[Pkg-owncloud-commits] [owncloud] 02/118: Return null when requesting tags for null user

David Prévot taffit at moszumanska.debian.org
Fri Mar 27 22:13:05 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit b63a6a4fc4bdd0df7118f6478768cc3c3e552668
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Wed Feb 25 17:20:26 2015 +0100

    Return null when requesting tags for null user
    
    The TagManager->load() now returns null if the user is not authenticated
    instead of failing with an error.
    
    Backport of 9ee37169a6615e06c397e3b623ca55805aebcea3 from master
---
 lib/private/tagmanager.php |  5 +++++
 tests/lib/tags.php         | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/lib/private/tagmanager.php b/lib/private/tagmanager.php
index 6c7eeab..c0ba56a 100644
--- a/lib/private/tagmanager.php
+++ b/lib/private/tagmanager.php
@@ -76,6 +76,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);
diff --git a/tests/lib/tags.php b/tests/lib/tags.php
index 547cd30..a50855c 100644
--- a/tests/lib/tags.php
+++ b/tests/lib/tags.php
@@ -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');
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list