Convert OAuthServer to Transactions + EditEngine
Summary: Ref T7303. This application is currently stone-age tech (no transactions, hard "delete" action). Bring it up to modern specs. Test Plan: - Created and edited an OAuth application. - Viewed transaction record. - Tried to create something with no name, invalid redirect URI, etc. Was gently rebuffed with detailed explanatory errors. Reviewers: chad Reviewed By: chad Maniphest Tasks: T7303 Differential Revision: https://secure.phabricator.com/D15609
This commit is contained in:
@@ -4,129 +4,9 @@ final class PhabricatorOAuthClientEditController
|
||||
extends PhabricatorOAuthClientController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
if ($id) {
|
||||
$client = id(new PhabricatorOAuthServerClientQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->executeOne();
|
||||
if (!$client) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$title = pht('Edit OAuth Application: %s', $client->getName());
|
||||
$submit_button = pht('Save Application');
|
||||
$crumb_text = pht('Edit');
|
||||
$cancel_uri = $client->getViewURI();
|
||||
$is_new = false;
|
||||
} else {
|
||||
$this->requireApplicationCapability(
|
||||
PhabricatorOAuthServerCreateClientsCapability::CAPABILITY);
|
||||
|
||||
$client = PhabricatorOAuthServerClient::initializeNewClient($viewer);
|
||||
|
||||
$title = pht('Create OAuth Application');
|
||||
$submit_button = pht('Create Application');
|
||||
$crumb_text = pht('Create Application');
|
||||
$cancel_uri = $this->getApplicationURI();
|
||||
$is_new = true;
|
||||
}
|
||||
|
||||
$errors = array();
|
||||
$e_redirect = true;
|
||||
$e_name = true;
|
||||
if ($request->isFormPost()) {
|
||||
$redirect_uri = $request->getStr('redirect_uri');
|
||||
$client->setName($request->getStr('name'));
|
||||
$client->setRedirectURI($redirect_uri);
|
||||
|
||||
if (!strlen($client->getName())) {
|
||||
$errors[] = pht('You must choose a name for this OAuth application.');
|
||||
$e_name = pht('Required');
|
||||
}
|
||||
|
||||
$server = new PhabricatorOAuthServer();
|
||||
$uri = new PhutilURI($redirect_uri);
|
||||
if (!$server->validateRedirectURI($uri)) {
|
||||
$errors[] = pht(
|
||||
'Redirect URI must be a fully qualified domain name '.
|
||||
'with no fragments. See %s for more information on the correct '.
|
||||
'format.',
|
||||
'http://tools.ietf.org/html/draft-ietf-oauth-v2-23#section-3.1.2');
|
||||
$e_redirect = pht('Invalid');
|
||||
}
|
||||
|
||||
$client->setViewPolicy($request->getStr('viewPolicy'));
|
||||
$client->setEditPolicy($request->getStr('editPolicy'));
|
||||
if (!$errors) {
|
||||
$client->save();
|
||||
$view_uri = $client->getViewURI();
|
||||
return id(new AphrontRedirectResponse())->setURI($view_uri);
|
||||
}
|
||||
}
|
||||
|
||||
$policies = id(new PhabricatorPolicyQuery())
|
||||
->setViewer($viewer)
|
||||
->setObject($client)
|
||||
->execute();
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($viewer)
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel(pht('Name'))
|
||||
->setName('name')
|
||||
->setValue($client->getName())
|
||||
->setError($e_name))
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel(pht('Redirect URI'))
|
||||
->setName('redirect_uri')
|
||||
->setValue($client->getRedirectURI())
|
||||
->setError($e_redirect))
|
||||
->appendChild(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setUser($viewer)
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
||||
->setPolicyObject($client)
|
||||
->setPolicies($policies)
|
||||
->setName('viewPolicy'))
|
||||
->appendChild(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setUser($viewer)
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
||||
->setPolicyObject($client)
|
||||
->setPolicies($policies)
|
||||
->setName('editPolicy'))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->addCancelButton($cancel_uri)
|
||||
->setValue($submit_button));
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
if (!$is_new) {
|
||||
$crumbs->addTextCrumb(
|
||||
$client->getName(),
|
||||
$client->getViewURI());
|
||||
}
|
||||
$crumbs->addTextCrumb($crumb_text);
|
||||
|
||||
$box = id(new PHUIObjectBoxView())
|
||||
->setHeaderText($title)
|
||||
->setFormErrors($errors)
|
||||
->setForm($form);
|
||||
|
||||
return $this->newPage()
|
||||
->setCrumbs($crumbs)
|
||||
->setTitle($title)
|
||||
->appendChild($box);
|
||||
return id(new PhabricatorOAuthServerEditEngine())
|
||||
->setController($this)
|
||||
->buildResponse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,38 +3,22 @@
|
||||
final class PhabricatorOAuthClientListController
|
||||
extends PhabricatorOAuthClientController {
|
||||
|
||||
private $queryKey;
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->queryKey = idx($data, 'queryKey');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$controller = id(new PhabricatorApplicationSearchController())
|
||||
->setQueryKey($this->queryKey)
|
||||
->setSearchEngine(new PhabricatorOAuthServerClientSearchEngine())
|
||||
->setNavigation($this->buildSideNavView());
|
||||
|
||||
return $this->delegateToController($controller);
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
return id(new PhabricatorOAuthServerClientSearchEngine())
|
||||
->setController($this)
|
||||
->buildResponse();
|
||||
}
|
||||
|
||||
protected function buildApplicationCrumbs() {
|
||||
$crumbs = parent::buildApplicationCrumbs();
|
||||
|
||||
$can_create = $this->hasApplicationCapability(
|
||||
PhabricatorOAuthServerCreateClientsCapability::CAPABILITY);
|
||||
|
||||
$crumbs->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setHref($this->getApplicationURI('client/create/'))
|
||||
->setName(pht('Create Application'))
|
||||
->setDisabled(!$can_create)
|
||||
->setWorkflow(!$can_create)
|
||||
->setIcon('fa-plus-square'));
|
||||
id(new PhabricatorOAuthServerEditEngine())
|
||||
->setViewer($this->getViewer())
|
||||
->addActionToCrumbs($crumbs);
|
||||
|
||||
return $crumbs;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,11 @@ final class PhabricatorOAuthClientViewController
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$crumbs->addTextCrumb($client->getName());
|
||||
|
||||
$timeline = $this->buildTransactionTimeline(
|
||||
$client,
|
||||
new PhabricatorOAuthServerTransactionQuery());
|
||||
$timeline->setShouldTerminate(true);
|
||||
|
||||
$box = id(new PHUIObjectBoxView())
|
||||
->setHeader($header)
|
||||
->addPropertyList($properties);
|
||||
@@ -31,7 +36,11 @@ final class PhabricatorOAuthClientViewController
|
||||
return $this->newPage()
|
||||
->setCrumbs($crumbs)
|
||||
->setTitle($title)
|
||||
->appendChild($box);
|
||||
->appendChild(
|
||||
array(
|
||||
$box,
|
||||
$timeline,
|
||||
));
|
||||
}
|
||||
|
||||
private function buildHeaderView(PhabricatorOAuthServerClient $client) {
|
||||
|
||||
Reference in New Issue
Block a user