mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #58896 from nextcloud/fix/fix-tags-user-event
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Integration sqlite / changes (push) Waiting to run
Integration sqlite / integration-sqlite (master, 8.4, main, --tags ~@large files_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, capabilities_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, collaboration_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, comments_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, dav_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, federation_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, file_conversions) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, files_reminders) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, filesdrop_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, ldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, openldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, openldap_numerical_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, remoteapi_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, routing_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, setup_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, sharees_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, sharing_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, theming_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, videoverification_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite-summary (push) Blocked by required conditions
Psalm static code analysis / static-code-analysis (push) Waiting to run
Psalm static code analysis / static-code-analysis-security (push) Waiting to run
Psalm static code analysis / static-code-analysis-ocp (push) Waiting to run
Psalm static code analysis / static-code-analysis-ncu (push) Waiting to run
Psalm static code analysis / static-code-analysis-strict (push) Waiting to run
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Integration sqlite / changes (push) Waiting to run
Integration sqlite / integration-sqlite (master, 8.4, main, --tags ~@large files_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, capabilities_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, collaboration_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, comments_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, dav_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, federation_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, file_conversions) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, files_reminders) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, filesdrop_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, ldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, openldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, openldap_numerical_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, remoteapi_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, routing_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, setup_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, sharees_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, sharing_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, theming_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, videoverification_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite-summary (push) Blocked by required conditions
Psalm static code analysis / static-code-analysis (push) Waiting to run
Psalm static code analysis / static-code-analysis-security (push) Waiting to run
Psalm static code analysis / static-code-analysis-ocp (push) Waiting to run
Psalm static code analysis / static-code-analysis-ncu (push) Waiting to run
Psalm static code analysis / static-code-analysis-strict (push) Waiting to run
fix: Fix user in Tags class, do not depend upon session
This commit is contained in:
commit
ca245b4cc6
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\Server;
|
||||
use OCP\Util;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
|
@ -55,7 +55,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 = [],
|
||||
) {
|
||||
|
|
@ -528,7 +528,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;
|
||||
}
|
||||
|
|
@ -573,7 +573,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 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