Moved user listing to API
This commit is contained in:
parent
f74213bafb
commit
243f22542d
5 changed files with 41 additions and 26 deletions
|
@ -140,6 +140,9 @@ $userValidations =
|
||||||
'filter' => '[^\/]+',
|
'filter' => '[^\/]+',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
\Chibi\Router::register(['UserController', 'listView'], 'GET', '/users', $userValidations);
|
||||||
|
\Chibi\Router::register(['UserController', 'listView'], 'GET', '/users/{page}', $userValidations);
|
||||||
|
\Chibi\Router::register(['UserController', 'listView'], 'GET', '/users/{filter}/{page}', $userValidations);
|
||||||
\Chibi\Router::register(['UserController', 'flagAction'], 'POST', '/user/{name}/flag', $userValidations);
|
\Chibi\Router::register(['UserController', 'flagAction'], 'POST', '/user/{name}/flag', $userValidations);
|
||||||
\Chibi\Router::register(['UserController', 'banAction'], 'POST', '/user/{name}/ban', $userValidations);
|
\Chibi\Router::register(['UserController', 'banAction'], 'POST', '/user/{name}/ban', $userValidations);
|
||||||
\Chibi\Router::register(['UserController', 'unbanAction'], 'POST', '/user/{name}/unban', $userValidations);
|
\Chibi\Router::register(['UserController', 'unbanAction'], 'POST', '/user/{name}/unban', $userValidations);
|
||||||
|
@ -151,10 +154,6 @@ foreach (['GET', 'POST'] as $method)
|
||||||
\Chibi\Router::register(['UserController', 'registrationAction'], $method, '/register', $userValidations);
|
\Chibi\Router::register(['UserController', 'registrationAction'], $method, '/register', $userValidations);
|
||||||
\Chibi\Router::register(['UserController', 'viewAction'], $method, '/user/{name}/{tab}', $userValidations);
|
\Chibi\Router::register(['UserController', 'viewAction'], $method, '/user/{name}/{tab}', $userValidations);
|
||||||
\Chibi\Router::register(['UserController', 'viewAction'], $method, '/user/{name}/{tab}/{page}', $userValidations);
|
\Chibi\Router::register(['UserController', 'viewAction'], $method, '/user/{name}/{tab}/{page}', $userValidations);
|
||||||
\Chibi\Router::register(['UserController', 'listAction'], $method, '/users', $userValidations);
|
|
||||||
\Chibi\Router::register(['UserController', 'listAction'], $method, '/users/{page}', $userValidations);
|
|
||||||
\Chibi\Router::register(['UserController', 'listAction'], $method, '/users/{filter}', $userValidations);
|
|
||||||
\Chibi\Router::register(['UserController', 'listAction'], $method, '/users/{filter}/{page}', $userValidations);
|
|
||||||
\Chibi\Router::register(['UserController', 'acceptRegistrationAction'], $method, '/user/{name}/accept-registration', $userValidations);
|
\Chibi\Router::register(['UserController', 'acceptRegistrationAction'], $method, '/user/{name}/accept-registration', $userValidations);
|
||||||
\Chibi\Router::register(['UserController', 'deleteAction'], $method, '/user/{name}/delete', $userValidations);
|
\Chibi\Router::register(['UserController', 'deleteAction'], $method, '/user/{name}/delete', $userValidations);
|
||||||
\Chibi\Router::register(['UserController', 'settingsAction'], $method, '/user/{name}/settings', $userValidations);
|
\Chibi\Router::register(['UserController', 'settingsAction'], $method, '/user/{name}/settings', $userValidations);
|
||||||
|
|
25
src/Api/Jobs/ListUsersJob.php
Normal file
25
src/Api/Jobs/ListUsersJob.php
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
class ListUsersJob extends AbstractPageJob
|
||||||
|
{
|
||||||
|
public function execute()
|
||||||
|
{
|
||||||
|
$pageSize = $this->getPageSize();
|
||||||
|
$page = $this->getArgument(self::PAGE_NUMBER);
|
||||||
|
$filter = $this->getArgument(self::QUERY);
|
||||||
|
|
||||||
|
$users = UserSearchService::getEntities($filter, $pageSize, $page);
|
||||||
|
$userCount = UserSearchService::getEntityCount($filter);
|
||||||
|
|
||||||
|
return $this->getPager($users, $userCount, $page, $pageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefaultPageSize()
|
||||||
|
{
|
||||||
|
return intval(getConfig()->browsing->usersPerPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requiresPrivilege()
|
||||||
|
{
|
||||||
|
return Privilege::ListUsers;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,29 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
class UserController
|
class UserController
|
||||||
{
|
{
|
||||||
public function listAction($filter, $page)
|
public function listView($filter = 'order:alpha,asc', $page = 1)
|
||||||
{
|
{
|
||||||
|
$ret = Api::run(
|
||||||
|
new ListUsersJob(),
|
||||||
|
[
|
||||||
|
ListUsersJob::PAGE_NUMBER => $page,
|
||||||
|
ListUsersJob::QUERY => $filter,
|
||||||
|
]);
|
||||||
|
|
||||||
$context = getContext();
|
$context = getContext();
|
||||||
Access::assert(
|
|
||||||
Privilege::ListUsers);
|
|
||||||
|
|
||||||
$suppliedFilter = $filter ?: InputHelper::get('filter') ?: 'order:alpha,asc';
|
$context->filter = $filter;
|
||||||
$page = max(1, intval($page));
|
$context->transport->users = $ret->entities;
|
||||||
$usersPerPage = intval(getConfig()->browsing->usersPerPage);
|
$context->transport->paginator = $ret;
|
||||||
|
|
||||||
$users = UserSearchService::getEntities($suppliedFilter, $usersPerPage, $page);
|
|
||||||
$userCount = UserSearchService::getEntityCount($suppliedFilter);
|
|
||||||
$pageCount = ceil($userCount / $usersPerPage);
|
|
||||||
$page = min($pageCount, $page);
|
|
||||||
|
|
||||||
$context->filter = $suppliedFilter;
|
|
||||||
$context->transport->users = $users;
|
|
||||||
$context->transport->paginator = new StdClass;
|
|
||||||
$context->transport->paginator->page = $page;
|
|
||||||
$context->transport->paginator->pageCount = $pageCount;
|
|
||||||
$context->transport->paginator->entityCount = $userCount;
|
|
||||||
$context->transport->paginator->entities = $users;
|
|
||||||
$context->transport->paginator->params = func_get_args();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function flagAction($name)
|
public function flagAction($name)
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
{
|
{
|
||||||
$registerNavItem(
|
$registerNavItem(
|
||||||
'Users',
|
'Users',
|
||||||
\Chibi\Router::linkTo(['UserController', 'listAction']),
|
\Chibi\Router::linkTo(['UserController', 'listView']),
|
||||||
$activeController == 'user' and $activeAction != 'registration' and
|
$activeController == 'user' and $activeAction != 'registration' and
|
||||||
(!isset($this->context->route->arguments['name']) or
|
(!isset($this->context->route->arguments['name']) or
|
||||||
$this->context->route->arguments['name'] != Auth::getCurrentUser()->name));
|
$this->context->route->arguments['name'] != Auth::getCurrentUser()->name));
|
||||||
|
|
|
@ -27,7 +27,7 @@ if (Auth::getCurrentUser()->hasEnabledEndlessScrolling())
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<li>
|
<li>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<a href="<?= \Chibi\Router::linkTo(['UserController', 'listAction'], ['filter' => $key]) ?>">
|
<a href="<?= \Chibi\Router::linkTo(['UserController', 'listView'], ['filter' => $key]) ?>">
|
||||||
<?= $text ?>
|
<?= $text ?>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Reference in a new issue