mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +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',
|
||||
'PhabricatorOAuthServerClient' => 'applications/oauthserver/storage/PhabricatorOAuthServerClient.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',
|
||||
'PhabricatorOAuthServerDAO' => 'applications/oauthserver/storage/PhabricatorOAuthServerDAO.php',
|
||||
'PhabricatorOAuthServerPHIDTypeClient' => 'applications/oauthserver/phid/PhabricatorOAuthServerPHIDTypeClient.php',
|
||||
|
@ -4479,7 +4479,7 @@ phutil_register_library_map(array(
|
|||
1 => 'PhabricatorPolicyInterface',
|
||||
),
|
||||
'PhabricatorOAuthServerClientQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorOAuthServerConsoleController' => 'PhabricatorOAuthServerController',
|
||||
'PhabricatorOAuthServerClientSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorOAuthServerController' => 'PhabricatorController',
|
||||
'PhabricatorOAuthServerDAO' => 'PhabricatorLiskDAO',
|
||||
'PhabricatorOAuthServerPHIDTypeClient' => 'PhabricatorPHIDType',
|
||||
|
|
|
@ -33,12 +33,12 @@ final class PhabricatorApplicationOAuthServer extends PhabricatorApplication {
|
|||
public function getRoutes() {
|
||||
return array(
|
||||
'/oauthserver/' => array(
|
||||
'' => 'PhabricatorOAuthServerConsoleController',
|
||||
'(?:query/(?P<queryKey>[^/]+)/)?'
|
||||
=> 'PhabricatorOAuthClientListController',
|
||||
'auth/' => 'PhabricatorOAuthServerAuthController',
|
||||
'test/' => 'PhabricatorOAuthServerTestController',
|
||||
'token/' => 'PhabricatorOAuthServerTokenController',
|
||||
'client/' => array(
|
||||
'' => 'PhabricatorOAuthClientListController',
|
||||
'create/' => 'PhabricatorOAuthClientEditController',
|
||||
'delete/(?P<phid>[^/]+)/' => 'PhabricatorOAuthClientDeleteController',
|
||||
'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) {
|
||||
$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
|
||||
|
||||
/**
|
||||
* @group oauthserver
|
||||
*/
|
||||
final class PhabricatorOAuthClientListController
|
||||
extends PhabricatorOAuthClientBaseController {
|
||||
extends PhabricatorOAuthClientBaseController
|
||||
implements PhabricatorApplicationSearchResultsControllerInterface {
|
||||
|
||||
public function getFilter() {
|
||||
return 'client';
|
||||
private $queryKey;
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->queryKey = idx($data, 'queryKey');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$title = 'OAuth Clients';
|
||||
$request = $this->getRequest();
|
||||
$current_user = $request->getUser();
|
||||
$offset = $request->getInt('offset', 0);
|
||||
$page_size = 100;
|
||||
$pager = new AphrontPagerView();
|
||||
$request_uri = $request->getRequestURI();
|
||||
$pager->setURI($request_uri, 'offset');
|
||||
$pager->setPageSize($page_size);
|
||||
$pager->setOffset($offset);
|
||||
$request = $this->getRequest();
|
||||
$controller = id(new PhabricatorApplicationSearchController($request))
|
||||
->setQueryKey($this->queryKey)
|
||||
->setSearchEngine(new PhabricatorOAuthServerClientSearchEngine())
|
||||
->setNavigation($this->buildSideNavView());
|
||||
|
||||
$query = id(new PhabricatorOAuthServerClientQuery())
|
||||
->setViewer($current_user)
|
||||
->withCreatorPHIDs(array($current_user->getPHID()));
|
||||
$clients = $query->executeWithOffsetPager($pager);
|
||||
return $this->delegateToController($controller);
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
$rowc = array();
|
||||
$highlight = $this->getHighlightPHIDs();
|
||||
public function renderResultsList(
|
||||
array $clients,
|
||||
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) {
|
||||
$row = array(
|
||||
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'),
|
||||
);
|
||||
$creator = $this->getHandle($client->getCreatorPHID());
|
||||
|
||||
$rows[] = $row;
|
||||
if (isset($highlight[$client->getPHID()])) {
|
||||
$rowc[] = 'highlighted';
|
||||
} else {
|
||||
$rowc[] = '';
|
||||
}
|
||||
$item = id(new PHUIObjectItemView())
|
||||
->setObjectName(pht('Application %d', $client->getID()))
|
||||
->setHeader($client->getName())
|
||||
->setHref($client->getViewURI())
|
||||
->setObject($client)
|
||||
->addByline(pht('Creator: %s', $creator->renderLink()));
|
||||
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
$panel = $this->buildClientList($rows, $rowc, $title);
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
array(
|
||||
$this->getNoticeView(),
|
||||
$panel->appendChild($pager)
|
||||
),
|
||||
array('title' => $title));
|
||||
return $list;
|
||||
}
|
||||
|
||||
private function buildClientList($rows, $rowc, $title) {
|
||||
$table = new AphrontTableView($rows);
|
||||
$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.');
|
||||
}
|
||||
public function buildApplicationCrumbs() {
|
||||
$crumbs = parent::buildApplicationCrumbs();
|
||||
|
||||
$panel = new AphrontPanelView();
|
||||
$panel->appendChild($table);
|
||||
$panel->setHeader($title);
|
||||
$crumbs->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->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();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
||||
$where_clause = $this->buildWhereClause($conn_r);
|
||||
$limit_clause = $this->buildLimitClause($conn_r);
|
||||
|
||||
$data = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT * FROM %T auth %Q %Q',
|
||||
'SELECT * FROM %T auth %Q %Q %Q',
|
||||
$table->getTableName(),
|
||||
$where_clause,
|
||||
$limit_clause);
|
||||
$this->buildWhereClause($conn_r),
|
||||
$this->buildOrderClause($conn_r),
|
||||
$this->buildLimitClause($conn_r));
|
||||
|
||||
return $table->loadAllFromArray($data);
|
||||
}
|
||||
|
|
|
@ -20,15 +20,14 @@ final class PhabricatorOAuthServerClientQuery
|
|||
$table = new PhabricatorOAuthServerClient();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
||||
$where_clause = $this->buildWhereClause($conn_r);
|
||||
$limit_clause = $this->buildLimitClause($conn_r);
|
||||
|
||||
$data = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT * FROM %T client %Q %Q',
|
||||
'SELECT * FROM %T client %Q %Q %Q',
|
||||
$table->getTableName(),
|
||||
$where_clause,
|
||||
$limit_clause);
|
||||
$this->buildWhereClause($conn_r),
|
||||
$this->buildOrderClause($conn_r),
|
||||
$this->buildLimitClause($conn_r));
|
||||
|
||||
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