mirror of
https://github.com/nextcloud/passman.git
synced 2024-09-20 23:06:24 +08:00
Add search for users
This commit is contained in:
parent
c99e03d950
commit
f547ca83a7
98
controller/sharecontroller.php
Normal file
98
controller/sharecontroller.php
Normal 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue