mirror of
https://github.com/nextcloud/server.git
synced 2026-04-21 06:08:46 -04:00
fix: Fix user in Tags class, do not depend upon session
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
a797903c86
commit
83e7ec6fa7
3 changed files with 38 additions and 18 deletions
|
|
@ -17,6 +17,7 @@ use OCP\Files\IRootFolder;
|
|||
use OCP\IDBConnection;
|
||||
use OCP\ITagManager;
|
||||
use OCP\ITags;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\User\Events\UserDeletedEvent;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
|
@ -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,
|
||||
|
|
@ -59,7 +61,7 @@ class TagManager implements ITagManager, IEventListener {
|
|||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use OCP\Files\Events\NodeRemovedFromFavorite;
|
|||
use OCP\Files\Folder;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\ITags;
|
||||
use OCP\IUserSession;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Share_Backend;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ class Tags implements ITags {
|
|||
private LoggerInterface $logger,
|
||||
private IDBConnection $db,
|
||||
private IEventDispatcher $dispatcher,
|
||||
private IUserSession $userSession,
|
||||
private IUserManager $userManager,
|
||||
private Folder $userFolder,
|
||||
array $defaultTags = [],
|
||||
) {
|
||||
|
|
@ -538,7 +538,7 @@ class Tags implements ITags {
|
|||
}
|
||||
}
|
||||
|
||||
$this->dispatcher->dispatchTyped(new NodeAddedToFavorite($this->userSession->getUser(), $objid, $path));
|
||||
$this->dispatcher->dispatchTyped(new NodeAddedToFavorite($this->userManager->getExistingUser($this->user), $objid, $path));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -583,7 +583,7 @@ class Tags implements ITags {
|
|||
}
|
||||
}
|
||||
|
||||
$this->dispatcher->dispatchTyped(new NodeRemovedFromFavorite($this->userSession->getUser(), $objid, $path));
|
||||
$this->dispatcher->dispatchTyped(new NodeRemovedFromFavorite($this->userManager->getExistingUser($this->user), $objid, $path));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ use OCP\Files\Folder;
|
|||
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;
|
||||
|
||||
/**
|
||||
|
|
@ -28,16 +28,13 @@ use Psr\Log\LoggerInterface;
|
|||
#[\PHPUnit\Framework\Attributes\Group('DB')]
|
||||
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();
|
||||
|
|
@ -50,6 +47,11 @@ class TagsTest extends \Test\TestCase {
|
|||
$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())
|
||||
|
|
@ -70,7 +72,15 @@ class TagsTest extends \Test\TestCase {
|
|||
|
||||
$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 {
|
||||
|
|
@ -87,7 +97,15 @@ class TagsTest extends \Test\TestCase {
|
|||
->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));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue