@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Restore old "author can not be a reviewer" rule to Transactions

Summary:
This is a bit messy, but not tooo bad:

- In general, stop the author from being added as a reviewer.
- In the specific case that "self accept" is enabled, allow it. This is easier than trying to special case it.
- When commandeering, we make the author a reviewer and make the actor the author, but these happen after validation. At validation time, it looks like we're making the author a reviewer. Just special case this.
- Provide a slightly nicer message when trying to add yourself from `arc`. We hit the Transactions message anyway, but it's not formatted as cleanly.
- Don't try to add the author via Herald.

Test Plan:
- Edited a revision with author = reviewer, got stopped.
- Commandeered revision.
- Updated from `arc`.
- Updated in general.
- Fired a "add author as reviewer" Herald rule without things breaking.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: aran, epriestley

Differential Revision: https://secure.phabricator.com/D8496

+75
+15
src/applications/differential/customfield/DifferentialReviewersField.php
··· 177 177 return $this->renderObjectList($handles); 178 178 } 179 179 180 + public function validateCommitMessageValue($value) { 181 + $author_phid = $this->getObject()->getAuthorPHID(); 182 + 183 + $config_self_accept_key = 'differential.allow-self-accept'; 184 + $allow_self_accept = PhabricatorEnv::getEnvConfig($config_self_accept_key); 185 + 186 + foreach ($value as $phid) { 187 + if (($phid == $author_phid) && !$allow_self_accept) { 188 + throw new DifferentialFieldValidationException( 189 + pht('The author of a revision can not be a reviewer.')); 190 + } 191 + } 192 + } 193 + 194 + 180 195 }
+48
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 395 395 ); 396 396 } 397 397 398 + // NOTE: We're setting setIsCommandeerSideEffect() on this because 399 + // normally you can't add a revision's author as a reviewer, but 400 + // this action swaps them after validation executes. 401 + 398 402 $results[] = id(new DifferentialTransaction()) 399 403 ->setTransactionType($type_edge) 400 404 ->setMetadataValue('edge:type', $edge_reviewer) 401 405 ->setIgnoreOnNoEffect(true) 406 + ->setIsCommandeerSideEffect(true) 402 407 ->setNewValue($edits); 403 408 404 409 break; ··· 625 630 626 631 $errors = parent::validateTransaction($object, $type, $xactions); 627 632 633 + $config_self_accept_key = 'differential.allow-self-accept'; 634 + $allow_self_accept = PhabricatorEnv::getEnvConfig($config_self_accept_key); 635 + 628 636 foreach ($xactions as $xaction) { 629 637 switch ($type) { 638 + case PhabricatorTransactions::TYPE_EDGE: 639 + switch ($xaction->getMetadataValue('edge:type')) { 640 + case PhabricatorEdgeConfig::TYPE_DREV_HAS_REVIEWER: 641 + 642 + // Prevent the author from becoming a reviewer. 643 + 644 + // NOTE: This is pretty gross, but this restriction is unusual. 645 + // If we end up with too much more of this, we should try to clean 646 + // this up -- maybe by moving validation to after transactions 647 + // are adjusted (so we can just examine the final value) or adding 648 + // a second phase there? 649 + 650 + $author_phid = $object->getAuthorPHID(); 651 + $new = $xaction->getNewValue(); 652 + 653 + $add = idx($new, '+', array()); 654 + $eq = idx($new, '=', array()); 655 + $phids = array_keys($add + $eq); 656 + 657 + foreach ($phids as $phid) { 658 + if (($phid == $author_phid) && 659 + !$allow_self_accept && 660 + !$xaction->getIsCommandeerSideEffect()) { 661 + $errors[] = 662 + new PhabricatorApplicationTransactionValidationError( 663 + $type, 664 + pht('Invalid'), 665 + pht('The author of a revision can not be a reviewer.'), 666 + $xaction); 667 + } 668 + } 669 + break; 670 + } 671 + break; 630 672 case DifferentialTransaction::TYPE_UPDATE: 631 673 $diff = $this->loadDiff($xaction->getNewValue()); 632 674 if (!$diff) { ··· 1340 1382 $value = array(); 1341 1383 foreach ($reviewers as $status => $phids) { 1342 1384 foreach ($phids as $phid) { 1385 + if ($phid == $object->getAuthorPHID()) { 1386 + // Don't try to add the revision's author as a reviewer, since this 1387 + // isn't valid and doesn't make sense. 1388 + continue; 1389 + } 1390 + 1343 1391 $value['+'][$phid] = array( 1344 1392 'data' => array( 1345 1393 'status' => $status,
+12
src/applications/differential/storage/DifferentialTransaction.php
··· 2 2 3 3 final class DifferentialTransaction extends PhabricatorApplicationTransaction { 4 4 5 + private $isCommandeerSideEffect; 6 + 7 + 8 + public function setIsCommandeerSideEffect($is_side_effect) { 9 + $this->isCommandeerSideEffect = $is_side_effect; 10 + return $this; 11 + } 12 + 13 + public function getIsCommandeerSideEffect() { 14 + return $this->isCommandeerSideEffect; 15 + } 16 + 5 17 const TYPE_INLINE = 'differential:inline'; 6 18 const TYPE_UPDATE = 'differential:update'; 7 19 const TYPE_ACTION = 'differential:action';