From cfbec38fbed7bd6c20bd6574df67e5d88c8059d1 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 27 Feb 2012 09:53:49 -0800 Subject: [PATCH] When a user makes an audit comment, retroactively trigger an audit Summary: If a user comments on a commit but they don't currently have any audits they're authoritative on, create a new one. This makes it easier to handle other things more consistently, like figuring out the overall audit status of a commit and who should get emails. Test Plan: Made comments on commits I had authority on and did not have authority on. Reviewers: btrahan, jungejason Reviewed By: jungejason CC: aran, epriestley Maniphest Tasks: T904 Differential Revision: https://secure.phabricator.com/D1697 --- .../comment/PhabricatorAuditCommentEditor.php | 27 ++++++++++++++----- .../audit/editor/comment/__init__.php | 1 + 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php b/src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php index 27db026dbe..a274b2221a 100644 --- a/src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php +++ b/src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php @@ -61,19 +61,34 @@ final class PhabricatorAuditCommentEditor { // Status may be empty for updates which don't affect status, like // "comment". - if ($status) { - foreach ($relationships as $relationship) { - if (empty($audit_phids[$relationship->getPackagePHID()])) { - continue; - } + $have_any_relationship = false; + foreach ($relationships as $relationship) { + if (empty($audit_phids[$relationship->getPackagePHID()])) { + continue; + } + $have_any_relationship = true; + if ($status) { $relationship->setAuditStatus($status); $relationship->save(); } } + if (!$have_any_relationship) { + // If the user has no current authority over any audit trigger, make a + // new one to represent their audit state. + $relationship = id(new PhabricatorOwnersPackageCommitRelationship()) + ->setCommitPHID($commit->getPHID()) + ->setPackagePHID($user->getPHID()) + ->setAuditStatus( + $status + ? $status + : PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED) + ->setAuditReasons(array("Voluntary Participant")) + ->save(); + } + $this->publishFeedStory($comment, array_keys($audit_phids)); PhabricatorSearchCommitIndexer::indexCommit($commit); - // TODO: Email. } diff --git a/src/applications/audit/editor/comment/__init__.php b/src/applications/audit/editor/comment/__init__.php index e85ccf3cd2..4fa8bbf9cf 100644 --- a/src/applications/audit/editor/comment/__init__.php +++ b/src/applications/audit/editor/comment/__init__.php @@ -9,6 +9,7 @@ phutil_require_module('phabricator', 'applications/audit/constants/action'); phutil_require_module('phabricator', 'applications/feed/constants/story'); phutil_require_module('phabricator', 'applications/feed/publisher'); +phutil_require_module('phabricator', 'applications/audit/constants/status'); phutil_require_module('phabricator', 'applications/owners/storage/owner'); phutil_require_module('phabricator', 'applications/owners/storage/package'); phutil_require_module('phabricator', 'applications/owners/storage/packagecommitrelationship');