Fix injection to get the user id

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2018-10-30 11:41:56 +01:00
parent e6952edaf4
commit 5a73a9b9de
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
2 changed files with 18 additions and 5 deletions

View File

@ -31,6 +31,7 @@ use OCP\Contacts\IManager;
use OCP\Federation\ICloudIdManager; use OCP\Federation\ICloudIdManager;
use OCP\IConfig; use OCP\IConfig;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share; use OCP\Share;
class RemotePlugin implements ISearchPlugin { class RemotePlugin implements ISearchPlugin {
@ -45,15 +46,17 @@ class RemotePlugin implements ISearchPlugin {
/** @var IUserManager */ /** @var IUserManager */
private $userManager; private $userManager;
/** @var string */ /** @var string */
private $userId; private $userId = '';
public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config, IUserManager $userManager, $userId) { public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config, IUserManager $userManager, IUserSession $userSession) {
$this->contactsManager = $contactsManager; $this->contactsManager = $contactsManager;
$this->cloudIdManager = $cloudIdManager; $this->cloudIdManager = $cloudIdManager;
$this->config = $config; $this->config = $config;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->userId = $userId; $user = $userSession->getUser();
if ($user !== null) {
$this->userId = $user->getUID();
}
$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
} }

View File

@ -31,7 +31,9 @@ use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\Contacts\IManager; use OCP\Contacts\IManager;
use OCP\Federation\ICloudIdManager; use OCP\Federation\ICloudIdManager;
use OCP\IConfig; use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share; use OCP\Share;
use Test\TestCase; use Test\TestCase;
@ -66,7 +68,15 @@ class RemotePluginTest extends TestCase {
} }
public function instantiatePlugin() { public function instantiatePlugin() {
$this->plugin = new RemotePlugin($this->contactsManager, $this->cloudIdManager, $this->config, $this->userManager, 'admin'); $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn('admin');
$userSession = $this->createMock(IUserSession::class);
$userSession->expects($this->any())
->method('getUser')
->willReturn($user);
$this->plugin = new RemotePlugin($this->contactsManager, $this->cloudIdManager, $this->config, $this->userManager, $userSession);
} }
/** /**