Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/private/TagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OCP\IDBConnection;
use OCP\ITagManager;
use OCP\ITags;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\User\Events\UserDeletedEvent;
use Psr\Log\LoggerInterface;
Expand All @@ -29,6 +30,7 @@ class TagManager implements ITagManager, IEventListener {
public function __construct(
private TagMapper $mapper,
private IUserSession $userSession,
private IUserManager $userManager,
private IDBConnection $connection,
private LoggerInterface $logger,
private IEventDispatcher $dispatcher,
Expand Down Expand Up @@ -59,7 +61,7 @@ public function load($type, $defaultTags = [], $includeShared = false, $userId =
$userId = $this->userSession->getUser()->getUId();
}
$userFolder = $this->rootFolder->getUserFolder($userId);
return new Tags($this->mapper, $userId, $type, $this->logger, $this->connection, $this->dispatcher, $this->userSession, $userFolder, $defaultTags);
return new Tags($this->mapper, $userId, $type, $this->logger, $this->connection, $this->dispatcher, $this->userManager, $userFolder, $defaultTags);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/private/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use OCP\Files\Folder;
use OCP\IDBConnection;
use OCP\ITags;
use OCP\IUserSession;
use OCP\IUserManager;
use OCP\Share_Backend;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -65,7 +65,7 @@
private LoggerInterface $logger,
private IDBConnection $db,
private IEventDispatcher $dispatcher,
private IUserSession $userSession,
private IUserManager $userManager,
private Folder $userFolder,
array $defaultTags = [],
) {
Expand Down Expand Up @@ -538,7 +538,7 @@
}
}

$this->dispatcher->dispatchTyped(new NodeAddedToFavorite($this->userSession->getUser(), $objid, $path));
$this->dispatcher->dispatchTyped(new NodeAddedToFavorite($this->userManager->getExistingUser($this->user), $objid, $path));

Check failure on line 541 in lib/private/Tags.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedInterfaceMethod

lib/private/Tags.php:541:81: UndefinedInterfaceMethod: Method OCP\IUserManager::getExistingUser does not exist (see https://psalm.dev/181)
}
return true;
}
Expand Down Expand Up @@ -583,7 +583,7 @@
}
}

$this->dispatcher->dispatchTyped(new NodeRemovedFromFavorite($this->userSession->getUser(), $objid, $path));
$this->dispatcher->dispatchTyped(new NodeRemovedFromFavorite($this->userManager->getExistingUser($this->user), $objid, $path));

Check failure on line 586 in lib/private/Tags.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedInterfaceMethod

lib/private/Tags.php:586:85: UndefinedInterfaceMethod: Method OCP\IUserManager::getExistingUser does not exist (see https://psalm.dev/181)
}
return true;
}
Expand Down
44 changes: 31 additions & 13 deletions tests/lib/TagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\IDBConnection;
use OCP\ITagManager;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Server;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

/**
Expand All @@ -29,16 +29,13 @@
*/
class TagsTest extends \Test\TestCase {
protected $objectType;
/** @var IUser */
protected $user;
/** @var IUserSession */
protected $userSession;
protected $backupGlobals = false;
/** @var \OC\Tagging\TagMapper */
protected $tagMapper;
/** @var ITagManager */
protected $tagMgr;
protected IRootFolder $rootFolder;
protected IUser&MockObject $user;
protected IUserSession&MockObject $userSession;
protected IUserManager&MockObject $userManager;
protected IRootFolder&MockObject $rootFolder;

protected TagMapper $tagMapper;
protected TagManager $tagMgr;

protected function setUp(): void {
parent::setUp();
Expand All @@ -51,6 +48,11 @@ protected function setUp(): void {
$this->user = $this->createMock(IUser::class);
$this->user->method('getUID')
->willReturn($userId);
$this->userManager = $this->createMock(IUserManager::class);
$this->userManager
->expects($this->any())
->method('getExistingUser')
->willReturn($this->user);
$this->userSession = $this->createMock(IUserSession::class);
$this->userSession
->expects($this->any())
Expand All @@ -71,7 +73,15 @@ protected function setUp(): void {

$this->objectType = $this->getUniqueID('type_');
$this->tagMapper = new TagMapper(Server::get(IDBConnection::class));
$this->tagMgr = new TagManager($this->tagMapper, $this->userSession, Server::get(IDBConnection::class), Server::get(LoggerInterface::class), Server::get(IEventDispatcher::class), $this->rootFolder);
$this->tagMgr = new TagManager(
$this->tagMapper,
$this->userSession,
$this->userManager,
Server::get(IDBConnection::class),
Server::get(LoggerInterface::class),
Server::get(IEventDispatcher::class),
$this->rootFolder
);
}

protected function tearDown(): void {
Expand All @@ -88,7 +98,15 @@ public function testTagManagerWithoutUserReturnsNull(): void {
->expects($this->any())
->method('getUser')
->willReturn(null);
$this->tagMgr = new TagManager($this->tagMapper, $this->userSession, Server::get(IDBConnection::class), Server::get(LoggerInterface::class), Server::get(IEventDispatcher::class), $this->rootFolder);
$this->tagMgr = new TagManager(
$this->tagMapper,
$this->userSession,
$this->userManager,
Server::get(IDBConnection::class),
Server::get(LoggerInterface::class),
Server::get(IEventDispatcher::class),
$this->rootFolder
);
$this->assertNull($this->tagMgr->load($this->objectType));
}

Expand Down
Loading