Skip to content

Commit feb2ea7

Browse files
authored
Merge pull request #59237 from nextcloud/backport/59236/stable32
2 parents eda5147 + ba04f37 commit feb2ea7

3 files changed

Lines changed: 38 additions & 18 deletions

File tree

lib/private/TagManager.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use OCP\IDBConnection;
1818
use OCP\ITagManager;
1919
use OCP\ITags;
20+
use OCP\IUserManager;
2021
use OCP\IUserSession;
2122
use OCP\User\Events\UserDeletedEvent;
2223
use Psr\Log\LoggerInterface;
@@ -29,6 +30,7 @@ class TagManager implements ITagManager, IEventListener {
2930
public function __construct(
3031
private TagMapper $mapper,
3132
private IUserSession $userSession,
33+
private IUserManager $userManager,
3234
private IDBConnection $connection,
3335
private LoggerInterface $logger,
3436
private IEventDispatcher $dispatcher,
@@ -59,7 +61,7 @@ public function load($type, $defaultTags = [], $includeShared = false, $userId =
5961
$userId = $this->userSession->getUser()->getUId();
6062
}
6163
$userFolder = $this->rootFolder->getUserFolder($userId);
62-
return new Tags($this->mapper, $userId, $type, $this->logger, $this->connection, $this->dispatcher, $this->userSession, $userFolder, $defaultTags);
64+
return new Tags($this->mapper, $userId, $type, $this->logger, $this->connection, $this->dispatcher, $this->userManager, $userFolder, $defaultTags);
6365
}
6466

6567
/**

lib/private/Tags.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use OCP\Files\Folder;
1818
use OCP\IDBConnection;
1919
use OCP\ITags;
20-
use OCP\IUserSession;
20+
use OCP\IUserManager;
2121
use OCP\Share_Backend;
2222
use Psr\Log\LoggerInterface;
2323

@@ -65,7 +65,7 @@ public function __construct(
6565
private LoggerInterface $logger,
6666
private IDBConnection $db,
6767
private IEventDispatcher $dispatcher,
68-
private IUserSession $userSession,
68+
private IUserManager $userManager,
6969
private Folder $userFolder,
7070
array $defaultTags = [],
7171
) {
@@ -538,7 +538,7 @@ public function tagAs($objid, $tag, ?string $path = null) {
538538
}
539539
}
540540

541-
$this->dispatcher->dispatchTyped(new NodeAddedToFavorite($this->userSession->getUser(), $objid, $path));
541+
$this->dispatcher->dispatchTyped(new NodeAddedToFavorite(new \OC\User\LazyUser($this->user, $this->userManager), $objid, $path));
542542
}
543543
return true;
544544
}
@@ -583,7 +583,7 @@ public function unTag($objid, $tag, ?string $path = null) {
583583
}
584584
}
585585

586-
$this->dispatcher->dispatchTyped(new NodeRemovedFromFavorite($this->userSession->getUser(), $objid, $path));
586+
$this->dispatcher->dispatchTyped(new NodeRemovedFromFavorite(new \OC\User\LazyUser($this->user, $this->userManager), $objid, $path));
587587
}
588588
return true;
589589
}

tests/lib/TagsTest.php

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
use OCP\Files\IRootFolder;
1616
use OCP\Files\Node;
1717
use OCP\IDBConnection;
18-
use OCP\ITagManager;
1918
use OCP\IUser;
2019
use OCP\IUserManager;
2120
use OCP\IUserSession;
2221
use OCP\Server;
22+
use PHPUnit\Framework\MockObject\MockObject;
2323
use Psr\Log\LoggerInterface;
2424

2525
/**
@@ -29,16 +29,13 @@
2929
*/
3030
class TagsTest extends \Test\TestCase {
3131
protected $objectType;
32-
/** @var IUser */
33-
protected $user;
34-
/** @var IUserSession */
35-
protected $userSession;
36-
protected $backupGlobals = false;
37-
/** @var \OC\Tagging\TagMapper */
38-
protected $tagMapper;
39-
/** @var ITagManager */
40-
protected $tagMgr;
41-
protected IRootFolder $rootFolder;
32+
protected IUser&MockObject $user;
33+
protected IUserSession&MockObject $userSession;
34+
protected IUserManager&MockObject $userManager;
35+
protected IRootFolder&MockObject $rootFolder;
36+
37+
protected TagMapper $tagMapper;
38+
protected TagManager $tagMgr;
4239

4340
protected function setUp(): void {
4441
parent::setUp();
@@ -51,6 +48,11 @@ protected function setUp(): void {
5148
$this->user = $this->createMock(IUser::class);
5249
$this->user->method('getUID')
5350
->willReturn($userId);
51+
$this->userManager = $this->createMock(IUserManager::class);
52+
$this->userManager
53+
->expects($this->any())
54+
->method('get')
55+
->willReturn($this->user);
5456
$this->userSession = $this->createMock(IUserSession::class);
5557
$this->userSession
5658
->expects($this->any())
@@ -71,7 +73,15 @@ protected function setUp(): void {
7173

7274
$this->objectType = $this->getUniqueID('type_');
7375
$this->tagMapper = new TagMapper(Server::get(IDBConnection::class));
74-
$this->tagMgr = new TagManager($this->tagMapper, $this->userSession, Server::get(IDBConnection::class), Server::get(LoggerInterface::class), Server::get(IEventDispatcher::class), $this->rootFolder);
76+
$this->tagMgr = new TagManager(
77+
$this->tagMapper,
78+
$this->userSession,
79+
$this->userManager,
80+
Server::get(IDBConnection::class),
81+
Server::get(LoggerInterface::class),
82+
Server::get(IEventDispatcher::class),
83+
$this->rootFolder
84+
);
7585
}
7686

7787
protected function tearDown(): void {
@@ -88,7 +98,15 @@ public function testTagManagerWithoutUserReturnsNull(): void {
8898
->expects($this->any())
8999
->method('getUser')
90100
->willReturn(null);
91-
$this->tagMgr = new TagManager($this->tagMapper, $this->userSession, Server::get(IDBConnection::class), Server::get(LoggerInterface::class), Server::get(IEventDispatcher::class), $this->rootFolder);
101+
$this->tagMgr = new TagManager(
102+
$this->tagMapper,
103+
$this->userSession,
104+
$this->userManager,
105+
Server::get(IDBConnection::class),
106+
Server::get(LoggerInterface::class),
107+
Server::get(IEventDispatcher::class),
108+
$this->rootFolder
109+
);
92110
$this->assertNull($this->tagMgr->load($this->objectType));
93111
}
94112

0 commit comments

Comments
 (0)