From bca9c08953bd40c0c534f7d94651e37c3513af85 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 8 Feb 2018 09:36:47 -0800 Subject: [PATCH] Add an "Acting user" field to Herald Summary: Ref T13053. Fixes T7804. Adds "Acting user" so you can have "always email me" stuff skip things you did or keep an eye on suspicious interns. For the test console, the current user is the acting user. For pushes, the pusher is the acting user. Test Plan: Wrote acting user rules, triggered them via test console and via multiple actors on real objects. Maniphest Tasks: T13053, T7804 Differential Revision: https://secure.phabricator.com/D19031 --- src/__phutil_library_map__.php | 2 ++ .../engine/DiffusionCommitHookEngine.php | 6 +++- .../herald/adapter/HeraldAdapter.php | 10 ++++++ .../HeraldTestConsoleController.php | 1 + .../herald/field/HeraldActingUserField.php | 32 +++++++++++++++++++ ...habricatorApplicationTransactionEditor.php | 1 + 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/applications/herald/field/HeraldActingUserField.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 301459869f..73632d11b4 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1346,6 +1346,7 @@ phutil_register_library_map(array( 'HarbormasterWaitForPreviousBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterWaitForPreviousBuildStepImplementation.php', 'HarbormasterWorker' => 'applications/harbormaster/worker/HarbormasterWorker.php', 'HarbormasterWorkingCopyArtifact' => 'applications/harbormaster/artifact/HarbormasterWorkingCopyArtifact.php', + 'HeraldActingUserField' => 'applications/herald/field/HeraldActingUserField.php', 'HeraldAction' => 'applications/herald/action/HeraldAction.php', 'HeraldActionGroup' => 'applications/herald/action/HeraldActionGroup.php', 'HeraldActionRecord' => 'applications/herald/storage/HeraldActionRecord.php', @@ -6589,6 +6590,7 @@ phutil_register_library_map(array( 'HarbormasterWaitForPreviousBuildStepImplementation' => 'HarbormasterBuildStepImplementation', 'HarbormasterWorker' => 'PhabricatorWorker', 'HarbormasterWorkingCopyArtifact' => 'HarbormasterDrydockLeaseArtifact', + 'HeraldActingUserField' => 'HeraldField', 'HeraldAction' => 'Phobject', 'HeraldActionGroup' => 'HeraldGroup', 'HeraldActionRecord' => 'HeraldDAO', diff --git a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php index 99df0e54af..a0769a51f0 100644 --- a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php +++ b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php @@ -297,7 +297,11 @@ final class DiffusionCommitHookEngine extends Phobject { return; } - $adapter_template->setHookEngine($this); + $viewer = $this->getViewer(); + + $adapter_template + ->setHookEngine($this) + ->setActingAsPHID($viewer->getPHID()); $engine = new HeraldEngine(); $rules = null; diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index cc0fdbd3b5..940d604019 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -40,6 +40,7 @@ abstract class HeraldAdapter extends Phobject { private $forbiddenActions = array(); private $viewer; private $mustEncryptReasons = array(); + private $actingAsPHID; public function getEmailPHIDs() { return array_values($this->emailPHIDs); @@ -49,6 +50,15 @@ abstract class HeraldAdapter extends Phobject { return array_values($this->forcedEmailPHIDs); } + final public function setActingAsPHID($acting_as_phid) { + $this->actingAsPHID = $acting_as_phid; + return $this; + } + + final public function getActingAsPHID() { + return $this->actingAsPHID; + } + public function addEmailPHID($phid, $force) { $this->emailPHIDs[$phid] = $phid; if ($force) { diff --git a/src/applications/herald/controller/HeraldTestConsoleController.php b/src/applications/herald/controller/HeraldTestConsoleController.php index 8a7a94963d..4ddab2669b 100644 --- a/src/applications/herald/controller/HeraldTestConsoleController.php +++ b/src/applications/herald/controller/HeraldTestConsoleController.php @@ -41,6 +41,7 @@ final class HeraldTestConsoleController extends HeraldController { $adapter ->setIsNewObject(false) + ->setActingAsPHID($viewer->getPHID()) ->setViewer($viewer); $rules = id(new HeraldRuleQuery()) diff --git a/src/applications/herald/field/HeraldActingUserField.php b/src/applications/herald/field/HeraldActingUserField.php new file mode 100644 index 0000000000..2245c7e9f7 --- /dev/null +++ b/src/applications/herald/field/HeraldActingUserField.php @@ -0,0 +1,32 @@ +getAdapter()->getActingAsPHID(); + } + + protected function getHeraldFieldStandardType() { + return self::STANDARD_PHID; + } + + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); + } + + public function supportsObject($object) { + return true; + } + + public function getFieldGroupKey() { + return HeraldEditFieldGroup::FIELDGROUPKEY; + } + +} diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php index 167aa05fed..8c319fc61e 100644 --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -3254,6 +3254,7 @@ abstract class PhabricatorApplicationTransactionEditor $adapter = $this->buildHeraldAdapter($object, $xactions) ->setContentSource($this->getContentSource()) ->setIsNewObject($this->getIsNewObject()) + ->setActingAsPHID($this->getActingAsPHID()) ->setAppliedTransactions($xactions); if ($this->getApplicationEmail()) {