From 4450c908818d8a8948867b4b72cca660fd7e78c4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 17 Jun 2019 10:00:21 -0700 Subject: [PATCH] When triggering audits, respect committer identities when importing commits Summary: Ref T13311. We currently don't use committer identity mappings when triggering audits, so if a user is only associated with an identity via manual mapping we won't treat them as the author. Instead, use the identity and manual mapping if they're available. Test Plan: - Pushed a commit as `xyz `, an address with no corresponding user. - In the UI, manually associated that identity with user `@alice`. - Ran `bin/repository reparse --publish ` to trigger audits and publishing for the commit. - Before: observed the `$author_phid` was `null`. - After: observed the `$author_phid` is Alice. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13311 Differential Revision: https://secure.phabricator.com/D20580 --- .../storage/PhabricatorRepositoryCommit.php | 12 ++++++++++++ .../PhabricatorRepositoryCommitPublishWorker.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/applications/repository/storage/PhabricatorRepositoryCommit.php b/src/applications/repository/storage/PhabricatorRepositoryCommit.php index 6b8ac687b3..b5c2fde82a 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryCommit.php +++ b/src/applications/repository/storage/PhabricatorRepositoryCommit.php @@ -466,6 +466,18 @@ final class PhabricatorRepositoryCommit return $data->getCommitDetail('authorPHID'); } + public function getEffectiveAuthorPHID() { + if ($this->hasAuthorIdentity()) { + $identity = $this->getAuthorIdentity(); + if ($identity->hasEffectiveUser()) { + return $identity->getCurrentEffectiveUserPHID(); + } + } + + $data = $this->getCommitData(); + return $data->getCommitDetail('authorPHID'); + } + public function getAuditStatusObject() { $status = $this->getAuditStatus(); return DiffusionCommitAuditStatus::newForStatus($status); diff --git a/src/applications/repository/worker/PhabricatorRepositoryCommitPublishWorker.php b/src/applications/repository/worker/PhabricatorRepositoryCommitPublishWorker.php index 3865050395..0b0a194806 100644 --- a/src/applications/repository/worker/PhabricatorRepositoryCommitPublishWorker.php +++ b/src/applications/repository/worker/PhabricatorRepositoryCommitPublishWorker.php @@ -147,7 +147,7 @@ final class PhabricatorRepositoryCommitPublishWorker $data = $commit->getCommitData(); - $author_phid = $data->getCommitDetail('authorPHID'); + $author_phid = $commit->getEffectiveAuthorPHID(); $revision = DiffusionCommitRevisionQuery::loadRevisionForCommit( $viewer,