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 @@ -1146,6 +1146,7 @@ 'DrydockLeaseReclaimLogType' => 'applications/drydock/logtype/DrydockLeaseReclaimLogType.php', 'DrydockLeaseReleaseController' => 'applications/drydock/controller/DrydockLeaseReleaseController.php', 'DrydockLeaseReleasedLogType' => 'applications/drydock/logtype/DrydockLeaseReleasedLogType.php', + 'DrydockLeaseSearchConduitAPIMethod' => 'applications/drydock/conduit/DrydockLeaseSearchConduitAPIMethod.php', 'DrydockLeaseSearchEngine' => 'applications/drydock/query/DrydockLeaseSearchEngine.php', 'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php', 'DrydockLeaseUpdateWorker' => 'applications/drydock/worker/DrydockLeaseUpdateWorker.php', @@ -6532,6 +6533,7 @@ 'DrydockLease' => array( 'DrydockDAO', 'PhabricatorPolicyInterface', + 'PhabricatorConduitResultInterface', ), 'DrydockLeaseAcquiredLogType' => 'DrydockLogType', 'DrydockLeaseActivatedLogType' => 'DrydockLogType', @@ -6552,6 +6554,7 @@ 'DrydockLeaseReclaimLogType' => 'DrydockLogType', 'DrydockLeaseReleaseController' => 'DrydockLeaseController', 'DrydockLeaseReleasedLogType' => 'DrydockLogType', + 'DrydockLeaseSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 'DrydockLeaseSearchEngine' => 'PhabricatorApplicationSearchEngine', 'DrydockLeaseStatus' => 'PhabricatorObjectStatus', 'DrydockLeaseUpdateWorker' => 'DrydockWorker', diff --git a/src/applications/drydock/conduit/DrydockLeaseSearchConduitAPIMethod.php b/src/applications/drydock/conduit/DrydockLeaseSearchConduitAPIMethod.php new file mode 100644 --- /dev/null +++ b/src/applications/drydock/conduit/DrydockLeaseSearchConduitAPIMethod.php @@ -0,0 +1,18 @@ +ownerPHIDs = $phids; + return $this; + } + public function withStatuses(array $statuses) { $this->statuses = $statuses; return $this; @@ -105,6 +111,13 @@ $this->resourcePHIDs); } + if ($this->ownerPHIDs !== null) { + $where[] = qsprintf( + $conn, + 'ownerPHID IN (%Ls)', + $this->ownerPHIDs); + } + if ($this->ids !== null) { $where[] = qsprintf( $conn, diff --git a/src/applications/drydock/query/DrydockLeaseSearchEngine.php b/src/applications/drydock/query/DrydockLeaseSearchEngine.php --- a/src/applications/drydock/query/DrydockLeaseSearchEngine.php +++ b/src/applications/drydock/query/DrydockLeaseSearchEngine.php @@ -40,6 +40,10 @@ $query->withStatuses($map['statuses']); } + if ($map['ownerPHIDs']) { + $query->withOwnerPHIDs($map['ownerPHIDs']); + } + return $query; } @@ -49,6 +53,11 @@ ->setLabel(pht('Statuses')) ->setKey('statuses') ->setOptions(DrydockLeaseStatus::getStatusMap()), + id(new PhabricatorPHIDsSearchField()) + ->setLabel(pht('Owners')) + ->setKey('ownerPHIDs') + ->setAliases(array('owner', 'owners', 'ownerPHID')) + ->setDescription(pht('Search leases by owner.')), ); } diff --git a/src/applications/drydock/storage/DrydockLease.php b/src/applications/drydock/storage/DrydockLease.php --- a/src/applications/drydock/storage/DrydockLease.php +++ b/src/applications/drydock/storage/DrydockLease.php @@ -1,7 +1,9 @@ array( 'columns' => array('status'), ), + 'key_owner' => array( + 'columns' => array('ownerPHID'), + ), ), ) + parent::getConfiguration(); } @@ -535,4 +540,66 @@ return pht('Leases inherit policies from the resources they lease.'); } + +/* -( PhabricatorConduitResultInterface )---------------------------------- */ + + + public function getFieldSpecificationsForConduit() { + return array( + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('resourcePHID') + ->setType('phid?') + ->setDescription(pht('PHID of the leased resource, if any.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('resourceType') + ->setType('string') + ->setDescription(pht('Type of resource being leased.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('until') + ->setType('int?') + ->setDescription(pht('Epoch at which this lease expires, if any.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('ownerPHID') + ->setType('phid?') + ->setDescription(pht('The PHID of the object that owns this lease.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('authorizingPHID') + ->setType('phid') + ->setDescription(pht( + 'The PHID of the object that authorized this lease.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('status') + ->setType('map') + ->setDescription(pht( + "The string constant and name of this lease's status.")), + ); + } + + public function getFieldValuesForConduit() { + $status = $this->getStatus(); + + $until = $this->getUntil(); + if ($until) { + $until = (int)$until; + } else { + $until = null; + } + + return array( + 'resourcePHID' => $this->getResourcePHID(), + 'resourceType' => $this->getResourceType(), + 'until' => $until, + 'ownerPHID' => $this->getOwnerPHID(), + 'authorizingPHID' => $this->getAuthorizingPHID(), + 'status' => array( + 'value' => $status, + 'name' => DrydockLeaseStatus::getNameForStatus($status), + ), + ); + } + + public function getConduitSearchAttachments() { + return array(); + } + }