mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 13:22:42 +01:00
Use ApplicationSearch in OAuthServer
Summary: Update the infrastructure and UI of the client list. Test Plan: {F131570} Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D8563
This commit is contained in:
parent
34c890b7e1
commit
1534033664
8 changed files with 152 additions and 161 deletions
|
@ -1721,7 +1721,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorOAuthServerCapabilityCreateClients' => 'applications/oauthserver/capability/PhabricatorOAuthServerCapabilityCreateClients.php',
|
'PhabricatorOAuthServerCapabilityCreateClients' => 'applications/oauthserver/capability/PhabricatorOAuthServerCapabilityCreateClients.php',
|
||||||
'PhabricatorOAuthServerClient' => 'applications/oauthserver/storage/PhabricatorOAuthServerClient.php',
|
'PhabricatorOAuthServerClient' => 'applications/oauthserver/storage/PhabricatorOAuthServerClient.php',
|
||||||
'PhabricatorOAuthServerClientQuery' => 'applications/oauthserver/query/PhabricatorOAuthServerClientQuery.php',
|
'PhabricatorOAuthServerClientQuery' => 'applications/oauthserver/query/PhabricatorOAuthServerClientQuery.php',
|
||||||
'PhabricatorOAuthServerConsoleController' => 'applications/oauthserver/controller/PhabricatorOAuthServerConsoleController.php',
|
'PhabricatorOAuthServerClientSearchEngine' => 'applications/oauthserver/query/PhabricatorOAuthServerClientSearchEngine.php',
|
||||||
'PhabricatorOAuthServerController' => 'applications/oauthserver/controller/PhabricatorOAuthServerController.php',
|
'PhabricatorOAuthServerController' => 'applications/oauthserver/controller/PhabricatorOAuthServerController.php',
|
||||||
'PhabricatorOAuthServerDAO' => 'applications/oauthserver/storage/PhabricatorOAuthServerDAO.php',
|
'PhabricatorOAuthServerDAO' => 'applications/oauthserver/storage/PhabricatorOAuthServerDAO.php',
|
||||||
'PhabricatorOAuthServerPHIDTypeClient' => 'applications/oauthserver/phid/PhabricatorOAuthServerPHIDTypeClient.php',
|
'PhabricatorOAuthServerPHIDTypeClient' => 'applications/oauthserver/phid/PhabricatorOAuthServerPHIDTypeClient.php',
|
||||||
|
@ -4479,7 +4479,7 @@ phutil_register_library_map(array(
|
||||||
1 => 'PhabricatorPolicyInterface',
|
1 => 'PhabricatorPolicyInterface',
|
||||||
),
|
),
|
||||||
'PhabricatorOAuthServerClientQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorOAuthServerClientQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhabricatorOAuthServerConsoleController' => 'PhabricatorOAuthServerController',
|
'PhabricatorOAuthServerClientSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'PhabricatorOAuthServerController' => 'PhabricatorController',
|
'PhabricatorOAuthServerController' => 'PhabricatorController',
|
||||||
'PhabricatorOAuthServerDAO' => 'PhabricatorLiskDAO',
|
'PhabricatorOAuthServerDAO' => 'PhabricatorLiskDAO',
|
||||||
'PhabricatorOAuthServerPHIDTypeClient' => 'PhabricatorPHIDType',
|
'PhabricatorOAuthServerPHIDTypeClient' => 'PhabricatorPHIDType',
|
||||||
|
|
|
@ -33,12 +33,12 @@ final class PhabricatorApplicationOAuthServer extends PhabricatorApplication {
|
||||||
public function getRoutes() {
|
public function getRoutes() {
|
||||||
return array(
|
return array(
|
||||||
'/oauthserver/' => array(
|
'/oauthserver/' => array(
|
||||||
'' => 'PhabricatorOAuthServerConsoleController',
|
'(?:query/(?P<queryKey>[^/]+)/)?'
|
||||||
|
=> 'PhabricatorOAuthClientListController',
|
||||||
'auth/' => 'PhabricatorOAuthServerAuthController',
|
'auth/' => 'PhabricatorOAuthServerAuthController',
|
||||||
'test/' => 'PhabricatorOAuthServerTestController',
|
'test/' => 'PhabricatorOAuthServerTestController',
|
||||||
'token/' => 'PhabricatorOAuthServerTokenController',
|
'token/' => 'PhabricatorOAuthServerTokenController',
|
||||||
'client/' => array(
|
'client/' => array(
|
||||||
'' => 'PhabricatorOAuthClientListController',
|
|
||||||
'create/' => 'PhabricatorOAuthClientEditController',
|
'create/' => 'PhabricatorOAuthClientEditController',
|
||||||
'delete/(?P<phid>[^/]+)/' => 'PhabricatorOAuthClientDeleteController',
|
'delete/(?P<phid>[^/]+)/' => 'PhabricatorOAuthClientDeleteController',
|
||||||
'edit/(?P<phid>[^/]+)/' => 'PhabricatorOAuthClientEditController',
|
'edit/(?P<phid>[^/]+)/' => 'PhabricatorOAuthClientEditController',
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
final class PhabricatorOAuthServerConsoleController
|
|
||||||
extends PhabricatorOAuthServerController {
|
|
||||||
|
|
||||||
public function processRequest() {
|
|
||||||
$request = $this->getRequest();
|
|
||||||
$viewer = $request->getUser();
|
|
||||||
|
|
||||||
$menu = id(new PHUIObjectItemListView())
|
|
||||||
->setUser($viewer);
|
|
||||||
|
|
||||||
$menu->addItem(
|
|
||||||
id(new PHUIObjectItemView())
|
|
||||||
->setHeader(pht('Applications'))
|
|
||||||
->setHref($this->getApplicationURI('client/'))
|
|
||||||
->addAttribute(
|
|
||||||
pht(
|
|
||||||
'Create a new OAuth application.')));
|
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
|
||||||
$crumbs->addTextCrumb(pht('Console'));
|
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
|
||||||
array(
|
|
||||||
$crumbs,
|
|
||||||
$menu,
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'title' => pht('OAuth Server Console'),
|
|
||||||
'device' => true,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -21,4 +21,20 @@ abstract class PhabricatorOAuthClientBaseController
|
||||||
public function willProcessRequest(array $data) {
|
public function willProcessRequest(array $data) {
|
||||||
$this->setClientPHID(idx($data, 'phid'));
|
$this->setClientPHID(idx($data, 'phid'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function buildSideNavView($for_app = false) {
|
||||||
|
$user = $this->getRequest()->getUser();
|
||||||
|
|
||||||
|
$nav = new AphrontSideNavFilterView();
|
||||||
|
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
||||||
|
|
||||||
|
id(new PhabricatorOAuthServerClientSearchEngine())
|
||||||
|
->setViewer($user)
|
||||||
|
->addNavigationItems($nav->getMenu());
|
||||||
|
|
||||||
|
$nav->selectFilter(null);
|
||||||
|
|
||||||
|
return $nav;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,131 +1,65 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* @group oauthserver
|
|
||||||
*/
|
|
||||||
final class PhabricatorOAuthClientListController
|
final class PhabricatorOAuthClientListController
|
||||||
extends PhabricatorOAuthClientBaseController {
|
extends PhabricatorOAuthClientBaseController
|
||||||
|
implements PhabricatorApplicationSearchResultsControllerInterface {
|
||||||
|
|
||||||
public function getFilter() {
|
private $queryKey;
|
||||||
return 'client';
|
|
||||||
|
public function shouldAllowPublic() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function willProcessRequest(array $data) {
|
||||||
|
$this->queryKey = idx($data, 'queryKey');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
$title = 'OAuth Clients';
|
$request = $this->getRequest();
|
||||||
$request = $this->getRequest();
|
$controller = id(new PhabricatorApplicationSearchController($request))
|
||||||
$current_user = $request->getUser();
|
->setQueryKey($this->queryKey)
|
||||||
$offset = $request->getInt('offset', 0);
|
->setSearchEngine(new PhabricatorOAuthServerClientSearchEngine())
|
||||||
$page_size = 100;
|
->setNavigation($this->buildSideNavView());
|
||||||
$pager = new AphrontPagerView();
|
|
||||||
$request_uri = $request->getRequestURI();
|
|
||||||
$pager->setURI($request_uri, 'offset');
|
|
||||||
$pager->setPageSize($page_size);
|
|
||||||
$pager->setOffset($offset);
|
|
||||||
|
|
||||||
$query = id(new PhabricatorOAuthServerClientQuery())
|
return $this->delegateToController($controller);
|
||||||
->setViewer($current_user)
|
}
|
||||||
->withCreatorPHIDs(array($current_user->getPHID()));
|
|
||||||
$clients = $query->executeWithOffsetPager($pager);
|
|
||||||
|
|
||||||
$rows = array();
|
public function renderResultsList(
|
||||||
$rowc = array();
|
array $clients,
|
||||||
$highlight = $this->getHighlightPHIDs();
|
PhabricatorSavedQuery $query) {
|
||||||
|
assert_instances_of($clients, 'PhabricatorOauthServerClient');
|
||||||
|
|
||||||
|
$viewer = $this->getRequest()->getUser();
|
||||||
|
$this->loadHandles(mpull($clients, 'getCreatorPHID'));
|
||||||
|
|
||||||
|
$list = id(new PHUIObjectItemListView())
|
||||||
|
->setUser($viewer);
|
||||||
foreach ($clients as $client) {
|
foreach ($clients as $client) {
|
||||||
$row = array(
|
$creator = $this->getHandle($client->getCreatorPHID());
|
||||||
phutil_tag(
|
|
||||||
'a',
|
|
||||||
array(
|
|
||||||
'href' => $client->getViewURI(),
|
|
||||||
),
|
|
||||||
$client->getName()),
|
|
||||||
$client->getPHID(),
|
|
||||||
$client->getSecret(),
|
|
||||||
phutil_tag(
|
|
||||||
'a',
|
|
||||||
array(
|
|
||||||
'href' => $client->getRedirectURI(),
|
|
||||||
),
|
|
||||||
$client->getRedirectURI()),
|
|
||||||
phutil_tag(
|
|
||||||
'a',
|
|
||||||
array(
|
|
||||||
'class' => 'small button grey',
|
|
||||||
'href' => $client->getEditURI(),
|
|
||||||
),
|
|
||||||
'Edit'),
|
|
||||||
);
|
|
||||||
|
|
||||||
$rows[] = $row;
|
$item = id(new PHUIObjectItemView())
|
||||||
if (isset($highlight[$client->getPHID()])) {
|
->setObjectName(pht('Application %d', $client->getID()))
|
||||||
$rowc[] = 'highlighted';
|
->setHeader($client->getName())
|
||||||
} else {
|
->setHref($client->getViewURI())
|
||||||
$rowc[] = '';
|
->setObject($client)
|
||||||
}
|
->addByline(pht('Creator: %s', $creator->renderLink()));
|
||||||
|
|
||||||
|
$list->addItem($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
$panel = $this->buildClientList($rows, $rowc, $title);
|
return $list;
|
||||||
|
|
||||||
return $this->buildStandardPageResponse(
|
|
||||||
array(
|
|
||||||
$this->getNoticeView(),
|
|
||||||
$panel->appendChild($pager)
|
|
||||||
),
|
|
||||||
array('title' => $title));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildClientList($rows, $rowc, $title) {
|
public function buildApplicationCrumbs() {
|
||||||
$table = new AphrontTableView($rows);
|
$crumbs = parent::buildApplicationCrumbs();
|
||||||
$table->setRowClasses($rowc);
|
|
||||||
$table->setHeaders(
|
|
||||||
array(
|
|
||||||
'Client',
|
|
||||||
'ID',
|
|
||||||
'Secret',
|
|
||||||
'Redirect URI',
|
|
||||||
'',
|
|
||||||
));
|
|
||||||
$table->setColumnClasses(
|
|
||||||
array(
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'action',
|
|
||||||
));
|
|
||||||
if (empty($rows)) {
|
|
||||||
$table->setNoDataString(
|
|
||||||
'You have not created any clients for this OAuthServer.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$panel = new AphrontPanelView();
|
$crumbs->addAction(
|
||||||
$panel->appendChild($table);
|
id(new PHUIListItemView())
|
||||||
$panel->setHeader($title);
|
->setHref($this->getApplicationURI('client/create/'))
|
||||||
|
->setName(pht('Create Application'))
|
||||||
|
->setIcon('create'));
|
||||||
|
|
||||||
return $panel;
|
return $crumbs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getNoticeView() {
|
|
||||||
$edited = $this->getRequest()->getStr('edited');
|
|
||||||
$new = $this->getRequest()->getStr('new');
|
|
||||||
$deleted = $this->getRequest()->getBool('deleted');
|
|
||||||
if ($edited) {
|
|
||||||
$title = 'Successfully edited client with id '.$edited.'.';
|
|
||||||
} else if ($new) {
|
|
||||||
$title = 'Successfully created client with id '.$new.'.';
|
|
||||||
} else if ($deleted) {
|
|
||||||
$title = 'Successfully deleted client.';
|
|
||||||
} else {
|
|
||||||
$title = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($title) {
|
|
||||||
$view = new AphrontErrorView();
|
|
||||||
$view->setTitle($title);
|
|
||||||
$view->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
|
||||||
} else {
|
|
||||||
$view = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $view;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,15 +20,13 @@ final class PhabricatorOAuthClientAuthorizationQuery
|
||||||
$table = new PhabricatorOAuthClientAuthorization();
|
$table = new PhabricatorOAuthClientAuthorization();
|
||||||
$conn_r = $table->establishConnection('r');
|
$conn_r = $table->establishConnection('r');
|
||||||
|
|
||||||
$where_clause = $this->buildWhereClause($conn_r);
|
|
||||||
$limit_clause = $this->buildLimitClause($conn_r);
|
|
||||||
|
|
||||||
$data = queryfx_all(
|
$data = queryfx_all(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'SELECT * FROM %T auth %Q %Q',
|
'SELECT * FROM %T auth %Q %Q %Q',
|
||||||
$table->getTableName(),
|
$table->getTableName(),
|
||||||
$where_clause,
|
$this->buildWhereClause($conn_r),
|
||||||
$limit_clause);
|
$this->buildOrderClause($conn_r),
|
||||||
|
$this->buildLimitClause($conn_r));
|
||||||
|
|
||||||
return $table->loadAllFromArray($data);
|
return $table->loadAllFromArray($data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,15 +20,14 @@ final class PhabricatorOAuthServerClientQuery
|
||||||
$table = new PhabricatorOAuthServerClient();
|
$table = new PhabricatorOAuthServerClient();
|
||||||
$conn_r = $table->establishConnection('r');
|
$conn_r = $table->establishConnection('r');
|
||||||
|
|
||||||
$where_clause = $this->buildWhereClause($conn_r);
|
|
||||||
$limit_clause = $this->buildLimitClause($conn_r);
|
|
||||||
|
|
||||||
$data = queryfx_all(
|
$data = queryfx_all(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'SELECT * FROM %T client %Q %Q',
|
'SELECT * FROM %T client %Q %Q %Q',
|
||||||
$table->getTableName(),
|
$table->getTableName(),
|
||||||
$where_clause,
|
$this->buildWhereClause($conn_r),
|
||||||
$limit_clause);
|
$this->buildOrderClause($conn_r),
|
||||||
|
$this->buildLimitClause($conn_r));
|
||||||
|
|
||||||
return $table->loadAllFromArray($data);
|
return $table->loadAllFromArray($data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorOAuthServerClientSearchEngine
|
||||||
|
extends PhabricatorApplicationSearchEngine {
|
||||||
|
|
||||||
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||||
|
$saved = new PhabricatorSavedQuery();
|
||||||
|
|
||||||
|
$saved->setParameter(
|
||||||
|
'creatorPHIDs',
|
||||||
|
$this->readUsersFromRequest($request, 'creators'));
|
||||||
|
|
||||||
|
return $saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||||
|
$query = id(new PhabricatorOAuthServerClientQuery());
|
||||||
|
|
||||||
|
$creator_phids = $saved->getParameter('creatorPHIDs', array());
|
||||||
|
if ($creator_phids) {
|
||||||
|
$query->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildSearchForm(
|
||||||
|
AphrontFormView $form,
|
||||||
|
PhabricatorSavedQuery $saved_query) {
|
||||||
|
|
||||||
|
$phids = $saved_query->getParameter('creatorPHIDs', array());
|
||||||
|
$creator_handles = id(new PhabricatorHandleQuery())
|
||||||
|
->setViewer($this->requireViewer())
|
||||||
|
->withPHIDs($phids)
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
$form
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormTokenizerControl())
|
||||||
|
->setDatasource('/typeahead/common/users/')
|
||||||
|
->setName('creators')
|
||||||
|
->setLabel(pht('Creators'))
|
||||||
|
->setValue($creator_handles));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getURI($path) {
|
||||||
|
return '/oauthserver/'.$path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuiltinQueryNames() {
|
||||||
|
$names = array();
|
||||||
|
|
||||||
|
if ($this->requireViewer()->isLoggedIn()) {
|
||||||
|
$names['created'] = pht('Created');
|
||||||
|
}
|
||||||
|
|
||||||
|
$names['all'] = pht('All Applications');
|
||||||
|
|
||||||
|
return $names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildSavedQueryFromBuiltin($query_key) {
|
||||||
|
$query = $this->newSavedQuery();
|
||||||
|
$query->setQueryKey($query_key);
|
||||||
|
|
||||||
|
switch ($query_key) {
|
||||||
|
case 'all':
|
||||||
|
return $query;
|
||||||
|
case 'created':
|
||||||
|
return $query->setParameter(
|
||||||
|
'creatorPHIDs',
|
||||||
|
array($this->requireViewer()->getPHID()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue