1
0
Fork 0
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:
epriestley 2014-03-18 13:31:04 -07:00
parent 34c890b7e1
commit 1534033664
8 changed files with 152 additions and 161 deletions

View file

@ -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',

View file

@ -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',

View file

@ -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,
));
}
}

View file

@ -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;
}
} }

View file

@ -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();
$current_user = $request->getUser(); $controller = id(new PhabricatorApplicationSearchController($request))
$offset = $request->getInt('offset', 0); ->setQueryKey($this->queryKey)
$page_size = 100; ->setSearchEngine(new PhabricatorOAuthServerClientSearchEngine())
$pager = new AphrontPagerView(); ->setNavigation($this->buildSideNavView());
$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( $crumbs->addAction(
array( id(new PHUIListItemView())
'Client', ->setHref($this->getApplicationURI('client/create/'))
'ID', ->setName(pht('Create Application'))
'Secret', ->setIcon('create'));
'Redirect URI',
'', return $crumbs;
));
$table->setColumnClasses(
array(
'',
'',
'',
'',
'action',
));
if (empty($rows)) {
$table->setNoDataString(
'You have not created any clients for this OAuthServer.');
} }
$panel = new AphrontPanelView();
$panel->appendChild($table);
$panel->setHeader($title);
return $panel;
}
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;
}
} }

View file

@ -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);
} }

View file

@ -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);
} }

View file

@ -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);
}
}