Page MenuHomePhabricator

D19338.id46248.diff
No OneTemporary

D19338.id46248.diff

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',
@@ -3222,6 +3225,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',
@@ -5269,12 +5273,14 @@
'PhabricatorDestructibleInterface',
'PhabricatorExtendedPolicyInterface',
'PhabricatorApplicationTransactionInterface',
+ 'PhabricatorConduitResultInterface',
),
'AlmanacInterfaceAddressTransaction' => 'AlmanacInterfaceTransactionType',
'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource',
'AlmanacInterfaceDeleteController' => 'AlmanacDeviceController',
'AlmanacInterfaceDestroyTransaction' => 'AlmanacInterfaceTransactionType',
'AlmanacInterfaceDeviceTransaction' => 'AlmanacInterfaceTransactionType',
+ 'AlmanacInterfaceEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
'AlmanacInterfaceEditController' => 'AlmanacDeviceController',
'AlmanacInterfaceEditEngine' => 'PhabricatorEditEngine',
'AlmanacInterfaceEditor' => 'AlmanacEditor',
@@ -5282,6 +5288,8 @@
'AlmanacInterfacePHIDType' => 'PhabricatorPHIDType',
'AlmanacInterfacePortTransaction' => 'AlmanacInterfaceTransactionType',
'AlmanacInterfaceQuery' => 'AlmanacQuery',
+ 'AlmanacInterfaceSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
+ 'AlmanacInterfaceSearchEngine' => 'PhabricatorApplicationSearchEngine',
'AlmanacInterfaceTableView' => 'AphrontView',
'AlmanacInterfaceTransaction' => 'AlmanacModularTransaction',
'AlmanacInterfaceTransactionType' => 'AlmanacTransactionType',
@@ -8893,6 +8901,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 @@
+<?php
+
+final class AlmanacInterfaceEditConduitAPIMethod
+ extends PhabricatorEditEngineAPIMethod {
+
+ public function getAPIMethodName() {
+ return 'almanac.interface.edit';
+ }
+
+ public function newEditEngine() {
+ return new AlmanacInterfaceEditEngine();
+ }
+
+ public function getMethodSummary() {
+ return pht(
+ 'Apply transactions to create a new interface or edit an existing one.');
+ }
+
+}
diff --git a/src/applications/almanac/conduit/AlmanacInterfaceSearchConduitAPIMethod.php b/src/applications/almanac/conduit/AlmanacInterfaceSearchConduitAPIMethod.php
new file mode 100644
--- /dev/null
+++ b/src/applications/almanac/conduit/AlmanacInterfaceSearchConduitAPIMethod.php
@@ -0,0 +1,18 @@
+<?php
+
+final class AlmanacInterfaceSearchConduitAPIMethod
+ extends PhabricatorSearchEngineAPIMethod {
+
+ public function getAPIMethodName() {
+ return 'almanac.interface.search';
+ }
+
+ public function newSearchEngine() {
+ return new AlmanacInterfaceSearchEngine();
+ }
+
+ public function getMethodSummary() {
+ return pht('Read information about Almanac interfaces.');
+ }
+
+}
diff --git a/src/applications/almanac/editor/AlmanacInterfaceEditEngine.php b/src/applications/almanac/editor/AlmanacInterfaceEditEngine.php
--- a/src/applications/almanac/editor/AlmanacInterfaceEditEngine.php
+++ b/src/applications/almanac/editor/AlmanacInterfaceEditEngine.php
@@ -50,6 +50,50 @@
return $interface;
}
+ protected function newEditableObjectForDocumentation() {
+ $this->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 @@
+<?php
+
+final class AlmanacInterfaceSearchEngine
+ extends PhabricatorApplicationSearchEngine {
+
+ public function getResultTypeDescription() {
+ return pht('Almanac Interfaces');
+ }
+
+ public function getApplicationClassName() {
+ return 'PhabricatorAlmanacApplication';
+ }
+
+ public function newQuery() {
+ return new AlmanacInterfaceQuery();
+ }
+
+ protected function buildCustomSearchFields() {
+ return array(
+ id(new PhabricatorPHIDsSearchField())
+ ->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 @@
+<?php
+
+final class PhabricatorIntEditField
+ extends PhabricatorEditField {
+
+ protected function newControl() {
+ return new AphrontFormTextControl();
+ }
+
+ protected function newConduitParameterType() {
+ return new ConduitIntParameterType();
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Tue, Mar 11, 6:24 PM (17 h, 50 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7543523
Default Alt Text
D19338.id46248.diff (12 KB)

Event Timeline