Path: blob/master/src/applications/passphrase/controller/PassphraseCredentialViewController.php
12256 views
<?php12final class PassphraseCredentialViewController extends PassphraseController {34public function handleRequest(AphrontRequest $request) {5$viewer = $request->getViewer();6$id = $request->getURIData('id');78$credential = id(new PassphraseCredentialQuery())9->setViewer($viewer)10->withIDs(array($id))11->executeOne();12if (!$credential) {13return new Aphront404Response();14}1516$type = $credential->getImplementation();1718$timeline = $this->buildTransactionTimeline(19$credential,20new PassphraseCredentialTransactionQuery());21$timeline->setShouldTerminate(true);2223$title = pht('%s %s', $credential->getMonogram(), $credential->getName());24$crumbs = $this->buildApplicationCrumbs();25$crumbs->addTextCrumb($credential->getMonogram());26$crumbs->setBorder(true);2728$header = $this->buildHeaderView($credential);29$curtain = $this->buildCurtain($credential, $type);30$subheader = $this->buildSubheaderView($credential);31$content = $this->buildPropertySectionView($credential, $type);3233$view = id(new PHUITwoColumnView())34->setHeader($header)35->setSubheader($subheader)36->setCurtain($curtain)37->setMainColumn($timeline)38->addPropertySection(pht('Properties'), $content);3940return $this->newPage()41->setTitle($title)42->setCrumbs($crumbs)43->appendChild($view);44}4546private function buildHeaderView(PassphraseCredential $credential) {47$viewer = $this->getRequest()->getUser();4849$header = id(new PHUIHeaderView())50->setUser($viewer)51->setHeader($credential->getName())52->setPolicyObject($credential)53->setHeaderIcon('fa-user-secret');5455if ($credential->getIsDestroyed()) {56$header->setStatus('fa-ban', 'red', pht('Destroyed'));57}5859return $header;60}6162private function buildSubheaderView(63PassphraseCredential $credential) {64$viewer = $this->getViewer();6566$author = $viewer->renderHandle($credential->getAuthorPHID())->render();67$date = phabricator_datetime($credential->getDateCreated(), $viewer);68$author = phutil_tag('strong', array(), $author);6970$person = id(new PhabricatorPeopleQuery())71->setViewer($viewer)72->withPHIDs(array($credential->getAuthorPHID()))73->needProfileImage(true)74->executeOne();7576if (!$person) {77return null;78}7980$image_uri = $person->getProfileImageURI();81$image_href = '/p/'.$credential->getUsername();8283$content = pht('Created by %s on %s.', $author, $date);8485return id(new PHUIHeadThingView())86->setImage($image_uri)87->setImageHref($image_href)88->setContent($content);89}9091private function buildCurtain(92PassphraseCredential $credential,93PassphraseCredentialType $type) {94$viewer = $this->getViewer();9596$id = $credential->getID();9798$is_locked = $credential->getIsLocked();99if ($is_locked) {100$credential_lock_text = pht('Locked Permanently');101$credential_lock_icon = 'fa-lock';102} else {103$credential_lock_text = pht('Lock Permanently');104$credential_lock_icon = 'fa-unlock';105}106107$allow_conduit = $credential->getAllowConduit();108if ($allow_conduit) {109$credential_conduit_text = pht('Prevent Conduit Access');110$credential_conduit_icon = 'fa-ban';111} else {112$credential_conduit_text = pht('Allow Conduit Access');113$credential_conduit_icon = 'fa-wrench';114}115116$can_edit = PhabricatorPolicyFilter::hasCapability(117$viewer,118$credential,119PhabricatorPolicyCapability::CAN_EDIT);120121$can_conduit = ($can_edit && !$is_locked);122123$curtain = $this->newCurtainView($credential);124125$curtain->addAction(126id(new PhabricatorActionView())127->setName(pht('Edit Credential'))128->setIcon('fa-pencil')129->setHref($this->getApplicationURI("edit/{$id}/"))130->setDisabled(!$can_edit)131->setWorkflow(!$can_edit));132133if (!$credential->getIsDestroyed()) {134$curtain->addAction(135id(new PhabricatorActionView())136->setName(pht('Destroy Credential'))137->setIcon('fa-times')138->setHref($this->getApplicationURI("destroy/{$id}/"))139->setDisabled(!$can_edit)140->setWorkflow(true));141142$curtain->addAction(143id(new PhabricatorActionView())144->setName(pht('Show Secret'))145->setIcon('fa-eye')146->setHref($this->getApplicationURI("reveal/{$id}/"))147->setDisabled(!$can_edit || $is_locked)148->setWorkflow(true));149150if ($type->hasPublicKey()) {151$curtain->addAction(152id(new PhabricatorActionView())153->setName(pht('Show Public Key'))154->setIcon('fa-download')155->setHref($this->getApplicationURI("public/{$id}/"))156->setWorkflow(true));157}158159$curtain->addAction(160id(new PhabricatorActionView())161->setName($credential_conduit_text)162->setIcon($credential_conduit_icon)163->setHref($this->getApplicationURI("conduit/{$id}/"))164->setDisabled(!$can_conduit)165->setWorkflow(true));166167$curtain->addAction(168id(new PhabricatorActionView())169->setName($credential_lock_text)170->setIcon($credential_lock_icon)171->setHref($this->getApplicationURI("lock/{$id}/"))172->setDisabled(!$can_edit || $is_locked)173->setWorkflow(true));174}175176return $curtain;177}178179private function buildPropertySectionView(180PassphraseCredential $credential,181PassphraseCredentialType $type) {182$viewer = $this->getRequest()->getUser();183184$properties = id(new PHUIPropertyListView())185->setUser($viewer);186187$properties->addProperty(188pht('Credential Type'),189$type->getCredentialTypeName());190191if ($type->shouldRequireUsername()) {192$properties->addProperty(193pht('Username'),194$credential->getUsername());195}196197$description = $credential->getDescription();198if (strlen($description)) {199$properties->addSectionHeader(200pht('Description'),201PHUIPropertyListView::ICON_SUMMARY);202$properties->addTextContent(203new PHUIRemarkupView($viewer, $description));204}205206return $properties;207}208209}210211212