add search parameter to autocomplete controller
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
3628d4d65d
commit
fa2f03979b
2 changed files with 22 additions and 5 deletions
|
@ -27,6 +27,7 @@ use OCP\AppFramework\Controller;
|
|||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\Collaboration\AutoComplete\IManager;
|
||||
use OCP\Collaboration\Collaborators\ISearch;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use OCP\Share;
|
||||
|
||||
|
@ -35,27 +36,38 @@ class AutoCompleteController extends Controller {
|
|||
private $collaboratorSearch;
|
||||
/** @var IManager */
|
||||
private $autoCompleteManager;
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
public function __construct($appName, IRequest $request, ISearch $collaboratorSearch, IManager $autoCompleteManager) {
|
||||
public function __construct(
|
||||
$appName,
|
||||
IRequest $request,
|
||||
ISearch $collaboratorSearch,
|
||||
IManager $autoCompleteManager,
|
||||
IConfig $config
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->collaboratorSearch = $collaboratorSearch;
|
||||
$this->autoCompleteManager = $autoCompleteManager;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param string $search
|
||||
* @param string $itemType
|
||||
* @param string $itemId
|
||||
* @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients"
|
||||
* @param array $shareTypes
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function get($itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER]) {
|
||||
public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER]) {
|
||||
// if enumeration/user listings are disabled, we'll receive an empty
|
||||
// result from search() – thus nothing else to do here.
|
||||
list($results,) = $this->collaboratorSearch->search('', $shareTypes, false, 20, 0);
|
||||
$limit = $this->config->getSystemValue('collaboration.maxAutocompleteResults', 50);
|
||||
list($results,) = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0);
|
||||
|
||||
// there won't be exact matches without a search string
|
||||
unset($results['exact']);
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace Tests\Core\Controller;
|
|||
use OC\Core\Controller\AutoCompleteController;
|
||||
use OCP\Collaboration\AutoComplete\IManager;
|
||||
use OCP\Collaboration\Collaborators\ISearch;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use Test\TestCase;
|
||||
|
||||
|
@ -35,6 +36,8 @@ class AutoCompleteControllerTest extends TestCase {
|
|||
protected $collaboratorSearch;
|
||||
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $autoCompleteManager;
|
||||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $config;
|
||||
/** @var AutoCompleteController */
|
||||
protected $controller;
|
||||
|
||||
|
@ -45,12 +48,14 @@ class AutoCompleteControllerTest extends TestCase {
|
|||
$request = $this->createMock(IRequest::class);
|
||||
$this->collaboratorSearch = $this->createMock(ISearch::class);
|
||||
$this->autoCompleteManager = $this->createMock(IManager::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
|
||||
$this->controller = new AutoCompleteController(
|
||||
'core',
|
||||
$request,
|
||||
$this->collaboratorSearch,
|
||||
$this->autoCompleteManager
|
||||
$this->autoCompleteManager,
|
||||
$this->config
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -75,7 +80,7 @@ class AutoCompleteControllerTest extends TestCase {
|
|||
->method('search')
|
||||
->willReturn([$searchResults, false]);
|
||||
|
||||
$response = $this->controller->get('files', '42', null);
|
||||
$response = $this->controller->get('', 'files', '42', null);
|
||||
|
||||
$list = $response->getData();
|
||||
$this->assertEquals($expected, $list); // has better error output…
|
||||
|
|
Loading…
Reference in a new issue