Differential D20625 Diff 49214 src/applications/oauthserver/controller/client/PhabricatorOAuthClientViewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/oauthserver/controller/client/PhabricatorOAuthClientViewController.php
Show All 9 Lines | $client = id(new PhabricatorOAuthServerClientQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIDs(array($request->getURIData('id'))) | ->withIDs(array($request->getURIData('id'))) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$client) { | if (!$client) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$header = $this->buildHeaderView($client); | $header = $this->buildHeaderView($client); | ||||
$actions = $this->buildActionView($client); | |||||
$properties = $this->buildPropertyListView($client); | $properties = $this->buildPropertyListView($client); | ||||
$properties->setActionList($actions); | |||||
$crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs() | ||||
$crumbs->addTextCrumb($client->getName()); | ->addTextCrumb($client->getName()) | ||||
->setBorder(true); | |||||
$timeline = $this->buildTransactionTimeline( | $timeline = $this->buildTransactionTimeline( | ||||
$client, | $client, | ||||
new PhabricatorOAuthServerTransactionQuery()); | new PhabricatorOAuthServerTransactionQuery()); | ||||
$timeline->setShouldTerminate(true); | $timeline->setShouldTerminate(true); | ||||
$box = id(new PHUIObjectBoxView()) | $box = id(new PHUIObjectBoxView()) | ||||
->setHeader($header) | ->setHeaderText(pht('Details')) | ||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | |||||
->addPropertyList($properties); | ->addPropertyList($properties); | ||||
$title = pht('OAuth Application: %s', $client->getName()); | $title = pht('OAuth Application: %s', $client->getName()); | ||||
return $this->newPage() | $curtain = $this->buildCurtain($client); | ||||
->setCrumbs($crumbs) | |||||
->setTitle($title) | $columns = id(new PHUITwoColumnView()) | ||||
->appendChild( | ->setHeader($header) | ||||
->setCurtain($curtain) | |||||
->setMainColumn( | |||||
array( | array( | ||||
$box, | $box, | ||||
$timeline, | $timeline, | ||||
)); | )); | ||||
return $this->newPage() | |||||
->setCrumbs($crumbs) | |||||
->setTitle($title) | |||||
->appendChild($columns); | |||||
} | } | ||||
private function buildHeaderView(PhabricatorOAuthServerClient $client) { | private function buildHeaderView(PhabricatorOAuthServerClient $client) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setHeader(pht('OAuth Application: %s', $client->getName())) | ->setHeader(pht('OAuth Application: %s', $client->getName())) | ||||
->setPolicyObject($client); | ->setPolicyObject($client); | ||||
if ($client->getIsDisabled()) { | if ($client->getIsDisabled()) { | ||||
$header->setStatus('fa-ban', 'indigo', pht('Disabled')); | $header->setStatus('fa-ban', 'indigo', pht('Disabled')); | ||||
} else { | } else { | ||||
$header->setStatus('fa-check', 'green', pht('Enabled')); | $header->setStatus('fa-check', 'green', pht('Enabled')); | ||||
} | } | ||||
return $header; | return $header; | ||||
} | } | ||||
private function buildActionView(PhabricatorOAuthServerClient $client) { | private function buildCurtain(PhabricatorOAuthServerClient $client) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$actions = array(); | |||||
$can_edit = PhabricatorPolicyFilter::hasCapability( | $can_edit = PhabricatorPolicyFilter::hasCapability( | ||||
$viewer, | $viewer, | ||||
$client, | $client, | ||||
PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
$id = $client->getID(); | $id = $client->getID(); | ||||
$view = id(new PhabricatorActionListView()) | $actions[] = id(new PhabricatorActionView()) | ||||
->setUser($viewer); | |||||
$view->addAction( | |||||
id(new PhabricatorActionView()) | |||||
->setName(pht('Edit Application')) | ->setName(pht('Edit Application')) | ||||
->setIcon('fa-pencil') | ->setIcon('fa-pencil') | ||||
->setWorkflow(!$can_edit) | ->setWorkflow(!$can_edit) | ||||
->setDisabled(!$can_edit) | ->setDisabled(!$can_edit) | ||||
->setHref($client->getEditURI())); | ->setHref($client->getEditURI()); | ||||
$view->addAction( | $actions[] = id(new PhabricatorActionView()) | ||||
id(new PhabricatorActionView()) | |||||
->setName(pht('Show Application Secret')) | ->setName(pht('Show Application Secret')) | ||||
->setIcon('fa-eye') | ->setIcon('fa-eye') | ||||
->setHref($this->getApplicationURI("client/secret/{$id}/")) | ->setHref($this->getApplicationURI("client/secret/{$id}/")) | ||||
->setDisabled(!$can_edit) | ->setDisabled(!$can_edit) | ||||
->setWorkflow(true)); | ->setWorkflow(true); | ||||
$is_disabled = $client->getIsDisabled(); | $is_disabled = $client->getIsDisabled(); | ||||
if ($is_disabled) { | if ($is_disabled) { | ||||
$disable_text = pht('Enable Application'); | $disable_text = pht('Enable Application'); | ||||
$disable_icon = 'fa-check'; | $disable_icon = 'fa-check'; | ||||
} else { | } else { | ||||
$disable_text = pht('Disable Application'); | $disable_text = pht('Disable Application'); | ||||
$disable_icon = 'fa-ban'; | $disable_icon = 'fa-ban'; | ||||
} | } | ||||
$disable_uri = $this->getApplicationURI("client/disable/{$id}/"); | $disable_uri = $this->getApplicationURI("client/disable/{$id}/"); | ||||
$view->addAction( | $actions[] = id(new PhabricatorActionView()) | ||||
id(new PhabricatorActionView()) | |||||
->setName($disable_text) | ->setName($disable_text) | ||||
->setIcon($disable_icon) | ->setIcon($disable_icon) | ||||
->setWorkflow(true) | ->setWorkflow(true) | ||||
->setDisabled(!$can_edit) | ->setDisabled(!$can_edit) | ||||
->setHref($disable_uri)); | ->setHref($disable_uri); | ||||
$view->addAction( | $actions[] = id(new PhabricatorActionView()) | ||||
id(new PhabricatorActionView()) | |||||
->setName(pht('Generate Test Token')) | ->setName(pht('Generate Test Token')) | ||||
->setIcon('fa-plus') | ->setIcon('fa-plus') | ||||
->setWorkflow(true) | ->setWorkflow(true) | ||||
->setHref($this->getApplicationURI("client/test/{$id}/"))); | ->setHref($this->getApplicationURI("client/test/{$id}/")); | ||||
return $view; | $curtain = $this->newCurtainView($client); | ||||
foreach ($actions as $action) { | |||||
$curtain->addAction($action); | |||||
} | |||||
return $curtain; | |||||
} | } | ||||
private function buildPropertyListView(PhabricatorOAuthServerClient $client) { | private function buildPropertyListView(PhabricatorOAuthServerClient $client) { | ||||
$viewer = $this->getRequest()->getUser(); | $viewer = $this->getRequest()->getUser(); | ||||
$view = id(new PHUIPropertyListView()) | $view = id(new PHUIPropertyListView()) | ||||
->setUser($viewer); | ->setUser($viewer); | ||||
$view->addProperty( | $view->addProperty( | ||||
pht('Client PHID'), | pht('Client PHID'), | ||||
$client->getPHID()); | $client->getPHID()); | ||||
$view->addProperty( | $view->addProperty( | ||||
pht('Redirect URI'), | pht('Redirect URI'), | ||||
$client->getRedirectURI()); | $client->getRedirectURI()); | ||||
$view->addProperty( | |||||
pht('Created'), | |||||
phabricator_datetime($client->getDateCreated(), $viewer)); | |||||
return $view; | return $view; | ||||
} | } | ||||
} | } |