2011-01-30 21:08:40 +01:00
|
|
|
<?php
|
|
|
|
|
2014-02-27 20:06:55 +01:00
|
|
|
final class DifferentialCommentSaveController
|
|
|
|
extends DifferentialController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
2011-01-30 21:08:40 +01:00
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
2014-02-27 20:06:55 +01:00
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
2011-01-30 21:08:40 +01:00
|
|
|
if (!$request->isFormPost()) {
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:37:19 +02:00
|
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
|
|
->setViewer($viewer)
|
2014-02-27 20:06:55 +01:00
|
|
|
->withIDs(array($this->id))
|
|
|
|
->needReviewerStatus(true)
|
|
|
|
->needReviewerAuthority(true)
|
2013-09-26 21:37:19 +02:00
|
|
|
->executeOne();
|
2011-01-30 21:08:40 +01:00
|
|
|
if (!$revision) {
|
2014-02-27 20:06:55 +01:00
|
|
|
return new Aphront404Response();
|
2011-01-30 21:08:40 +01:00
|
|
|
}
|
|
|
|
|
2014-02-27 20:06:55 +01:00
|
|
|
$type_action = DifferentialTransaction::TYPE_ACTION;
|
|
|
|
$type_subscribers = PhabricatorTransactions::TYPE_SUBSCRIBERS;
|
|
|
|
$type_edge = PhabricatorTransactions::TYPE_EDGE;
|
|
|
|
$type_comment = PhabricatorTransactions::TYPE_COMMENT;
|
|
|
|
$type_inline = DifferentialTransaction::TYPE_INLINE;
|
|
|
|
|
2015-01-01 04:43:26 +01:00
|
|
|
$edge_reviewer = DifferentialRevisionHasReviewerEdgeType::EDGECONST;
|
2014-02-27 20:06:55 +01:00
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
|
|
|
|
$action = $request->getStr('action');
|
|
|
|
switch ($action) {
|
|
|
|
case DifferentialAction::ACTION_COMMENT:
|
|
|
|
case DifferentialAction::ACTION_ADDREVIEWERS:
|
|
|
|
case DifferentialAction::ACTION_ADDCCS:
|
|
|
|
// These transaction types have no direct effect, they just
|
|
|
|
// accompany other transaction types which can have an effect.
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$xactions[] = id(new DifferentialTransaction())
|
|
|
|
->setTransactionType($type_action)
|
|
|
|
->setNewValue($request->getStr('action'));
|
|
|
|
break;
|
|
|
|
}
|
2011-01-30 21:08:40 +01:00
|
|
|
|
2014-02-27 20:06:55 +01:00
|
|
|
$ccs = $request->getArr('ccs');
|
|
|
|
if ($ccs) {
|
|
|
|
$xactions[] = id(new DifferentialTransaction())
|
|
|
|
->setTransactionType($type_subscribers)
|
|
|
|
->setNewValue(array('+' => $ccs));
|
|
|
|
}
|
2011-01-30 21:08:40 +01:00
|
|
|
|
2014-02-27 20:06:55 +01:00
|
|
|
$current_reviewers = mpull(
|
|
|
|
$revision->getReviewerStatus(),
|
|
|
|
null,
|
|
|
|
'getReviewerPHID');
|
Track content sources (email, web, conduit, mobile) for replies
Summary:
When an object is updated, record the content source for the update. This mostly
isn't terribly useful but one concrete thing I want to do with it is let admins
audit via-email replies more easily since there are a bunch of options which let
you do hyjinx if you intentionally configure them insecurely. I think having a
little more auditability around this feature is generally good. At some point
I'm going to turn this into a link admins can click to see details.
It also allows us to see how frequently different mechanisms are used, and lets
you see if someone is at their desk or on a mobile or whatever, at least
indirectly.
The "tablet" and "mobile" sources are currently unused but I figured I'd throw
them in anyway. SMS support should definitely happen at some point.
Not 100% sure about the design for this, I might change it to plain text at some
point.
Test Plan: Updated objects and saw update sources rendered.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, epriestley, jungejason
Differential Revision: 844
2011-08-22 19:25:45 +02:00
|
|
|
|
2014-02-27 20:06:55 +01:00
|
|
|
$reviewer_edges = array();
|
|
|
|
$add_reviewers = $request->getArr('reviewers');
|
|
|
|
foreach ($add_reviewers as $reviewer_phid) {
|
|
|
|
if (isset($current_reviewers[$reviewer_phid])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$reviewer = new DifferentialReviewer(
|
|
|
|
$reviewer_phid,
|
|
|
|
array(
|
|
|
|
'status' => DifferentialReviewerStatus::STATUS_ADDED,
|
|
|
|
));
|
|
|
|
$reviewer_edges[$reviewer_phid] = array(
|
|
|
|
'data' => $reviewer->getEdgeData(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($add_reviewers) {
|
|
|
|
$xactions[] = id(new DifferentialTransaction())
|
|
|
|
->setTransactionType($type_edge)
|
|
|
|
->setMetadataValue('edge:type', $edge_reviewer)
|
|
|
|
->setNewValue(array('+' => $reviewer_edges));
|
|
|
|
}
|
|
|
|
|
2014-03-08 02:44:10 +01:00
|
|
|
$inlines = DifferentialTransactionQuery::loadUnsubmittedInlineComments(
|
|
|
|
$viewer,
|
|
|
|
$revision);
|
2014-02-27 20:06:55 +01:00
|
|
|
foreach ($inlines as $inline) {
|
|
|
|
$xactions[] = id(new DifferentialTransaction())
|
|
|
|
->setTransactionType($type_inline)
|
|
|
|
->attachComment($inline);
|
|
|
|
}
|
Improve behavior when user submits a no-op action in Differential
Summary:
See T730 and the slightly-less-pretty version of this in D1398.
When a user takes an action in Differential that has no effect (for instance,
accepting an already-accepted revision), prompt them:
Action Has No Effect
You can not accept this revision because it has already been accepted.
Do you want to post the feedback anyway, as a normal comment?
[Cancel] [Post as Comment]
If they have no comment text, the dialog only says "Cancel".
I think this is probably the best way to balance all the concerns here -- it
might occasionally be a little annoying, but that should be rare, and it should
never be confusing (the current workflow is extremely confusing).
This also fixes the issue where you can add all sorts of CCs who are already
part of the revision, either explicitly or via mentions.
Test Plan:
Posted some has-effect and has-no-effect comments, made different
choices in the dialog, everything seems to work OK?
Reviewers: vrana, btrahan, jungejason
Reviewed By: vrana
CC: aran, vrana
Maniphest Tasks: T730
Differential Revision: https://secure.phabricator.com/D1403
2012-01-14 20:39:22 +01:00
|
|
|
|
2014-02-27 20:06:55 +01:00
|
|
|
// 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');
|
|
|
|
if (strlen($comment) || $no_xactions) {
|
|
|
|
$xactions[] = id(new DifferentialTransaction())
|
|
|
|
->setTransactionType($type_comment)
|
|
|
|
->attachComment(
|
|
|
|
id(new DifferentialTransactionComment())
|
|
|
|
->setRevisionPHID($revision->getPHID())
|
|
|
|
->setContent($comment));
|
Improve behavior when user submits a no-op action in Differential
Summary:
See T730 and the slightly-less-pretty version of this in D1398.
When a user takes an action in Differential that has no effect (for instance,
accepting an already-accepted revision), prompt them:
Action Has No Effect
You can not accept this revision because it has already been accepted.
Do you want to post the feedback anyway, as a normal comment?
[Cancel] [Post as Comment]
If they have no comment text, the dialog only says "Cancel".
I think this is probably the best way to balance all the concerns here -- it
might occasionally be a little annoying, but that should be rare, and it should
never be confusing (the current workflow is extremely confusing).
This also fixes the issue where you can add all sorts of CCs who are already
part of the revision, either explicitly or via mentions.
Test Plan:
Posted some has-effect and has-no-effect comments, made different
choices in the dialog, everything seems to work OK?
Reviewers: vrana, btrahan, jungejason
Reviewed By: vrana
CC: aran, vrana
Maniphest Tasks: T730
Differential Revision: https://secure.phabricator.com/D1403
2012-01-14 20:39:22 +01:00
|
|
|
}
|
2011-01-30 21:08:40 +01:00
|
|
|
|
2014-02-27 20:06:55 +01:00
|
|
|
|
|
|
|
$editor = id(new DifferentialTransactionEditor())
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnMissingFields(true)
|
|
|
|
->setContinueOnNoEffect($request->isContinueRequest());
|
|
|
|
|
|
|
|
$revision_uri = '/D'.$revision->getID();
|
|
|
|
|
|
|
|
try {
|
|
|
|
$editor->applyTransactions($revision, $xactions);
|
|
|
|
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
|
|
|
|
return id(new PhabricatorApplicationTransactionNoEffectResponse())
|
|
|
|
->setCancelURI($revision_uri)
|
|
|
|
->setException($ex);
|
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
2015-01-20 22:59:17 +01:00
|
|
|
return id(new PhabricatorApplicationTransactionValidationResponse())
|
|
|
|
->setCancelURI($revision_uri)
|
|
|
|
->setException($ex);
|
2014-02-27 20:06:55 +01:00
|
|
|
}
|
2011-02-06 01:57:21 +01:00
|
|
|
|
2014-02-19 01:25:16 +01:00
|
|
|
$user = $request->getUser();
|
2011-02-06 01:57:21 +01:00
|
|
|
$draft = id(new PhabricatorDraft())->loadOneWhere(
|
|
|
|
'authorPHID = %s AND draftKey = %s',
|
2014-02-19 01:25:16 +01:00
|
|
|
$user->getPHID(),
|
2011-02-06 01:57:21 +01:00
|
|
|
'differential-comment-'.$revision->getID());
|
|
|
|
if ($draft) {
|
|
|
|
$draft->delete();
|
|
|
|
}
|
2014-02-19 01:25:16 +01:00
|
|
|
DifferentialDraft::deleteAllDrafts($user->getPHID(), $revision->getPHID());
|
2011-01-30 21:08:40 +01:00
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('/D'.$revision->getID());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|