1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 10:12:41 +01:00

Fix incorrect construction of subtype map when validating "subtype" transactions against non-subtypable objects

Summary:
Fixes T13389. Currently, we try to "newSubtypeMap()" unconditionally, even if the underlying object does not support subtypes.

  - Only try to build a subtype map if subtype transactions are actually being applied.
  - When subtype transactions are applied to a non-subtypable object, fail more explicitly.

Test Plan: Clicked "Make Editable" in a fresh Calendar transaction form, got an editable form instead of a fatal from "newSubtypeMap()". (Calendar events are not currently subtypable.)

Maniphest Tasks: T13389

Differential Revision: https://secure.phabricator.com/D20741
This commit is contained in:
epriestley 2019-08-27 07:05:11 -07:00
parent 7198bd7db7
commit 0943561dcb

View file

@ -25,11 +25,30 @@ final class PhabricatorEditEngineSubtypeTransaction
} }
public function validateTransactions($object, array $xactions) { public function validateTransactions($object, array $xactions) {
$map = $object->getEngine() $errors = array();
if (!$xactions) {
return $errors;
}
$engine = $object->getEngine();
if (!$engine->supportsSubtypes()) {
foreach ($xactions as $xaction) {
$errors[] = $this->newInvalidError(
pht(
'Edit engine (of class "%s") does not support subtypes, so '.
'subtype transactions can not be applied to it.',
get_class($engine)),
$xaction);
}
return $errors;
}
$map = $engine
->setViewer($this->getActor()) ->setViewer($this->getActor())
->newSubtypeMap(); ->newSubtypeMap();
$errors = array();
foreach ($xactions as $xaction) { foreach ($xactions as $xaction) {
$new = $xaction->getNewValue(); $new = $xaction->getNewValue();