Changeset View
Changeset View
Standalone View
Standalone View
src/applications/audit/editor/PhabricatorAuditEditor.php
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | public function getTransactionTypes() { | ||||
$types[] = PhabricatorTransactions::TYPE_COMMENT; | $types[] = PhabricatorTransactions::TYPE_COMMENT; | ||||
$types[] = PhabricatorTransactions::TYPE_EDGE; | $types[] = PhabricatorTransactions::TYPE_EDGE; | ||||
$types[] = PhabricatorTransactions::TYPE_INLINESTATE; | $types[] = PhabricatorTransactions::TYPE_INLINESTATE; | ||||
$types[] = PhabricatorAuditTransaction::TYPE_COMMIT; | $types[] = PhabricatorAuditTransaction::TYPE_COMMIT; | ||||
// TODO: These will get modernized eventually, but that can happen one | // TODO: These will get modernized eventually, but that can happen one | ||||
// at a time later on. | // at a time later on. | ||||
$types[] = PhabricatorAuditActionConstants::ACTION; | |||||
$types[] = PhabricatorAuditActionConstants::INLINE; | $types[] = PhabricatorAuditActionConstants::INLINE; | ||||
$types[] = PhabricatorAuditActionConstants::ADD_AUDITORS; | $types[] = PhabricatorAuditActionConstants::ADD_AUDITORS; | ||||
return $types; | return $types; | ||||
} | } | ||||
protected function expandTransactions( | protected function expandTransactions( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
Show All 21 Lines | protected function transactionHasEffect( | ||||
return parent::transactionHasEffect($object, $xaction); | return parent::transactionHasEffect($object, $xaction); | ||||
} | } | ||||
protected function getCustomTransactionOldValue( | protected function getCustomTransactionOldValue( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorAuditActionConstants::ACTION: | |||||
case PhabricatorAuditActionConstants::INLINE: | case PhabricatorAuditActionConstants::INLINE: | ||||
case PhabricatorAuditTransaction::TYPE_COMMIT: | case PhabricatorAuditTransaction::TYPE_COMMIT: | ||||
return null; | return null; | ||||
case PhabricatorAuditActionConstants::ADD_AUDITORS: | case PhabricatorAuditActionConstants::ADD_AUDITORS: | ||||
// TODO: For now, just record the added PHIDs. Eventually, turn these | // TODO: For now, just record the added PHIDs. Eventually, turn these | ||||
// into real edge transactions, probably? | // into real edge transactions, probably? | ||||
return array(); | return array(); | ||||
} | } | ||||
return parent::getCustomTransactionOldValue($object, $xaction); | return parent::getCustomTransactionOldValue($object, $xaction); | ||||
} | } | ||||
protected function getCustomTransactionNewValue( | protected function getCustomTransactionNewValue( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorAuditActionConstants::ACTION: | |||||
case PhabricatorAuditActionConstants::INLINE: | case PhabricatorAuditActionConstants::INLINE: | ||||
case PhabricatorAuditActionConstants::ADD_AUDITORS: | case PhabricatorAuditActionConstants::ADD_AUDITORS: | ||||
case PhabricatorAuditTransaction::TYPE_COMMIT: | case PhabricatorAuditTransaction::TYPE_COMMIT: | ||||
return $xaction->getNewValue(); | return $xaction->getNewValue(); | ||||
} | } | ||||
return parent::getCustomTransactionNewValue($object, $xaction); | return parent::getCustomTransactionNewValue($object, $xaction); | ||||
} | } | ||||
protected function applyCustomInternalTransaction( | protected function applyCustomInternalTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorAuditActionConstants::ACTION: | |||||
case PhabricatorAuditActionConstants::INLINE: | case PhabricatorAuditActionConstants::INLINE: | ||||
case PhabricatorAuditActionConstants::ADD_AUDITORS: | case PhabricatorAuditActionConstants::ADD_AUDITORS: | ||||
case PhabricatorAuditTransaction::TYPE_COMMIT: | case PhabricatorAuditTransaction::TYPE_COMMIT: | ||||
return; | return; | ||||
} | } | ||||
return parent::applyCustomInternalTransaction($object, $xaction); | return parent::applyCustomInternalTransaction($object, $xaction); | ||||
} | } | ||||
protected function applyCustomExternalTransaction( | protected function applyCustomExternalTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorAuditActionConstants::ACTION: | |||||
case PhabricatorAuditTransaction::TYPE_COMMIT: | case PhabricatorAuditTransaction::TYPE_COMMIT: | ||||
return; | return; | ||||
case PhabricatorAuditActionConstants::INLINE: | case PhabricatorAuditActionConstants::INLINE: | ||||
$reply = $xaction->getComment()->getReplyToComment(); | $reply = $xaction->getComment()->getReplyToComment(); | ||||
if ($reply && !$reply->getHasReplies()) { | if ($reply && !$reply->getHasReplies()) { | ||||
$reply->setHasReplies(1)->save(); | $reply->setHasReplies(1)->save(); | ||||
} | } | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | $actor_is_author = ($object->getAuthorPHID()) && | ||||
($actor_phid == $object->getAuthorPHID()); | ($actor_phid == $object->getAuthorPHID()); | ||||
$import_status_flag = null; | $import_status_flag = null; | ||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorAuditTransaction::TYPE_COMMIT: | case PhabricatorAuditTransaction::TYPE_COMMIT: | ||||
$import_status_flag = PhabricatorRepositoryCommit::IMPORTED_HERALD; | $import_status_flag = PhabricatorRepositoryCommit::IMPORTED_HERALD; | ||||
break; | break; | ||||
case PhabricatorAuditActionConstants::ACTION: | |||||
$new = $xaction->getNewValue(); | |||||
switch ($new) { | |||||
case PhabricatorAuditActionConstants::CLOSE: | |||||
// "Close" means wipe out all the concerns. | |||||
$requests = $object->getAudits(); | |||||
foreach ($requests as $request) { | |||||
if ($request->getAuditStatus() == $status_concerned) { | |||||
$request | |||||
->setAuditStatus($status_closed) | |||||
->save(); | |||||
} | |||||
} | |||||
break; | |||||
case PhabricatorAuditActionConstants::RESIGN: | |||||
$requests = $object->getAudits(); | |||||
$requests = mpull($requests, null, 'getAuditorPHID'); | |||||
$actor_request = idx($requests, $actor_phid); | |||||
// If the actor doesn't currently have a relationship to the | |||||
// commit, add one explicitly. For example, this allows members | |||||
// of a project to resign from a commit and have it drop out of | |||||
// their queue. | |||||
if (!$actor_request) { | |||||
$actor_request = id(new PhabricatorRepositoryAuditRequest()) | |||||
->setCommitPHID($object->getPHID()) | |||||
->setAuditorPHID($actor_phid); | |||||
$requests[] = $actor_request; | |||||
$object->attachAudits($requests); | |||||
} | |||||
$actor_request | |||||
->setAuditStatus($status_resigned) | |||||
->save(); | |||||
break; | |||||
case PhabricatorAuditActionConstants::ACCEPT: | |||||
case PhabricatorAuditActionConstants::CONCERN: | |||||
if ($new == PhabricatorAuditActionConstants::ACCEPT) { | |||||
$new_status = $status_accepted; | |||||
} else { | |||||
$new_status = $status_concerned; | |||||
} | |||||
$requests = $object->getAudits(); | |||||
$requests = mpull($requests, null, 'getAuditorPHID'); | |||||
// Figure out which requests the actor has authority over: these | |||||
// are user requests where they are the auditor, and packages | |||||
// and projects they are a member of. | |||||
if ($actor_is_author) { | |||||
// When modifying your own commits, you act only on behalf of | |||||
// yourself, not your packages/projects -- the idea being that | |||||
// you can't accept your own commits. | |||||
$authority_phids = array($actor_phid); | |||||
} else { | |||||
$authority_phids = | |||||
PhabricatorAuditCommentEditor::loadAuditPHIDsForUser( | |||||
$this->requireActor()); | |||||
} | |||||
$authority = array_select_keys( | |||||
$requests, | |||||
$authority_phids); | |||||
if (!$authority) { | |||||
// If the actor has no authority over any existing requests, | |||||
// create a new request for them. | |||||
$actor_request = id(new PhabricatorRepositoryAuditRequest()) | |||||
->setCommitPHID($object->getPHID()) | |||||
->setAuditorPHID($actor_phid) | |||||
->setAuditStatus($new_status) | |||||
->save(); | |||||
$requests[$actor_phid] = $actor_request; | |||||
$object->attachAudits($requests); | |||||
} else { | |||||
// Otherwise, update the audit status of the existing requests. | |||||
foreach ($authority as $request) { | |||||
$request | |||||
->setAuditStatus($new_status) | |||||
->save(); | |||||
} | |||||
} | |||||
break; | |||||
} | |||||
break; | |||||
} | } | ||||
} | } | ||||
$old_status = $object->getAuditStatus(); | $old_status = $object->getAuditStatus(); | ||||
$requests = $object->getAudits(); | $requests = $object->getAudits(); | ||||
$object->updateAuditStatus($requests); | $object->updateAuditStatus($requests); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | switch ($xaction->getTransactionType()) { | ||||
break; | break; | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
if (!$this->didExpandInlineState) { | if (!$this->didExpandInlineState) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorTransactions::TYPE_COMMENT: | case PhabricatorTransactions::TYPE_COMMENT: | ||||
case PhabricatorAuditActionConstants::ACTION: | |||||
$this->didExpandInlineState = true; | $this->didExpandInlineState = true; | ||||
$actor_phid = $this->getActingAsPHID(); | $actor_phid = $this->getActingAsPHID(); | ||||
$actor_is_author = ($object->getAuthorPHID() == $actor_phid); | $actor_is_author = ($object->getAuthorPHID() == $actor_phid); | ||||
if (!$actor_is_author) { | if (!$actor_is_author) { | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | foreach ($xactions as $xaction) { | ||||
} else { | } else { | ||||
$head[] = $xaction; | $head[] = $xaction; | ||||
} | } | ||||
} | } | ||||
return array_values(array_merge($head, $tail)); | return array_values(array_merge($head, $tail)); | ||||
} | } | ||||
protected function validateTransaction( | |||||
PhabricatorLiskDAO $object, | |||||
$type, | |||||
array $xactions) { | |||||
$errors = parent::validateTransaction($object, $type, $xactions); | |||||
foreach ($xactions as $xaction) { | |||||
switch ($type) { | |||||
case PhabricatorAuditActionConstants::ACTION: | |||||
$error = $this->validateAuditAction( | |||||
$object, | |||||
$type, | |||||
$xaction, | |||||
$xaction->getNewValue()); | |||||
if ($error) { | |||||
$errors[] = new PhabricatorApplicationTransactionValidationError( | |||||
$type, | |||||
pht('Invalid'), | |||||
$error, | |||||
$xaction); | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
return $errors; | |||||
} | |||||
private function validateAuditAction( | |||||
PhabricatorLiskDAO $object, | |||||
$type, | |||||
PhabricatorAuditTransaction $xaction, | |||||
$action) { | |||||
$can_author_close_key = 'audit.can-author-close-audit'; | |||||
$can_author_close = PhabricatorEnv::getEnvConfig($can_author_close_key); | |||||
$actor_is_author = ($object->getAuthorPHID()) && | |||||
($object->getAuthorPHID() == $this->getActingAsPHID()); | |||||
switch ($action) { | |||||
case PhabricatorAuditActionConstants::CLOSE: | |||||
if (!$actor_is_author) { | |||||
return pht( | |||||
'You can not close this audit because you are not the author '. | |||||
'of the commit.'); | |||||
} | |||||
if (!$can_author_close) { | |||||
return pht( | |||||
'You can not close this audit because "%s" is disabled in '. | |||||
'the Phabricator configuration.', | |||||
$can_author_close_key); | |||||
} | |||||
break; | |||||
} | |||||
return null; | |||||
} | |||||
protected function supportsSearch() { | protected function supportsSearch() { | ||||
return true; | return true; | ||||
} | } | ||||
protected function expandCustomRemarkupBlockTransactions( | protected function expandCustomRemarkupBlockTransactions( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions, | array $xactions, | ||||
array $changes, | array $changes, | ||||
▲ Show 20 Lines • Show All 447 Lines • Show Last 20 Lines |