diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1721,7 +1721,7 @@ '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 @@ 1 => 'PhabricatorPolicyInterface', ), 'PhabricatorOAuthServerClientQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', - 'PhabricatorOAuthServerConsoleController' => 'PhabricatorOAuthServerController', + 'PhabricatorOAuthServerClientSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorOAuthServerController' => 'PhabricatorController', 'PhabricatorOAuthServerDAO' => 'PhabricatorLiskDAO', 'PhabricatorOAuthServerPHIDTypeClient' => 'PhabricatorPHIDType', diff --git a/src/applications/oauthserver/application/PhabricatorApplicationOAuthServer.php b/src/applications/oauthserver/application/PhabricatorApplicationOAuthServer.php --- a/src/applications/oauthserver/application/PhabricatorApplicationOAuthServer.php +++ b/src/applications/oauthserver/application/PhabricatorApplicationOAuthServer.php @@ -33,12 +33,12 @@ public function getRoutes() { return array( '/oauthserver/' => array( - '' => 'PhabricatorOAuthServerConsoleController', + '(?:query/(?P[^/]+)/)?' + => 'PhabricatorOAuthClientListController', 'auth/' => 'PhabricatorOAuthServerAuthController', 'test/' => 'PhabricatorOAuthServerTestController', 'token/' => 'PhabricatorOAuthServerTokenController', 'client/' => array( - '' => 'PhabricatorOAuthClientListController', 'create/' => 'PhabricatorOAuthClientEditController', 'delete/(?P[^/]+)/' => 'PhabricatorOAuthClientDeleteController', 'edit/(?P[^/]+)/' => 'PhabricatorOAuthClientEditController', diff --git a/src/applications/oauthserver/controller/PhabricatorOAuthServerConsoleController.php b/src/applications/oauthserver/controller/PhabricatorOAuthServerConsoleController.php deleted file mode 100644 --- a/src/applications/oauthserver/controller/PhabricatorOAuthServerConsoleController.php +++ /dev/null @@ -1,35 +0,0 @@ -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, - )); - } - -} diff --git a/src/applications/oauthserver/controller/client/PhabricatorOAuthClientBaseController.php b/src/applications/oauthserver/controller/client/PhabricatorOAuthClientBaseController.php --- a/src/applications/oauthserver/controller/client/PhabricatorOAuthClientBaseController.php +++ b/src/applications/oauthserver/controller/client/PhabricatorOAuthClientBaseController.php @@ -21,4 +21,20 @@ 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; + } + } diff --git a/src/applications/oauthserver/controller/client/PhabricatorOAuthClientListController.php b/src/applications/oauthserver/controller/client/PhabricatorOAuthClientListController.php --- a/src/applications/oauthserver/controller/client/PhabricatorOAuthClientListController.php +++ b/src/applications/oauthserver/controller/client/PhabricatorOAuthClientListController.php @@ -1,131 +1,65 @@ 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); - - $query = id(new PhabricatorOAuthServerClientQuery()) - ->setViewer($current_user) - ->withCreatorPHIDs(array($current_user->getPHID())); - $clients = $query->executeWithOffsetPager($pager); - - $rows = array(); - $rowc = array(); - $highlight = $this->getHighlightPHIDs(); - 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'), - ); - - $rows[] = $row; - if (isset($highlight[$client->getPHID()])) { - $rowc[] = 'highlighted'; - } else { - $rowc[] = ''; - } - } + public function willProcessRequest(array $data) { + $this->queryKey = idx($data, 'queryKey'); + } - $panel = $this->buildClientList($rows, $rowc, $title); + public function processRequest() { + $request = $this->getRequest(); + $controller = id(new PhabricatorApplicationSearchController($request)) + ->setQueryKey($this->queryKey) + ->setSearchEngine(new PhabricatorOAuthServerClientSearchEngine()) + ->setNavigation($this->buildSideNavView()); - return $this->buildStandardPageResponse( - array( - $this->getNoticeView(), - $panel->appendChild($pager) - ), - array('title' => $title)); + return $this->delegateToController($controller); } - 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 renderResultsList( + array $clients, + PhabricatorSavedQuery $query) { + assert_instances_of($clients, 'PhabricatorOauthServerClient'); - $panel = new AphrontPanelView(); - $panel->appendChild($table); - $panel->setHeader($title); + $viewer = $this->getRequest()->getUser(); + $this->loadHandles(mpull($clients, 'getCreatorPHID')); - return $panel; - } + $list = id(new PHUIObjectItemListView()) + ->setUser($viewer); + foreach ($clients as $client) { + $creator = $this->getHandle($client->getCreatorPHID()); - 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; - } + $item = id(new PHUIObjectItemView()) + ->setObjectName(pht('Application %d', $client->getID())) + ->setHeader($client->getName()) + ->setHref($client->getViewURI()) + ->setObject($client) + ->addByline(pht('Creator: %s', $creator->renderLink())); - if ($title) { - $view = new AphrontErrorView(); - $view->setTitle($title); - $view->setSeverity(AphrontErrorView::SEVERITY_NOTICE); - } else { - $view = null; + $list->addItem($item); } - return $view; + return $list; } + + public function buildApplicationCrumbs() { + $crumbs = parent::buildApplicationCrumbs(); + + $crumbs->addAction( + id(new PHUIListItemView()) + ->setHref($this->getApplicationURI('client/create/')) + ->setName(pht('Create Application')) + ->setIcon('create')); + + return $crumbs; + } + } diff --git a/src/applications/oauthserver/query/PhabricatorOAuthClientAuthorizationQuery.php b/src/applications/oauthserver/query/PhabricatorOAuthClientAuthorizationQuery.php --- a/src/applications/oauthserver/query/PhabricatorOAuthClientAuthorizationQuery.php +++ b/src/applications/oauthserver/query/PhabricatorOAuthClientAuthorizationQuery.php @@ -20,15 +20,13 @@ $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); } diff --git a/src/applications/oauthserver/query/PhabricatorOAuthServerClientQuery.php b/src/applications/oauthserver/query/PhabricatorOAuthServerClientQuery.php --- a/src/applications/oauthserver/query/PhabricatorOAuthServerClientQuery.php +++ b/src/applications/oauthserver/query/PhabricatorOAuthServerClientQuery.php @@ -20,15 +20,14 @@ $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); } diff --git a/src/applications/oauthserver/query/PhabricatorOAuthServerClientSearchEngine.php b/src/applications/oauthserver/query/PhabricatorOAuthServerClientSearchEngine.php new file mode 100644 --- /dev/null +++ b/src/applications/oauthserver/query/PhabricatorOAuthServerClientSearchEngine.php @@ -0,0 +1,79 @@ +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); + } + +}