@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove TYPE_INTERFACE transaction from Almanac Device

Summary:
Depends on D19325. Ref T13120. Ref T12414.

This no longer has any callers in the upstream or in Phacility support libraries, so get rid of it.

This will make modularizing Device transactions significantly easier, since the other transactions are reasonable, normal sorts of transactions.

For existing devices, this leaves some "author edited this object." transactions in the log. I might just leave those since they aren't really hurting anything, or maybe I'll clean them up or hide them later once I have more confidence that these changes are stable.

Test Plan: Grepped for `TYPE_INTERFACE` and `AlmanacDeviceTransaction`, found no callsites.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13120, T12414

Differential Revision: https://secure.phabricator.com/D19328

+1 -237
+1 -182
src/applications/almanac/editor/AlmanacDeviceEditor.php
··· 11 11 $types = parent::getTransactionTypes(); 12 12 13 13 $types[] = AlmanacDeviceTransaction::TYPE_NAME; 14 - $types[] = AlmanacDeviceTransaction::TYPE_INTERFACE; 14 + 15 15 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 16 16 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 17 17 ··· 35 35 36 36 switch ($xaction->getTransactionType()) { 37 37 case AlmanacDeviceTransaction::TYPE_NAME: 38 - case AlmanacDeviceTransaction::TYPE_INTERFACE: 39 38 return $xaction->getNewValue(); 40 39 } 41 40 ··· 50 49 case AlmanacDeviceTransaction::TYPE_NAME: 51 50 $object->setName($xaction->getNewValue()); 52 51 return; 53 - case AlmanacDeviceTransaction::TYPE_INTERFACE: 54 - return; 55 52 } 56 53 57 54 return parent::applyCustomInternalTransaction($object, $xaction); ··· 64 61 switch ($xaction->getTransactionType()) { 65 62 case AlmanacDeviceTransaction::TYPE_NAME: 66 63 return; 67 - case AlmanacDeviceTransaction::TYPE_INTERFACE: 68 - $old = $xaction->getOldValue(); 69 - if ($old) { 70 - $interface = id(new AlmanacInterfaceQuery()) 71 - ->setViewer($this->requireActor()) 72 - ->withIDs(array($old['id'])) 73 - ->executeOne(); 74 - if (!$interface) { 75 - throw new Exception(pht('Unable to load interface!')); 76 - } 77 - } else { 78 - $interface = AlmanacInterface::initializeNewInterface() 79 - ->setDevicePHID($object->getPHID()); 80 - } 81 - 82 - $new = $xaction->getNewValue(); 83 - if ($new) { 84 - $interface 85 - ->setNetworkPHID($new['networkPHID']) 86 - ->setAddress($new['address']) 87 - ->setPort((int)$new['port']); 88 - 89 - if (idx($new, 'phid')) { 90 - $interface->setPHID($new['phid']); 91 - } 92 - 93 - $interface->save(); 94 - } else { 95 - $interface->delete(); 96 - } 97 - return; 98 64 } 99 65 100 66 return parent::applyCustomExternalTransaction($object, $xaction); ··· 180 146 } 181 147 182 148 break; 183 - case AlmanacDeviceTransaction::TYPE_INTERFACE: 184 - // We want to make sure that all the affected networks are visible to 185 - // the actor, any edited interfaces exist, and that the actual address 186 - // components are valid. 187 - 188 - $network_phids = array(); 189 - foreach ($xactions as $xaction) { 190 - $old = $xaction->getOldValue(); 191 - $new = $xaction->getNewValue(); 192 - if ($old) { 193 - $network_phids[] = $old['networkPHID']; 194 - } 195 - if ($new) { 196 - $network_phids[] = $new['networkPHID']; 197 - 198 - $address = $new['address']; 199 - if (!strlen($address)) { 200 - $error = new PhabricatorApplicationTransactionValidationError( 201 - $type, 202 - pht('Invalid'), 203 - pht('Interfaces must have an address.'), 204 - $xaction); 205 - $errors[] = $error; 206 - } else { 207 - // TODO: Validate addresses, but IPv6 addresses are not trivial 208 - // to validate. 209 - } 210 - 211 - $port = $new['port']; 212 - if (!strlen($port)) { 213 - $error = new PhabricatorApplicationTransactionValidationError( 214 - $type, 215 - pht('Invalid'), 216 - pht('Interfaces must have a port.'), 217 - $xaction); 218 - $errors[] = $error; 219 - } else if ((int)$port < 1 || (int)$port > 65535) { 220 - $error = new PhabricatorApplicationTransactionValidationError( 221 - $type, 222 - pht('Invalid'), 223 - pht( 224 - 'Port numbers must be between 1 and 65535, inclusive.'), 225 - $xaction); 226 - $errors[] = $error; 227 - } 228 - 229 - $phid = idx($new, 'phid'); 230 - if ($phid) { 231 - $interface_phid_type = AlmanacInterfacePHIDType::TYPECONST; 232 - if (phid_get_type($phid) !== $interface_phid_type) { 233 - $error = new PhabricatorApplicationTransactionValidationError( 234 - $type, 235 - pht('Invalid'), 236 - pht( 237 - 'Precomputed interface PHIDs must be of type '. 238 - 'AlmanacInterfacePHIDType.'), 239 - $xaction); 240 - $errors[] = $error; 241 - } 242 - } 243 - } 244 - } 245 - 246 - if ($network_phids) { 247 - $networks = id(new AlmanacNetworkQuery()) 248 - ->setViewer($this->requireActor()) 249 - ->withPHIDs($network_phids) 250 - ->execute(); 251 - $networks = mpull($networks, null, 'getPHID'); 252 - } else { 253 - $networks = array(); 254 - } 255 - 256 - $addresses = array(); 257 - foreach ($xactions as $xaction) { 258 - $old = $xaction->getOldValue(); 259 - if ($old) { 260 - $network = idx($networks, $old['networkPHID']); 261 - if (!$network) { 262 - $error = new PhabricatorApplicationTransactionValidationError( 263 - $type, 264 - pht('Invalid'), 265 - pht( 266 - 'You can not edit an interface which belongs to a '. 267 - 'nonexistent or restricted network.'), 268 - $xaction); 269 - $errors[] = $error; 270 - } 271 - 272 - $addresses[] = $old['id']; 273 - } 274 - 275 - $new = $xaction->getNewValue(); 276 - if ($new) { 277 - $network = idx($networks, $new['networkPHID']); 278 - if (!$network) { 279 - $error = new PhabricatorApplicationTransactionValidationError( 280 - $type, 281 - pht('Invalid'), 282 - pht( 283 - 'You can not add an interface on a nonexistent or '. 284 - 'restricted network.'), 285 - $xaction); 286 - $errors[] = $error; 287 - } 288 - } 289 - } 290 - 291 - if ($addresses) { 292 - $interfaces = id(new AlmanacInterfaceQuery()) 293 - ->setViewer($this->requireActor()) 294 - ->withDevicePHIDs(array($object->getPHID())) 295 - ->withIDs($addresses) 296 - ->execute(); 297 - $interfaces = mpull($interfaces, null, 'getID'); 298 - } else { 299 - $interfaces = array(); 300 - } 301 - 302 - foreach ($xactions as $xaction) { 303 - $old = $xaction->getOldValue(); 304 - if ($old) { 305 - $interface = idx($interfaces, $old['id']); 306 - if (!$interface) { 307 - $error = new PhabricatorApplicationTransactionValidationError( 308 - $type, 309 - pht('Invalid'), 310 - pht('You can not edit an invalid or restricted interface.'), 311 - $xaction); 312 - $errors[] = $error; 313 - continue; 314 - } 315 - 316 - $new = $xaction->getNewValue(); 317 - if (!$new) { 318 - if ($interface->loadIsInUse()) { 319 - $error = new PhabricatorApplicationTransactionValidationError( 320 - $type, 321 - pht('In Use'), 322 - pht('You can not delete an interface which is still in use.'), 323 - $xaction); 324 - $errors[] = $error; 325 - } 326 - } 327 - } 328 - } 329 - break; 330 149 } 331 150 332 151 return $errors;
-55
src/applications/almanac/storage/AlmanacDeviceTransaction.php
··· 4 4 extends AlmanacTransaction { 5 5 6 6 const TYPE_NAME = 'almanac:device:name'; 7 - const TYPE_INTERFACE = 'almanac:device:interface'; 8 7 9 8 public function getApplicationName() { 10 9 return 'almanac'; ··· 18 17 return null; 19 18 } 20 19 21 - public function getRequiredHandlePHIDs() { 22 - $phids = parent::getRequiredHandlePHIDs(); 23 - 24 - $old = $this->getOldValue(); 25 - $new = $this->getNewValue(); 26 - 27 - switch ($this->getTransactionType()) { 28 - case self::TYPE_INTERFACE: 29 - if ($old) { 30 - $phids[] = $old['networkPHID']; 31 - } 32 - if ($new) { 33 - $phids[] = $new['networkPHID']; 34 - } 35 - break; 36 - } 37 - 38 - return $phids; 39 - } 40 - 41 20 public function getTitle() { 42 21 $author_phid = $this->getAuthorPHID(); 43 22 ··· 58 37 $new); 59 38 } 60 39 break; 61 - case self::TYPE_INTERFACE: 62 - if ($old && $new) { 63 - return pht( 64 - '%s changed interface %s on this device to %s.', 65 - $this->renderHandleLink($author_phid), 66 - $this->describeInterface($old), 67 - $this->describeInterface($new)); 68 - } else if ($old) { 69 - return pht( 70 - '%s removed the interface %s from this device.', 71 - $this->renderHandleLink($author_phid), 72 - $this->describeInterface($old)); 73 - } else if ($new) { 74 - return pht( 75 - '%s added the interface %s to this device.', 76 - $this->renderHandleLink($author_phid), 77 - $this->describeInterface($new)); 78 - } 79 40 } 80 41 81 42 return parent::getTitle(); 82 - } 83 - 84 - public function shouldGenerateOldValue() { 85 - switch ($this->getTransactionType()) { 86 - case self::TYPE_INTERFACE: 87 - return false; 88 - } 89 - return parent::shouldGenerateOldValue(); 90 - } 91 - 92 - private function describeInterface(array $info) { 93 - return pht( 94 - '%s:%s (%s)', 95 - $info['address'], 96 - $info['port'], 97 - $this->renderHandleLink($info['networkPHID'])); 98 43 } 99 44 100 45 }