File tree Expand file tree Collapse file tree 6 files changed +85
-1
lines changed Expand file tree Collapse file tree 6 files changed +85
-1
lines changed Original file line number Diff line number Diff line change 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',
41844185 'ConduitStringParameterType' => 'ConduitParameterType',
41854186 'ConduitTokenGarbageCollector' => 'PhabricatorGarbageCollector',
41864187 'ConduitUserListParameterType' => 'ConduitListParameterType',
4188+ 'ConduitUserParameterType' => 'ConduitParameterType',
41874189 'ConduitWildParameterType' => 'ConduitListParameterType',
41884190 'ConpherenceColumnViewController' => 'ConpherenceController',
41894191 'ConpherenceConduitAPIMethod' => 'ConduitAPIMethod',
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments