mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 10:12:41 +01:00
Replace "Add Auth Provider" radio buttons with a more modern "click to select" UI
Summary: Depends on D20094. Ref T13244. Ref T6703. See PHI774. Currently, we use an older-style radio-button UI to choose an auth provider type (Google, Password, LDAP, etc). Instead, use a more modern click-to-select UI. Test Plan: {F6184343} Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13244, T6703 Differential Revision: https://secure.phabricator.com/D20095
This commit is contained in:
parent
6f3bd13cf5
commit
8c8d56dc56
4 changed files with 56 additions and 86 deletions
|
@ -48,8 +48,7 @@ final class PhabricatorAuthApplication extends PhabricatorApplication {
|
||||||
'' => 'PhabricatorAuthListController',
|
'' => 'PhabricatorAuthListController',
|
||||||
'config/' => array(
|
'config/' => array(
|
||||||
'new/' => 'PhabricatorAuthNewController',
|
'new/' => 'PhabricatorAuthNewController',
|
||||||
'new/(?P<className>[^/]+)/' => 'PhabricatorAuthEditController',
|
'edit/(?:(?P<id>\d+)/)?' => 'PhabricatorAuthEditController',
|
||||||
'edit/(?P<id>\d+)/' => 'PhabricatorAuthEditController',
|
|
||||||
'(?P<action>enable|disable)/(?P<id>\d+)/'
|
'(?P<action>enable|disable)/(?P<id>\d+)/'
|
||||||
=> 'PhabricatorAuthDisableController',
|
=> 'PhabricatorAuthDisableController',
|
||||||
),
|
),
|
||||||
|
|
|
@ -6,8 +6,9 @@ final class PhabricatorAuthEditController
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
$this->requireApplicationCapability(
|
$this->requireApplicationCapability(
|
||||||
AuthManageProvidersCapability::CAPABILITY);
|
AuthManageProvidersCapability::CAPABILITY);
|
||||||
$viewer = $request->getUser();
|
|
||||||
$provider_class = $request->getURIData('className');
|
$viewer = $this->getViewer();
|
||||||
|
$provider_class = $request->getStr('provider');
|
||||||
$config_id = $request->getURIData('id');
|
$config_id = $request->getURIData('id');
|
||||||
|
|
||||||
if ($config_id) {
|
if ($config_id) {
|
||||||
|
@ -275,6 +276,7 @@ final class PhabricatorAuthEditController
|
||||||
|
|
||||||
$form = id(new AphrontFormView())
|
$form = id(new AphrontFormView())
|
||||||
->setUser($viewer)
|
->setUser($viewer)
|
||||||
|
->addHiddenInput('provider', $provider_class)
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormCheckboxControl())
|
id(new AphrontFormCheckboxControl())
|
||||||
->setLabel(pht('Allow'))
|
->setLabel(pht('Allow'))
|
||||||
|
|
|
@ -6,44 +6,12 @@ final class PhabricatorAuthNewController
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
$this->requireApplicationCapability(
|
$this->requireApplicationCapability(
|
||||||
AuthManageProvidersCapability::CAPABILITY);
|
AuthManageProvidersCapability::CAPABILITY);
|
||||||
$request = $this->getRequest();
|
|
||||||
$viewer = $request->getUser();
|
$viewer = $this->getViewer();
|
||||||
|
$cancel_uri = $this->getApplicationURI();
|
||||||
|
|
||||||
$providers = PhabricatorAuthProvider::getAllBaseProviders();
|
$providers = PhabricatorAuthProvider::getAllBaseProviders();
|
||||||
|
|
||||||
$e_provider = null;
|
|
||||||
$errors = array();
|
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
|
||||||
$provider_string = $request->getStr('provider');
|
|
||||||
if (!strlen($provider_string)) {
|
|
||||||
$e_provider = pht('Required');
|
|
||||||
$errors[] = pht('You must select an authentication provider.');
|
|
||||||
} else {
|
|
||||||
$found = false;
|
|
||||||
foreach ($providers as $provider) {
|
|
||||||
if (get_class($provider) === $provider_string) {
|
|
||||||
$found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!$found) {
|
|
||||||
$e_provider = pht('Invalid');
|
|
||||||
$errors[] = pht('You must select a valid provider.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$errors) {
|
|
||||||
return id(new AphrontRedirectResponse())->setURI(
|
|
||||||
$this->getApplicationURI('/config/new/'.$provider_string.'/'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$options = id(new AphrontFormRadioButtonControl())
|
|
||||||
->setLabel(pht('Provider'))
|
|
||||||
->setName('provider')
|
|
||||||
->setError($e_provider);
|
|
||||||
|
|
||||||
$configured = PhabricatorAuthProvider::getAllProviders();
|
$configured = PhabricatorAuthProvider::getAllProviders();
|
||||||
$configured_classes = array();
|
$configured_classes = array();
|
||||||
foreach ($configured as $configured_provider) {
|
foreach ($configured as $configured_provider) {
|
||||||
|
@ -55,57 +23,52 @@ final class PhabricatorAuthNewController
|
||||||
$providers = msort($providers, 'getLoginOrder');
|
$providers = msort($providers, 'getLoginOrder');
|
||||||
$providers = array_diff_key($providers, $configured_classes) + $providers;
|
$providers = array_diff_key($providers, $configured_classes) + $providers;
|
||||||
|
|
||||||
foreach ($providers as $provider) {
|
$menu = id(new PHUIObjectItemListView())
|
||||||
if (isset($configured_classes[get_class($provider)])) {
|
->setViewer($viewer)
|
||||||
$disabled = true;
|
->setBig(true)
|
||||||
$description = pht('This provider is already configured.');
|
->setFlush(true);
|
||||||
|
|
||||||
|
foreach ($providers as $provider_key => $provider) {
|
||||||
|
$provider_class = get_class($provider);
|
||||||
|
|
||||||
|
$provider_uri = id(new PhutilURI('/config/edit/'))
|
||||||
|
->setQueryParam('provider', $provider_class);
|
||||||
|
$provider_uri = $this->getApplicationURI($provider_uri);
|
||||||
|
|
||||||
|
$already_exists = isset($configured_classes[get_class($provider)]);
|
||||||
|
|
||||||
|
$item = id(new PHUIObjectItemView())
|
||||||
|
->setHeader($provider->getNameForCreate())
|
||||||
|
->setImageIcon($provider->newIconView())
|
||||||
|
->addAttribute($provider->getDescriptionForCreate());
|
||||||
|
|
||||||
|
if (!$already_exists) {
|
||||||
|
$item
|
||||||
|
->setHref($provider_uri)
|
||||||
|
->setClickable(true);
|
||||||
} else {
|
} else {
|
||||||
$disabled = false;
|
$item->setDisabled(true);
|
||||||
$description = $provider->getDescriptionForCreate();
|
|
||||||
}
|
|
||||||
$options->addButton(
|
|
||||||
get_class($provider),
|
|
||||||
$provider->getNameForCreate(),
|
|
||||||
$description,
|
|
||||||
$disabled ? 'disabled' : null,
|
|
||||||
$disabled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = id(new AphrontFormView())
|
if ($already_exists) {
|
||||||
->setUser($viewer)
|
$messages = array();
|
||||||
->appendChild($options)
|
$messages[] = pht('You already have a provider of this type.');
|
||||||
->appendChild(
|
|
||||||
id(new AphrontFormSubmitControl())
|
|
||||||
->addCancelButton($this->getApplicationURI())
|
|
||||||
->setValue(pht('Continue')));
|
|
||||||
|
|
||||||
$form_box = id(new PHUIObjectBoxView())
|
$info = id(new PHUIInfoView())
|
||||||
->setHeaderText(pht('Provider'))
|
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
|
||||||
->setFormErrors($errors)
|
->setErrors($messages);
|
||||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
|
||||||
->setForm($form);
|
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
$item->appendChild($info);
|
||||||
$crumbs->addTextCrumb(pht('Add Provider'));
|
}
|
||||||
$crumbs->setBorder(true);
|
|
||||||
|
|
||||||
$title = pht('Add Auth Provider');
|
$menu->addItem($item);
|
||||||
|
}
|
||||||
$header = id(new PHUIHeaderView())
|
|
||||||
->setHeader($title)
|
|
||||||
->setHeaderIcon('fa-plus-square');
|
|
||||||
|
|
||||||
$view = id(new PHUITwoColumnView())
|
|
||||||
->setHeader($header)
|
|
||||||
->setFooter(array(
|
|
||||||
$form_box,
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this->newPage()
|
|
||||||
->setTitle($title)
|
|
||||||
->setCrumbs($crumbs)
|
|
||||||
->appendChild($view);
|
|
||||||
|
|
||||||
|
return $this->newDialog()
|
||||||
|
->setTitle(pht('Add Auth Provider'))
|
||||||
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
||||||
|
->appendChild($menu)
|
||||||
|
->addCancelButton($cancel_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,6 +311,12 @@ abstract class PhabricatorAuthProvider extends Phobject {
|
||||||
return 'Generic';
|
return 'Generic';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function newIconView() {
|
||||||
|
return id(new PHUIIconView())
|
||||||
|
->setSpriteSheet(PHUIIconView::SPRITE_LOGIN)
|
||||||
|
->setSpriteIcon($this->getLoginIcon());
|
||||||
|
}
|
||||||
|
|
||||||
public function isLoginFormAButton() {
|
public function isLoginFormAButton() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue