1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +01:00

Add List/ApplicationSearch to AuthProviderConfig

Summary: Ref T1536. Adds a list controller and ApplicationSearch integration for listing providers.

Test Plan: {F46308}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1536

Differential Revision: https://secure.phabricator.com/D6198
This commit is contained in:
epriestley 2013-06-17 10:50:43 -07:00
parent f0ddfe6565
commit b927dc057d
5 changed files with 167 additions and 4 deletions

View file

@ -819,10 +819,13 @@ phutil_register_library_map(array(
'PhabricatorAuthController' => 'applications/auth/controller/PhabricatorAuthController.php',
'PhabricatorAuthDAO' => 'applications/auth/storage/PhabricatorAuthDAO.php',
'PhabricatorAuthLinkController' => 'applications/auth/controller/PhabricatorAuthLinkController.php',
'PhabricatorAuthListController' => 'applications/auth/controller/config/PhabricatorAuthListController.php',
'PhabricatorAuthLoginController' => 'applications/auth/controller/PhabricatorAuthLoginController.php',
'PhabricatorAuthProvider' => 'applications/auth/provider/PhabricatorAuthProvider.php',
'PhabricatorAuthProviderConfig' => 'applications/auth/storage/PhabricatorAuthProviderConfig.php',
'PhabricatorAuthProviderConfigController' => 'applications/auth/controller/config/PhabricatorAuthProviderConfigController.php',
'PhabricatorAuthProviderConfigQuery' => 'applications/auth/query/PhabricatorAuthProviderConfigQuery.php',
'PhabricatorAuthProviderConfigSearchEngine' => 'applications/auth/query/PhabricatorAuthProviderConfigSearchEngine.php',
'PhabricatorAuthProviderConfigTransaction' => 'applications/auth/storage/PhabricatorAuthProviderConfigTransaction.php',
'PhabricatorAuthProviderConfigTransactionQuery' => 'applications/auth/query/PhabricatorAuthProviderConfigTransactionQuery.php',
'PhabricatorAuthProviderLDAP' => 'applications/auth/provider/PhabricatorAuthProviderLDAP.php',
@ -2689,13 +2692,20 @@ phutil_register_library_map(array(
'PhabricatorAuthController' => 'PhabricatorController',
'PhabricatorAuthDAO' => 'PhabricatorLiskDAO',
'PhabricatorAuthLinkController' => 'PhabricatorAuthController',
'PhabricatorAuthListController' =>
array(
0 => 'PhabricatorAuthProviderConfigController',
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
),
'PhabricatorAuthLoginController' => 'PhabricatorAuthController',
'PhabricatorAuthProviderConfig' =>
array(
0 => 'PhabricatorAuthDAO',
1 => 'PhabricatorPolicyInterface',
),
'PhabricatorAuthProviderConfigController' => 'PhabricatorAuthController',
'PhabricatorAuthProviderConfigQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorAuthProviderConfigSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorAuthProviderConfigTransaction' => 'PhabricatorApplicationTransaction',
'PhabricatorAuthProviderConfigTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhabricatorAuthProviderLDAP' => 'PhabricatorAuthProvider',

View file

@ -2,10 +2,6 @@
final class PhabricatorApplicationAuth extends PhabricatorApplication {
public function shouldAppearInLaunchView() {
return false;
}
public function canUninstall() {
return false;
}
@ -33,9 +29,19 @@ final class PhabricatorApplicationAuth extends PhabricatorApplication {
return $items;
}
public function shouldAppearInLaunchView() {
return false;
}
public function getRoutes() {
return array(
'/auth/' => array(
/*
'(query/(?P<key>[^/]+)/)?' =>
'PhabricatorAuthListController',
*/
'login/(?P<pkey>[^/]+)/' => 'PhabricatorAuthLoginController',
'register/(?:(?P<akey>[^/]+)/)?' => 'PhabricatorAuthRegisterController',
'start/' => 'PhabricatorAuthStartController',

View file

@ -0,0 +1,37 @@
<?php
final class PhabricatorAuthListController
extends PhabricatorAuthProviderConfigController
implements PhabricatorApplicationSearchResultsControllerInterface {
private $key;
public function willProcessRequest(array $data) {
$this->key = idx($data, 'key');
}
public function processRequest() {
$request = $this->getRequest();
$controller = id(new PhabricatorApplicationSearchController($request))
->setQueryKey($this->key)
->setSearchEngine(new PhabricatorAuthProviderConfigSearchEngine())
->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller);
}
public function renderResultsList(array $configs) {
assert_instances_of($configs, 'PhabricatorAuthProviderConfig');
$viewer = $this->getRequest()->getUser();
$list = new PhabricatorObjectItemListView();
foreach ($configs as $config) {
$item = new PHUIListItemView();
$list->addItem($item);
}
return $list;
}
}

View file

@ -0,0 +1,44 @@
<?php
abstract class PhabricatorAuthProviderConfigController
extends PhabricatorAuthController {
public function shouldRequireAdmin() {
return true;
}
protected function buildSideNavView($for_app = false) {
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
if ($for_app) {
$nav->addLabel(pht('Create'));
$nav->addFilter('',
pht('Add Authentication Provider'),
$this->getApplicationURI('/config/new/'));
}
id(new PhabricatorAuthProviderConfigSearchEngine())
->setViewer($this->getRequest()->getUser())
->addNavigationItems($nav->getMenu());
return $nav;
}
public function buildApplicationMenu() {
return $this->buildSideNavView($for_app = true)->getMenu();
}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('Add Authentication Provider'))
->setHref($this->getApplicationURI('/config/new/'))
->setIcon('create'));
return $crumbs;
}
}

View file

@ -0,0 +1,66 @@
<?php
final class PhabricatorAuthProviderConfigSearchEngine
extends PhabricatorApplicationSearchEngine {
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter('status', $request->getStr('status'));
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = new PhabricatorAuthProviderConfigQuery();
$status = $saved->getParameter('status');
$options = PhabricatorAuthProviderConfigQuery::getStatusOptions();
if (empty($options[$status])) {
$status = head_key($options);
}
$query->withStatus($status);
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
$status = $saved_query->getParameter('status');
$form
->appendChild(
id(new AphrontFormSelectControl())
->setName('status')
->setLabel(pht('Status'))
->setOptions(PhabricatorAuthProviderConfigQuery::getStatusOptions())
->setValue($status));
}
protected function getURI($path) {
return '/auth/'.$path;
}
public function getBuiltinQueryNames() {
$names = array(
'all' => pht('All'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query->setParameter(
'status',
PhabricatorAuthProviderConfigQuery::STATUS_ALL);
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
}