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
2 changes: 2 additions & 0 deletions core/AppInfo/ConfigLexicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ConfigLexicon implements ILexicon {
public const SHARE_LINK_EXPIRE_DATE_ENFORCED = 'shareapi_enforce_expire_date';
public const USER_LANGUAGE = 'lang';
public const OCM_DISCOVERY_ENABLED = 'ocm_discovery_enabled';
public const LOOKUP_LOCAL_ACCOUNT_SEARCH = 'lus_local_account_search';

public const USER_LOCALE = 'locale';
public const USER_TIMEZONE = 'timezone';
Expand Down Expand Up @@ -93,6 +94,7 @@ public function getAppConfigs(): array {
),
new Entry(self::LASTCRON_TIMESTAMP, ValueType::INT, 0, 'timestamp of last cron execution'),
new Entry(self::OCM_DISCOVERY_ENABLED, ValueType::BOOL, true, 'enable/disable OCM'),
new Entry(self::LOOKUP_LOCAL_ACCOUNT_SEARCH, ValueType::BOOL, false, 'use lookup result only when searching for local account'),
new Entry(self::UNIFIED_SEARCH_MIN_SEARCH_LENGTH, ValueType::INT, 1, 'Minimum search length to trigger the request', rename: 'unified-search.min-search-length'),
new Entry(self::UNIFIED_SEARCH_MAX_RESULTS_PER_REQUEST, ValueType::INT, 25, 'Maximum results returned per search request', rename: 'unified-search.max-results-per-request'),
new Entry(
Expand Down
5 changes: 4 additions & 1 deletion lib/private/Collaboration/Collaborators/LookupPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

namespace OC\Collaboration\Collaborators;

use OC\Core\AppInfo\ConfigLexicon;
use OCA\Federation\TrustedServers;
use OCP\Collaboration\Collaborators\ISearchPlugin;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\Federation\ICloudIdManager;
use OCP\Http\Client\IClientService;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IUserSession;
use OCP\Share\IShare;
Expand All @@ -24,6 +26,7 @@ class LookupPlugin implements ISearchPlugin {

public function __construct(
private IConfig $config,
private readonly IAppConfig $appConfig,
private IClientService $clientService,
IUserSession $userSession,
private ICloudIdManager $cloudIdManager,
Expand Down Expand Up @@ -75,7 +78,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
]);
continue;
}
if ($this->currentUserRemote === $remote) {
if ($this->currentUserRemote === $remote && !$this->appConfig->getValueBool('core', ConfigLexicon::LOOKUP_LOCAL_ACCOUNT_SEARCH)) {
continue;
}
$name = $lookup['name']['value'] ?? '';
Expand Down
6 changes: 6 additions & 0 deletions lib/private/Collaboration/Collaborators/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

namespace OC\Collaboration\Collaborators;

use OC\Core\AppInfo\ConfigLexicon;
use OCP\AppFramework\QueryException;
use OCP\Collaboration\Collaborators\ISearch;
use OCP\Collaboration\Collaborators\ISearchPlugin;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\IAppConfig;
use OCP\IContainer;
use OCP\Share\IShare;

Expand All @@ -20,6 +22,7 @@ class Search implements ISearch {

public function __construct(
private IContainer $container,
private readonly IAppConfig $appConfig,
) {
}

Expand Down Expand Up @@ -47,6 +50,9 @@ public function search($search, array $shareTypes, $lookup, $limit, $offset): ar
foreach ($this->pluginList[$type] as $plugin) {
/** @var ISearchPlugin $searchPlugin */
$searchPlugin = $this->container->resolve($plugin);
if ($searchPlugin instanceof UserPlugin && $lookup && $this->appConfig->getValueBool('core', ConfigLexicon::LOOKUP_LOCAL_ACCOUNT_SEARCH)) {
continue;
}
$hasMoreResults = $searchPlugin->search($search, $limit, $offset, $searchResult) || $hasMoreResults;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1035,8 +1035,8 @@ public function __construct(

$this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class);

$this->registerService(ISearch::class, function (Server $c): ISearch {
$instance = new Search($c);
$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c): \OCP\Collaboration\Collaborators\ISearch {
$instance = new \OC\Collaboration\Collaborators\Search($c, $c->get(IAppConfig::class));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new namespacing seems not required, maybe a rebasing issue


// register default plugins
$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/Collaboration/Collaborators/LookupPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserSession;
Expand All @@ -27,6 +28,8 @@
class LookupPluginTest extends TestCase {
/** @var IConfig|MockObject */
protected $config;
/** @var IAppConfig|MockObject */
protected $appConfig;
Comment on lines +31 to +32

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var IAppConfig|MockObject */
protected $appConfig;
protected IAppConfig&MockObject $appConfig;

/** @var IClientService|MockObject */
protected $clientService;
/** @var IUserSession|MockObject */
Expand All @@ -45,6 +48,7 @@ protected function setUp(): void {
$this->userSession = $this->createMock(IUserSession::class);
$this->cloudIdManager = $this->createMock(ICloudIdManager::class);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->clientService = $this->createMock(IClientService::class);
$cloudId = $this->createMock(ICloudId::class);
Expand All @@ -67,6 +71,7 @@ protected function setUp(): void {

$this->plugin = new LookupPlugin(
$this->config,
$this->appConfig,
$this->clientService,
$this->userSession,
$this->cloudIdManager,
Expand Down
12 changes: 7 additions & 5 deletions tests/lib/Collaboration/Collaborators/SearchResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@
use OC\Collaboration\Collaborators\SearchResult;
use OCP\Collaboration\Collaborators\ISearch;
use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\IAppConfig;
use OCP\IContainer;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class SearchResultTest extends TestCase {
/** @var IContainer|\PHPUnit\Framework\MockObject\MockObject */
protected $container;
/** @var ISearch */
protected $search;
protected IContainer&MockObject $container;
protected IAppConfig&MockObject $appConfig;
protected ISearch $search;

#[\Override]
protected function setUp(): void {
parent::setUp();

$this->container = $this->createMock(IContainer::class);
$this->appConfig = $this->createMock(IAppConfig::class);

$this->search = new Search($this->container);
$this->search = new Search($this->container, $this->appConfig);
}

public static function dataAddResultSet(): array {
Expand Down
12 changes: 7 additions & 5 deletions tests/lib/Collaboration/Collaborators/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,25 @@
use OCP\Collaboration\Collaborators\ISearch;
use OCP\Collaboration\Collaborators\ISearchPlugin;
use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\IAppConfig;
use OCP\IContainer;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class SearchTest extends TestCase {
/** @var IContainer|\PHPUnit\Framework\MockObject\MockObject */
protected $container;
/** @var ISearch */
protected $search;
protected IContainer&MockObject $container;
protected IAppConfig&MockObject $appConfig;
protected ISearch $search;

#[\Override]
protected function setUp(): void {
parent::setUp();

$this->container = $this->createMock(IContainer::class);
$this->appConfig = $this->createMock(IAppConfig::class);

$this->search = new Search($this->container);
$this->search = new Search($this->container, $this->appConfig);
}

#[\PHPUnit\Framework\Attributes\DataProvider('dataSearchSharees')]
Expand Down
Loading