Changeset View
Changeset View
Standalone View
Standalone View
src/applications/audit/editor/PhabricatorAuditCommentEditor.php
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public function addComments(array $comments) { | ||||
// they have authority over to reflect the most recent status. The general | // they have authority over to reflect the most recent status. The general | ||||
// idea here is that if audit has triggered for, e.g., several packages, but | // idea here is that if audit has triggered for, e.g., several packages, but | ||||
// a user owns all of them, they can clear the audit requirement in one go | // a user owns all of them, they can clear the audit requirement in one go | ||||
// without auditing the commit for each trigger. | // without auditing the commit for each trigger. | ||||
$audit_phids = self::loadAuditPHIDsForUser($actor); | $audit_phids = self::loadAuditPHIDsForUser($actor); | ||||
$audit_phids = array_fill_keys($audit_phids, true); | $audit_phids = array_fill_keys($audit_phids, true); | ||||
$requests = id(new PhabricatorRepositoryAuditRequest()) | $requests = $commit->getAudits(); | ||||
->loadAllWhere( | |||||
'commitPHID = %s', | |||||
$commit->getPHID()); | |||||
// TODO: We should validate the action, currently we allow anyone to, e.g., | // TODO: We should validate the action, currently we allow anyone to, e.g., | ||||
// close an audit if they muck with form parameters. I'll followup with this | // close an audit if they muck with form parameters. I'll followup with this | ||||
// and handle the no-effect cases (e.g., closing and already-closed audit). | // and handle the no-effect cases (e.g., closing and already-closed audit). | ||||
$actor_is_author = ($actor->getPHID() == $commit->getAuthorPHID()); | $actor_is_author = ($actor->getPHID() == $commit->getAuthorPHID()); | ||||
// Pick a meaningful action, if we have one. | // Pick a meaningful action, if we have one. | ||||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | if ($action == PhabricatorAuditActionConstants::CLOSE) { | ||||
->setAuditStatus($new_status) | ->setAuditStatus($new_status) | ||||
->setAuditReasons(array('Voluntary Participant')) | ->setAuditReasons(array('Voluntary Participant')) | ||||
->save(); | ->save(); | ||||
$requests[] = $request; | $requests[] = $request; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
$auditors = array(); | |||||
foreach ($comments as $comment) { | |||||
$meta = $comment->getMetadata(); | |||||
$auditor_phids = idx( | |||||
$meta, | |||||
PhabricatorAuditComment::METADATA_ADDED_AUDITORS, | |||||
array()); | |||||
foreach ($auditor_phids as $phid) { | |||||
$auditors[] = $phid; | |||||
} | |||||
} | |||||
$requests_by_auditor = mpull($requests, null, 'getAuditorPHID'); | |||||
$requests_phids = array_keys($requests_by_auditor); | |||||
$auditors = array_diff($auditors, $requests_phids); | |||||
if ($auditors) { | |||||
foreach ($auditors as $auditor_phid) { | |||||
$audit_requested = PhabricatorAuditStatusConstants::AUDIT_REQUESTED; | |||||
$requests[] = id (new PhabricatorRepositoryAuditRequest()) | |||||
->setCommitPHID($commit->getPHID()) | |||||
->setAuditorPHID($auditor_phid) | |||||
->setAuditStatus($audit_requested) | |||||
->setAuditReasons( | |||||
array('Added by '.$actor->getUsername())) | |||||
->save(); | |||||
} | |||||
} | |||||
$commit->updateAuditStatus($requests); | $commit->updateAuditStatus($requests); | ||||
$commit->save(); | $commit->save(); | ||||
$commit->attachAudits($requests); | $commit->attachAudits($requests); | ||||
// Convert old comments into real transactions and apply them with a | // Convert old comments into real transactions and apply them with a | ||||
// normal editor. | // normal editor. | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |