Skip to content

Commit 1534033

Browse files
author
epriestley
committed
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
1 parent 34c890b commit 1534033

8 files changed

+154
-163
lines changed

src/__phutil_library_map__.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@
17211721
'PhabricatorOAuthServerCapabilityCreateClients' => 'applications/oauthserver/capability/PhabricatorOAuthServerCapabilityCreateClients.php',
17221722
'PhabricatorOAuthServerClient' => 'applications/oauthserver/storage/PhabricatorOAuthServerClient.php',
17231723
'PhabricatorOAuthServerClientQuery' => 'applications/oauthserver/query/PhabricatorOAuthServerClientQuery.php',
1724-
'PhabricatorOAuthServerConsoleController' => 'applications/oauthserver/controller/PhabricatorOAuthServerConsoleController.php',
1724+
'PhabricatorOAuthServerClientSearchEngine' => 'applications/oauthserver/query/PhabricatorOAuthServerClientSearchEngine.php',
17251725
'PhabricatorOAuthServerController' => 'applications/oauthserver/controller/PhabricatorOAuthServerController.php',
17261726
'PhabricatorOAuthServerDAO' => 'applications/oauthserver/storage/PhabricatorOAuthServerDAO.php',
17271727
'PhabricatorOAuthServerPHIDTypeClient' => 'applications/oauthserver/phid/PhabricatorOAuthServerPHIDTypeClient.php',
@@ -4479,7 +4479,7 @@
44794479
1 => 'PhabricatorPolicyInterface',
44804480
),
44814481
'PhabricatorOAuthServerClientQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
4482-
'PhabricatorOAuthServerConsoleController' => 'PhabricatorOAuthServerController',
4482+
'PhabricatorOAuthServerClientSearchEngine' => 'PhabricatorApplicationSearchEngine',
44834483
'PhabricatorOAuthServerController' => 'PhabricatorController',
44844484
'PhabricatorOAuthServerDAO' => 'PhabricatorLiskDAO',
44854485
'PhabricatorOAuthServerPHIDTypeClient' => 'PhabricatorPHIDType',

src/applications/oauthserver/application/PhabricatorApplicationOAuthServer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public function isBeta() {
3333
public function getRoutes() {
3434
return array(
3535
'/oauthserver/' => array(
36-
'' => 'PhabricatorOAuthServerConsoleController',
36+
'(?:query/(?P<queryKey>[^/]+)/)?'
37+
=> 'PhabricatorOAuthClientListController',
3738
'auth/' => 'PhabricatorOAuthServerAuthController',
3839
'test/' => 'PhabricatorOAuthServerTestController',
3940
'token/' => 'PhabricatorOAuthServerTokenController',
4041
'client/' => array(
41-
'' => 'PhabricatorOAuthClientListController',
4242
'create/' => 'PhabricatorOAuthClientEditController',
4343
'delete/(?P<phid>[^/]+)/' => 'PhabricatorOAuthClientDeleteController',
4444
'edit/(?P<phid>[^/]+)/' => 'PhabricatorOAuthClientEditController',

src/applications/oauthserver/controller/PhabricatorOAuthServerConsoleController.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/applications/oauthserver/controller/client/PhabricatorOAuthClientBaseController.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,20 @@ public function shouldRequireLogin() {
2121
public function willProcessRequest(array $data) {
2222
$this->setClientPHID(idx($data, 'phid'));
2323
}
24+
25+
public function buildSideNavView($for_app = false) {
26+
$user = $this->getRequest()->getUser();
27+
28+
$nav = new AphrontSideNavFilterView();
29+
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
30+
31+
id(new PhabricatorOAuthServerClientSearchEngine())
32+
->setViewer($user)
33+
->addNavigationItems($nav->getMenu());
34+
35+
$nav->selectFilter(null);
36+
37+
return $nav;
38+
}
39+
2440
}
Lines changed: 47 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,65 @@
11
<?php
22

3-
/**
4-
* @group oauthserver
5-
*/
63
final class PhabricatorOAuthClientListController
7-
extends PhabricatorOAuthClientBaseController {
4+
extends PhabricatorOAuthClientBaseController
5+
implements PhabricatorApplicationSearchResultsControllerInterface {
86

9-
public function getFilter() {
10-
return 'client';
7+
private $queryKey;
8+
9+
public function shouldAllowPublic() {
10+
return true;
1111
}
1212

13-
public function processRequest() {
14-
$title = 'OAuth Clients';
15-
$request = $this->getRequest();
16-
$current_user = $request->getUser();
17-
$offset = $request->getInt('offset', 0);
18-
$page_size = 100;
19-
$pager = new AphrontPagerView();
20-
$request_uri = $request->getRequestURI();
21-
$pager->setURI($request_uri, 'offset');
22-
$pager->setPageSize($page_size);
23-
$pager->setOffset($offset);
24-
25-
$query = id(new PhabricatorOAuthServerClientQuery())
26-
->setViewer($current_user)
27-
->withCreatorPHIDs(array($current_user->getPHID()));
28-
$clients = $query->executeWithOffsetPager($pager);
29-
30-
$rows = array();
31-
$rowc = array();
32-
$highlight = $this->getHighlightPHIDs();
33-
foreach ($clients as $client) {
34-
$row = array(
35-
phutil_tag(
36-
'a',
37-
array(
38-
'href' => $client->getViewURI(),
39-
),
40-
$client->getName()),
41-
$client->getPHID(),
42-
$client->getSecret(),
43-
phutil_tag(
44-
'a',
45-
array(
46-
'href' => $client->getRedirectURI(),
47-
),
48-
$client->getRedirectURI()),
49-
phutil_tag(
50-
'a',
51-
array(
52-
'class' => 'small button grey',
53-
'href' => $client->getEditURI(),
54-
),
55-
'Edit'),
56-
);
57-
58-
$rows[] = $row;
59-
if (isset($highlight[$client->getPHID()])) {
60-
$rowc[] = 'highlighted';
61-
} else {
62-
$rowc[] = '';
63-
}
64-
}
13+
public function willProcessRequest(array $data) {
14+
$this->queryKey = idx($data, 'queryKey');
15+
}
6516

66-
$panel = $this->buildClientList($rows, $rowc, $title);
17+
public function processRequest() {
18+
$request = $this->getRequest();
19+
$controller = id(new PhabricatorApplicationSearchController($request))
20+
->setQueryKey($this->queryKey)
21+
->setSearchEngine(new PhabricatorOAuthServerClientSearchEngine())
22+
->setNavigation($this->buildSideNavView());
6723

68-
return $this->buildStandardPageResponse(
69-
array(
70-
$this->getNoticeView(),
71-
$panel->appendChild($pager)
72-
),
73-
array('title' => $title));
24+
return $this->delegateToController($controller);
7425
}
7526

76-
private function buildClientList($rows, $rowc, $title) {
77-
$table = new AphrontTableView($rows);
78-
$table->setRowClasses($rowc);
79-
$table->setHeaders(
80-
array(
81-
'Client',
82-
'ID',
83-
'Secret',
84-
'Redirect URI',
85-
'',
86-
));
87-
$table->setColumnClasses(
88-
array(
89-
'',
90-
'',
91-
'',
92-
'',
93-
'action',
94-
));
95-
if (empty($rows)) {
96-
$table->setNoDataString(
97-
'You have not created any clients for this OAuthServer.');
98-
}
27+
public function renderResultsList(
28+
array $clients,
29+
PhabricatorSavedQuery $query) {
30+
assert_instances_of($clients, 'PhabricatorOauthServerClient');
9931

100-
$panel = new AphrontPanelView();
101-
$panel->appendChild($table);
102-
$panel->setHeader($title);
32+
$viewer = $this->getRequest()->getUser();
33+
$this->loadHandles(mpull($clients, 'getCreatorPHID'));
10334

104-
return $panel;
105-
}
35+
$list = id(new PHUIObjectItemListView())
36+
->setUser($viewer);
37+
foreach ($clients as $client) {
38+
$creator = $this->getHandle($client->getCreatorPHID());
10639

107-
private function getNoticeView() {
108-
$edited = $this->getRequest()->getStr('edited');
109-
$new = $this->getRequest()->getStr('new');
110-
$deleted = $this->getRequest()->getBool('deleted');
111-
if ($edited) {
112-
$title = 'Successfully edited client with id '.$edited.'.';
113-
} else if ($new) {
114-
$title = 'Successfully created client with id '.$new.'.';
115-
} else if ($deleted) {
116-
$title = 'Successfully deleted client.';
117-
} else {
118-
$title = null;
119-
}
40+
$item = id(new PHUIObjectItemView())
41+
->setObjectName(pht('Application %d', $client->getID()))
42+
->setHeader($client->getName())
43+
->setHref($client->getViewURI())
44+
->setObject($client)
45+
->addByline(pht('Creator: %s', $creator->renderLink()));
12046

121-
if ($title) {
122-
$view = new AphrontErrorView();
123-
$view->setTitle($title);
124-
$view->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
125-
} else {
126-
$view = null;
47+
$list->addItem($item);
12748
}
12849

129-
return $view;
50+
return $list;
13051
}
52+
53+
public function buildApplicationCrumbs() {
54+
$crumbs = parent::buildApplicationCrumbs();
55+
56+
$crumbs->addAction(
57+
id(new PHUIListItemView())
58+
->setHref($this->getApplicationURI('client/create/'))
59+
->setName(pht('Create Application'))
60+
->setIcon('create'));
61+
62+
return $crumbs;
63+
}
64+
13165
}

src/applications/oauthserver/query/PhabricatorOAuthClientAuthorizationQuery.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ public function loadPage() {
2020
$table = new PhabricatorOAuthClientAuthorization();
2121
$conn_r = $table->establishConnection('r');
2222

23-
$where_clause = $this->buildWhereClause($conn_r);
24-
$limit_clause = $this->buildLimitClause($conn_r);
25-
2623
$data = queryfx_all(
2724
$conn_r,
28-
'SELECT * FROM %T auth %Q %Q',
25+
'SELECT * FROM %T auth %Q %Q %Q',
2926
$table->getTableName(),
30-
$where_clause,
31-
$limit_clause);
27+
$this->buildWhereClause($conn_r),
28+
$this->buildOrderClause($conn_r),
29+
$this->buildLimitClause($conn_r));
3230

3331
return $table->loadAllFromArray($data);
3432
}

src/applications/oauthserver/query/PhabricatorOAuthServerClientQuery.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ public function loadPage() {
2020
$table = new PhabricatorOAuthServerClient();
2121
$conn_r = $table->establishConnection('r');
2222

23-
$where_clause = $this->buildWhereClause($conn_r);
24-
$limit_clause = $this->buildLimitClause($conn_r);
2523

2624
$data = queryfx_all(
2725
$conn_r,
28-
'SELECT * FROM %T client %Q %Q',
26+
'SELECT * FROM %T client %Q %Q %Q',
2927
$table->getTableName(),
30-
$where_clause,
31-
$limit_clause);
28+
$this->buildWhereClause($conn_r),
29+
$this->buildOrderClause($conn_r),
30+
$this->buildLimitClause($conn_r));
3231

3332
return $table->loadAllFromArray($data);
3433
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
final class PhabricatorOAuthServerClientSearchEngine
4+
extends PhabricatorApplicationSearchEngine {
5+
6+
public function buildSavedQueryFromRequest(AphrontRequest $request) {
7+
$saved = new PhabricatorSavedQuery();
8+
9+
$saved->setParameter(
10+
'creatorPHIDs',
11+
$this->readUsersFromRequest($request, 'creators'));
12+
13+
return $saved;
14+
}
15+
16+
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
17+
$query = id(new PhabricatorOAuthServerClientQuery());
18+
19+
$creator_phids = $saved->getParameter('creatorPHIDs', array());
20+
if ($creator_phids) {
21+
$query->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array()));
22+
}
23+
24+
return $query;
25+
}
26+
27+
public function buildSearchForm(
28+
AphrontFormView $form,
29+
PhabricatorSavedQuery $saved_query) {
30+
31+
$phids = $saved_query->getParameter('creatorPHIDs', array());
32+
$creator_handles = id(new PhabricatorHandleQuery())
33+
->setViewer($this->requireViewer())
34+
->withPHIDs($phids)
35+
->execute();
36+
37+
$form
38+
->appendChild(
39+
id(new AphrontFormTokenizerControl())
40+
->setDatasource('/typeahead/common/users/')
41+
->setName('creators')
42+
->setLabel(pht('Creators'))
43+
->setValue($creator_handles));
44+
45+
}
46+
47+
protected function getURI($path) {
48+
return '/oauthserver/'.$path;
49+
}
50+
51+
public function getBuiltinQueryNames() {
52+
$names = array();
53+
54+
if ($this->requireViewer()->isLoggedIn()) {
55+
$names['created'] = pht('Created');
56+
}
57+
58+
$names['all'] = pht('All Applications');
59+
60+
return $names;
61+
}
62+
63+
public function buildSavedQueryFromBuiltin($query_key) {
64+
$query = $this->newSavedQuery();
65+
$query->setQueryKey($query_key);
66+
67+
switch ($query_key) {
68+
case 'all':
69+
return $query;
70+
case 'created':
71+
return $query->setParameter(
72+
'creatorPHIDs',
73+
array($this->requireViewer()->getPHID()));
74+
}
75+
76+
return parent::buildSavedQueryFromBuiltin($query_key);
77+
}
78+
79+
}

0 commit comments

Comments
 (0)