diff --git a/resources/sql/patches/draft-metadata.sql b/resources/sql/patches/draft-metadata.sql new file mode 100644 index 0000000000..25b12d0933 --- /dev/null +++ b/resources/sql/patches/draft-metadata.sql @@ -0,0 +1,4 @@ +ALTER TABLE `{$NAMESPACE}_draft`.`draft` +ADD `metadata` longtext NOT NULL DEFAULT '' AFTER `draft`; + +UPDATE `{$NAMESPACE}_draft`.`draft` SET `metadata` = '[]'; diff --git a/src/applications/differential/constants/DifferentialAction.php b/src/applications/differential/constants/DifferentialAction.php index 99c042047f..ddca9f26a7 100644 --- a/src/applications/differential/constants/DifferentialAction.php +++ b/src/applications/differential/constants/DifferentialAction.php @@ -85,4 +85,12 @@ final class DifferentialAction { } } + public static function allowReviewers($action) { + if ($action == DifferentialAction::ACTION_ADDREVIEWERS || + $action == DifferentialAction::ACTION_REQUEST) { + return true; + } + return false; + } + } diff --git a/src/applications/differential/controller/DifferentialCommentPreviewController.php b/src/applications/differential/controller/DifferentialCommentPreviewController.php index b02aeb8361..c6b7063f6e 100644 --- a/src/applications/differential/controller/DifferentialCommentPreviewController.php +++ b/src/applications/differential/controller/DifferentialCommentPreviewController.php @@ -42,18 +42,15 @@ final class DifferentialCommentPreviewController $handles = array($author_phid); - $reviewers = $request->getStr('reviewers'); - if (($action == DifferentialAction::ACTION_ADDREVIEWERS - || $action == DifferentialAction::ACTION_REQUEST) && $reviewers) { - $reviewers = explode(',', $reviewers); + $reviewers = $request->getStrList('reviewers'); + if (DifferentialAction::allowReviewers($action) && $reviewers) { $comment->setMetadata(array( DifferentialComment::METADATA_ADDED_REVIEWERS => $reviewers)); $handles = array_merge($handles, $reviewers); } - $ccs = $request->getStr('ccs'); + $ccs = $request->getStrList('ccs'); if ($action == DifferentialAction::ACTION_ADDCCS && $ccs) { - $ccs = explode(',', $ccs); $comment->setMetadata(array( DifferentialComment::METADATA_ADDED_CCS => $ccs)); $handles = array_merge($handles, $ccs); @@ -74,6 +71,11 @@ final class DifferentialCommentPreviewController ->setAuthorPHID($author_phid) ->setDraftKey('differential-comment-'.$this->id) ->setDraft($comment->getContent()) + ->setMetadata(array( + 'action' => $action, + 'reviewers' => $reviewers, + 'ccs' => $ccs, + )) ->replace(); return id(new AphrontAjaxResponse()) diff --git a/src/applications/differential/controller/DifferentialRevisionViewController.php b/src/applications/differential/controller/DifferentialRevisionViewController.php index 4bf00c909d..8fcaec8397 100644 --- a/src/applications/differential/controller/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/DifferentialRevisionViewController.php @@ -353,10 +353,17 @@ final class DifferentialRevisionViewController extends DifferentialController { 'authorPHID = %s AND draftKey = %s', $user->getPHID(), 'differential-comment-'.$revision->getID()); + + $reviewers = array(); + $ccs = array(); if ($draft) { - $draft = $draft->getDraft(); - } else { - $draft = null; + $reviewers = idx($draft->getMetadata(), 'reviewers', array()); + $ccs = idx($draft->getMetadata(), 'ccs', array()); + if ($reviewers || $ccs) { + $handles = $this->loadViewerHandles(array_merge($reviewers, $ccs)); + $reviewers = array_select_keys($handles, $reviewers); + $ccs = array_select_keys($handles, $ccs); + } } $comment_form = new DifferentialAddCommentView(); @@ -366,6 +373,8 @@ final class DifferentialRevisionViewController extends DifferentialController { $comment_form->setActionURI('/differential/comment/save/'); $comment_form->setUser($user); $comment_form->setDraft($draft); + $comment_form->setReviewers(mpull($reviewers, 'getFullName', 'getPHID')); + $comment_form->setCCs(mpull($ccs, 'getFullName', 'getPHID')); } $pane_id = celerity_generate_unique_node_id(); diff --git a/src/applications/differential/view/DifferentialAddCommentView.php b/src/applications/differential/view/DifferentialAddCommentView.php index 5725717774..21320f4afb 100644 --- a/src/applications/differential/view/DifferentialAddCommentView.php +++ b/src/applications/differential/view/DifferentialAddCommentView.php @@ -24,6 +24,8 @@ final class DifferentialAddCommentView extends AphrontView { private $user; private $draft; private $auxFields; + private $reviewers = array(); + private $ccs = array(); public function setRevision($revision) { $this->revision = $revision; @@ -51,11 +53,21 @@ final class DifferentialAddCommentView extends AphrontView { return $this; } - public function setDraft($draft) { + public function setDraft(PhabricatorDraft $draft = null) { $this->draft = $draft; return $this; } + public function setReviewers(array $names) { + $this->reviewers = $names; + return $this; + } + + public function setCCs(array $names) { + $this->ccs = $names; + return $this; + } + private function generateWarningView( $status, array $titles, @@ -79,6 +91,14 @@ final class DifferentialAddCommentView extends AphrontView { $revision = $this->revision; + $action = null; + if ($this->draft) { + $action = idx($this->draft->getMetadata(), 'action'); + } + + $enable_reviewers = DifferentialAction::allowReviewers($action); + $enable_ccs = ($action == DifferentialAction::ACTION_ADDCCS); + $form = new AphrontFormView(); $form ->setWorkflow(true) @@ -89,6 +109,7 @@ final class DifferentialAddCommentView extends AphrontView { id(new AphrontFormSelectControl()) ->setLabel('Action') ->setName('action') + ->setValue($action) ->setID('comment-action') ->setOptions($this->actions)) ->appendChild( @@ -96,7 +117,7 @@ final class DifferentialAddCommentView extends AphrontView { ->setLabel('Add Reviewers') ->setName('reviewers') ->setControlID('add-reviewers') - ->setControlStyle('display: none') + ->setControlStyle($enable_reviewers ? null : 'display: none') ->setID('add-reviewers-tokenizer') ->setDisableBehavior(true)) ->appendChild( @@ -104,7 +125,7 @@ final class DifferentialAddCommentView extends AphrontView { ->setLabel('Add CCs') ->setName('ccs') ->setControlID('add-ccs') - ->setControlStyle('display: none') + ->setControlStyle($enable_ccs ? null : 'display: none') ->setID('add-ccs-tokenizer') ->setDisableBehavior(true)) ->appendChild( @@ -113,7 +134,7 @@ final class DifferentialAddCommentView extends AphrontView { ->setID('comment-content') ->setLabel('Comment') ->setEnableDragAndDropFileUploads(true) - ->setValue($this->draft)) + ->setValue($this->draft->getDraft())) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue($is_serious ? 'Submit' : 'Clowncopterize')); @@ -125,6 +146,7 @@ final class DifferentialAddCommentView extends AphrontView { 'add-reviewers-tokenizer' => array( 'actions' => array('request_review' => 1, 'add_reviewers' => 1), 'src' => '/typeahead/common/users/', + 'value' => $this->reviewers, 'row' => 'add-reviewers', 'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'), 'placeholder' => 'Type a user name...', @@ -132,6 +154,7 @@ final class DifferentialAddCommentView extends AphrontView { 'add-ccs-tokenizer' => array( 'actions' => array('add_ccs' => 1), 'src' => '/typeahead/common/mailable/', + 'value' => $this->ccs, 'row' => 'add-ccs', 'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'), 'placeholder' => 'Type a user or mailing list...', diff --git a/src/applications/draft/storage/PhabricatorDraft.php b/src/applications/draft/storage/PhabricatorDraft.php index f1ec973622..102f8946d7 100644 --- a/src/applications/draft/storage/PhabricatorDraft.php +++ b/src/applications/draft/storage/PhabricatorDraft.php @@ -21,5 +21,14 @@ final class PhabricatorDraft extends PhabricatorDraftDAO { protected $authorPHID; protected $draftKey; protected $draft; + protected $metadata = array(); + + public function getConfiguration() { + return array( + self::CONFIG_SERIALIZATION => array( + 'metadata' => self::SERIALIZATION_JSON, + ), + ) + parent::getConfiguration(); + } } diff --git a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php index 46bb8a15c4..33cfa46ac4 100644 --- a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php +++ b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php @@ -984,6 +984,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList { 'type' => 'sql', 'name' => $this->getPatchPath('xhprof.sql'), ), + 'draft-metadata.sql' => array( + 'type' => 'sql', + 'name' => $this->getPatchPath('draft-metadata.sql'), + ), ); }