@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+33 -2
+4
src/applications/harbormaster/artifact/HarbormasterArtifact.php
··· 16 16 abstract public function getArtifactParameterDescriptions(); 17 17 abstract public function willCreateArtifact(PhabricatorUser $actor); 18 18 19 + public function readArtifactHTTPParameter($key, $value) { 20 + return $value; 21 + } 22 + 19 23 public function validateArtifactData(array $artifact_data) { 20 24 $artifact_spec = $this->getArtifactParameterSpecification(); 21 25 PhutilTypeSpec::checkMap($artifact_data, $artifact_spec);
+10
src/applications/harbormaster/artifact/HarbormasterURIArtifact.php
··· 27 27 ); 28 28 } 29 29 30 + public function readArtifactHTTPParameter($key, $value) { 31 + // TODO: This is hacky and artifact parameters should be replaced more 32 + // broadly, likely with EditFields. See T11887. 33 + switch ($key) { 34 + case 'ui.external': 35 + return (bool)$value; 36 + } 37 + return $value; 38 + } 39 + 30 40 public function getArtifactParameterDescriptions() { 31 41 return array( 32 42 'uri' => pht('The URI to store.'),
+19 -2
src/applications/harbormaster/conduit/HarbormasterCreateArtifactConduitAPIMethod.php
··· 115 115 $build_target_phid)); 116 116 } 117 117 118 + $artifact_type = $request->getValue('artifactType'); 119 + 120 + // Cast "artifactData" parameters to acceptable types if this request 121 + // is submitting raw HTTP parameters. This is not ideal. See T11887 for 122 + // discussion. 123 + $artifact_data = $request->getValue('artifactData'); 124 + if (!$request->getIsStrictlyTyped()) { 125 + $impl = HarbormasterArtifact::getArtifactType($artifact_type); 126 + if ($impl) { 127 + foreach ($artifact_data as $key => $value) { 128 + $artifact_data[$key] = $impl->readArtifactHTTPParameter( 129 + $key, 130 + $value); 131 + } 132 + } 133 + } 134 + 118 135 $artifact = $build_target->createArtifact( 119 136 $viewer, 120 137 $request->getValue('artifactKey'), 121 - $request->getValue('artifactType'), 122 - $request->getValue('artifactData')); 138 + $artifact_type, 139 + $artifact_data); 123 140 124 141 return array( 125 142 'data' => $this->returnArtifactList(array($artifact)),