1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

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
This commit is contained in:
epriestley 2018-02-08 09:36:47 -08:00
parent 6186f0aa91
commit bca9c08953
6 changed files with 51 additions and 1 deletions

View file

@ -1346,6 +1346,7 @@ phutil_register_library_map(array(
'HarbormasterWaitForPreviousBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterWaitForPreviousBuildStepImplementation.php', 'HarbormasterWaitForPreviousBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterWaitForPreviousBuildStepImplementation.php',
'HarbormasterWorker' => 'applications/harbormaster/worker/HarbormasterWorker.php', 'HarbormasterWorker' => 'applications/harbormaster/worker/HarbormasterWorker.php',
'HarbormasterWorkingCopyArtifact' => 'applications/harbormaster/artifact/HarbormasterWorkingCopyArtifact.php', 'HarbormasterWorkingCopyArtifact' => 'applications/harbormaster/artifact/HarbormasterWorkingCopyArtifact.php',
'HeraldActingUserField' => 'applications/herald/field/HeraldActingUserField.php',
'HeraldAction' => 'applications/herald/action/HeraldAction.php', 'HeraldAction' => 'applications/herald/action/HeraldAction.php',
'HeraldActionGroup' => 'applications/herald/action/HeraldActionGroup.php', 'HeraldActionGroup' => 'applications/herald/action/HeraldActionGroup.php',
'HeraldActionRecord' => 'applications/herald/storage/HeraldActionRecord.php', 'HeraldActionRecord' => 'applications/herald/storage/HeraldActionRecord.php',
@ -6589,6 +6590,7 @@ phutil_register_library_map(array(
'HarbormasterWaitForPreviousBuildStepImplementation' => 'HarbormasterBuildStepImplementation', 'HarbormasterWaitForPreviousBuildStepImplementation' => 'HarbormasterBuildStepImplementation',
'HarbormasterWorker' => 'PhabricatorWorker', 'HarbormasterWorker' => 'PhabricatorWorker',
'HarbormasterWorkingCopyArtifact' => 'HarbormasterDrydockLeaseArtifact', 'HarbormasterWorkingCopyArtifact' => 'HarbormasterDrydockLeaseArtifact',
'HeraldActingUserField' => 'HeraldField',
'HeraldAction' => 'Phobject', 'HeraldAction' => 'Phobject',
'HeraldActionGroup' => 'HeraldGroup', 'HeraldActionGroup' => 'HeraldGroup',
'HeraldActionRecord' => 'HeraldDAO', 'HeraldActionRecord' => 'HeraldDAO',

View file

@ -297,7 +297,11 @@ final class DiffusionCommitHookEngine extends Phobject {
return; return;
} }
$adapter_template->setHookEngine($this); $viewer = $this->getViewer();
$adapter_template
->setHookEngine($this)
->setActingAsPHID($viewer->getPHID());
$engine = new HeraldEngine(); $engine = new HeraldEngine();
$rules = null; $rules = null;

View file

@ -40,6 +40,7 @@ abstract class HeraldAdapter extends Phobject {
private $forbiddenActions = array(); private $forbiddenActions = array();
private $viewer; private $viewer;
private $mustEncryptReasons = array(); private $mustEncryptReasons = array();
private $actingAsPHID;
public function getEmailPHIDs() { public function getEmailPHIDs() {
return array_values($this->emailPHIDs); return array_values($this->emailPHIDs);
@ -49,6 +50,15 @@ abstract class HeraldAdapter extends Phobject {
return array_values($this->forcedEmailPHIDs); 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) { public function addEmailPHID($phid, $force) {
$this->emailPHIDs[$phid] = $phid; $this->emailPHIDs[$phid] = $phid;
if ($force) { if ($force) {

View file

@ -41,6 +41,7 @@ final class HeraldTestConsoleController extends HeraldController {
$adapter $adapter
->setIsNewObject(false) ->setIsNewObject(false)
->setActingAsPHID($viewer->getPHID())
->setViewer($viewer); ->setViewer($viewer);
$rules = id(new HeraldRuleQuery()) $rules = id(new HeraldRuleQuery())

View file

@ -0,0 +1,32 @@
<?php
final class HeraldActingUserField
extends HeraldField {
const FIELDCONST = 'herald.acting-user';
public function getHeraldFieldName() {
return pht('Acting user');
}
public function getHeraldFieldValue($object) {
return $this->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;
}
}

View file

@ -3254,6 +3254,7 @@ abstract class PhabricatorApplicationTransactionEditor
$adapter = $this->buildHeraldAdapter($object, $xactions) $adapter = $this->buildHeraldAdapter($object, $xactions)
->setContentSource($this->getContentSource()) ->setContentSource($this->getContentSource())
->setIsNewObject($this->getIsNewObject()) ->setIsNewObject($this->getIsNewObject())
->setActingAsPHID($this->getActingAsPHID())
->setAppliedTransactions($xactions); ->setAppliedTransactions($xactions);
if ($this->getApplicationEmail()) { if ($this->getApplicationEmail()) {