@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.

Implement "almanac.interface.search" and "almanac.interface.edit"

Summary: Depends on D19337. Ref T13120. Ref T12414. These are slightly more substantive than namespace/network, but pretty much standard fare.

Test Plan:
- Searched for interfaces with "almanac.interface.search".
- Created and edited interfaces with "almanac.interface.edit".
- Created and edited interfaces with web UI since some stuff got tweaked.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13120, T12414

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

+216 -2
+9
src/__phutil_library_map__.php
··· 67 67 'AlmanacInterfaceDeleteController' => 'applications/almanac/controller/AlmanacInterfaceDeleteController.php', 68 68 'AlmanacInterfaceDestroyTransaction' => 'applications/almanac/xaction/AlmanacInterfaceDestroyTransaction.php', 69 69 'AlmanacInterfaceDeviceTransaction' => 'applications/almanac/xaction/AlmanacInterfaceDeviceTransaction.php', 70 + 'AlmanacInterfaceEditConduitAPIMethod' => 'applications/almanac/conduit/AlmanacInterfaceEditConduitAPIMethod.php', 70 71 'AlmanacInterfaceEditController' => 'applications/almanac/controller/AlmanacInterfaceEditController.php', 71 72 'AlmanacInterfaceEditEngine' => 'applications/almanac/editor/AlmanacInterfaceEditEngine.php', 72 73 'AlmanacInterfaceEditor' => 'applications/almanac/editor/AlmanacInterfaceEditor.php', ··· 74 75 'AlmanacInterfacePHIDType' => 'applications/almanac/phid/AlmanacInterfacePHIDType.php', 75 76 'AlmanacInterfacePortTransaction' => 'applications/almanac/xaction/AlmanacInterfacePortTransaction.php', 76 77 'AlmanacInterfaceQuery' => 'applications/almanac/query/AlmanacInterfaceQuery.php', 78 + 'AlmanacInterfaceSearchConduitAPIMethod' => 'applications/almanac/conduit/AlmanacInterfaceSearchConduitAPIMethod.php', 79 + 'AlmanacInterfaceSearchEngine' => 'applications/almanac/query/AlmanacInterfaceSearchEngine.php', 77 80 'AlmanacInterfaceTableView' => 'applications/almanac/view/AlmanacInterfaceTableView.php', 78 81 'AlmanacInterfaceTransaction' => 'applications/almanac/storage/AlmanacInterfaceTransaction.php', 79 82 'AlmanacInterfaceTransactionType' => 'applications/almanac/xaction/AlmanacInterfaceTransactionType.php', ··· 3223 3226 'PhabricatorInlineSummaryView' => 'infrastructure/diff/view/PhabricatorInlineSummaryView.php', 3224 3227 'PhabricatorInstructionsEditField' => 'applications/transactions/editfield/PhabricatorInstructionsEditField.php', 3225 3228 'PhabricatorIntConfigType' => 'applications/config/type/PhabricatorIntConfigType.php', 3229 + 'PhabricatorIntEditField' => 'applications/transactions/editfield/PhabricatorIntEditField.php', 3226 3230 'PhabricatorIntExportField' => 'infrastructure/export/field/PhabricatorIntExportField.php', 3227 3231 'PhabricatorInternalSetting' => 'applications/settings/setting/PhabricatorInternalSetting.php', 3228 3232 'PhabricatorInternationalizationManagementExtractWorkflow' => 'infrastructure/internationalization/management/PhabricatorInternationalizationManagementExtractWorkflow.php', ··· 5270 5274 'PhabricatorDestructibleInterface', 5271 5275 'PhabricatorExtendedPolicyInterface', 5272 5276 'PhabricatorApplicationTransactionInterface', 5277 + 'PhabricatorConduitResultInterface', 5273 5278 ), 5274 5279 'AlmanacInterfaceAddressTransaction' => 'AlmanacInterfaceTransactionType', 5275 5280 'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource', 5276 5281 'AlmanacInterfaceDeleteController' => 'AlmanacDeviceController', 5277 5282 'AlmanacInterfaceDestroyTransaction' => 'AlmanacInterfaceTransactionType', 5278 5283 'AlmanacInterfaceDeviceTransaction' => 'AlmanacInterfaceTransactionType', 5284 + 'AlmanacInterfaceEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 5279 5285 'AlmanacInterfaceEditController' => 'AlmanacDeviceController', 5280 5286 'AlmanacInterfaceEditEngine' => 'PhabricatorEditEngine', 5281 5287 'AlmanacInterfaceEditor' => 'AlmanacEditor', ··· 5283 5289 'AlmanacInterfacePHIDType' => 'PhabricatorPHIDType', 5284 5290 'AlmanacInterfacePortTransaction' => 'AlmanacInterfaceTransactionType', 5285 5291 'AlmanacInterfaceQuery' => 'AlmanacQuery', 5292 + 'AlmanacInterfaceSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 5293 + 'AlmanacInterfaceSearchEngine' => 'PhabricatorApplicationSearchEngine', 5286 5294 'AlmanacInterfaceTableView' => 'AphrontView', 5287 5295 'AlmanacInterfaceTransaction' => 'AlmanacModularTransaction', 5288 5296 'AlmanacInterfaceTransactionType' => 'AlmanacTransactionType', ··· 8895 8903 'PhabricatorInlineSummaryView' => 'AphrontView', 8896 8904 'PhabricatorInstructionsEditField' => 'PhabricatorEditField', 8897 8905 'PhabricatorIntConfigType' => 'PhabricatorTextConfigType', 8906 + 'PhabricatorIntEditField' => 'PhabricatorEditField', 8898 8907 'PhabricatorIntExportField' => 'PhabricatorExportField', 8899 8908 'PhabricatorInternalSetting' => 'PhabricatorSetting', 8900 8909 'PhabricatorInternationalizationManagementExtractWorkflow' => 'PhabricatorInternationalizationManagementWorkflow',
+19
src/applications/almanac/conduit/AlmanacInterfaceEditConduitAPIMethod.php
··· 1 + <?php 2 + 3 + final class AlmanacInterfaceEditConduitAPIMethod 4 + extends PhabricatorEditEngineAPIMethod { 5 + 6 + public function getAPIMethodName() { 7 + return 'almanac.interface.edit'; 8 + } 9 + 10 + public function newEditEngine() { 11 + return new AlmanacInterfaceEditEngine(); 12 + } 13 + 14 + public function getMethodSummary() { 15 + return pht( 16 + 'Apply transactions to create a new interface or edit an existing one.'); 17 + } 18 + 19 + }
+18
src/applications/almanac/conduit/AlmanacInterfaceSearchConduitAPIMethod.php
··· 1 + <?php 2 + 3 + final class AlmanacInterfaceSearchConduitAPIMethod 4 + extends PhabricatorSearchEngineAPIMethod { 5 + 6 + public function getAPIMethodName() { 7 + return 'almanac.interface.search'; 8 + } 9 + 10 + public function newSearchEngine() { 11 + return new AlmanacInterfaceSearchEngine(); 12 + } 13 + 14 + public function getMethodSummary() { 15 + return pht('Read information about Almanac interfaces.'); 16 + } 17 + 18 + }
+45 -1
src/applications/almanac/editor/AlmanacInterfaceEditEngine.php
··· 50 50 return $interface; 51 51 } 52 52 53 + protected function newEditableObjectForDocumentation() { 54 + $this->setDevice(new AlmanacDevice()); 55 + return $this->newEditableObject(); 56 + } 57 + 58 + protected function newEditableObjectFromConduit(array $raw_xactions) { 59 + $device_phid = null; 60 + foreach ($raw_xactions as $raw_xaction) { 61 + if ($raw_xaction['type'] !== 'device') { 62 + continue; 63 + } 64 + 65 + $device_phid = $raw_xaction['value']; 66 + } 67 + 68 + if ($device_phid === null) { 69 + throw new Exception( 70 + pht( 71 + 'When creating a new Almanac interface via the Conduit API, you '. 72 + 'must provide a "device" transaction to select a device.')); 73 + } 74 + 75 + $device = id(new AlmanacDeviceQuery()) 76 + ->setViewer($this->getViewer()) 77 + ->withPHIDs(array($device_phid)) 78 + ->requireCapabilities( 79 + array( 80 + PhabricatorPolicyCapability::CAN_VIEW, 81 + PhabricatorPolicyCapability::CAN_EDIT, 82 + )) 83 + ->executeOne(); 84 + if (!$device) { 85 + throw new Exception( 86 + pht( 87 + 'Device "%s" is unrecognized, restricted, or you do not have '. 88 + 'permission to edit it.', 89 + $device_phid)); 90 + } 91 + 92 + $this->setDevice($device); 93 + 94 + return $this->newEditableObject(); 95 + } 96 + 53 97 protected function newObjectQuery() { 54 98 return new AlmanacInterfaceQuery(); 55 99 } ··· 126 170 AlmanacInterfaceAddressTransaction::TRANSACTIONTYPE) 127 171 ->setIsRequired(true) 128 172 ->setValue($object->getAddress()), 129 - id(new PhabricatorTextEditField()) 173 + id(new PhabricatorIntEditField()) 130 174 ->setKey('port') 131 175 ->setLabel(pht('Port')) 132 176 ->setDescription(pht('Port of the service.'))
+71
src/applications/almanac/query/AlmanacInterfaceSearchEngine.php
··· 1 + <?php 2 + 3 + final class AlmanacInterfaceSearchEngine 4 + extends PhabricatorApplicationSearchEngine { 5 + 6 + public function getResultTypeDescription() { 7 + return pht('Almanac Interfaces'); 8 + } 9 + 10 + public function getApplicationClassName() { 11 + return 'PhabricatorAlmanacApplication'; 12 + } 13 + 14 + public function newQuery() { 15 + return new AlmanacInterfaceQuery(); 16 + } 17 + 18 + protected function buildCustomSearchFields() { 19 + return array( 20 + id(new PhabricatorPHIDsSearchField()) 21 + ->setLabel(pht('Devices')) 22 + ->setKey('devicePHIDs') 23 + ->setAliases(array('device', 'devicePHID', 'devices')) 24 + ->setDescription(pht('Search for interfaces on particular devices.')), 25 + ); 26 + } 27 + 28 + protected function buildQueryFromParameters(array $map) { 29 + $query = $this->newQuery(); 30 + 31 + if ($map['devicePHIDs']) { 32 + $query->withDevicePHIDs($map['devicePHIDs']); 33 + } 34 + 35 + return $query; 36 + } 37 + 38 + protected function getURI($path) { 39 + return '/almanac/interface/'.$path; 40 + } 41 + 42 + protected function getBuiltinQueryNames() { 43 + $names = array( 44 + 'all' => pht('All Interfaces'), 45 + ); 46 + 47 + return $names; 48 + } 49 + 50 + public function buildSavedQueryFromBuiltin($query_key) { 51 + $query = $this->newSavedQuery(); 52 + $query->setQueryKey($query_key); 53 + 54 + switch ($query_key) { 55 + case 'all': 56 + return $query; 57 + } 58 + 59 + return parent::buildSavedQueryFromBuiltin($query_key); 60 + } 61 + 62 + protected function renderResultList( 63 + array $devices, 64 + PhabricatorSavedQuery $query, 65 + array $handles) { 66 + 67 + // For now, this SearchEngine just supports API access via Conduit. 68 + throw new PhutilMethodNotImplementedException(); 69 + } 70 + 71 + }
+40 -1
src/applications/almanac/storage/AlmanacInterface.php
··· 6 6 PhabricatorPolicyInterface, 7 7 PhabricatorDestructibleInterface, 8 8 PhabricatorExtendedPolicyInterface, 9 - PhabricatorApplicationTransactionInterface { 9 + PhabricatorApplicationTransactionInterface, 10 + PhabricatorConduitResultInterface { 10 11 11 12 protected $devicePHID; 12 13 protected $networkPHID; ··· 175 176 PhabricatorApplicationTransactionView $timeline, 176 177 AphrontRequest $request) { 177 178 return $timeline; 179 + } 180 + 181 + 182 + /* -( PhabricatorConduitResultInterface )---------------------------------- */ 183 + 184 + 185 + public function getFieldSpecificationsForConduit() { 186 + return array( 187 + id(new PhabricatorConduitSearchFieldSpecification()) 188 + ->setKey('devicePHID') 189 + ->setType('phid') 190 + ->setDescription(pht('The device the interface is on.')), 191 + id(new PhabricatorConduitSearchFieldSpecification()) 192 + ->setKey('networkPHID') 193 + ->setType('phid') 194 + ->setDescription(pht('The network the interface is part of.')), 195 + id(new PhabricatorConduitSearchFieldSpecification()) 196 + ->setKey('address') 197 + ->setType('string') 198 + ->setDescription(pht('The address of the interface.')), 199 + id(new PhabricatorConduitSearchFieldSpecification()) 200 + ->setKey('port') 201 + ->setType('int') 202 + ->setDescription(pht('The port number of the interface.')), 203 + ); 204 + } 205 + 206 + public function getFieldValuesForConduit() { 207 + return array( 208 + 'devicePHID' => $this->getDevicePHID(), 209 + 'networkPHID' => $this->getNetworkPHID(), 210 + 'address' => (string)$this->getAddress(), 211 + 'port' => (int)$this->getPort(), 212 + ); 213 + } 214 + 215 + public function getConduitSearchAttachments() { 216 + return array(); 178 217 } 179 218 180 219 }
+14
src/applications/transactions/editfield/PhabricatorIntEditField.php
··· 1 + <?php 2 + 3 + final class PhabricatorIntEditField 4 + extends PhabricatorEditField { 5 + 6 + protected function newControl() { 7 + return new AphrontFormTextControl(); 8 + } 9 + 10 + protected function newConduitParameterType() { 11 + return new ConduitIntParameterType(); 12 + } 13 + 14 + }