diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -67,6 +67,7 @@ 'AlmanacInterfaceDeleteController' => 'applications/almanac/controller/AlmanacInterfaceDeleteController.php', 'AlmanacInterfaceDestroyTransaction' => 'applications/almanac/xaction/AlmanacInterfaceDestroyTransaction.php', 'AlmanacInterfaceDeviceTransaction' => 'applications/almanac/xaction/AlmanacInterfaceDeviceTransaction.php', + 'AlmanacInterfaceEditConduitAPIMethod' => 'applications/almanac/conduit/AlmanacInterfaceEditConduitAPIMethod.php', 'AlmanacInterfaceEditController' => 'applications/almanac/controller/AlmanacInterfaceEditController.php', 'AlmanacInterfaceEditEngine' => 'applications/almanac/editor/AlmanacInterfaceEditEngine.php', 'AlmanacInterfaceEditor' => 'applications/almanac/editor/AlmanacInterfaceEditor.php', @@ -74,6 +75,8 @@ 'AlmanacInterfacePHIDType' => 'applications/almanac/phid/AlmanacInterfacePHIDType.php', 'AlmanacInterfacePortTransaction' => 'applications/almanac/xaction/AlmanacInterfacePortTransaction.php', 'AlmanacInterfaceQuery' => 'applications/almanac/query/AlmanacInterfaceQuery.php', + 'AlmanacInterfaceSearchConduitAPIMethod' => 'applications/almanac/conduit/AlmanacInterfaceSearchConduitAPIMethod.php', + 'AlmanacInterfaceSearchEngine' => 'applications/almanac/query/AlmanacInterfaceSearchEngine.php', 'AlmanacInterfaceTableView' => 'applications/almanac/view/AlmanacInterfaceTableView.php', 'AlmanacInterfaceTransaction' => 'applications/almanac/storage/AlmanacInterfaceTransaction.php', 'AlmanacInterfaceTransactionType' => 'applications/almanac/xaction/AlmanacInterfaceTransactionType.php', @@ -3223,6 +3226,7 @@ 'PhabricatorInlineSummaryView' => 'infrastructure/diff/view/PhabricatorInlineSummaryView.php', 'PhabricatorInstructionsEditField' => 'applications/transactions/editfield/PhabricatorInstructionsEditField.php', 'PhabricatorIntConfigType' => 'applications/config/type/PhabricatorIntConfigType.php', + 'PhabricatorIntEditField' => 'applications/transactions/editfield/PhabricatorIntEditField.php', 'PhabricatorIntExportField' => 'infrastructure/export/field/PhabricatorIntExportField.php', 'PhabricatorInternalSetting' => 'applications/settings/setting/PhabricatorInternalSetting.php', 'PhabricatorInternationalizationManagementExtractWorkflow' => 'infrastructure/internationalization/management/PhabricatorInternationalizationManagementExtractWorkflow.php', @@ -5270,12 +5274,14 @@ 'PhabricatorDestructibleInterface', 'PhabricatorExtendedPolicyInterface', 'PhabricatorApplicationTransactionInterface', + 'PhabricatorConduitResultInterface', ), 'AlmanacInterfaceAddressTransaction' => 'AlmanacInterfaceTransactionType', 'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource', 'AlmanacInterfaceDeleteController' => 'AlmanacDeviceController', 'AlmanacInterfaceDestroyTransaction' => 'AlmanacInterfaceTransactionType', 'AlmanacInterfaceDeviceTransaction' => 'AlmanacInterfaceTransactionType', + 'AlmanacInterfaceEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 'AlmanacInterfaceEditController' => 'AlmanacDeviceController', 'AlmanacInterfaceEditEngine' => 'PhabricatorEditEngine', 'AlmanacInterfaceEditor' => 'AlmanacEditor', @@ -5283,6 +5289,8 @@ 'AlmanacInterfacePHIDType' => 'PhabricatorPHIDType', 'AlmanacInterfacePortTransaction' => 'AlmanacInterfaceTransactionType', 'AlmanacInterfaceQuery' => 'AlmanacQuery', + 'AlmanacInterfaceSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', + 'AlmanacInterfaceSearchEngine' => 'PhabricatorApplicationSearchEngine', 'AlmanacInterfaceTableView' => 'AphrontView', 'AlmanacInterfaceTransaction' => 'AlmanacModularTransaction', 'AlmanacInterfaceTransactionType' => 'AlmanacTransactionType', @@ -8895,6 +8903,7 @@ 'PhabricatorInlineSummaryView' => 'AphrontView', 'PhabricatorInstructionsEditField' => 'PhabricatorEditField', 'PhabricatorIntConfigType' => 'PhabricatorTextConfigType', + 'PhabricatorIntEditField' => 'PhabricatorEditField', 'PhabricatorIntExportField' => 'PhabricatorExportField', 'PhabricatorInternalSetting' => 'PhabricatorSetting', 'PhabricatorInternationalizationManagementExtractWorkflow' => 'PhabricatorInternationalizationManagementWorkflow', diff --git a/src/applications/almanac/conduit/AlmanacInterfaceEditConduitAPIMethod.php b/src/applications/almanac/conduit/AlmanacInterfaceEditConduitAPIMethod.php new file mode 100644 --- /dev/null +++ b/src/applications/almanac/conduit/AlmanacInterfaceEditConduitAPIMethod.php @@ -0,0 +1,19 @@ +setDevice(new AlmanacDevice()); + return $this->newEditableObject(); + } + + protected function newEditableObjectFromConduit(array $raw_xactions) { + $device_phid = null; + foreach ($raw_xactions as $raw_xaction) { + if ($raw_xaction['type'] !== 'device') { + continue; + } + + $device_phid = $raw_xaction['value']; + } + + if ($device_phid === null) { + throw new Exception( + pht( + 'When creating a new Almanac interface via the Conduit API, you '. + 'must provide a "device" transaction to select a device.')); + } + + $device = id(new AlmanacDeviceQuery()) + ->setViewer($this->getViewer()) + ->withPHIDs(array($device_phid)) + ->requireCapabilities( + array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + )) + ->executeOne(); + if (!$device) { + throw new Exception( + pht( + 'Device "%s" is unrecognized, restricted, or you do not have '. + 'permission to edit it.', + $device_phid)); + } + + $this->setDevice($device); + + return $this->newEditableObject(); + } + protected function newObjectQuery() { return new AlmanacInterfaceQuery(); } @@ -126,7 +170,7 @@ AlmanacInterfaceAddressTransaction::TRANSACTIONTYPE) ->setIsRequired(true) ->setValue($object->getAddress()), - id(new PhabricatorTextEditField()) + id(new PhabricatorIntEditField()) ->setKey('port') ->setLabel(pht('Port')) ->setDescription(pht('Port of the service.')) diff --git a/src/applications/almanac/query/AlmanacInterfaceSearchEngine.php b/src/applications/almanac/query/AlmanacInterfaceSearchEngine.php new file mode 100644 --- /dev/null +++ b/src/applications/almanac/query/AlmanacInterfaceSearchEngine.php @@ -0,0 +1,71 @@ +setLabel(pht('Devices')) + ->setKey('devicePHIDs') + ->setAliases(array('device', 'devicePHID', 'devices')) + ->setDescription(pht('Search for interfaces on particular devices.')), + ); + } + + protected function buildQueryFromParameters(array $map) { + $query = $this->newQuery(); + + if ($map['devicePHIDs']) { + $query->withDevicePHIDs($map['devicePHIDs']); + } + + return $query; + } + + protected function getURI($path) { + return '/almanac/interface/'.$path; + } + + protected function getBuiltinQueryNames() { + $names = array( + 'all' => pht('All Interfaces'), + ); + + return $names; + } + + public function buildSavedQueryFromBuiltin($query_key) { + $query = $this->newSavedQuery(); + $query->setQueryKey($query_key); + + switch ($query_key) { + case 'all': + return $query; + } + + return parent::buildSavedQueryFromBuiltin($query_key); + } + + protected function renderResultList( + array $devices, + PhabricatorSavedQuery $query, + array $handles) { + + // For now, this SearchEngine just supports API access via Conduit. + throw new PhutilMethodNotImplementedException(); + } + +} diff --git a/src/applications/almanac/storage/AlmanacInterface.php b/src/applications/almanac/storage/AlmanacInterface.php --- a/src/applications/almanac/storage/AlmanacInterface.php +++ b/src/applications/almanac/storage/AlmanacInterface.php @@ -6,7 +6,8 @@ PhabricatorPolicyInterface, PhabricatorDestructibleInterface, PhabricatorExtendedPolicyInterface, - PhabricatorApplicationTransactionInterface { + PhabricatorApplicationTransactionInterface, + PhabricatorConduitResultInterface { protected $devicePHID; protected $networkPHID; @@ -177,4 +178,42 @@ return $timeline; } + +/* -( PhabricatorConduitResultInterface )---------------------------------- */ + + + public function getFieldSpecificationsForConduit() { + return array( + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('devicePHID') + ->setType('phid') + ->setDescription(pht('The device the interface is on.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('networkPHID') + ->setType('phid') + ->setDescription(pht('The network the interface is part of.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('address') + ->setType('string') + ->setDescription(pht('The address of the interface.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('port') + ->setType('int') + ->setDescription(pht('The port number of the interface.')), + ); + } + + public function getFieldValuesForConduit() { + return array( + 'devicePHID' => $this->getDevicePHID(), + 'networkPHID' => $this->getNetworkPHID(), + 'address' => (string)$this->getAddress(), + 'port' => (int)$this->getPort(), + ); + } + + public function getConduitSearchAttachments() { + return array(); + } + } diff --git a/src/applications/transactions/editfield/PhabricatorIntEditField.php b/src/applications/transactions/editfield/PhabricatorIntEditField.php new file mode 100644 --- /dev/null +++ b/src/applications/transactions/editfield/PhabricatorIntEditField.php @@ -0,0 +1,14 @@ +