1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 20:40:56 +01:00

Allow "harbormaster.createartifact" to decode raw HTTP parameter types of artifact properties

Summary:
Ref T11887. This isn't a great fix but makes the method behave properly until I get around to a real fix.

In the longer term, I want to convert all of this pluggable Harbormaster/Drydock stuff (blueprints, artifacts, build plans) to use EditEngine + EditField instead of the weird mishmash of older/custom stuff it currently uses. However, this is a more involved project to execute and I'd like to be in that area of the codebase first so it gets adequate testing.

Until that happens, just put a reasonble-ish mechanism in place to let artifacts correct inbound types. This is the only artifact type and only parameter which needs casting.

Test Plan:
  - Made a `curl` call to `harbormaster.createartifact` to create a URI artifact with `?...&ui.external=1`.
  - Before patch: type error on `ui.external` not being a boolean.
  - After patch: artifact created successfully.

Reviewers: chad

Reviewed By: chad

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T11887

Differential Revision: https://secure.phabricator.com/D16887
This commit is contained in:
epriestley 2016-11-17 05:41:13 -08:00
parent b02f64f6ee
commit b4faf2e63e
3 changed files with 33 additions and 2 deletions

View file

@ -16,6 +16,10 @@ abstract class HarbormasterArtifact extends Phobject {
abstract public function getArtifactParameterDescriptions();
abstract public function willCreateArtifact(PhabricatorUser $actor);
public function readArtifactHTTPParameter($key, $value) {
return $value;
}
public function validateArtifactData(array $artifact_data) {
$artifact_spec = $this->getArtifactParameterSpecification();
PhutilTypeSpec::checkMap($artifact_data, $artifact_spec);

View file

@ -27,6 +27,16 @@ final class HarbormasterURIArtifact extends HarbormasterArtifact {
);
}
public function readArtifactHTTPParameter($key, $value) {
// TODO: This is hacky and artifact parameters should be replaced more
// broadly, likely with EditFields. See T11887.
switch ($key) {
case 'ui.external':
return (bool)$value;
}
return $value;
}
public function getArtifactParameterDescriptions() {
return array(
'uri' => pht('The URI to store.'),

View file

@ -115,11 +115,28 @@ final class HarbormasterCreateArtifactConduitAPIMethod
$build_target_phid));
}
$artifact_type = $request->getValue('artifactType');
// Cast "artifactData" parameters to acceptable types if this request
// is submitting raw HTTP parameters. This is not ideal. See T11887 for
// discussion.
$artifact_data = $request->getValue('artifactData');
if (!$request->getIsStrictlyTyped()) {
$impl = HarbormasterArtifact::getArtifactType($artifact_type);
if ($impl) {
foreach ($artifact_data as $key => $value) {
$artifact_data[$key] = $impl->readArtifactHTTPParameter(
$key,
$value);
}
}
}
$artifact = $build_target->createArtifact(
$viewer,
$request->getValue('artifactKey'),
$request->getValue('artifactType'),
$request->getValue('artifactData'));
$artifact_type,
$artifact_data);
return array(
'data' => $this->returnArtifactList(array($artifact)),