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

Implement Commandeer action in ApplicationTransactions

Summary: Ref T2222. Implements Commandeer on the new stuff.

Test Plan:
{F117768}

{F117769}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2222

Differential Revision: https://secure.phabricator.com/D8331
This commit is contained in:
epriestley 2014-02-25 12:36:24 -08:00
parent 0f0673b9e5
commit d07292df7f
2 changed files with 58 additions and 4 deletions

View file

@ -90,6 +90,9 @@ final class DifferentialTransactionEditor
} }
} }
return false; return false;
case DifferentialAction::ACTION_CLAIM:
$actor_phid = $this->getActor()->getPHID();
return ($actor_phid != $object->getAuthorPHID());
} }
} }
@ -145,6 +148,9 @@ final class DifferentialTransactionEditor
case DifferentialAction::ACTION_CLOSE: case DifferentialAction::ACTION_CLOSE:
$object->setStatus(ArcanistDifferentialRevisionStatus::CLOSED); $object->setStatus(ArcanistDifferentialRevisionStatus::CLOSED);
break; break;
case DifferentialAction::ACTION_CLAIM:
$object->setAuthorPHID($this->getActor()->getPHID());
break;
default: default:
// TODO: For now, we're just shipping the rest of these through // TODO: For now, we're just shipping the rest of these through
// without acting on them. // without acting on them.
@ -163,15 +169,48 @@ final class DifferentialTransactionEditor
$results = parent::expandTransaction($object, $xaction); $results = parent::expandTransaction($object, $xaction);
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case DifferentialTransaction::TYPE_ACTION: case DifferentialTransaction::TYPE_ACTION:
$actor_phid = $this->getActor()->getPHID();
$type_edge = PhabricatorTransactions::TYPE_EDGE;
$edge_reviewer = PhabricatorEdgeConfig::TYPE_DREV_HAS_REVIEWER;
switch ($xaction->getNewValue()) { switch ($xaction->getNewValue()) {
case DifferentialAction::ACTION_CLAIM:
// If the user is commandeering, add the previous owner as a
// reviewer and remove the actor.
$edits = array(
'-' => array(
$actor_phid => $actor_phid,
),
);
$owner_phid = $object->getAuthorPHID();
if ($owner_phid) {
$reviewer = new DifferentialReviewer(
$owner_phid,
array(
'status' => DifferentialReviewerStatus::STATUS_ADDED,
));
$edits['+'] = array(
$owner_phid => array(
'data' => $reviewer->getEdgeData(),
),
);
}
$results[] = id(new DifferentialTransaction())
->setTransactionType($type_edge)
->setMetadataValue('edge:type', $edge_reviewer)
->setIgnoreOnNoEffect(true)
->setNewValue($edits);
break;
case DifferentialAction::ACTION_RESIGN: case DifferentialAction::ACTION_RESIGN:
// If the user is resigning, add a separate reviewer edit // If the user is resigning, add a separate reviewer edit
// transaction which removes them as a reviewer. // transaction which removes them as a reviewer.
$actor_phid = $this->getActor()->getPHID();
$type_edge = PhabricatorTransactions::TYPE_EDGE;
$edge_reviewer = PhabricatorEdgeConfig::TYPE_DREV_HAS_REVIEWER;
$results[] = id(new DifferentialTransaction()) $results[] = id(new DifferentialTransaction())
->setTransactionType($type_edge) ->setTransactionType($type_edge)
->setMetadataValue('edge:type', $edge_reviewer) ->setMetadataValue('edge:type', $edge_reviewer)
@ -267,6 +306,17 @@ final class DifferentialTransactionEditor
// aren't, this is a no-op rather than invalid. // aren't, this is a no-op rather than invalid.
break; break;
case DifferentialAction::ACTION_CLAIM:
// You can claim a revision if you're not the owner. If you are, this
// is a no-op rather than invalid.
if ($revision_status == $status_closed) {
return pht(
"You can not commandeer this revision because it has already been ".
"closed.");
}
break;
case DifferentialAction::ACTION_ABANDON: case DifferentialAction::ACTION_ABANDON:
if (!$actor_is_author) { if (!$actor_is_author) {
return pht( return pht(

View file

@ -147,6 +147,10 @@ final class DifferentialTransaction extends PhabricatorApplicationTransaction {
return pht( return pht(
'You can not resign from this revision because you are not '. 'You can not resign from this revision because you are not '.
'a reviewer.'); 'a reviewer.');
case DifferentialAction::ACTION_CLAIM:
return pht(
'You can not commandeer this revision because you already own '.
'it.');
} }
break; break;
} }