summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-03-11 16:30:22 +0100
committerMorris Jobke <hey@morrisjobke.de>2015-03-11 16:30:22 +0100
commitb95405e09a81ff63ea1ae3d6c48a5f29cad8d8ed (patch)
tree30626069409f08c989fb5628bac9ac4725782b41
parent8a5ef62b60faa04e7f362623734fd42afc98814a (diff)
parentb63a6a4fc4bdd0df7118f6478768cc3c3e552668 (diff)
downloadnextcloud-server-b95405e09a81ff63ea1ae3d6c48a5f29cad8d8ed.tar.gz
nextcloud-server-b95405e09a81ff63ea1ae3d6c48a5f29cad8d8ed.zip
Merge pull request #14514 from owncloud/stable8-tagmanager-nouser
[stable8] Return null when requesting tags for null user
-rw-r--r--lib/private/tagmanager.php5
-rw-r--r--tests/lib/tags.php10
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/private/tagmanager.php b/lib/private/tagmanager.php
index 6c7eeab87eb..c0ba56a2da8 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 547cd302d5d..a50855c88f3 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');