@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+151 -160
+2 -2
src/__phutil_library_map__.php
··· 1721 1721 'PhabricatorOAuthServerCapabilityCreateClients' => 'applications/oauthserver/capability/PhabricatorOAuthServerCapabilityCreateClients.php', 1722 1722 'PhabricatorOAuthServerClient' => 'applications/oauthserver/storage/PhabricatorOAuthServerClient.php', 1723 1723 'PhabricatorOAuthServerClientQuery' => 'applications/oauthserver/query/PhabricatorOAuthServerClientQuery.php', 1724 - 'PhabricatorOAuthServerConsoleController' => 'applications/oauthserver/controller/PhabricatorOAuthServerConsoleController.php', 1724 + 'PhabricatorOAuthServerClientSearchEngine' => 'applications/oauthserver/query/PhabricatorOAuthServerClientSearchEngine.php', 1725 1725 'PhabricatorOAuthServerController' => 'applications/oauthserver/controller/PhabricatorOAuthServerController.php', 1726 1726 'PhabricatorOAuthServerDAO' => 'applications/oauthserver/storage/PhabricatorOAuthServerDAO.php', 1727 1727 'PhabricatorOAuthServerPHIDTypeClient' => 'applications/oauthserver/phid/PhabricatorOAuthServerPHIDTypeClient.php', ··· 4479 4479 1 => 'PhabricatorPolicyInterface', 4480 4480 ), 4481 4481 'PhabricatorOAuthServerClientQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 4482 - 'PhabricatorOAuthServerConsoleController' => 'PhabricatorOAuthServerController', 4482 + 'PhabricatorOAuthServerClientSearchEngine' => 'PhabricatorApplicationSearchEngine', 4483 4483 'PhabricatorOAuthServerController' => 'PhabricatorController', 4484 4484 'PhabricatorOAuthServerDAO' => 'PhabricatorLiskDAO', 4485 4485 'PhabricatorOAuthServerPHIDTypeClient' => 'PhabricatorPHIDType',
+2 -2
src/applications/oauthserver/application/PhabricatorApplicationOAuthServer.php
··· 33 33 public function getRoutes() { 34 34 return array( 35 35 '/oauthserver/' => array( 36 - '' => 'PhabricatorOAuthServerConsoleController', 36 + '(?:query/(?P<queryKey>[^/]+)/)?' 37 + => 'PhabricatorOAuthClientListController', 37 38 'auth/' => 'PhabricatorOAuthServerAuthController', 38 39 'test/' => 'PhabricatorOAuthServerTestController', 39 40 'token/' => 'PhabricatorOAuthServerTokenController', 40 41 'client/' => array( 41 - '' => 'PhabricatorOAuthClientListController', 42 42 'create/' => 'PhabricatorOAuthClientEditController', 43 43 'delete/(?P<phid>[^/]+)/' => 'PhabricatorOAuthClientDeleteController', 44 44 'edit/(?P<phid>[^/]+)/' => 'PhabricatorOAuthClientEditController',
-35
src/applications/oauthserver/controller/PhabricatorOAuthServerConsoleController.php
··· 1 - <?php 2 - 3 - final class PhabricatorOAuthServerConsoleController 4 - extends PhabricatorOAuthServerController { 5 - 6 - public function processRequest() { 7 - $request = $this->getRequest(); 8 - $viewer = $request->getUser(); 9 - 10 - $menu = id(new PHUIObjectItemListView()) 11 - ->setUser($viewer); 12 - 13 - $menu->addItem( 14 - id(new PHUIObjectItemView()) 15 - ->setHeader(pht('Applications')) 16 - ->setHref($this->getApplicationURI('client/')) 17 - ->addAttribute( 18 - pht( 19 - 'Create a new OAuth application.'))); 20 - 21 - $crumbs = $this->buildApplicationCrumbs(); 22 - $crumbs->addTextCrumb(pht('Console')); 23 - 24 - return $this->buildApplicationPage( 25 - array( 26 - $crumbs, 27 - $menu, 28 - ), 29 - array( 30 - 'title' => pht('OAuth Server Console'), 31 - 'device' => true, 32 - )); 33 - } 34 - 35 - }
+16
src/applications/oauthserver/controller/client/PhabricatorOAuthClientBaseController.php
··· 21 21 public function willProcessRequest(array $data) { 22 22 $this->setClientPHID(idx($data, 'phid')); 23 23 } 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 + 24 40 }
+44 -110
src/applications/oauthserver/controller/client/PhabricatorOAuthClientListController.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group oauthserver 5 - */ 6 3 final class PhabricatorOAuthClientListController 7 - extends PhabricatorOAuthClientBaseController { 4 + extends PhabricatorOAuthClientBaseController 5 + implements PhabricatorApplicationSearchResultsControllerInterface { 6 + 7 + private $queryKey; 8 8 9 - public function getFilter() { 10 - return 'client'; 9 + public function shouldAllowPublic() { 10 + return true; 11 + } 12 + 13 + public function willProcessRequest(array $data) { 14 + $this->queryKey = idx($data, 'queryKey'); 11 15 } 12 16 13 17 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); 18 + $request = $this->getRequest(); 19 + $controller = id(new PhabricatorApplicationSearchController($request)) 20 + ->setQueryKey($this->queryKey) 21 + ->setSearchEngine(new PhabricatorOAuthServerClientSearchEngine()) 22 + ->setNavigation($this->buildSideNavView()); 24 23 25 - $query = id(new PhabricatorOAuthServerClientQuery()) 26 - ->setViewer($current_user) 27 - ->withCreatorPHIDs(array($current_user->getPHID())); 28 - $clients = $query->executeWithOffsetPager($pager); 24 + return $this->delegateToController($controller); 25 + } 29 26 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 - ); 27 + public function renderResultsList( 28 + array $clients, 29 + PhabricatorSavedQuery $query) { 30 + assert_instances_of($clients, 'PhabricatorOauthServerClient'); 57 31 58 - $rows[] = $row; 59 - if (isset($highlight[$client->getPHID()])) { 60 - $rowc[] = 'highlighted'; 61 - } else { 62 - $rowc[] = ''; 63 - } 64 - } 32 + $viewer = $this->getRequest()->getUser(); 33 + $this->loadHandles(mpull($clients, 'getCreatorPHID')); 65 34 66 - $panel = $this->buildClientList($rows, $rowc, $title); 35 + $list = id(new PHUIObjectItemListView()) 36 + ->setUser($viewer); 37 + foreach ($clients as $client) { 38 + $creator = $this->getHandle($client->getCreatorPHID()); 67 39 68 - return $this->buildStandardPageResponse( 69 - array( 70 - $this->getNoticeView(), 71 - $panel->appendChild($pager) 72 - ), 73 - array('title' => $title)); 74 - } 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())); 75 46 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.'); 47 + $list->addItem($item); 98 48 } 99 49 100 - $panel = new AphrontPanelView(); 101 - $panel->appendChild($table); 102 - $panel->setHeader($title); 103 - 104 - return $panel; 50 + return $list; 105 51 } 106 52 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 - } 53 + public function buildApplicationCrumbs() { 54 + $crumbs = parent::buildApplicationCrumbs(); 120 55 121 - if ($title) { 122 - $view = new AphrontErrorView(); 123 - $view->setTitle($title); 124 - $view->setSeverity(AphrontErrorView::SEVERITY_NOTICE); 125 - } else { 126 - $view = null; 127 - } 56 + $crumbs->addAction( 57 + id(new PHUIListItemView()) 58 + ->setHref($this->getApplicationURI('client/create/')) 59 + ->setName(pht('Create Application')) 60 + ->setIcon('create')); 128 61 129 - return $view; 62 + return $crumbs; 130 63 } 64 + 131 65 }
+4 -6
src/applications/oauthserver/query/PhabricatorOAuthClientAuthorizationQuery.php
··· 20 20 $table = new PhabricatorOAuthClientAuthorization(); 21 21 $conn_r = $table->establishConnection('r'); 22 22 23 - $where_clause = $this->buildWhereClause($conn_r); 24 - $limit_clause = $this->buildLimitClause($conn_r); 25 - 26 23 $data = queryfx_all( 27 24 $conn_r, 28 - 'SELECT * FROM %T auth %Q %Q', 25 + 'SELECT * FROM %T auth %Q %Q %Q', 29 26 $table->getTableName(), 30 - $where_clause, 31 - $limit_clause); 27 + $this->buildWhereClause($conn_r), 28 + $this->buildOrderClause($conn_r), 29 + $this->buildLimitClause($conn_r)); 32 30 33 31 return $table->loadAllFromArray($data); 34 32 }
+4 -5
src/applications/oauthserver/query/PhabricatorOAuthServerClientQuery.php
··· 20 20 $table = new PhabricatorOAuthServerClient(); 21 21 $conn_r = $table->establishConnection('r'); 22 22 23 - $where_clause = $this->buildWhereClause($conn_r); 24 - $limit_clause = $this->buildLimitClause($conn_r); 25 23 26 24 $data = queryfx_all( 27 25 $conn_r, 28 - 'SELECT * FROM %T client %Q %Q', 26 + 'SELECT * FROM %T client %Q %Q %Q', 29 27 $table->getTableName(), 30 - $where_clause, 31 - $limit_clause); 28 + $this->buildWhereClause($conn_r), 29 + $this->buildOrderClause($conn_r), 30 + $this->buildLimitClause($conn_r)); 32 31 33 32 return $table->loadAllFromArray($data); 34 33 }
+79
src/applications/oauthserver/query/PhabricatorOAuthServerClientSearchEngine.php
··· 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 + }