Skip to content

Commit 9f3210c

Browse files
author
epriestley
committed
Publish draft "done" status when submitting comments/updates/actions/inlines
Summary: Ref T1460. When a revision author updates/comments/etc on a revision, publish all their checkmarks. This doesn't handle Diffusion/audits yet. Test Plan: {F346870} Reviewers: btrahan Reviewed By: btrahan Subscribers: yelirekim, epriestley Maniphest Tasks: T1460 Differential Revision: https://secure.phabricator.com/D12126
1 parent 4310c4e commit 9f3210c

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed

src/applications/differential/editor/DifferentialTransactionEditor.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ final class DifferentialTransactionEditor
77
private $changedPriorToCommitURI;
88
private $isCloseByCommit;
99
private $repositoryPHIDOverride = false;
10+
private $expandedDone = false;
1011

1112
public function getEditorApplicationClass() {
1213
return 'PhabricatorDifferentialApplication';
@@ -99,6 +100,7 @@ protected function getCustomTransactionNewValue(
99100
case PhabricatorTransactions::TYPE_EDIT_POLICY:
100101
case DifferentialTransaction::TYPE_ACTION:
101102
case DifferentialTransaction::TYPE_UPDATE:
103+
case DifferentialTransaction::TYPE_INLINEDONE:
102104
return $xaction->getNewValue();
103105
case DifferentialTransaction::TYPE_INLINE:
104106
return null;
@@ -197,6 +199,7 @@ protected function applyCustomInternalTransaction(
197199
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
198200
case PhabricatorTransactions::TYPE_COMMENT:
199201
case DifferentialTransaction::TYPE_INLINE:
202+
case DifferentialTransaction::TYPE_INLINEDONE:
200203
return;
201204
case PhabricatorTransactions::TYPE_EDGE:
202205
return;
@@ -524,6 +527,52 @@ protected function expandTransaction(
524527
break;
525528
}
526529

530+
if (!$this->expandedDone) {
531+
switch ($xaction->getTransactionType()) {
532+
case PhabricatorTransactions::TYPE_COMMENT:
533+
case DifferentialTransaction::TYPE_ACTION:
534+
case DifferentialTransaction::TYPE_UPDATE:
535+
case DifferentialTransaction::TYPE_INLINE:
536+
$this->expandedDone = true;
537+
538+
$actor_phid = $this->getActingAsPHID();
539+
$actor_is_author = ($object->getAuthorPHID() == $actor_phid);
540+
if (!$actor_is_author) {
541+
break;
542+
}
543+
544+
$state_map = array(
545+
PhabricatorInlineCommentInterface::STATE_DRAFT =>
546+
PhabricatorInlineCommentInterface::STATE_DONE,
547+
PhabricatorInlineCommentInterface::STATE_UNDRAFT =>
548+
PhabricatorInlineCommentInterface::STATE_UNDONE,
549+
);
550+
551+
$inlines = id(new DifferentialDiffInlineCommentQuery())
552+
->setViewer($this->getActor())
553+
->withRevisionPHIDs(array($object->getPHID()))
554+
->withFixedStates(array_keys($state_map))
555+
->execute();
556+
557+
if (!$inlines) {
558+
break;
559+
}
560+
561+
$old_value = mpull($inlines, 'getFixedState', 'getPHID');
562+
$new_value = array();
563+
foreach ($old_value as $key => $state) {
564+
$new_value[$key] = $state_map[$state];
565+
}
566+
567+
$results[] = id(new DifferentialTransaction())
568+
->setTransactionType(DifferentialTransaction::TYPE_INLINEDONE)
569+
->setIgnoreOnNoEffect(true)
570+
->setOldValue($old_value)
571+
->setNewValue($new_value);
572+
break;
573+
}
574+
}
575+
527576
return $results;
528577
}
529578

@@ -546,6 +595,18 @@ protected function applyCustomExternalTransaction(
546595
$reply->setHasReplies(1)->save();
547596
}
548597
return;
598+
case DifferentialTransaction::TYPE_INLINEDONE:
599+
$table = new DifferentialTransactionComment();
600+
$conn_w = $table->establishConnection('w');
601+
foreach ($xaction->getNewValue() as $phid => $state) {
602+
queryfx(
603+
$conn_w,
604+
'UPDATE %T SET fixedState = %s WHERE phid = %s',
605+
$table->getTableName(),
606+
$state,
607+
$phid);
608+
}
609+
return;
549610
case DifferentialTransaction::TYPE_UPDATE:
550611
// Now that we're inside the transaction, do a final check.
551612
$diff = $this->requireDiff($xaction->getNewValue());

src/applications/differential/storage/DifferentialTransaction.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function getIsCommandeerSideEffect() {
1818
const TYPE_UPDATE = 'differential:update';
1919
const TYPE_ACTION = 'differential:action';
2020
const TYPE_STATUS = 'differential:status';
21+
const TYPE_INLINEDONE = 'differential:inlinedone';
2122

2223
public function getApplicationName() {
2324
return 'differential';
@@ -35,6 +36,15 @@ public function getApplicationTransactionViewObject() {
3536
return new DifferentialTransactionView();
3637
}
3738

39+
public function shouldGenerateOldValue() {
40+
switch ($this->getTransactionType()) {
41+
case DifferentialTransaction::TYPE_INLINEDONE:
42+
return false;
43+
}
44+
45+
return parent::shouldGenerateOldValue();
46+
}
47+
3848
public function shouldHide() {
3949
$old = $this->getOldValue();
4050
$new = $this->getNewValue();
@@ -231,6 +241,35 @@ public function getTitle() {
231241
return pht(
232242
'%s added inline comments.',
233243
$author_handle);
244+
case self::TYPE_INLINEDONE:
245+
$done = 0;
246+
$undone = 0;
247+
foreach ($new as $phid => $state) {
248+
if ($state == PhabricatorInlineCommentInterface::STATE_DONE) {
249+
$done++;
250+
} else {
251+
$undone++;
252+
}
253+
}
254+
if ($done && $undone) {
255+
return pht(
256+
'%s marked %s inline comment(s) as done and %s inline comment(s) '.
257+
'as not done.',
258+
$author_handle,
259+
new PhutilNumber($done),
260+
new PhutilNumber($undone));
261+
} else if ($done) {
262+
return pht(
263+
'%s marked %s inline comment(s) as done.',
264+
$author_handle,
265+
new PhutilNumber($done));
266+
} else {
267+
return pht(
268+
'%s marked %s inline comment(s) as not done.',
269+
$author_handle,
270+
new PhutilNumber($undone));
271+
}
272+
break;
234273
case self::TYPE_UPDATE:
235274
if ($this->getMetadataValue('isCommitUpdate')) {
236275
return pht(

src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,33 @@
33
abstract class PhabricatorDiffInlineCommentQuery
44
extends PhabricatorApplicationTransactionCommentQuery {
55

6+
private $fixedStates;
67
private $needReplyToComments;
78

9+
public function withFixedStates(array $states) {
10+
$this->fixedStates = $states;
11+
return $this;
12+
}
13+
814
public function needReplyToComments($need_reply_to) {
915
$this->needReplyToComments = $need_reply_to;
1016
return $this;
1117
}
1218

19+
protected function buildWhereClauseComponents(
20+
AphrontDatabaseConnection $conn_r) {
21+
$where = parent::buildWhereClauseComponents($conn_r);
22+
23+
if ($this->fixedStates !== null) {
24+
$where[] = qsprintf(
25+
$conn_r,
26+
'fixedState IN (%Ls)',
27+
$this->fixedStates);
28+
}
29+
30+
return $where;
31+
}
32+
1333
protected function willFilterPage(array $comments) {
1434
if ($this->needReplyToComments) {
1535
$reply_phids = array();

src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,38 @@ protected function getTranslations() {
967967
'Show Last %d Lines',
968968
),
969969

970+
'%s marked %s inline comment(s) as done and %s inline comment(s) as '.
971+
'not done.' => array(
972+
array(
973+
array(
974+
'%s marked an inline comment as done and an inline comment '.
975+
'as not done.',
976+
'%s marked an inline comment as done and %3$s inline comments '.
977+
'as not done.',
978+
),
979+
array(
980+
'%s marked %s inline comments as done and an inline comment '.
981+
'as not done.',
982+
'%s marked %s inline comments as done and %s inline comments '.
983+
'as done.',
984+
),
985+
),
986+
),
987+
988+
'%s marked %s inline comment(s) as done.' => array(
989+
array(
990+
'%s marked an inline comment as done.',
991+
'%s marked %s inline comments as done.',
992+
),
993+
),
994+
995+
'%s marked %s inline comment(s) as not done.' => array(
996+
array(
997+
'%s marked an inline comment as not done.',
998+
'%s marked %s inline comments as not done.',
999+
),
1000+
),
1001+
9701002
);
9711003
}
9721004

0 commit comments

Comments
 (0)