Add search for users

This commit is contained in:
brantje 2016-09-23 12:02:41 +02:00
parent c99e03d950
commit f547ca83a7
2 changed files with 121 additions and 0 deletions

View file

@ -0,0 +1,98 @@
<?php
/**
* Nextcloud - passman
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sander Brand <brantje@gmail.com>
* @copyright Sander Brand 2016
*/
namespace OCA\Passman\Controller;
use OCP\IRequest;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\ApiController;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\IUser;
use OCA\Passman\Service\VaultService;
use OCA\Passman\Service\CredentialService;
use OCA\Passman\Service\UserService;
class ShareController extends ApiController {
private $userId;
private $vaultService;
private $credentialService;
private $userService;
private $groupManager;
private $userManager;
private $limit = 50;
private $offset = 0;
private $result = [];
public function __construct($AppName,
IRequest $request,
IUser $UserId,
IGroupManager $groupManager,
IUserManager $userManager
) {
parent::__construct($AppName, $request);
$this->userId = $UserId;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
}
public function searchUsers($search) {
$users = array();
$usersTmp = $this->userManager->searchDisplayName($search, $this->limit, $this->offset);
foreach ($usersTmp as $user) {
$users[] = array(
'text' => $user->getDisplayName(),
'uid' => $user->getUID(),
'type' => 'user'
);
}
$this->result = array_merge($this->result, $users);
}
public function searchGroups($search){
$groups = array();
$groupsTmp = $this->groupManager->search($search, $this->limit, $this->offset);
foreach ($groupsTmp as $group) {
$groups[] = array(
'text' => $group->getGID(),
'uid' => $group->getGID(),
'type' => 'group'
);
}
$this->result = array_merge($this->result, $groups);
}
/**
* @NoAdminRequired
*/
public function search($search) {
$this->searchUsers($search);
$this->searchGroups($search);
return new JSONResponse($this->result);
}
}

View file

@ -14,7 +14,9 @@ use OC\Files\View;
use OCA\Passman\Controller\CredentialController;
use OCA\Passman\Controller\PageController;
use OCA\Passman\Controller\ShareController;
use OCA\Passman\Controller\VaultController;
use OCA\Passman\Service\UserService;
use OCP\AppFramework\App;
use OCP\IL10N;
@ -23,6 +25,7 @@ class Application extends App {
public function __construct () {
parent::__construct('passman');
$container = $this->getContainer();
$server = $container->getServer();
// Allow automatic DI for the View, until we migrated to Nodes API
$container->registerService(View::class, function() {
return new View('');
@ -30,11 +33,31 @@ class Application extends App {
$container->registerService('isCLI', function() {
return \OC::$CLI;
});
/**
* Controllers
*/
$container->registerService('ShareController', function($c) {
$container = $this->getContainer();
$server = $container->getServer();
return new ShareController(
$c->query('AppName'),
$c->query('Request'),
$server->getUserSession()->getUser(),
$server->getGroupManager(),
$server->getUserManager(),
$server->getShareManager(),
$server->getURLGenerator(),
$server->getL10N($c->query('AppName'))
);
});
// Aliases for the controllers so we can use the automatic DI
$container->registerAlias('CredentialController', CredentialController::class);
$container->registerAlias('PageController', PageController::class);
$container->registerAlias('VaultController', VaultController::class);
}
/**
* Register the navigation entry
*/