1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

Add inline comment support to "Pro" comment save controller

Summary: Ref T2222. Makes the "pro" controller work with inlines.

Test Plan: Added a bunch of inlines and saved them with the "pro" controller.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2222

Differential Revision: https://secure.phabricator.com/D8306
This commit is contained in:
epriestley 2014-02-24 15:57:35 -08:00
parent c7d208fda1
commit d48a88d4cd
4 changed files with 91 additions and 14 deletions

View file

@ -86,8 +86,30 @@ final class DifferentialCommentSaveControllerPro
->setNewValue(array('+' => $reviewer_edges)); ->setNewValue(array('+' => $reviewer_edges));
} }
$inline_phids = $this->loadUnsubmittedInlinePHIDs($revision);
if ($inline_phids) {
$inlines = id(new PhabricatorApplicationTransactionCommentQuery())
->setTemplate(new DifferentialTransactionComment())
->setViewer($viewer)
->withPHIDs($inline_phids)
->execute();
} else {
$inlines = null;
}
foreach ($inlines as $inline) {
$xactions[] = id(new DifferentialTransaction())
->setTransactionType($type_inline)
->attachComment($inline);
}
// NOTE: If there are no other transactions, add an empty comment
// transaction so that we'll raise a more user-friendly error message,
// to the effect of "you can not post an empty comment".
$no_xactions = !$xactions;
$comment = $request->getStr('comment'); $comment = $request->getStr('comment');
if (strlen($comment)) { if (strlen($comment) || $no_xactions) {
$xactions[] = id(new DifferentialTransaction()) $xactions[] = id(new DifferentialTransaction())
->setTransactionType($type_comment) ->setTransactionType($type_comment)
->attachComment( ->attachComment(
@ -96,7 +118,6 @@ final class DifferentialCommentSaveControllerPro
->setContent($comment)); ->setContent($comment));
} }
// TODO: Inlines!
$editor = id(new DifferentialTransactionEditor()) $editor = id(new DifferentialTransactionEditor())
->setActor($viewer) ->setActor($viewer)
@ -114,8 +135,6 @@ final class DifferentialCommentSaveControllerPro
->setException($ex); ->setException($ex);
} }
// TODO: Diff change detection?
$user = $request->getUser(); $user = $request->getUser();
$draft = id(new PhabricatorDraft())->loadOneWhere( $draft = id(new PhabricatorDraft())->loadOneWhere(
'authorPHID = %s AND draftKey = %s', 'authorPHID = %s AND draftKey = %s',
@ -130,4 +149,30 @@ final class DifferentialCommentSaveControllerPro
->setURI('/D'.$revision->getID()); ->setURI('/D'.$revision->getID());
} }
private function loadUnsubmittedInlinePHIDs(DifferentialRevision $revision) {
$viewer = $this->getRequest()->getUser();
// TODO: This probably needs to move somewhere more central as we move
// away from DifferentialInlineCommentQuery, but
// PhabricatorApplicationTransactionCommentQuery is currently `final` and
// I'm not yet decided on how to approach that. For now, just get the PHIDs
// and then execute a PHID-based query through the standard stack.
$table = new DifferentialTransactionComment();
$conn_r = $table->establishConnection('r');
$phids = queryfx_all(
$conn_r,
'SELECT phid FROM %T
WHERE revisionPHID = %s
AND authorPHID = %s
AND transactionPHID IS NULL',
$table->getTableName(),
$revision->getPHID(),
$viewer->getPHID());
return ipull($phids, 'phid');
}
} }

View file

@ -12,10 +12,10 @@ final class DifferentialTransactionEditor
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
$types[] = DifferentialTransaction::TYPE_ACTION; $types[] = DifferentialTransaction::TYPE_ACTION;
$types[] = DifferentialTransaction::TYPE_INLINE;
/* /*
$types[] = DifferentialTransaction::TYPE_INLINE;
$types[] = DifferentialTransaction::TYPE_UPDATE; $types[] = DifferentialTransaction::TYPE_UPDATE;
*/ */
@ -33,6 +33,8 @@ final class DifferentialTransactionEditor
return $object->getEditPolicy(); return $object->getEditPolicy();
case DifferentialTransaction::TYPE_ACTION: case DifferentialTransaction::TYPE_ACTION:
return null; return null;
case DifferentialTransaction::TYPE_INLINE:
return null;
} }
return parent::getCustomTransactionOldValue($object, $xaction); return parent::getCustomTransactionOldValue($object, $xaction);
@ -47,6 +49,8 @@ final class DifferentialTransactionEditor
case PhabricatorTransactions::TYPE_EDIT_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY:
case DifferentialTransaction::TYPE_ACTION: case DifferentialTransaction::TYPE_ACTION:
return $xaction->getNewValue(); return $xaction->getNewValue();
case DifferentialTransaction::TYPE_INLINE:
return null;
} }
return parent::getCustomTransactionNewValue($object, $xaction); return parent::getCustomTransactionNewValue($object, $xaction);
@ -57,6 +61,8 @@ final class DifferentialTransactionEditor
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case DifferentialTransaction::TYPE_INLINE:
return $xaction->hasComment();
} }
return parent::transactionHasEffect($object, $xaction); return parent::transactionHasEffect($object, $xaction);
@ -76,6 +82,8 @@ final class DifferentialTransactionEditor
return; return;
case PhabricatorTransactions::TYPE_SUBSCRIBERS: case PhabricatorTransactions::TYPE_SUBSCRIBERS:
case PhabricatorTransactions::TYPE_COMMENT: case PhabricatorTransactions::TYPE_COMMENT:
case DifferentialTransaction::TYPE_INLINE:
return;
case PhabricatorTransactions::TYPE_EDGE: case PhabricatorTransactions::TYPE_EDGE:
// TODO: When removing reviewers, we may be able to move the revision // TODO: When removing reviewers, we may be able to move the revision
// to "Accepted". // to "Accepted".
@ -101,6 +109,7 @@ final class DifferentialTransactionEditor
case PhabricatorTransactions::TYPE_EDGE: case PhabricatorTransactions::TYPE_EDGE:
case PhabricatorTransactions::TYPE_COMMENT: case PhabricatorTransactions::TYPE_COMMENT:
case DifferentialTransaction::TYPE_ACTION: case DifferentialTransaction::TYPE_ACTION:
case DifferentialTransaction::TYPE_INLINE:
return; return;
} }
@ -120,6 +129,23 @@ final class DifferentialTransactionEditor
return $errors; return $errors;
} }
protected function sortTransactions(array $xactions) {
$head = array();
$tail = array();
// Move bare comments to the end, so the actions precede them.
foreach ($xactions as $xaction) {
$type = $xaction->getTransactionType();
if ($type == DifferentialTransaction::TYPE_INLINE) {
$tail[] = $xaction;
} else {
$head[] = $xaction;
}
}
return array_values(array_merge($head, $tail));
}
protected function requireCapabilities( protected function requireCapabilities(
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {

View file

@ -1335,12 +1335,7 @@ abstract class PhabricatorApplicationTransactionEditor
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) { return $xaction->isCommentTransaction();
case PhabricatorTransactions::TYPE_COMMENT:
return true;
default:
return false;
}
} }

View file

@ -528,6 +528,19 @@ abstract class PhabricatorApplicationTransaction
return 1.0; return 1.0;
} }
public function isCommentTransaction() {
if ($this->hasComment()) {
return true;
}
switch ($this->getTransactionType()) {
case PhabricatorTransactions::TYPE_COMMENT:
return true;
}
return false;
}
public function getActionName() { public function getActionName() {
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case PhabricatorTransactions::TYPE_COMMENT: case PhabricatorTransactions::TYPE_COMMENT:
@ -605,8 +618,6 @@ abstract class PhabricatorApplicationTransaction
* @return bool True to display in a group with the other transactions. * @return bool True to display in a group with the other transactions.
*/ */
public function shouldDisplayGroupWith(array $group) { public function shouldDisplayGroupWith(array $group) {
$type_comment = PhabricatorTransactions::TYPE_COMMENT;
$this_source = null; $this_source = null;
if ($this->getContentSource()) { if ($this->getContentSource()) {
$this_source = $this->getContentSource()->getSource(); $this_source = $this->getContentSource()->getSource();
@ -624,7 +635,7 @@ abstract class PhabricatorApplicationTransaction
} }
// Don't group anything into a group which already has a comment. // Don't group anything into a group which already has a comment.
if ($xaction->getTransactionType() == $type_comment) { if ($xaction->isCommentTransaction()) {
return false; return false;
} }