From 63bfa5ccb5bebb3a9268ec4c2107542fab97fa78 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 8 Jan 2017 12:30:39 -0800 Subject: [PATCH] Add "project.column.search" for querying workboard column information Summary: Ref T12074. Provide a basic but functional v3 API endpoint for reading workboard column information. There is no equivalent to this in the UI yet, although there may be some day (perhaps adjacent to T5024). Test Plan: - Queried for all columns. - Queried for columns on a particular board using `projectPHIDs`. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12074 Differential Revision: https://secure.phabricator.com/D17157 --- src/__phutil_library_map__.php | 5 ++ .../ProjectColumnSearchConduitAPIMethod.php | 18 +++++ .../PhabricatorProjectColumnSearchEngine.php | 74 +++++++++++++++++++ .../storage/PhabricatorProjectColumn.php | 37 +++++++++- 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 src/applications/project/conduit/ProjectColumnSearchConduitAPIMethod.php create mode 100644 src/applications/project/query/PhabricatorProjectColumnSearchEngine.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 72bbae9a78..810f0c6b16 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3427,6 +3427,7 @@ phutil_register_library_map(array( 'PhabricatorProjectColumnPosition' => 'applications/project/storage/PhabricatorProjectColumnPosition.php', 'PhabricatorProjectColumnPositionQuery' => 'applications/project/query/PhabricatorProjectColumnPositionQuery.php', 'PhabricatorProjectColumnQuery' => 'applications/project/query/PhabricatorProjectColumnQuery.php', + 'PhabricatorProjectColumnSearchEngine' => 'applications/project/query/PhabricatorProjectColumnSearchEngine.php', 'PhabricatorProjectColumnTransaction' => 'applications/project/storage/PhabricatorProjectColumnTransaction.php', 'PhabricatorProjectColumnTransactionEditor' => 'applications/project/editor/PhabricatorProjectColumnTransactionEditor.php', 'PhabricatorProjectColumnTransactionQuery' => 'applications/project/query/PhabricatorProjectColumnTransactionQuery.php', @@ -4454,6 +4455,7 @@ phutil_register_library_map(array( 'ProjectAddProjectsEmailCommand' => 'applications/project/command/ProjectAddProjectsEmailCommand.php', 'ProjectBoardTaskCard' => 'applications/project/view/ProjectBoardTaskCard.php', 'ProjectCanLockProjectsCapability' => 'applications/project/capability/ProjectCanLockProjectsCapability.php', + 'ProjectColumnSearchConduitAPIMethod' => 'applications/project/conduit/ProjectColumnSearchConduitAPIMethod.php', 'ProjectConduitAPIMethod' => 'applications/project/conduit/ProjectConduitAPIMethod.php', 'ProjectCreateConduitAPIMethod' => 'applications/project/conduit/ProjectCreateConduitAPIMethod.php', 'ProjectCreateProjectsCapability' => 'applications/project/capability/ProjectCreateProjectsCapability.php', @@ -8565,6 +8567,7 @@ phutil_register_library_map(array( 'PhabricatorPolicyInterface', 'PhabricatorDestructibleInterface', 'PhabricatorExtendedPolicyInterface', + 'PhabricatorConduitResultInterface', ), 'PhabricatorProjectColumnDetailController' => 'PhabricatorProjectBoardController', 'PhabricatorProjectColumnEditController' => 'PhabricatorProjectBoardController', @@ -8576,6 +8579,7 @@ phutil_register_library_map(array( ), 'PhabricatorProjectColumnPositionQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorProjectColumnQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'PhabricatorProjectColumnSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorProjectColumnTransaction' => 'PhabricatorApplicationTransaction', 'PhabricatorProjectColumnTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorProjectColumnTransactionQuery' => 'PhabricatorApplicationTransactionQuery', @@ -9849,6 +9853,7 @@ phutil_register_library_map(array( 'ProjectAddProjectsEmailCommand' => 'MetaMTAEmailTransactionCommand', 'ProjectBoardTaskCard' => 'Phobject', 'ProjectCanLockProjectsCapability' => 'PhabricatorPolicyCapability', + 'ProjectColumnSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 'ProjectConduitAPIMethod' => 'ConduitAPIMethod', 'ProjectCreateConduitAPIMethod' => 'ProjectConduitAPIMethod', 'ProjectCreateProjectsCapability' => 'PhabricatorPolicyCapability', diff --git a/src/applications/project/conduit/ProjectColumnSearchConduitAPIMethod.php b/src/applications/project/conduit/ProjectColumnSearchConduitAPIMethod.php new file mode 100644 index 0000000000..7cf21922b4 --- /dev/null +++ b/src/applications/project/conduit/ProjectColumnSearchConduitAPIMethod.php @@ -0,0 +1,18 @@ +setLabel(pht('Projects')) + ->setKey('projectPHIDs') + ->setAliases(array('project', 'projects', 'projectPHID')), + ); + } + + + protected function buildQueryFromParameters(array $map) { + $query = $this->newQuery(); + + if ($map['projectPHIDs']) { + $query->withProjectPHIDs($map['projectPHIDs']); + } + + return $query; + } + + protected function getURI($path) { + // NOTE: There's no way to query columns in the web UI, at least for + // the moment. + return null; + } + + protected function getBuiltinQueryNames() { + $names = array(); + + $names['all'] = pht('All'); + + 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 $projects, + PhabricatorSavedQuery $query, + array $handles) { + assert_instances_of($projects, 'PhabricatorProjectColumn'); + $viewer = $this->requireViewer(); + + return null; + } + +} diff --git a/src/applications/project/storage/PhabricatorProjectColumn.php b/src/applications/project/storage/PhabricatorProjectColumn.php index 7f6417db51..7ddfb4351d 100644 --- a/src/applications/project/storage/PhabricatorProjectColumn.php +++ b/src/applications/project/storage/PhabricatorProjectColumn.php @@ -6,7 +6,8 @@ final class PhabricatorProjectColumn PhabricatorApplicationTransactionInterface, PhabricatorPolicyInterface, PhabricatorDestructibleInterface, - PhabricatorExtendedPolicyInterface { + PhabricatorExtendedPolicyInterface, + PhabricatorConduitResultInterface { const STATUS_ACTIVE = 0; const STATUS_HIDDEN = 1; @@ -183,6 +184,40 @@ final class PhabricatorProjectColumn return sprintf('%s%012d', $group, $sequence); } +/* -( PhabricatorConduitResultInterface )---------------------------------- */ + + public function getFieldSpecificationsForConduit() { + return array( + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('name') + ->setType('string') + ->setDescription(pht('The display name of the column.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('project') + ->setType('map') + ->setDescription(pht('The project the column belongs to.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('proxyPHID') + ->setType('phid?') + ->setDescription( + pht( + 'For columns that proxy another object (like a subproject or '. + 'milestone), the PHID of the object they proxy.')), + ); + } + + public function getFieldValuesForConduit() { + return array( + 'name' => $this->getDisplayName(), + 'proxyPHID' => $this->getProxyPHID(), + 'project' => $this->getProject()->getRefForConduit(), + ); + } + + public function getConduitSearchAttachments() { + return array(); + } + public function getRefForConduit() { return array( 'id' => (int)$this->getID(),