Differential D18019 Diff 43343 src/applications/differential/xaction/DifferentialRevisionAcceptTransaction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/xaction/DifferentialRevisionAcceptTransaction.php
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | final class DifferentialRevisionAcceptTransaction | ||||
} | } | ||||
public function getCommandSummary() { | public function getCommandSummary() { | ||||
return pht('Accept a revision.'); | return pht('Accept a revision.'); | ||||
} | } | ||||
protected function getActionOptions( | protected function getActionOptions( | ||||
PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
DifferentialRevision $revision) { | DifferentialRevision $revision, | ||||
$include_accepted = false) { | |||||
$reviewers = $revision->getReviewers(); | $reviewers = $revision->getReviewers(); | ||||
$options = array(); | $options = array(); | ||||
$value = array(); | $value = array(); | ||||
// Put the viewer's user reviewer first, if it exists, so that "Accept as | // Put the viewer's user reviewer first, if it exists, so that "Accept as | ||||
// yourself" is always at the top. | // yourself" is always at the top. | ||||
Show All 31 Lines | foreach ($reviewers as $reviewer) { | ||||
// we check if they can accept by force. | // we check if they can accept by force. | ||||
if ($revision->canReviewerForceAccept($viewer, $reviewer)) { | if ($revision->canReviewerForceAccept($viewer, $reviewer)) { | ||||
$default_unchecked[$reviewer_phid] = true; | $default_unchecked[$reviewer_phid] = true; | ||||
} else { | } else { | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
if (!$include_accepted) { | |||||
if ($reviewer->isAccepted($diff_phid)) { | if ($reviewer->isAccepted($diff_phid)) { | ||||
// If a reviewer is already in a full "accepted" state, don't | // If a reviewer is already in a full "accepted" state, don't | ||||
// include that reviewer as an option. | // include that reviewer as an option unless we're listing all | ||||
// reviwers, including reviewers who have already accepted. | |||||
continue; | continue; | ||||
} | } | ||||
} | |||||
$reviewer_phids[$reviewer_phid] = $reviewer_phid; | $reviewer_phids[$reviewer_phid] = $reviewer_phid; | ||||
} | } | ||||
$handles = $viewer->loadHandles($reviewer_phids); | $handles = $viewer->loadHandles($reviewer_phids); | ||||
$head = array(); | $head = array(); | ||||
$tail = array(); | $tail = array(); | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | final class DifferentialRevisionAcceptTransaction | ||||
protected function validateOptionValue($object, $actor, array $value) { | protected function validateOptionValue($object, $actor, array $value) { | ||||
if (!$value) { | if (!$value) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'When accepting a revision, you must accept on behalf of at '. | 'When accepting a revision, you must accept on behalf of at '. | ||||
'least one reviewer.')); | 'least one reviewer.')); | ||||
} | } | ||||
list($options) = $this->getActionOptions($actor, $object); | // NOTE: We're including reviewers who have already been accepted in this | ||||
// check. Legitimate users may race one another to accept on behalf of | |||||
// packages. If we get a form submission which includes a reviewer which | |||||
// someone has already accepted, that's fine. See T12757. | |||||
list($options) = $this->getActionOptions($actor, $object, true); | |||||
foreach ($value as $phid) { | foreach ($value as $phid) { | ||||
if (!isset($options[$phid])) { | if (!isset($options[$phid])) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Reviewer "%s" is not a valid reviewer which you have authority '. | 'Reviewer "%s" is not a valid reviewer which you have authority '. | ||||
'to accept on behalf of.', | 'to accept on behalf of.', | ||||
$phid)); | $phid)); | ||||
} | } | ||||
Show All 26 Lines |