Skip to content

Commit add8333

Browse files
author
epriestley
committed
Improve behavior of "owner" transaction in "maniphest.edit" endpoint
Summary: Fixes T10117. - I accidentally broke setting `null` to unassign tasks at some point when I added richer validation. - Raise a better error if the user passes junk. Test Plan: - Unassigned a task via API and web UI. - Reassigned a task via API and web UI. - Tried to do an invalid assign via API, got a sensible error. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10117 Differential Revision: https://secure.phabricator.com/D14992
1 parent b848ab8 commit add8333

File tree

6 files changed

+85
-1
lines changed

6 files changed

+85
-1
lines changed

src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@
249249
'ConduitStringParameterType' => 'applications/conduit/parametertype/ConduitStringParameterType.php',
250250
'ConduitTokenGarbageCollector' => 'applications/conduit/garbagecollector/ConduitTokenGarbageCollector.php',
251251
'ConduitUserListParameterType' => 'applications/conduit/parametertype/ConduitUserListParameterType.php',
252+
'ConduitUserParameterType' => 'applications/conduit/parametertype/ConduitUserParameterType.php',
252253
'ConduitWildParameterType' => 'applications/conduit/parametertype/ConduitWildParameterType.php',
253254
'ConpherenceColumnViewController' => 'applications/conpherence/controller/ConpherenceColumnViewController.php',
254255
'ConpherenceConduitAPIMethod' => 'applications/conpherence/conduit/ConpherenceConduitAPIMethod.php',
@@ -4184,6 +4185,7 @@
41844185
'ConduitStringParameterType' => 'ConduitParameterType',
41854186
'ConduitTokenGarbageCollector' => 'PhabricatorGarbageCollector',
41864187
'ConduitUserListParameterType' => 'ConduitListParameterType',
4188+
'ConduitUserParameterType' => 'ConduitParameterType',
41874189
'ConduitWildParameterType' => 'ConduitListParameterType',
41884190
'ConpherenceColumnViewController' => 'ConpherenceController',
41894191
'ConpherenceConduitAPIMethod' => 'ConduitAPIMethod',
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
final class ConduitUserParameterType
4+
extends ConduitParameterType {
5+
6+
protected function getParameterValue(array $request, $key) {
7+
$value = parent::getParameterValue($request, $key);
8+
9+
if ($value === null) {
10+
return null;
11+
}
12+
13+
if (!is_string($value)) {
14+
$this->raiseValidationException(
15+
$request,
16+
$key,
17+
pht('Expected PHID or null, got something else.'));
18+
}
19+
20+
$user_phids = id(new PhabricatorUserPHIDResolver())
21+
->setViewer($this->getViewer())
22+
->resolvePHIDs(array($value));
23+
24+
return nonempty(head($user_phids), null);
25+
}
26+
27+
protected function getParameterTypeName() {
28+
return 'phid|string|null';
29+
}
30+
31+
protected function getParameterFormatDescriptions() {
32+
return array(
33+
pht('User PHID.'),
34+
pht('Username.'),
35+
pht('Literal null.'),
36+
);
37+
}
38+
39+
protected function getParameterExamples() {
40+
return array(
41+
'"PHID-USER-1111"',
42+
'"alincoln"',
43+
'null',
44+
);
45+
}
46+
47+
}

src/applications/maniphest/editor/ManiphestTransactionEditor.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,33 @@ protected function validateTransaction(
829829
last($with_effect));
830830
}
831831
break;
832+
case ManiphestTransaction::TYPE_OWNER:
833+
foreach ($xactions as $xaction) {
834+
$old = $xaction->getOldValue();
835+
$new = $xaction->getNewValue();
836+
if (!strlen($new)) {
837+
continue;
838+
}
839+
840+
if ($new === $old) {
841+
continue;
842+
}
843+
844+
$assignee_list = id(new PhabricatorPeopleQuery())
845+
->setViewer($this->getActor())
846+
->withPHIDs(array($new))
847+
->execute();
848+
if (!$assignee_list) {
849+
$errors[] = new PhabricatorApplicationTransactionValidationError(
850+
$type,
851+
pht('Invalid'),
852+
pht(
853+
'User "%s" is not a valid user.',
854+
$new),
855+
$xaction);
856+
}
857+
}
858+
break;
832859
}
833860

834861
return $errors;

src/applications/transactions/editengine/PhabricatorEditEngine.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,7 @@ private function getConduitTransactions(
16321632
array $types,
16331633
PhabricatorApplicationTransaction $template) {
16341634

1635+
$viewer = $request->getUser();
16351636
$transactions_key = 'transactions';
16361637

16371638
$xactions = $request->getValue($transactions_key);
@@ -1688,6 +1689,8 @@ private function getConduitTransactions(
16881689
// use usernames in list<user> fields, for example.
16891690
$parameter_type = $type->getConduitParameterType();
16901691

1692+
$parameter_type->setViewer($viewer);
1693+
16911694
try {
16921695
$xaction['value'] = $parameter_type->getValue($xaction, 'value');
16931696
} catch (Exception $ex) {

src/applications/transactions/editfield/PhabricatorPHIDListEditField.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ protected function newEditType() {
100100

101101
$type = new PhabricatorDatasourceEditType();
102102
$type->setIsSingleValue($this->getIsSingleValue());
103+
$type->setConduitParameterType($this->newConduitParameterType());
103104
return $type;
104105
}
105106

src/applications/transactions/editfield/PhabricatorUsersEditField.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ protected function newHTTPParameterType() {
1212
}
1313

1414
protected function newConduitParameterType() {
15-
return new ConduitUserListParameterType();
15+
if ($this->getIsSingleValue()) {
16+
return new ConduitUserParameterType();
17+
} else {
18+
return new ConduitUserListParameterType();
19+
}
1620
}
1721

1822
}

0 commit comments

Comments
 (0)