Changeset View
Changeset View
Standalone View
Standalone View
src/applications/maniphest/editor/ManiphestTransactionEditor.php
Show First 20 Lines • Show All 322 Lines • ▼ Show 20 Lines | protected function expandTransactions( | ||||
$actor = $this->getActor(); | $actor = $this->getActor(); | ||||
$actor_phid = $actor->getPHID(); | $actor_phid = $actor->getPHID(); | ||||
$results = parent::expandTransactions($object, $xactions); | $results = parent::expandTransactions($object, $xactions); | ||||
$is_unassigned = ($object->getOwnerPHID() === null); | $is_unassigned = ($object->getOwnerPHID() === null); | ||||
$any_assign = false; | $any_assign = false; | ||||
$new_assignee = null; | |||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
if ($xaction->getTransactionType() == | if ($xaction->getTransactionType() == | ||||
ManiphestTaskOwnerTransaction::TRANSACTIONTYPE) { | ManiphestTaskOwnerTransaction::TRANSACTIONTYPE) { | ||||
$any_assign = true; | $any_assign = true; | ||||
$new_assignee = $xaction->getNewValue(); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
$is_open = !$object->isClosed(); | $is_open = !$object->isClosed(); | ||||
$new_status = null; | $new_status = null; | ||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case ManiphestTaskStatusTransaction::TRANSACTIONTYPE: | case ManiphestTaskStatusTransaction::TRANSACTIONTYPE: | ||||
$new_status = $xaction->getNewValue(); | $new_status = $xaction->getNewValue(); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if ($new_status === null) { | if ($new_status === null) { | ||||
$is_closing = false; | $is_closing = false; | ||||
} else { | } else { | ||||
$is_closing = ManiphestTaskStatus::isClosedStatus($new_status); | $is_closing = ManiphestTaskStatus::isClosedStatus($new_status); | ||||
} | } | ||||
// If the task is not assigned, not being assigned, currently open, and | // Check if status is configured to claim (silently set actor as owner). | ||||
// being closed, try to assign the actor as the owner. | |||||
if ($is_unassigned && !$any_assign && $is_open && $is_closing) { | |||||
$is_claim = ManiphestTaskStatus::isClaimStatus($new_status); | $is_claim = ManiphestTaskStatus::isClaimStatus($new_status); | ||||
// Don't assign the actor if they aren't a real user. | // Check if the task is not assigned, currently open, and being closed. | ||||
// Don't claim the task if the status is configured to not claim. | if ($is_unassigned && $is_open && $is_closing) { | ||||
// If the task is not being assigned, try to assign the actor as owner. | |||||
if (!$any_assign) { | |||||
// Assign the actor only if they are a real user. | |||||
// Claim the task only if the status is configured to claim. | |||||
if ($actor_phid && $is_claim) { | if ($actor_phid && $is_claim) { | ||||
$results[] = id(new ManiphestTransaction()) | $results[] = id(new ManiphestTransaction()) | ||||
->setTransactionType(ManiphestTaskOwnerTransaction::TRANSACTIONTYPE) | ->setTransactionType(ManiphestTaskOwnerTransaction::TRANSACTIONTYPE) | ||||
->setNewValue($actor_phid); | ->setNewValue($actor_phid); | ||||
} | } | ||||
} | } | ||||
// If the actor is going to set a status configured to claim && the actor | |||||
// has opened "Add Field... > Assigned To" (so $any_assign is true) && the | |||||
// actor has removed themselves from "Assigned To" (so $new_assignee is | |||||
// null), we de-facto are not going to change the (empty) assignee anyway. | |||||
// Thus remove the reassign transaction from $results to avoid the | |||||
// unwanted "Action with no effect" dialog. - https://we.phorge.it/T15164 | |||||
if ($any_assign && $is_claim && !$new_assignee) { | |||||
for ($i = 0; $i < count($results); $i++) { | |||||
if ($results[$i]->getTransactionType() === | |||||
ManiphestTaskOwnerTransaction::TRANSACTIONTYPE) { | |||||
unset($results[$i]); | |||||
$results = array_values($results); // close gap | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
// Automatically subscribe the author when they create a task. | // Automatically subscribe the author when they create a task. | ||||
if ($this->getIsNewObject()) { | if ($this->getIsNewObject()) { | ||||
if ($actor_phid) { | if ($actor_phid) { | ||||
$results[] = id(new ManiphestTransaction()) | $results[] = id(new ManiphestTransaction()) | ||||
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) | ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) | ||||
->setNewValue( | ->setNewValue( | ||||
array( | array( | ||||
'+' => array($actor_phid => $actor_phid), | '+' => array($actor_phid => $actor_phid), | ||||
▲ Show 20 Lines • Show All 558 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0