From b3cf00333cfa6cfaa815282b9c8916235eb63b91 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 4 Dec 2015 07:21:50 -0800 Subject: [PATCH] Limit number of EditEngine tokenizer tokens in "Owner" field UI to 1 Summary: Ref T9132. Only allow a task to have a single owner in the UI. In Conduit, make this field appear and behave as "phid" instead of "list". Test Plan: Edited a task with new fancy form, got limited to one owner. Assigned/unassigned. Used Conduit to assign/unassign. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9132 Differential Revision: https://secure.phabricator.com/D14666 --- .../maniphest/editor/ManiphestEditEngine.php | 14 ++------ .../PhabricatorPHIDListEditField.php | 32 ++++++++++++++++++- .../PhabricatorTokenizerEditField.php | 4 +++ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/applications/maniphest/editor/ManiphestEditEngine.php b/src/applications/maniphest/editor/ManiphestEditEngine.php index ada1eef8d1..9f78e0c4b8 100644 --- a/src/applications/maniphest/editor/ManiphestEditEngine.php +++ b/src/applications/maniphest/editor/ManiphestEditEngine.php @@ -58,17 +58,9 @@ final class ManiphestEditEngine unset($status_map[$dup_status]); } - $owner_phid = $object->getOwnerPHID(); - if ($owner_phid) { - $owner_value = array($owner_phid); - } else { - $owner_value = array(); - } - $priority_map = ManiphestTaskPriority::getTaskPriorityMap(); // TODO: Restore these or toss them: - // - Require a single owner. // - Default owner to viewer. // - Don't show "change status" for closed tasks. // - Don't show "change owner" for closed tasks. @@ -92,12 +84,12 @@ final class ManiphestEditEngine ->setValue($object->getStatus()) ->setOptions($status_map), id(new PhabricatorUsersEditField()) - ->setKey('assigned') - ->setAliases(array('assign', 'assignee')) + ->setKey('owner') + ->setAliases(array('ownerPHID', 'assign', 'assigned')) ->setLabel(pht('Assigned To')) ->setDescription(pht('User who is responsible for the task.')) ->setTransactionType(ManiphestTransaction::TYPE_OWNER) - ->setValue($owner_value), + ->setSingleValue($object->getOwnerPHID()), id(new PhabricatorSelectEditField()) ->setKey('priority') ->setLabel(pht('Priority')) diff --git a/src/applications/transactions/editfield/PhabricatorPHIDListEditField.php b/src/applications/transactions/editfield/PhabricatorPHIDListEditField.php index b1ce19a1e0..85e0dc8fb1 100644 --- a/src/applications/transactions/editfield/PhabricatorPHIDListEditField.php +++ b/src/applications/transactions/editfield/PhabricatorPHIDListEditField.php @@ -5,6 +5,7 @@ abstract class PhabricatorPHIDListEditField private $useEdgeTransactions; private $transactionDescriptions = array(); + private $isSingleValue; public function setUseEdgeTransactions($use_edge_transactions) { $this->useEdgeTransactions = $use_edge_transactions; @@ -24,6 +25,21 @@ abstract class PhabricatorPHIDListEditField return $this; } + public function setSingleValue($value) { + if ($value === null) { + $value = array(); + } else { + $value = array($value); + } + + $this->isSingleValue = true; + return $this->setValue($value); + } + + public function getIsSingleValue() { + return $this->isSingleValue; + } + protected function newHTTPParameterType() { return new AphrontPHIDListHTTPParameterType(); } @@ -31,6 +47,14 @@ abstract class PhabricatorPHIDListEditField public function getValueForTransaction() { $new = parent::getValueForTransaction(); + if ($this->getIsSingleValue()) { + if ($new) { + return head($new); + } else { + return null; + } + } + if (!$this->getUseEdgeTransactions()) { return $new; } @@ -68,7 +92,13 @@ abstract class PhabricatorPHIDListEditField return new PhabricatorEdgeEditType(); } - return parent::newEditType(); + $type = parent::newEditType(); + + if ($this->getIsSingleValue()) { + $type->setValueType('phid'); + } + + return $type; } public function getConduitEditTypes() { diff --git a/src/applications/transactions/editfield/PhabricatorTokenizerEditField.php b/src/applications/transactions/editfield/PhabricatorTokenizerEditField.php index 3fe45fc5b6..0ac5ba5083 100644 --- a/src/applications/transactions/editfield/PhabricatorTokenizerEditField.php +++ b/src/applications/transactions/editfield/PhabricatorTokenizerEditField.php @@ -25,6 +25,10 @@ abstract class PhabricatorTokenizerEditField $control->setOriginalValue($initial_value); } + if ($this->getIsSingleValue()) { + $control->setLimit(1); + } + return $control; }