Differential D20645 Diff 49256 src/applications/auth/controller/config/PhabricatorAuthEditController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/controller/config/PhabricatorAuthEditController.php
Show All 21 Lines | if ($config_id) { | ||||
->withIDs(array($config_id)) | ->withIDs(array($config_id)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$config) { | if (!$config) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$provider = $config->getProvider(); | $provider = $config->getProvider(); | ||||
if (!$provider) { | if (!$provider) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
epriestley: You can reduce boilerplate with `return $this->newDialog()->...` in a `Controller`, and… | |||||
$is_new = false; | $is_new = false; | ||||
} else { | } else { | ||||
$provider = null; | $provider = null; | ||||
$providers = PhabricatorAuthProvider::getAllBaseProviders(); | $providers = PhabricatorAuthProvider::getAllBaseProviders(); | ||||
foreach ($providers as $candidate_provider) { | foreach ($providers as $candidate_provider) { | ||||
if (get_class($candidate_provider) === $provider_class) { | if (get_class($candidate_provider) === $provider_class) { | ||||
$provider = $candidate_provider; | $provider = $candidate_provider; | ||||
Show All 33 Lines | if ($config_id) { | ||||
$config = $provider->getDefaultProviderConfig(); | $config = $provider->getDefaultProviderConfig(); | ||||
$provider->attachProviderConfig($config); | $provider->attachProviderConfig($config); | ||||
$is_new = true; | $is_new = true; | ||||
} | } | ||||
$errors = array(); | $errors = array(); | ||||
$validation_exception = null; | |||||
$v_login = $config->getShouldAllowLogin(); | $v_login = $config->getShouldAllowLogin(); | ||||
$v_registration = $config->getShouldAllowRegistration(); | $v_registration = $config->getShouldAllowRegistration(); | ||||
$v_link = $config->getShouldAllowLink(); | $v_link = $config->getShouldAllowLink(); | ||||
$v_unlink = $config->getShouldAllowUnlink(); | $v_unlink = $config->getShouldAllowUnlink(); | ||||
$v_trust_email = $config->getShouldTrustEmails(); | $v_trust_email = $config->getShouldTrustEmails(); | ||||
$v_auto_login = $config->getShouldAutoLogin(); | $v_auto_login = $config->getShouldAutoLogin(); | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | if ($request->isFormPost()) { | ||||
if ($is_new) { | if ($is_new) { | ||||
$config->save(); | $config->save(); | ||||
} | } | ||||
$editor = id(new PhabricatorAuthProviderConfigEditor()) | $editor = id(new PhabricatorAuthProviderConfigEditor()) | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true); | ||||
->applyTransactions($config, $xactions); | |||||
try { | |||||
$editor->applyTransactions($config, $xactions); | |||||
$next_uri = $config->getURI(); | $next_uri = $config->getURI(); | ||||
return id(new AphrontRedirectResponse())->setURI($next_uri); | return id(new AphrontRedirectResponse())->setURI($next_uri); | ||||
} catch (Exception $ex) { | |||||
$validation_exception = $ex; | |||||
} | |||||
} | } | ||||
} else { | } else { | ||||
$properties = $provider->readFormValuesFromProvider(); | $properties = $provider->readFormValuesFromProvider(); | ||||
$issues = array(); | $issues = array(); | ||||
} | } | ||||
if ($is_new) { | if ($is_new) { | ||||
if ($provider->hasSetupStep()) { | if ($provider->hasSetupStep()) { | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | if ($provider->supportsAutoLogin()) { | ||||
'autoLogin', | 'autoLogin', | ||||
1, | 1, | ||||
$str_auto_login, | $str_auto_login, | ||||
$v_auto_login)); | $v_auto_login)); | ||||
} | } | ||||
$provider->extendEditForm($request, $form, $properties, $issues); | $provider->extendEditForm($request, $form, $properties, $issues); | ||||
$locked_config_key = 'auth.lock-config'; | |||||
$is_locked = PhabricatorEnv::getEnvConfig($locked_config_key); | |||||
$locked_warning = null; | |||||
if ($is_locked && !$validation_exception) { | |||||
$message = pht( | |||||
'Authentication provider configuration is locked, and can not be '. | |||||
'changed without being unlocked. See the configuration setting %s '. | |||||
'for details.', | |||||
phutil_tag( | |||||
'a', | |||||
array( | |||||
'href' => '/config/edit/'.$locked_config_key, | |||||
), | |||||
$locked_config_key)); | |||||
$locked_warning = id(new PHUIInfoView()) | |||||
->setViewer($viewer) | |||||
->setSeverity(PHUIInfoView::SEVERITY_WARNING) | |||||
->setErrors(array($message)); | |||||
} | |||||
$form | $form | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormSubmitControl()) | id(new AphrontFormSubmitControl()) | ||||
->addCancelButton($cancel_uri) | ->addCancelButton($cancel_uri) | ||||
->setDisabled($is_locked) | |||||
->setValue($button)); | ->setValue($button)); | ||||
$help = $provider->getConfigurationHelp(); | $help = $provider->getConfigurationHelp(); | ||||
if ($help) { | if ($help) { | ||||
$form->appendChild(id(new PHUIFormDividerControl())); | $form->appendChild(id(new PHUIFormDividerControl())); | ||||
$form->appendRemarkupInstructions($help); | $form->appendRemarkupInstructions($help); | ||||
} | } | ||||
$footer = $provider->renderConfigurationFooter(); | $footer = $provider->renderConfigurationFooter(); | ||||
$crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
$crumbs->addTextCrumb($crumb); | $crumbs->addTextCrumb($crumb); | ||||
$crumbs->setBorder(true); | $crumbs->setBorder(true); | ||||
$form_box = id(new PHUIObjectBoxView()) | $form_box = id(new PHUIObjectBoxView()) | ||||
->setHeaderText(pht('Provider')) | ->setHeaderText(pht('Provider')) | ||||
->setFormErrors($errors) | ->setFormErrors($errors) | ||||
->setValidationException($validation_exception) | |||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
->setForm($form); | ->setForm($form); | ||||
$view = id(new PHUITwoColumnView()) | $view = id(new PHUITwoColumnView()) | ||||
->setHeader($header) | ->setHeader($header) | ||||
->setFooter(array( | ->setFooter(array( | ||||
$locked_warning, | |||||
$form_box, | $form_box, | ||||
$footer, | $footer, | ||||
)); | )); | ||||
return $this->newPage() | return $this->newPage() | ||||
->setTitle($title) | ->setTitle($title) | ||||
->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
->appendChild($view); | ->appendChild($view); | ||||
} | } | ||||
} | } |
You can reduce boilerplate with return $this->newDialog()->... in a Controller, and setMethod() shouldn't be necessary (cancel buttons are just links that look like buttons visually, only "submit" is ever actually a button).