[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PassphraseCredentialViewController extends PassphraseController { 4 5 private $id; 6 7 public function willProcessRequest(array $data) { 8 $this->id = $data['id']; 9 } 10 11 public function processRequest() { 12 $request = $this->getRequest(); 13 $viewer = $request->getUser(); 14 15 $credential = id(new PassphraseCredentialQuery()) 16 ->setViewer($viewer) 17 ->withIDs(array($this->id)) 18 ->executeOne(); 19 if (!$credential) { 20 return new Aphront404Response(); 21 } 22 23 $type = PassphraseCredentialType::getTypeByConstant( 24 $credential->getCredentialType()); 25 if (!$type) { 26 throw new Exception(pht('Credential has invalid type "%s"!', $type)); 27 } 28 29 $xactions = id(new PassphraseCredentialTransactionQuery()) 30 ->setViewer($viewer) 31 ->withObjectPHIDs(array($credential->getPHID())) 32 ->execute(); 33 34 $engine = id(new PhabricatorMarkupEngine()) 35 ->setViewer($viewer); 36 37 $timeline = id(new PhabricatorApplicationTransactionView()) 38 ->setUser($viewer) 39 ->setObjectPHID($credential->getPHID()) 40 ->setTransactions($xactions); 41 42 $title = pht('%s %s', 'K'.$credential->getID(), $credential->getName()); 43 $crumbs = $this->buildApplicationCrumbs(); 44 $crumbs->addTextCrumb('K'.$credential->getID()); 45 46 $header = $this->buildHeaderView($credential); 47 $actions = $this->buildActionView($credential, $type); 48 $properties = $this->buildPropertyView($credential, $type, $actions); 49 50 $crumbs->setActionList($actions); 51 52 $box = id(new PHUIObjectBoxView()) 53 ->setHeader($header) 54 ->addPropertyList($properties); 55 56 return $this->buildApplicationPage( 57 array( 58 $crumbs, 59 $box, 60 $timeline, 61 ), 62 array( 63 'title' => $title, 64 )); 65 } 66 67 private function buildHeaderView(PassphraseCredential $credential) { 68 $viewer = $this->getRequest()->getUser(); 69 70 $header = id(new PHUIHeaderView()) 71 ->setUser($viewer) 72 ->setHeader($credential->getName()) 73 ->setPolicyObject($credential); 74 75 if ($credential->getIsDestroyed()) { 76 $header->setStatus('fa-ban', 'red', pht('Destroyed')); 77 } 78 79 return $header; 80 } 81 82 private function buildActionView( 83 PassphraseCredential $credential, 84 PassphraseCredentialType $type) { 85 $viewer = $this->getRequest()->getUser(); 86 87 $id = $credential->getID(); 88 89 $is_locked = $credential->getIsLocked(); 90 if ($is_locked) { 91 $credential_lock_text = pht('Locked Permanently'); 92 $credential_lock_icon = 'fa-lock'; 93 } else { 94 $credential_lock_text = pht('Lock Permanently'); 95 $credential_lock_icon = 'fa-unlock'; 96 } 97 98 $allow_conduit = $credential->getAllowConduit(); 99 if ($allow_conduit) { 100 $credential_conduit_text = pht('Prevent Conduit Access'); 101 $credential_conduit_icon = 'fa-ban'; 102 } else { 103 $credential_conduit_text = pht('Allow Conduit Access'); 104 $credential_conduit_icon = 'fa-wrench'; 105 } 106 107 $actions = id(new PhabricatorActionListView()) 108 ->setObjectURI('/K'.$id) 109 ->setUser($viewer); 110 111 $can_edit = PhabricatorPolicyFilter::hasCapability( 112 $viewer, 113 $credential, 114 PhabricatorPolicyCapability::CAN_EDIT); 115 116 $actions->addAction( 117 id(new PhabricatorActionView()) 118 ->setName(pht('Edit Credential')) 119 ->setIcon('fa-pencil') 120 ->setHref($this->getApplicationURI("edit/{$id}/")) 121 ->setDisabled(!$can_edit) 122 ->setWorkflow(!$can_edit)); 123 124 if (!$credential->getIsDestroyed()) { 125 $actions->addAction( 126 id(new PhabricatorActionView()) 127 ->setName(pht('Destroy Credential')) 128 ->setIcon('fa-times') 129 ->setHref($this->getApplicationURI("destroy/{$id}/")) 130 ->setDisabled(!$can_edit) 131 ->setWorkflow(true)); 132 133 $actions->addAction( 134 id(new PhabricatorActionView()) 135 ->setName(pht('Show Secret')) 136 ->setIcon('fa-eye') 137 ->setHref($this->getApplicationURI("reveal/{$id}/")) 138 ->setDisabled(!$can_edit || $is_locked) 139 ->setWorkflow(true)); 140 141 if ($type->hasPublicKey()) { 142 $actions->addAction( 143 id(new PhabricatorActionView()) 144 ->setName(pht('Show Public Key')) 145 ->setIcon('fa-download') 146 ->setHref($this->getApplicationURI("public/{$id}/")) 147 ->setWorkflow(true)); 148 } 149 150 $actions->addAction( 151 id(new PhabricatorActionView()) 152 ->setName($credential_conduit_text) 153 ->setIcon($credential_conduit_icon) 154 ->setHref($this->getApplicationURI("conduit/{$id}/")) 155 ->setWorkflow(true)); 156 157 $actions->addAction( 158 id(new PhabricatorActionView()) 159 ->setName($credential_lock_text) 160 ->setIcon($credential_lock_icon) 161 ->setHref($this->getApplicationURI("lock/{$id}/")) 162 ->setDisabled($is_locked) 163 ->setWorkflow(true)); 164 } 165 166 167 return $actions; 168 } 169 170 private function buildPropertyView( 171 PassphraseCredential $credential, 172 PassphraseCredentialType $type, 173 PhabricatorActionListView $actions) { 174 $viewer = $this->getRequest()->getUser(); 175 176 $properties = id(new PHUIPropertyListView()) 177 ->setUser($viewer) 178 ->setObject($credential) 179 ->setActionList($actions); 180 181 $properties->addProperty( 182 pht('Credential Type'), 183 $type->getCredentialTypeName()); 184 185 $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( 186 $viewer, 187 $credential); 188 189 $properties->addProperty( 190 pht('Editable By'), 191 $descriptions[PhabricatorPolicyCapability::CAN_EDIT]); 192 193 $properties->addProperty( 194 pht('Username'), 195 $credential->getUsername()); 196 197 $used_by_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( 198 $credential->getPHID(), 199 PhabricatorEdgeConfig::TYPE_CREDENTIAL_USED_BY_OBJECT); 200 201 if ($used_by_phids) { 202 $this->loadHandles($used_by_phids); 203 $properties->addProperty( 204 pht('Used By'), 205 $this->renderHandlesForPHIDs($used_by_phids)); 206 } 207 208 $description = $credential->getDescription(); 209 if (strlen($description)) { 210 $properties->addSectionHeader( 211 pht('Description'), 212 PHUIPropertyListView::ICON_SUMMARY); 213 $properties->addTextContent( 214 PhabricatorMarkupEngine::renderOneObject( 215 id(new PhabricatorMarkupOneOff()) 216 ->setContent($description), 217 'default', 218 $viewer)); 219 } 220 221 return $properties; 222 } 223 224 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |