Skip to content
Snippets Groups Projects
Commit 64c333c4 authored by Vincent Petry's avatar Vincent Petry
Browse files

Merge pull request #14508 from owncloud/tagmanager-nouser

Return null when requesting tags for null user
parents e8c3e331 9ee37169
No related branches found
No related tags found
No related merge requests found
...@@ -65,6 +65,11 @@ class TagManager implements \OCP\ITagManager { ...@@ -65,6 +65,11 @@ class TagManager implements \OCP\ITagManager {
*/ */
public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) { public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) {
if (is_null($userId)) { 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(); $userId = $this->userSession->getUser()->getUId();
} }
return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared); return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared);
......
...@@ -62,6 +62,16 @@ class Test_Tags extends \Test\TestCase { ...@@ -62,6 +62,16 @@ class Test_Tags extends \Test\TestCase {
parent::tearDown(); 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() { public function testInstantiateWithDefaults() {
$defaultTags = array('Friends', 'Family', 'Work', 'Other'); $defaultTags = array('Friends', 'Family', 'Work', 'Other');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment