1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01: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',
'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',

View file

@ -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;

View file

@ -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) {

View file

@ -41,6 +41,7 @@ final class HeraldTestConsoleController extends HeraldController {
$adapter
->setIsNewObject(false)
->setActingAsPHID($viewer->getPHID())
->setViewer($viewer);
$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)
->setContentSource($this->getContentSource())
->setIsNewObject($this->getIsNewObject())
->setActingAsPHID($this->getActingAsPHID())
->setAppliedTransactions($xactions);
if ($this->getApplicationEmail()) {