[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PassphraseCredentialTransactionEditor 4 extends PhabricatorApplicationTransactionEditor { 5 6 public function getEditorApplicationClass() { 7 return 'PhabricatorPassphraseApplication'; 8 } 9 10 public function getEditorObjectsDescription() { 11 return pht('Passphrase Credentials'); 12 } 13 14 public function getTransactionTypes() { 15 $types = parent::getTransactionTypes(); 16 17 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 18 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 19 20 $types[] = PassphraseCredentialTransaction::TYPE_NAME; 21 $types[] = PassphraseCredentialTransaction::TYPE_DESCRIPTION; 22 $types[] = PassphraseCredentialTransaction::TYPE_USERNAME; 23 $types[] = PassphraseCredentialTransaction::TYPE_SECRET_ID; 24 $types[] = PassphraseCredentialTransaction::TYPE_DESTROY; 25 $types[] = PassphraseCredentialTransaction::TYPE_LOOKEDATSECRET; 26 $types[] = PassphraseCredentialTransaction::TYPE_LOCK; 27 $types[] = PassphraseCredentialTransaction::TYPE_CONDUIT; 28 29 return $types; 30 } 31 32 protected function getCustomTransactionOldValue( 33 PhabricatorLiskDAO $object, 34 PhabricatorApplicationTransaction $xaction) { 35 switch ($xaction->getTransactionType()) { 36 case PassphraseCredentialTransaction::TYPE_NAME: 37 if ($this->getIsNewObject()) { 38 return null; 39 } 40 return $object->getName(); 41 case PassphraseCredentialTransaction::TYPE_DESCRIPTION: 42 return $object->getDescription(); 43 case PassphraseCredentialTransaction::TYPE_USERNAME: 44 return $object->getUsername(); 45 case PassphraseCredentialTransaction::TYPE_SECRET_ID: 46 return $object->getSecretID(); 47 case PassphraseCredentialTransaction::TYPE_DESTROY: 48 return (int)$object->getIsDestroyed(); 49 case PassphraseCredentialTransaction::TYPE_LOCK: 50 return (int)$object->getIsLocked(); 51 case PassphraseCredentialTransaction::TYPE_CONDUIT: 52 return (int)$object->getAllowConduit(); 53 case PassphraseCredentialTransaction::TYPE_LOOKEDATSECRET: 54 return null; 55 } 56 57 return parent::getCustomTransactionOldValue($object, $xaction); 58 } 59 60 protected function getCustomTransactionNewValue( 61 PhabricatorLiskDAO $object, 62 PhabricatorApplicationTransaction $xaction) { 63 switch ($xaction->getTransactionType()) { 64 case PassphraseCredentialTransaction::TYPE_NAME: 65 case PassphraseCredentialTransaction::TYPE_DESCRIPTION: 66 case PassphraseCredentialTransaction::TYPE_USERNAME: 67 case PassphraseCredentialTransaction::TYPE_SECRET_ID: 68 case PassphraseCredentialTransaction::TYPE_LOOKEDATSECRET: 69 return $xaction->getNewValue(); 70 case PassphraseCredentialTransaction::TYPE_DESTROY: 71 case PassphraseCredentialTransaction::TYPE_LOCK: 72 return (int)$xaction->getNewValue(); 73 case PassphraseCredentialTransaction::TYPE_CONDUIT: 74 return (int)$xaction->getNewValue(); 75 } 76 return parent::getCustomTransactionNewValue($object, $xaction); 77 } 78 79 protected function applyCustomInternalTransaction( 80 PhabricatorLiskDAO $object, 81 PhabricatorApplicationTransaction $xaction) { 82 switch ($xaction->getTransactionType()) { 83 case PassphraseCredentialTransaction::TYPE_NAME: 84 $object->setName($xaction->getNewValue()); 85 return; 86 case PassphraseCredentialTransaction::TYPE_DESCRIPTION: 87 $object->setDescription($xaction->getNewValue()); 88 return; 89 case PassphraseCredentialTransaction::TYPE_USERNAME: 90 $object->setUsername($xaction->getNewValue()); 91 return; 92 case PassphraseCredentialTransaction::TYPE_SECRET_ID: 93 $old_id = $object->getSecretID(); 94 if ($old_id) { 95 $this->destroySecret($old_id); 96 } 97 $object->setSecretID($xaction->getNewValue()); 98 return; 99 case PassphraseCredentialTransaction::TYPE_DESTROY: 100 // When destroying a credential, wipe out its secret. 101 $is_destroyed = $xaction->getNewValue(); 102 $object->setIsDestroyed($is_destroyed); 103 if ($is_destroyed) { 104 $secret_id = $object->getSecretID(); 105 if ($secret_id) { 106 $this->destroySecret($secret_id); 107 $object->setSecretID(null); 108 } 109 } 110 return; 111 case PhabricatorTransactions::TYPE_VIEW_POLICY: 112 $object->setViewPolicy($xaction->getNewValue()); 113 return; 114 case PhabricatorTransactions::TYPE_EDIT_POLICY: 115 $object->setEditPolicy($xaction->getNewValue()); 116 return; 117 case PassphraseCredentialTransaction::TYPE_LOOKEDATSECRET: 118 return; 119 case PassphraseCredentialTransaction::TYPE_LOCK: 120 $object->setIsLocked((int)$xaction->getNewValue()); 121 return; 122 case PassphraseCredentialTransaction::TYPE_CONDUIT: 123 $object->setAllowConduit((int)$xaction->getNewValue()); 124 return; 125 } 126 127 return parent::applyCustomInternalTransaction($object, $xaction); 128 } 129 130 protected function applyCustomExternalTransaction( 131 PhabricatorLiskDAO $object, 132 PhabricatorApplicationTransaction $xaction) { 133 134 switch ($xaction->getTransactionType()) { 135 case PassphraseCredentialTransaction::TYPE_NAME: 136 case PassphraseCredentialTransaction::TYPE_DESCRIPTION: 137 case PassphraseCredentialTransaction::TYPE_USERNAME: 138 case PassphraseCredentialTransaction::TYPE_SECRET_ID: 139 case PassphraseCredentialTransaction::TYPE_DESTROY: 140 case PassphraseCredentialTransaction::TYPE_LOOKEDATSECRET: 141 case PassphraseCredentialTransaction::TYPE_LOCK: 142 case PassphraseCredentialTransaction::TYPE_CONDUIT: 143 case PhabricatorTransactions::TYPE_VIEW_POLICY: 144 case PhabricatorTransactions::TYPE_EDIT_POLICY: 145 return; 146 } 147 148 return parent::applyCustomExternalTransaction($object, $xaction); 149 } 150 151 private function destroySecret($secret_id) { 152 $table = new PassphraseSecret(); 153 queryfx( 154 $table->establishConnection('w'), 155 'DELETE FROM %T WHERE id = %d', 156 $table->getTableName(), 157 $secret_id); 158 } 159 160 protected function validateTransaction( 161 PhabricatorLiskDAO $object, 162 $type, 163 array $xactions) { 164 165 $errors = parent::validateTransaction($object, $type, $xactions); 166 167 switch ($type) { 168 case PassphraseCredentialTransaction::TYPE_NAME: 169 $missing = $this->validateIsEmptyTextField( 170 $object->getName(), 171 $xactions); 172 173 if ($missing) { 174 $error = new PhabricatorApplicationTransactionValidationError( 175 $type, 176 pht('Required'), 177 pht('Credential name is required.'), 178 nonempty(last($xactions), null)); 179 180 $error->setIsMissingFieldError(true); 181 $errors[] = $error; 182 } 183 break; 184 case PassphraseCredentialTransaction::TYPE_USERNAME: 185 $missing = $this->validateIsEmptyTextField( 186 $object->getUsername(), 187 $xactions); 188 189 if ($missing) { 190 $error = new PhabricatorApplicationTransactionValidationError( 191 $type, 192 pht('Required'), 193 pht('Username is required.'), 194 nonempty(last($xactions), null)); 195 196 $error->setIsMissingFieldError(true); 197 $errors[] = $error; 198 } 199 break; 200 } 201 202 return $errors; 203 } 204 205 206 }
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 |