diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 8bcf3d6120..a472b66411 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1146,6 +1146,7 @@ phutil_register_library_map(array( '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 @@ phutil_register_library_map(array( 'DrydockLease' => array( 'DrydockDAO', 'PhabricatorPolicyInterface', + 'PhabricatorConduitResultInterface', ), 'DrydockLeaseAcquiredLogType' => 'DrydockLogType', 'DrydockLeaseActivatedLogType' => 'DrydockLogType', @@ -6552,6 +6554,7 @@ phutil_register_library_map(array( '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 index 0000000000..6d75ed1718 --- /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 @@ final class DrydockLeaseQuery extends DrydockQuery { $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 index 3b551023b2..39c91e66bf 100644 --- a/src/applications/drydock/query/DrydockLeaseSearchEngine.php +++ b/src/applications/drydock/query/DrydockLeaseSearchEngine.php @@ -40,6 +40,10 @@ final class DrydockLeaseSearchEngine $query->withStatuses($map['statuses']); } + if ($map['ownerPHIDs']) { + $query->withOwnerPHIDs($map['ownerPHIDs']); + } + return $query; } @@ -49,6 +53,11 @@ final class DrydockLeaseSearchEngine ->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 index 866bb21b37..2b77146495 100644 --- 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 @@ final class DrydockLease extends DrydockDAO 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(); + } + }