1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-17 01:08:41 +01:00

Fix an issue where the Herald test console doesn't work with "Content source" rules

Summary:
Ref T13130. See PHI619. Currently, the Herald "Test Console" doesn't pass a "Content Source" to the adapter, so if any rules of the given type execute a "Content source" field rule, they'll fatal.

Provide a content source:

  - If possible, use the content source from the most recent transaction.
  - Otherwise, build a default "web" content source from the current request.

Test Plan:
  - Wrote a "When [content source][is][whatever]" rule for tasks.
  - Ran test console against a task.
  - Before: got a fatal trying to interact with the content source.
  - After: transcript reports sensible content source.
    - Also commented out the "xaction" logic to test the fallback behavior.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13130

Differential Revision: https://secure.phabricator.com/D19411
This commit is contained in:
epriestley 2018-04-27 11:13:00 -07:00
parent 223d7b84dd
commit d40007aa32

View file

@ -38,8 +38,10 @@ final class HeraldTestConsoleController extends HeraldController {
$object = $this->getTestObject();
$adapter = $this->getTestAdapter();
$source = $this->newContentSource($object);
$adapter
->setContentSource($source)
->setIsNewObject(false)
->setActingAsPHID($viewer->getPHID())
->setViewer($viewer);
@ -218,4 +220,29 @@ final class HeraldTestConsoleController extends HeraldController {
->appendChild($view);
}
private function newContentSource($object) {
$viewer = $this->getViewer();
// Try using the content source associated with the most recent transaction
// on the object.
$query = PhabricatorApplicationTransactionQuery::newQueryForObject($object);
$xaction = $query
->setViewer($viewer)
->withObjectPHIDs(array($object->getPHID()))
->setLimit(1)
->setOrder('newest')
->executeOne();
if ($xaction) {
return $xaction->getContentSource();
}
// If we couldn't find a transaction (which should be rare), fall back to
// building a new content source from the test console request itself.
$request = $this->getRequest();
return PhabricatorContentSource::newFromRequest($request);
}
}