[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/passphrase/controller/ -> PassphraseCredentialLockController.php (source)

   1  <?php
   2  
   3  final class PassphraseCredentialLockController
   4    extends PassphraseController {
   5  
   6    private $id;
   7  
   8    public function willProcessRequest(array $data) {
   9      $this->id = $data['id'];
  10    }
  11  
  12    public function processRequest() {
  13      $request = $this->getRequest();
  14      $viewer = $request->getUser();
  15  
  16      $credential = id(new PassphraseCredentialQuery())
  17        ->setViewer($viewer)
  18        ->withIDs(array($this->id))
  19        ->requireCapabilities(
  20          array(
  21            PhabricatorPolicyCapability::CAN_VIEW,
  22            PhabricatorPolicyCapability::CAN_EDIT,
  23          ))
  24        ->executeOne();
  25      if (!$credential) {
  26        return new Aphront404Response();
  27      }
  28  
  29      $type = PassphraseCredentialType::getTypeByConstant(
  30        $credential->getCredentialType());
  31      if (!$type) {
  32        throw new Exception(pht('Credential has invalid type "%s"!', $type));
  33      }
  34  
  35      $view_uri = '/K'.$credential->getID();
  36  
  37      if ($credential->getIsLocked()) {
  38        return $this->newDialog()
  39          ->setTitle(pht('Credential Already Locked'))
  40          ->appendChild(
  41            pht(
  42              'This credential has been locked and the secret is '.
  43              'hidden forever. Anything relying on this credential will '.
  44              'still function. This operation can not be undone.'))
  45          ->addCancelButton($view_uri, pht('Close'));
  46      }
  47  
  48      if ($request->isFormPost()) {
  49        $xactions = array();
  50        $xactions[] = id(new PassphraseCredentialTransaction())
  51          ->setTransactionType(PassphraseCredentialTransaction::TYPE_LOCK)
  52          ->setNewValue(1);
  53  
  54        $editor = id(new PassphraseCredentialTransactionEditor())
  55          ->setActor($viewer)
  56          ->setContinueOnMissingFields(true)
  57          ->setContentSourceFromRequest($request)
  58          ->applyTransactions($credential, $xactions);
  59  
  60        return id(new AphrontRedirectResponse())->setURI($view_uri);
  61      }
  62  
  63      return $this->newDialog()
  64        ->setTitle(pht('Really lock credential?'))
  65        ->appendChild(
  66          pht(
  67            'This credential will be locked and the secret will be '.
  68            'hidden forever. Anything relying on this credential will '.
  69            'still function. This operation can not be undone.'))
  70        ->addSubmitButton(pht('Lock Credential'))
  71        ->addCancelButton($view_uri);
  72    }
  73  
  74  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1