Differential D16178 Diff 38919 src/applications/tokens/controller/PhabricatorTokenViewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/tokens/controller/PhabricatorTokenViewController.php
- This file was added.
<?php | |||||
final class PhabricatorTokenViewController | |||||
extends PhabricatorTokenController { | |||||
public function shouldAllowPublic() { | |||||
return true; | |||||
} | |||||
public function handleRequest(AphrontRequest $request) { | |||||
$viewer = $request->getViewer(); | |||||
$id = $request->getURIData('id'); | |||||
$token = id(new PhabricatorTokenQuery()) | |||||
->setViewer($viewer) | |||||
->withIDs(array($id)) | |||||
->executeOne(); | |||||
if (!$token) { | |||||
return new Aphront404Response(); | |||||
} | |||||
$crumbs = $this->buildApplicationCrumbs(); | |||||
$crumbs->addTextCrumb($token->getName()); | |||||
$crumbs->setBorder(true); | |||||
$title = $token->getName(); | |||||
if ($token->isArchived()) { | |||||
$status_icon = 'fa-ban'; | |||||
$status_color = 'dark'; | |||||
} else { | |||||
$status_icon = 'fa-check'; | |||||
$status_color = 'bluegrey'; | |||||
} | |||||
$status_name = idx( | |||||
PhabricatorTokensToken::getStatusNameMap(), | |||||
$token->getStatus()); | |||||
$header = id(new PHUIHeaderView()) | |||||
->setHeader($token->getName()) | |||||
->setUser($viewer) | |||||
->setPolicyObject($token) | |||||
->setStatus($status_icon, $status_color, $status_name) | |||||
->setHeaderIcon('fa-trophy'); | |||||
$curtain = $this->buildCurtain($token); | |||||
$details = $this->buildDetailsView($token); | |||||
$timeline = $this->buildTransactionTimeline( | |||||
$token, | |||||
new PhabricatorTokensTransactionQuery()); | |||||
$comment_view = id(new PhabricatorTokenEditEngine()) | |||||
->setViewer($viewer) | |||||
->buildEditEngineCommentView($token); | |||||
$view = id(new PHUITwoColumnView()) | |||||
->setHeader($header) | |||||
->setCurtain($curtain) | |||||
->setMainColumn(array( | |||||
$timeline, | |||||
$comment_view, | |||||
)) | |||||
->addPropertySection(pht('Description'), $details); | |||||
return $this->newPage() | |||||
->setTitle($title) | |||||
->setCrumbs($crumbs) | |||||
->setPageObjectPHIDs(array($token->getPHID())) | |||||
->appendChild($view); | |||||
} | |||||
private function buildDetailsView( | |||||
PhabricatorBadgesBadge $token) { | |||||
$viewer = $this->getViewer(); | |||||
$view = id(new PHUIPropertyListView()) | |||||
->setUser($viewer); | |||||
return $view; | |||||
} | |||||
private function buildCurtain(PhabricatorTokensToken $token) { | |||||
$viewer = $this->getViewer(); | |||||
$can_edit = PhabricatorPolicyFilter::hasCapability( | |||||
$viewer, | |||||
$token, | |||||
PhabricatorPolicyCapability::CAN_EDIT); | |||||
$id = $token->getID(); | |||||
$edit_uri = $this->getApplicationURI("/edit/{$id}/"); | |||||
$archive_uri = $this->getApplicationURI("/archive/{$id}/"); | |||||
$curtain = $this->newCurtainView($token); | |||||
$curtain->addAction( | |||||
id(new PhabricatorActionView()) | |||||
->setName(pht('Edit Token')) | |||||
->setIcon('fa-pencil') | |||||
->setDisabled(!$can_edit) | |||||
->setHref($edit_uri)); | |||||
if ($token->isArchived()) { | |||||
$curtain->addAction( | |||||
id(new PhabricatorActionView()) | |||||
->setName(pht('Activate Token')) | |||||
->setIcon('fa-check') | |||||
->setDisabled(!$can_edit) | |||||
->setWorkflow($can_edit) | |||||
->setHref($archive_uri)); | |||||
} else { | |||||
$curtain->addAction( | |||||
id(new PhabricatorActionView()) | |||||
->setName(pht('Archive Token')) | |||||
->setIcon('fa-ban') | |||||
->setDisabled(!$can_edit) | |||||
->setWorkflow($can_edit) | |||||
->setHref($archive_uri)); | |||||
} | |||||
return $curtain; | |||||
} | |||||
} |