mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-27 07:50:57 +01:00
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
This commit is contained in:
parent
10947c8684
commit
e502df509d
7 changed files with 216 additions and 2 deletions
|
@ -67,6 +67,7 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'AlmanacInterfacePHIDType' => 'PhabricatorPHIDType',
|
||||
'AlmanacInterfacePortTransaction' => 'AlmanacInterfaceTransactionType',
|
||||
'AlmanacInterfaceQuery' => 'AlmanacQuery',
|
||||
'AlmanacInterfaceSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
|
||||
'AlmanacInterfaceSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'AlmanacInterfaceTableView' => 'AphrontView',
|
||||
'AlmanacInterfaceTransaction' => 'AlmanacModularTransaction',
|
||||
'AlmanacInterfaceTransactionType' => 'AlmanacTransactionType',
|
||||
|
@ -8895,6 +8903,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorInlineSummaryView' => 'AphrontView',
|
||||
'PhabricatorInstructionsEditField' => 'PhabricatorEditField',
|
||||
'PhabricatorIntConfigType' => 'PhabricatorTextConfigType',
|
||||
'PhabricatorIntEditField' => 'PhabricatorEditField',
|
||||
'PhabricatorIntExportField' => 'PhabricatorExportField',
|
||||
'PhabricatorInternalSetting' => 'PhabricatorSetting',
|
||||
'PhabricatorInternationalizationManagementExtractWorkflow' => 'PhabricatorInternationalizationManagementWorkflow',
|
||||
|
|
|
@ -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.');
|
||||
}
|
||||
|
||||
}
|
|
@ -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.');
|
||||
}
|
||||
|
||||
}
|
|
@ -50,6 +50,50 @@ final class AlmanacInterfaceEditEngine
|
|||
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 @@ final class AlmanacInterfaceEditEngine
|
|||
AlmanacInterfaceAddressTransaction::TRANSACTIONTYPE)
|
||||
->setIsRequired(true)
|
||||
->setValue($object->getAddress()),
|
||||
id(new PhabricatorTextEditField())
|
||||
id(new PhabricatorIntEditField())
|
||||
->setKey('port')
|
||||
->setLabel(pht('Port'))
|
||||
->setDescription(pht('Port of the service.'))
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,8 @@ final class AlmanacInterface
|
|||
PhabricatorPolicyInterface,
|
||||
PhabricatorDestructibleInterface,
|
||||
PhabricatorExtendedPolicyInterface,
|
||||
PhabricatorApplicationTransactionInterface {
|
||||
PhabricatorApplicationTransactionInterface,
|
||||
PhabricatorConduitResultInterface {
|
||||
|
||||
protected $devicePHID;
|
||||
protected $networkPHID;
|
||||
|
@ -177,4 +178,42 @@ final class AlmanacInterface
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorIntEditField
|
||||
extends PhabricatorEditField {
|
||||
|
||||
protected function newControl() {
|
||||
return new AphrontFormTextControl();
|
||||
}
|
||||
|
||||
protected function newConduitParameterType() {
|
||||
return new ConduitIntParameterType();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue