Page MenuHomePhabricator

D14992.diff
No OneTemporary

D14992.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -249,6 +249,7 @@
'ConduitStringParameterType' => 'applications/conduit/parametertype/ConduitStringParameterType.php',
'ConduitTokenGarbageCollector' => 'applications/conduit/garbagecollector/ConduitTokenGarbageCollector.php',
'ConduitUserListParameterType' => 'applications/conduit/parametertype/ConduitUserListParameterType.php',
+ 'ConduitUserParameterType' => 'applications/conduit/parametertype/ConduitUserParameterType.php',
'ConduitWildParameterType' => 'applications/conduit/parametertype/ConduitWildParameterType.php',
'ConpherenceColumnViewController' => 'applications/conpherence/controller/ConpherenceColumnViewController.php',
'ConpherenceConduitAPIMethod' => 'applications/conpherence/conduit/ConpherenceConduitAPIMethod.php',
@@ -4184,6 +4185,7 @@
'ConduitStringParameterType' => 'ConduitParameterType',
'ConduitTokenGarbageCollector' => 'PhabricatorGarbageCollector',
'ConduitUserListParameterType' => 'ConduitListParameterType',
+ 'ConduitUserParameterType' => 'ConduitParameterType',
'ConduitWildParameterType' => 'ConduitListParameterType',
'ConpherenceColumnViewController' => 'ConpherenceController',
'ConpherenceConduitAPIMethod' => 'ConduitAPIMethod',
diff --git a/src/applications/conduit/parametertype/ConduitUserParameterType.php b/src/applications/conduit/parametertype/ConduitUserParameterType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/conduit/parametertype/ConduitUserParameterType.php
@@ -0,0 +1,47 @@
+<?php
+
+final class ConduitUserParameterType
+ extends ConduitParameterType {
+
+ protected function getParameterValue(array $request, $key) {
+ $value = parent::getParameterValue($request, $key);
+
+ if ($value === null) {
+ return null;
+ }
+
+ if (!is_string($value)) {
+ $this->raiseValidationException(
+ $request,
+ $key,
+ pht('Expected PHID or null, got something else.'));
+ }
+
+ $user_phids = id(new PhabricatorUserPHIDResolver())
+ ->setViewer($this->getViewer())
+ ->resolvePHIDs(array($value));
+
+ return nonempty(head($user_phids), null);
+ }
+
+ protected function getParameterTypeName() {
+ return 'phid|string|null';
+ }
+
+ protected function getParameterFormatDescriptions() {
+ return array(
+ pht('User PHID.'),
+ pht('Username.'),
+ pht('Literal null.'),
+ );
+ }
+
+ protected function getParameterExamples() {
+ return array(
+ '"PHID-USER-1111"',
+ '"alincoln"',
+ 'null',
+ );
+ }
+
+}
diff --git a/src/applications/maniphest/editor/ManiphestTransactionEditor.php b/src/applications/maniphest/editor/ManiphestTransactionEditor.php
--- a/src/applications/maniphest/editor/ManiphestTransactionEditor.php
+++ b/src/applications/maniphest/editor/ManiphestTransactionEditor.php
@@ -829,6 +829,33 @@
last($with_effect));
}
break;
+ case ManiphestTransaction::TYPE_OWNER:
+ foreach ($xactions as $xaction) {
+ $old = $xaction->getOldValue();
+ $new = $xaction->getNewValue();
+ if (!strlen($new)) {
+ continue;
+ }
+
+ if ($new === $old) {
+ continue;
+ }
+
+ $assignee_list = id(new PhabricatorPeopleQuery())
+ ->setViewer($this->getActor())
+ ->withPHIDs(array($new))
+ ->execute();
+ if (!$assignee_list) {
+ $errors[] = new PhabricatorApplicationTransactionValidationError(
+ $type,
+ pht('Invalid'),
+ pht(
+ 'User "%s" is not a valid user.',
+ $new),
+ $xaction);
+ }
+ }
+ break;
}
return $errors;
diff --git a/src/applications/transactions/editengine/PhabricatorEditEngine.php b/src/applications/transactions/editengine/PhabricatorEditEngine.php
--- a/src/applications/transactions/editengine/PhabricatorEditEngine.php
+++ b/src/applications/transactions/editengine/PhabricatorEditEngine.php
@@ -1632,6 +1632,7 @@
array $types,
PhabricatorApplicationTransaction $template) {
+ $viewer = $request->getUser();
$transactions_key = 'transactions';
$xactions = $request->getValue($transactions_key);
@@ -1688,6 +1689,8 @@
// use usernames in list<user> fields, for example.
$parameter_type = $type->getConduitParameterType();
+ $parameter_type->setViewer($viewer);
+
try {
$xaction['value'] = $parameter_type->getValue($xaction, 'value');
} catch (Exception $ex) {
diff --git a/src/applications/transactions/editfield/PhabricatorPHIDListEditField.php b/src/applications/transactions/editfield/PhabricatorPHIDListEditField.php
--- a/src/applications/transactions/editfield/PhabricatorPHIDListEditField.php
+++ b/src/applications/transactions/editfield/PhabricatorPHIDListEditField.php
@@ -100,6 +100,7 @@
$type = new PhabricatorDatasourceEditType();
$type->setIsSingleValue($this->getIsSingleValue());
+ $type->setConduitParameterType($this->newConduitParameterType());
return $type;
}
diff --git a/src/applications/transactions/editfield/PhabricatorUsersEditField.php b/src/applications/transactions/editfield/PhabricatorUsersEditField.php
--- a/src/applications/transactions/editfield/PhabricatorUsersEditField.php
+++ b/src/applications/transactions/editfield/PhabricatorUsersEditField.php
@@ -12,7 +12,11 @@
}
protected function newConduitParameterType() {
- return new ConduitUserListParameterType();
+ if ($this->getIsSingleValue()) {
+ return new ConduitUserParameterType();
+ } else {
+ return new ConduitUserListParameterType();
+ }
}
}

File Metadata

Mime Type
text/plain
Expires
Tue, Mar 18, 2:13 PM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7452957
Default Alt Text
D14992.diff (5 KB)

Event Timeline