mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-18 18:51:12 +01:00
Expose Drydock authorizations via Conduit
Summary: `DrydockAuthorizationSearchEngine` was being used solely to display authorizations for a specific blueprint from the web UI and consequently expected that callers set a specific blueprint before performing a query. Here we check to see if a blueprint has been set in cases where the engine could be operating from either Conduit or the web. Ref T11694 Test Plan: - called the API method from the console - approved an authorization - followed the "view all" link from a blueprint page Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley Maniphest Tasks: T11694 Differential Revision: https://secure.phabricator.com/D16592
This commit is contained in:
parent
eec2d953e0
commit
fa90f8bef4
4 changed files with 106 additions and 3 deletions
|
@ -919,6 +919,7 @@ phutil_register_library_map(array(
|
|||
'DrydockAuthorizationListView' => 'applications/drydock/view/DrydockAuthorizationListView.php',
|
||||
'DrydockAuthorizationPHIDType' => 'applications/drydock/phid/DrydockAuthorizationPHIDType.php',
|
||||
'DrydockAuthorizationQuery' => 'applications/drydock/query/DrydockAuthorizationQuery.php',
|
||||
'DrydockAuthorizationSearchConduitAPIMethod' => 'applications/drydock/conduit/DrydockAuthorizationSearchConduitAPIMethod.php',
|
||||
'DrydockAuthorizationSearchEngine' => 'applications/drydock/query/DrydockAuthorizationSearchEngine.php',
|
||||
'DrydockAuthorizationViewController' => 'applications/drydock/controller/DrydockAuthorizationViewController.php',
|
||||
'DrydockBlueprint' => 'applications/drydock/storage/DrydockBlueprint.php',
|
||||
|
@ -5468,12 +5469,14 @@ phutil_register_library_map(array(
|
|||
'DrydockAuthorization' => array(
|
||||
'DrydockDAO',
|
||||
'PhabricatorPolicyInterface',
|
||||
'PhabricatorConduitResultInterface',
|
||||
),
|
||||
'DrydockAuthorizationAuthorizeController' => 'DrydockController',
|
||||
'DrydockAuthorizationListController' => 'DrydockController',
|
||||
'DrydockAuthorizationListView' => 'AphrontView',
|
||||
'DrydockAuthorizationPHIDType' => 'PhabricatorPHIDType',
|
||||
'DrydockAuthorizationQuery' => 'DrydockQuery',
|
||||
'DrydockAuthorizationSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
|
||||
'DrydockAuthorizationSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'DrydockAuthorizationViewController' => 'DrydockController',
|
||||
'DrydockBlueprint' => array(
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
final class DrydockAuthorizationSearchConduitAPIMethod
|
||||
extends PhabricatorSearchEngineAPIMethod {
|
||||
|
||||
public function getAPIMethodName() {
|
||||
return 'drydock.authorization.search';
|
||||
}
|
||||
|
||||
public function newSearchEngine() {
|
||||
return new DrydockAuthorizationSearchEngine();
|
||||
}
|
||||
|
||||
public function getMethodSummary() {
|
||||
return pht('Retrieve information about Drydock authorizations.');
|
||||
}
|
||||
|
||||
}
|
|
@ -30,7 +30,9 @@ final class DrydockAuthorizationSearchEngine
|
|||
$query = new DrydockAuthorizationQuery();
|
||||
|
||||
$blueprint = $this->getBlueprint();
|
||||
if ($blueprint) {
|
||||
$query->withBlueprintPHIDs(array($blueprint->getPHID()));
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
@ -38,15 +40,46 @@ final class DrydockAuthorizationSearchEngine
|
|||
protected function buildQueryFromParameters(array $map) {
|
||||
$query = $this->newQuery();
|
||||
|
||||
if ($map['blueprintPHIDs']) {
|
||||
$query->withBlueprintPHIDs($map['blueprintPHIDs']);
|
||||
}
|
||||
|
||||
if ($map['objectPHIDs']) {
|
||||
$query->withObjectPHIDs($map['objectPHIDs']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function buildCustomSearchFields() {
|
||||
return array();
|
||||
return array(
|
||||
id(new PhabricatorSearchDatasourceField())
|
||||
->setLabel(pht('Blueprints'))
|
||||
->setKey('blueprintPHIDs')
|
||||
->setConduitParameterType(new ConduitPHIDListParameterType())
|
||||
->setDescription(pht('Search authorizations for specific blueprints.'))
|
||||
->setAliases(array('blueprint', 'blueprints'))
|
||||
->setDatasource(new DrydockBlueprintDatasource()),
|
||||
id(new PhabricatorPHIDsSearchField())
|
||||
->setLabel(pht('Objects'))
|
||||
->setKey('objectPHIDs')
|
||||
->setDescription(pht('Search authorizations from specific objects.'))
|
||||
->setAliases(array('object', 'objects')),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getHiddenFields() {
|
||||
return array(
|
||||
'blueprintPHIDs',
|
||||
'objectPHIDs',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
$blueprint = $this->getBlueprint();
|
||||
if (!$blueprint) {
|
||||
throw new PhutilInvalidStateException('setBlueprint');
|
||||
}
|
||||
$id = $blueprint->getID();
|
||||
return "/drydock/blueprint/{$id}/authorizations/".$path;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
final class DrydockAuthorization extends DrydockDAO
|
||||
implements
|
||||
PhabricatorPolicyInterface {
|
||||
PhabricatorPolicyInterface,
|
||||
PhabricatorConduitResultInterface {
|
||||
|
||||
const OBJECTAUTH_ACTIVE = 'active';
|
||||
const OBJECTAUTH_INACTIVE = 'inactive';
|
||||
|
@ -204,4 +205,52 @@ final class DrydockAuthorization extends DrydockDAO
|
|||
}
|
||||
|
||||
|
||||
/* -( PhabricatorConduitResultInterface )---------------------------------- */
|
||||
|
||||
|
||||
public function getFieldSpecificationsForConduit() {
|
||||
return array(
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('blueprintPHID')
|
||||
->setType('phid')
|
||||
->setDescription(pht(
|
||||
'PHID of the blueprint this request was made for.')),
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('blueprintAuthorizationState')
|
||||
->setType('map<string, wild>')
|
||||
->setDescription(pht('Authorization state of this request.')),
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('objectPHID')
|
||||
->setType('phid')
|
||||
->setDescription(pht(
|
||||
'PHID of the object which requested authorization.')),
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('objectAuthorizationState')
|
||||
->setType('map<string, wild>')
|
||||
->setDescription(pht('Authorization state of the requesting object.')),
|
||||
);
|
||||
}
|
||||
|
||||
public function getFieldValuesForConduit() {
|
||||
$blueprint_state = $this->getBlueprintAuthorizationState();
|
||||
$object_state = $this->getObjectAuthorizationState();
|
||||
return array(
|
||||
'blueprintPHID' => $this->getBlueprintPHID(),
|
||||
'blueprintAuthorizationState' => array(
|
||||
'value' => $blueprint_state,
|
||||
'name' => self::getBlueprintStateName($blueprint_state),
|
||||
),
|
||||
'objectPHID' => $this->getObjectPHID(),
|
||||
'objectAuthorizationState' => array(
|
||||
'value' => $object_state,
|
||||
'name' => self::getObjectStateName($object_state),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function getConduitSearchAttachments() {
|
||||
return array(
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue