Path: blob/master/src/applications/passphrase/controller/PassphraseCredentialConduitController.php
12262 views
<?php12final class PassphraseCredentialConduitController3extends PassphraseController {45public function handleRequest(AphrontRequest $request) {6$viewer = $request->getViewer();7$id = $request->getURIData('id');89$credential = id(new PassphraseCredentialQuery())10->setViewer($viewer)11->withIDs(array($id))12->requireCapabilities(13array(14PhabricatorPolicyCapability::CAN_VIEW,15PhabricatorPolicyCapability::CAN_EDIT,16))17->executeOne();18if (!$credential) {19return new Aphront404Response();20}2122$view_uri = '/K'.$credential->getID();2324$token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession(25$viewer,26$request,27$view_uri);2829$type = PassphraseCredentialType::getTypeByConstant(30$credential->getCredentialType());31if (!$type) {32throw new Exception(pht('Credential has invalid type "%s"!', $type));33}3435$is_locked = $credential->getIsLocked();3637if ($is_locked) {38return $this->newDialog()39->setUser($viewer)40->setTitle(pht('Credential Locked'))41->appendChild(42pht(43'This credential can not be made available via Conduit because '.44'it is locked.'))45->addCancelButton($view_uri);46}4748if ($request->isFormPost()) {49$xactions = array();5051$xactions[] = id(new PassphraseCredentialTransaction())52->setTransactionType(53PassphraseCredentialConduitTransaction::TRANSACTIONTYPE)54->setNewValue(!$credential->getAllowConduit());5556$editor = id(new PassphraseCredentialTransactionEditor())57->setActor($viewer)58->setContinueOnMissingFields(true)59->setContentSourceFromRequest($request)60->applyTransactions($credential, $xactions);6162return id(new AphrontRedirectResponse())->setURI($view_uri);63}6465if ($credential->getAllowConduit()) {66return $this->newDialog()67->setTitle(pht('Prevent Conduit access?'))68->appendChild(69pht(70'This credential and its secret will no longer be able '.71'to be retrieved using the `%s` method in Conduit.',72'passphrase.query'))73->addSubmitButton(pht('Prevent Conduit Access'))74->addCancelButton($view_uri);75} else {76return $this->newDialog()77->setTitle(pht('Allow Conduit access?'))78->appendChild(79pht(80'This credential will be able to be retrieved via the Conduit '.81'API by users who have access to this credential. You should '.82'only enable this for credentials which need to be accessed '.83'programmatically (such as from build agents).'))84->addSubmitButton(pht('Allow Conduit Access'))85->addCancelButton($view_uri);86}87}8889}909192