From 663dce5029f592b7a09ae0a57ec457cdc7f1a8db Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 13 Dec 2015 07:29:05 -0800 Subject: [PATCH] Flesh out Conduit parameter types for Owners + CustomFields Summary: Ref T9964. Fill in more parameter types and descriptions. (No date support yet since it's a bit more involved.) Test Plan: {F1024022} Reviewers: chad Reviewed By: chad Maniphest Tasks: T9964 Differential Revision: https://secure.phabricator.com/D14766 --- src/__phutil_library_map__.php | 6 +++ .../ConduitBoolParameterType.php | 36 ++++++++++++++++++ .../ConduitEpochParameterType.php | 13 +++++-- .../parametertype/ConduitIntParameterType.php | 37 +++++++++++++++++++ .../ConduitStringParameterType.php | 35 ++++++++++++++++++ .../PhabricatorOwnersPackageSearchEngine.php | 12 +++++- .../PhabricatorSearchEngineAPIMethod.php | 8 +++- ...PhabricatorSearchCustomFieldProxyField.php | 8 ++++ .../PhabricatorSearchDatasourceField.php | 4 ++ .../field/PhabricatorCustomField.php | 11 ++++++ .../PhabricatorStandardCustomField.php | 1 + .../PhabricatorStandardCustomFieldBool.php | 3 ++ .../PhabricatorStandardCustomFieldDate.php | 5 +++ .../PhabricatorStandardCustomFieldHeader.php | 4 ++ .../PhabricatorStandardCustomFieldInt.php | 3 ++ .../PhabricatorStandardCustomFieldLink.php | 3 ++ ...PhabricatorStandardCustomFieldRemarkup.php | 3 ++ .../PhabricatorStandardCustomFieldSelect.php | 3 ++ .../PhabricatorStandardCustomFieldText.php | 4 ++ .../PhabricatorStandardCustomFieldUsers.php | 4 ++ 20 files changed, 196 insertions(+), 7 deletions(-) create mode 100644 src/applications/conduit/parametertype/ConduitBoolParameterType.php create mode 100644 src/applications/conduit/parametertype/ConduitIntParameterType.php create mode 100644 src/applications/conduit/parametertype/ConduitStringParameterType.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index dc97c2c93c..bb384b09e2 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -223,6 +223,7 @@ phutil_register_library_map(array( 'ConduitAPIRequest' => 'applications/conduit/protocol/ConduitAPIRequest.php', 'ConduitAPIResponse' => 'applications/conduit/protocol/ConduitAPIResponse.php', 'ConduitApplicationNotInstalledException' => 'applications/conduit/protocol/exception/ConduitApplicationNotInstalledException.php', + 'ConduitBoolParameterType' => 'applications/conduit/parametertype/ConduitBoolParameterType.php', 'ConduitCall' => 'applications/conduit/call/ConduitCall.php', 'ConduitCallTestCase' => 'applications/conduit/call/__tests__/ConduitCallTestCase.php', 'ConduitConnectConduitAPIMethod' => 'applications/conduit/method/ConduitConnectConduitAPIMethod.php', @@ -232,6 +233,7 @@ phutil_register_library_map(array( 'ConduitException' => 'applications/conduit/protocol/exception/ConduitException.php', 'ConduitGetCapabilitiesConduitAPIMethod' => 'applications/conduit/method/ConduitGetCapabilitiesConduitAPIMethod.php', 'ConduitGetCertificateConduitAPIMethod' => 'applications/conduit/method/ConduitGetCertificateConduitAPIMethod.php', + 'ConduitIntParameterType' => 'applications/conduit/parametertype/ConduitIntParameterType.php', 'ConduitListParameterType' => 'applications/conduit/parametertype/ConduitListParameterType.php', 'ConduitLogGarbageCollector' => 'applications/conduit/garbagecollector/ConduitLogGarbageCollector.php', 'ConduitMethodDoesNotExistException' => 'applications/conduit/protocol/exception/ConduitMethodDoesNotExistException.php', @@ -244,6 +246,7 @@ phutil_register_library_map(array( 'ConduitResultSearchEngineExtension' => 'applications/conduit/query/ConduitResultSearchEngineExtension.php', 'ConduitSSHWorkflow' => 'applications/conduit/ssh/ConduitSSHWorkflow.php', 'ConduitStringListParameterType' => 'applications/conduit/parametertype/ConduitStringListParameterType.php', + 'ConduitStringParameterType' => 'applications/conduit/parametertype/ConduitStringParameterType.php', 'ConduitTokenGarbageCollector' => 'applications/conduit/garbagecollector/ConduitTokenGarbageCollector.php', 'ConduitUserListParameterType' => 'applications/conduit/parametertype/ConduitUserListParameterType.php', 'ConpherenceColumnViewController' => 'applications/conpherence/controller/ConpherenceColumnViewController.php', @@ -4072,6 +4075,7 @@ phutil_register_library_map(array( 'ConduitAPIRequest' => 'Phobject', 'ConduitAPIResponse' => 'Phobject', 'ConduitApplicationNotInstalledException' => 'ConduitMethodNotFoundException', + 'ConduitBoolParameterType' => 'ConduitListParameterType', 'ConduitCall' => 'Phobject', 'ConduitCallTestCase' => 'PhabricatorTestCase', 'ConduitConnectConduitAPIMethod' => 'ConduitAPIMethod', @@ -4081,6 +4085,7 @@ phutil_register_library_map(array( 'ConduitException' => 'Exception', 'ConduitGetCapabilitiesConduitAPIMethod' => 'ConduitAPIMethod', 'ConduitGetCertificateConduitAPIMethod' => 'ConduitAPIMethod', + 'ConduitIntParameterType' => 'ConduitListParameterType', 'ConduitListParameterType' => 'ConduitParameterType', 'ConduitLogGarbageCollector' => 'PhabricatorGarbageCollector', 'ConduitMethodDoesNotExistException' => 'ConduitMethodNotFoundException', @@ -4093,6 +4098,7 @@ phutil_register_library_map(array( 'ConduitResultSearchEngineExtension' => 'PhabricatorSearchEngineExtension', 'ConduitSSHWorkflow' => 'PhabricatorSSHWorkflow', 'ConduitStringListParameterType' => 'ConduitListParameterType', + 'ConduitStringParameterType' => 'ConduitListParameterType', 'ConduitTokenGarbageCollector' => 'PhabricatorGarbageCollector', 'ConduitUserListParameterType' => 'ConduitListParameterType', 'ConpherenceColumnViewController' => 'ConpherenceController', diff --git a/src/applications/conduit/parametertype/ConduitBoolParameterType.php b/src/applications/conduit/parametertype/ConduitBoolParameterType.php new file mode 100644 index 0000000000..e15925827e --- /dev/null +++ b/src/applications/conduit/parametertype/ConduitBoolParameterType.php @@ -0,0 +1,36 @@ +raiseValidationException( + $request, + $key, + pht('Expected boolean (true or false), got something else.')); + } + + return $value; + } + + protected function getParameterTypeName() { + return 'bool'; + } + + protected function getParameterFormatDescriptions() { + return array( + pht('A boolean.'), + ); + } + + protected function getParameterExamples() { + return array( + 'true', + 'false', + ); + } + +} diff --git a/src/applications/conduit/parametertype/ConduitEpochParameterType.php b/src/applications/conduit/parametertype/ConduitEpochParameterType.php index 2c85378bb3..9f906c9c31 100644 --- a/src/applications/conduit/parametertype/ConduitEpochParameterType.php +++ b/src/applications/conduit/parametertype/ConduitEpochParameterType.php @@ -10,7 +10,14 @@ final class ConduitEpochParameterType $this->raiseValidationException( $request, $key, - pht('Expected integer, got something else.')); + pht('Expected epoch timestamp as integer, got something else.')); + } + + if ($value <= 0) { + $this->raiseValidationException( + $request, + $key, + pht('Epoch timestamp must be larger than 0, got %d.', $value)); } return $value; @@ -28,9 +35,7 @@ final class ConduitEpochParameterType protected function getParameterExamples() { return array( - '["PHID-PROJ-1111"]', - '["backend"]', - '["PHID-PROJ-2222", "frontend"]', + '1450019509', ); } diff --git a/src/applications/conduit/parametertype/ConduitIntParameterType.php b/src/applications/conduit/parametertype/ConduitIntParameterType.php new file mode 100644 index 0000000000..e9943e53a7 --- /dev/null +++ b/src/applications/conduit/parametertype/ConduitIntParameterType.php @@ -0,0 +1,37 @@ +raiseValidationException( + $request, + $key, + pht('Expected integer, got something else.')); + } + + return $value; + } + + protected function getParameterTypeName() { + return 'int'; + } + + protected function getParameterFormatDescriptions() { + return array( + pht('An integer.'), + ); + } + + protected function getParameterExamples() { + return array( + '123', + '0', + '-345', + ); + } + +} diff --git a/src/applications/conduit/parametertype/ConduitStringParameterType.php b/src/applications/conduit/parametertype/ConduitStringParameterType.php new file mode 100644 index 0000000000..cb4e71ff7e --- /dev/null +++ b/src/applications/conduit/parametertype/ConduitStringParameterType.php @@ -0,0 +1,35 @@ +raiseValidationException( + $request, + $key, + pht('Expected string, got something else.')); + } + + return $value; + } + + protected function getParameterTypeName() { + return 'string'; + } + + protected function getParameterFormatDescriptions() { + return array( + pht('A string.'), + ); + } + + protected function getParameterExamples() { + return array( + '"papaya"', + ); + } + +} diff --git a/src/applications/owners/query/PhabricatorOwnersPackageSearchEngine.php b/src/applications/owners/query/PhabricatorOwnersPackageSearchEngine.php index d3131bba47..ec84b6793f 100644 --- a/src/applications/owners/query/PhabricatorOwnersPackageSearchEngine.php +++ b/src/applications/owners/query/PhabricatorOwnersPackageSearchEngine.php @@ -21,19 +21,29 @@ final class PhabricatorOwnersPackageSearchEngine ->setLabel(pht('Authority')) ->setKey('authorityPHIDs') ->setAliases(array('authority', 'authorities')) + ->setConduitKey('owners') + ->setDescription( + pht('Search for packages with specific owners.')) ->setDatasource(new PhabricatorProjectOrUserDatasource()), id(new PhabricatorSearchDatasourceField()) ->setLabel(pht('Repositories')) ->setKey('repositoryPHIDs') + ->setConduitKey('repositories') ->setAliases(array('repository', 'repositories')) + ->setDescription( + pht('Search for packages by included repositories.')) ->setDatasource(new DiffusionRepositoryDatasource()), id(new PhabricatorSearchStringListField()) ->setLabel(pht('Paths')) ->setKey('paths') - ->setAliases(array('path')), + ->setAliases(array('path')) + ->setDescription( + pht('Search for packages affecting specific paths.')), id(new PhabricatorSearchCheckboxesField()) ->setKey('statuses') ->setLabel(pht('Status')) + ->setDescription( + pht('Search for active or archived packages.')) ->setOptions( id(new PhabricatorOwnersPackage()) ->getStatusNameMap()), diff --git a/src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php b/src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php index 66da79e28a..21fb4b54a1 100644 --- a/src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php +++ b/src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php @@ -196,13 +196,13 @@ EOTEXT ); $head_builtin = pht('Builtin Order'); - $head_description = pht('Description'); + $head_label = pht('Label'); $head_columns = pht('Columns'); $orders = $query->getBuiltinOrders(); $table = array(); - $table[] = "| {$head_builtin} | {$head_description} | {$head_columns} |"; + $table[] = "| {$head_builtin} | {$head_label} | {$head_columns} |"; $table[] = '|-----------------|---------------------|-----------------|'; foreach ($orders as $key => $order) { $name = $order['name']; @@ -310,6 +310,10 @@ These are the fields available on this object type: EOTEXT ); + $head_key = pht('Key'); + $head_type = pht('Type'); + $head_description = pht('Description'); + $specs = $engine->getAllConduitFieldSpecifications(); $table = array(); diff --git a/src/applications/search/field/PhabricatorSearchCustomFieldProxyField.php b/src/applications/search/field/PhabricatorSearchCustomFieldProxyField.php index 1144377d68..58d50a245e 100644 --- a/src/applications/search/field/PhabricatorSearchCustomFieldProxyField.php +++ b/src/applications/search/field/PhabricatorSearchCustomFieldProxyField.php @@ -63,4 +63,12 @@ final class PhabricatorSearchCustomFieldProxyField $this->getValue()); } + public function getDescription() { + return $this->getCustomField()->getFieldDescription(); + } + + protected function newConduitParameterType() { + return $this->getCustomField()->getConduitSearchParameterType(); + } + } diff --git a/src/applications/search/field/PhabricatorSearchDatasourceField.php b/src/applications/search/field/PhabricatorSearchDatasourceField.php index 2e05d60643..cb48b06d52 100644 --- a/src/applications/search/field/PhabricatorSearchDatasourceField.php +++ b/src/applications/search/field/PhabricatorSearchDatasourceField.php @@ -14,4 +14,8 @@ final class PhabricatorSearchDatasourceField return $this; } + protected function newConduitParameterType() { + return new ConduitStringListParameterType(); + } + } diff --git a/src/infrastructure/customfield/field/PhabricatorCustomField.php b/src/infrastructure/customfield/field/PhabricatorCustomField.php index edc077ff6f..e0062e6fac 100644 --- a/src/infrastructure/customfield/field/PhabricatorCustomField.php +++ b/src/infrastructure/customfield/field/PhabricatorCustomField.php @@ -1337,6 +1337,17 @@ abstract class PhabricatorCustomField extends Phobject { return false; } + public function getConduitSearchParameterType() { + return $this->newConduitSearchParameterType(); + } + + protected function newConduitSearchParameterType() { + if ($this->proxy) { + return $this->proxy->newConduitSearchParameterType(); + } + return null; + } + /* -( Herald )------------------------------------------------------------- */ diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php index 302607acfa..a63f32addd 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php @@ -463,4 +463,5 @@ abstract class PhabricatorStandardCustomField return $this->getFieldValue(); } + } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php index e31b6bc6e8..04ac3ac822 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php @@ -133,4 +133,7 @@ final class PhabricatorStandardCustomFieldBool return new AphrontBoolHTTPParameterType(); } + protected function newConduitSearchParameterType() { + return new ConduitBoolParameterType(); + } } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php index eb6ea96bf4..1114284acf 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php @@ -197,4 +197,9 @@ final class PhabricatorStandardCustomFieldDate return false; } + protected function newConduitSearchParameterType() { + // TODO: Build a new "pair" type or similar. + return null; + } + } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldHeader.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldHeader.php index e826917ea9..b95531538a 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldHeader.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldHeader.php @@ -30,4 +30,8 @@ final class PhabricatorStandardCustomFieldHeader return $this->getFieldName(); } + public function shouldAppearInApplicationSearch() { + return false; + } + } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php index 8c54b45c3d..ac569ee8bc 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php @@ -116,5 +116,8 @@ final class PhabricatorStandardCustomFieldInt return new AphrontIntHTTPParameterType(); } + protected function newConduitSearchParameterType() { + return new ConduitIntParameterType(); + } } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldLink.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldLink.php index 91352e3d60..524aaa56e4 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldLink.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldLink.php @@ -84,4 +84,7 @@ final class PhabricatorStandardCustomFieldLink return new AphrontStringHTTPParameterType(); } + protected function newConduitSearchParameterType() { + return new ConduitStringListParameterType(); + } } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php index 894d48dbb3..eadb382af7 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php @@ -99,5 +99,8 @@ final class PhabricatorStandardCustomFieldRemarkup return new AphrontStringHTTPParameterType(); } + public function shouldAppearInApplicationSearch() { + return false; + } } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php index 06b5d5e01b..bf835eacc2 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php @@ -140,4 +140,7 @@ final class PhabricatorStandardCustomFieldSelect return new AphrontSelectHTTPParameterType(); } + protected function newConduitSearchParameterType() { + return new ConduitStringListParameterType(); + } } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php index 4f6590b6a4..3c02c7dd20 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php @@ -67,4 +67,8 @@ final class PhabricatorStandardCustomFieldText return new AphrontStringHTTPParameterType(); } + public function shouldAppearInApplicationSearch() { + return false; + } + } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php index 17b082e583..7625298f39 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php @@ -15,4 +15,8 @@ final class PhabricatorStandardCustomFieldUsers return new AphrontUserListHTTPParameterType(); } + protected function newConduitSearchParameterType() { + return new ConduitUserListParameterType(); + } + }