Changeset View
Changeset View
Standalone View
Standalone View
src/applications/audit/editor/PhabricatorAuditCommentEditor.php
| Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | foreach ($comments as $comment) { | ||||
| case PhabricatorAuditActionConstants::RESIGN: | case PhabricatorAuditActionConstants::RESIGN: | ||||
| case PhabricatorAuditActionConstants::ACCEPT: | case PhabricatorAuditActionConstants::ACCEPT: | ||||
| case PhabricatorAuditActionConstants::CONCERN: | case PhabricatorAuditActionConstants::CONCERN: | ||||
| $action = $comment->getAction(); | $action = $comment->getAction(); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| $add_self_cc = false; | |||||
| if ($action == PhabricatorAuditActionConstants::CLOSE) { | if ($action == PhabricatorAuditActionConstants::CLOSE) { | ||||
| if (!PhabricatorEnv::getEnvConfig('audit.can-author-close-audit')) { | if (!PhabricatorEnv::getEnvConfig('audit.can-author-close-audit')) { | ||||
| throw new Exception('Cannot Close Audit without enabling'. | throw new Exception('Cannot Close Audit without enabling'. | ||||
| 'audit.can-author-close-audit'); | 'audit.can-author-close-audit'); | ||||
| } | } | ||||
| // "Close" means wipe out all the concerns. | // "Close" means wipe out all the concerns. | ||||
| $concerned_status = PhabricatorAuditStatusConstants::CONCERNED; | $concerned_status = PhabricatorAuditStatusConstants::CONCERNED; | ||||
| foreach ($requests as $request) { | foreach ($requests as $request) { | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | if ($action == PhabricatorAuditActionConstants::CLOSE) { | ||||
| } | } | ||||
| // If the actor has no current authority over any audit trigger, make a | // If the actor has no current authority over any audit trigger, make a | ||||
| // new one to represent their audit state. | // new one to represent their audit state. | ||||
| if (!$have_any_requests) { | if (!$have_any_requests) { | ||||
| $new_status = null; | $new_status = null; | ||||
| switch ($action) { | switch ($action) { | ||||
| case PhabricatorAuditActionConstants::COMMENT: | case PhabricatorAuditActionConstants::COMMENT: | ||||
| case PhabricatorAuditActionConstants::ADD_CCS: | |||||
| case PhabricatorAuditActionConstants::ADD_AUDITORS: | case PhabricatorAuditActionConstants::ADD_AUDITORS: | ||||
| $new_status = PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED; | case PhabricatorAuditActionConstants::ADD_CCS: | ||||
| $add_self_cc = true; | |||||
| break; | break; | ||||
| case PhabricatorAuditActionConstants::ACCEPT: | case PhabricatorAuditActionConstants::ACCEPT: | ||||
| $new_status = PhabricatorAuditStatusConstants::ACCEPTED; | $new_status = PhabricatorAuditStatusConstants::ACCEPTED; | ||||
| break; | break; | ||||
| case PhabricatorAuditActionConstants::CONCERN: | case PhabricatorAuditActionConstants::CONCERN: | ||||
| $new_status = PhabricatorAuditStatusConstants::CONCERNED; | $new_status = PhabricatorAuditStatusConstants::CONCERNED; | ||||
| break; | break; | ||||
| case PhabricatorAuditActionConstants::CLOSE: | case PhabricatorAuditActionConstants::CLOSE: | ||||
| // Impossible to reach this block with 'close'. | // Impossible to reach this block with 'close'. | ||||
| default: | default: | ||||
| throw new Exception("Unknown or invalid action '{$action}'!"); | throw new Exception("Unknown or invalid action '{$action}'!"); | ||||
| } | } | ||||
| if ($new_status !== null) { | |||||
| $request = id(new PhabricatorRepositoryAuditRequest()) | $request = id(new PhabricatorRepositoryAuditRequest()) | ||||
| ->setCommitPHID($commit->getPHID()) | ->setCommitPHID($commit->getPHID()) | ||||
| ->setAuditorPHID($actor->getPHID()) | ->setAuditorPHID($actor->getPHID()) | ||||
| ->setAuditStatus($new_status) | ->setAuditStatus($new_status) | ||||
| ->setAuditReasons(array('Voluntary Participant')) | ->setAuditReasons(array('Voluntary Participant')) | ||||
| ->save(); | ->save(); | ||||
| $requests[] = $request; | $requests[] = $request; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| $auditors = array(); | $auditors = array(); | ||||
| $ccs = array(); | $ccs = array(); | ||||
| if ($add_self_cc) { | |||||
| $ccs[] = $actor->getPHID(); | |||||
| } | |||||
| foreach ($comments as $comment) { | foreach ($comments as $comment) { | ||||
| $meta = $comment->getMetadata(); | $meta = $comment->getMetadata(); | ||||
| $auditor_phids = idx( | $auditor_phids = idx( | ||||
| $meta, | $meta, | ||||
| PhabricatorAuditComment::METADATA_ADDED_AUDITORS, | PhabricatorAuditComment::METADATA_ADDED_AUDITORS, | ||||
| array()); | array()); | ||||
| foreach ($auditor_phids as $phid) { | foreach ($auditor_phids as $phid) { | ||||
| Show All 23 Lines | if ($auditors) { | ||||
| ->setAuditorPHID($auditor_phid) | ->setAuditorPHID($auditor_phid) | ||||
| ->setAuditStatus($audit_requested) | ->setAuditStatus($audit_requested) | ||||
| ->setAuditReasons( | ->setAuditReasons( | ||||
| array('Added by '.$actor->getUsername())) | array('Added by '.$actor->getUsername())) | ||||
| ->save(); | ->save(); | ||||
| } | } | ||||
| } | } | ||||
| $commit->updateAuditStatus($requests); | |||||
| $commit->save(); | |||||
| if ($ccs) { | if ($ccs) { | ||||
| foreach ($ccs as $cc_phid) { | id(new PhabricatorSubscriptionsEditor()) | ||||
| $audit_cc = PhabricatorAuditStatusConstants::CC; | ->setActor($actor) | ||||
| $requests[] = id (new PhabricatorRepositoryAuditRequest()) | ->setObject($commit) | ||||
| ->setCommitPHID($commit->getPHID()) | ->subscribeExplicit($ccs) | ||||
| ->setAuditorPHID($cc_phid) | |||||
| ->setAuditStatus($audit_cc) | |||||
| ->setAuditReasons( | |||||
| array('Added by '.$actor->getUsername())) | |||||
| ->save(); | ->save(); | ||||
| } | } | ||||
| } | |||||
| $commit->updateAuditStatus($requests); | |||||
| $commit->save(); | |||||
| $content_source = PhabricatorContentSource::newForSource( | $content_source = PhabricatorContentSource::newForSource( | ||||
| PhabricatorContentSource::SOURCE_LEGACY, | PhabricatorContentSource::SOURCE_LEGACY, | ||||
| array()); | array()); | ||||
| foreach ($comments as $comment) { | foreach ($comments as $comment) { | ||||
| $comment | $comment | ||||
| ->setActorPHID($actor->getPHID()) | ->setActorPHID($actor->getPHID()) | ||||
| Show All 13 Lines | foreach ($inline_comments as $inline) { | ||||
| $comments[] = $xaction; | $comments[] = $xaction; | ||||
| } | } | ||||
| $feed_dont_publish_phids = array(); | $feed_dont_publish_phids = array(); | ||||
| foreach ($requests as $request) { | foreach ($requests as $request) { | ||||
| $status = $request->getAuditStatus(); | $status = $request->getAuditStatus(); | ||||
| switch ($status) { | switch ($status) { | ||||
| case PhabricatorAuditStatusConstants::RESIGNED: | case PhabricatorAuditStatusConstants::RESIGNED: | ||||
| case PhabricatorAuditStatusConstants::NONE: | case PhabricatorAuditStatusConstants::NONE: | ||||
| case PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED: | case PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED: | ||||
| case PhabricatorAuditStatusConstants::CC: | |||||
| $feed_dont_publish_phids[$request->getAuditorPHID()] = 1; | $feed_dont_publish_phids[$request->getAuditorPHID()] = 1; | ||||
| break; | break; | ||||
| default: | default: | ||||
| unset($feed_dont_publish_phids[$request->getAuditorPHID()]); | unset($feed_dont_publish_phids[$request->getAuditorPHID()]); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| $feed_dont_publish_phids = array_keys($feed_dont_publish_phids); | $feed_dont_publish_phids = array_keys($feed_dont_publish_phids); | ||||
| $feed_phids = array_diff($requests_phids, $feed_dont_publish_phids); | $feed_phids = array_diff($requests_phids, $feed_dont_publish_phids); | ||||
| foreach ($comments as $comment) { | foreach ($comments as $comment) { | ||||
| $this->publishFeedStory($comment, $feed_phids); | $this->publishFeedStory($comment, $feed_phids); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | private function sendMail( | ||||
| if ($author_phid) { | if ($author_phid) { | ||||
| $email_to[$author_phid] = true; | $email_to[$author_phid] = true; | ||||
| } | } | ||||
| foreach ($other_comments as $other_comment) { | foreach ($other_comments as $other_comment) { | ||||
| $email_cc[$other_comment->getActorPHID()] = true; | $email_cc[$other_comment->getActorPHID()] = true; | ||||
| } | } | ||||
| $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( | |||||
| $commit->getPHID()); | |||||
| foreach ($subscribers as $subscriber) { | |||||
| $email_cc[$subscriber] = true; | |||||
| } | |||||
| foreach ($requests as $request) { | foreach ($requests as $request) { | ||||
| switch ($request->getAuditStatus()) { | switch ($request->getAuditStatus()) { | ||||
| case PhabricatorAuditStatusConstants::CC: | |||||
| case PhabricatorAuditStatusConstants::AUDIT_REQUIRED: | case PhabricatorAuditStatusConstants::AUDIT_REQUIRED: | ||||
| $email_cc[$request->getAuditorPHID()] = true; | $email_cc[$request->getAuditorPHID()] = true; | ||||
| break; | break; | ||||
| case PhabricatorAuditStatusConstants::RESIGNED: | case PhabricatorAuditStatusConstants::RESIGNED: | ||||
| unset($email_cc[$request->getAuditorPHID()]); | unset($email_cc[$request->getAuditorPHID()]); | ||||
| break; | break; | ||||
| case PhabricatorAuditStatusConstants::CONCERNED: | case PhabricatorAuditStatusConstants::CONCERNED: | ||||
| case PhabricatorAuditStatusConstants::AUDIT_REQUESTED: | case PhabricatorAuditStatusConstants::AUDIT_REQUESTED: | ||||
| ▲ Show 20 Lines • Show All 126 Lines • Show Last 20 Lines | |||||