1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 14:30:56 +01:00

Support "Subtype" in Herald

Summary: See PHI1434. For objects that support subtypes and have subtypes configured, allow Herald rules to act on subtypes.

Test Plan:
  - Configured task and project subtypes, wrote Herald rules, saw "Subtypes" as an option, saw appropriate typeahead values and detail page rendering.
  - Unconfigured project subtypes, saw field vanish from UI for new rules.
  - Wrote a "subtype"-depenent rule that added a comment, interacted with tasks of that subtype and a different subtype. Saw Herald act only on tasks with the correct subtype.

Differential Revision: https://secure.phabricator.com/D20809
This commit is contained in:
epriestley 2019-09-12 13:11:18 -07:00
parent d60d4e6a05
commit 3e60128037
5 changed files with 72 additions and 2 deletions

View file

@ -3217,6 +3217,7 @@ phutil_register_library_map(array(
'PhabricatorEditEngineSettingsPanel' => 'applications/settings/panel/PhabricatorEditEngineSettingsPanel.php', 'PhabricatorEditEngineSettingsPanel' => 'applications/settings/panel/PhabricatorEditEngineSettingsPanel.php',
'PhabricatorEditEngineStaticCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineStaticCommentAction.php', 'PhabricatorEditEngineStaticCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineStaticCommentAction.php',
'PhabricatorEditEngineSubtype' => 'applications/transactions/editengine/PhabricatorEditEngineSubtype.php', 'PhabricatorEditEngineSubtype' => 'applications/transactions/editengine/PhabricatorEditEngineSubtype.php',
'PhabricatorEditEngineSubtypeHeraldField' => 'applications/transactions/herald/PhabricatorEditEngineSubtypeHeraldField.php',
'PhabricatorEditEngineSubtypeInterface' => 'applications/transactions/editengine/PhabricatorEditEngineSubtypeInterface.php', 'PhabricatorEditEngineSubtypeInterface' => 'applications/transactions/editengine/PhabricatorEditEngineSubtypeInterface.php',
'PhabricatorEditEngineSubtypeMap' => 'applications/transactions/editengine/PhabricatorEditEngineSubtypeMap.php', 'PhabricatorEditEngineSubtypeMap' => 'applications/transactions/editengine/PhabricatorEditEngineSubtypeMap.php',
'PhabricatorEditEngineSubtypeTestCase' => 'applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php', 'PhabricatorEditEngineSubtypeTestCase' => 'applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php',
@ -9550,6 +9551,7 @@ phutil_register_library_map(array(
'PhabricatorEditEngineSettingsPanel' => 'PhabricatorSettingsPanel', 'PhabricatorEditEngineSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorEditEngineStaticCommentAction' => 'PhabricatorEditEngineCommentAction', 'PhabricatorEditEngineStaticCommentAction' => 'PhabricatorEditEngineCommentAction',
'PhabricatorEditEngineSubtype' => 'Phobject', 'PhabricatorEditEngineSubtype' => 'Phobject',
'PhabricatorEditEngineSubtypeHeraldField' => 'HeraldField',
'PhabricatorEditEngineSubtypeMap' => 'Phobject', 'PhabricatorEditEngineSubtypeMap' => 'Phobject',
'PhabricatorEditEngineSubtypeTestCase' => 'PhabricatorTestCase', 'PhabricatorEditEngineSubtypeTestCase' => 'PhabricatorTestCase',
'PhabricatorEditEngineSubtypeTransaction' => 'PhabricatorEditEngineTransactionType', 'PhabricatorEditEngineSubtypeTransaction' => 'PhabricatorEditEngineTransactionType',

View file

@ -564,7 +564,8 @@ final class ManiphestTask extends ManiphestDAO
public function newEditEngineSubtypeMap() { public function newEditEngineSubtypeMap() {
$config = PhabricatorEnv::getEnvConfig('maniphest.subtypes'); $config = PhabricatorEnv::getEnvConfig('maniphest.subtypes');
return PhabricatorEditEngineSubtype::newSubtypeMap($config); return PhabricatorEditEngineSubtype::newSubtypeMap($config)
->setDatasource(new ManiphestTaskSubtypeDatasource());
} }

View file

@ -904,7 +904,8 @@ final class PhabricatorProject extends PhabricatorProjectDAO
public function newEditEngineSubtypeMap() { public function newEditEngineSubtypeMap() {
$config = PhabricatorEnv::getEnvConfig('projects.subtypes'); $config = PhabricatorEnv::getEnvConfig('projects.subtypes');
return PhabricatorEditEngineSubtype::newSubtypeMap($config); return PhabricatorEditEngineSubtype::newSubtypeMap($config)
->setDatasource(new PhabricatorProjectSubtypeDatasource());
} }
public function newSubtypeObject() { public function newSubtypeObject() {

View file

@ -5,6 +5,7 @@ final class PhabricatorEditEngineSubtypeMap
extends Phobject { extends Phobject {
private $subtypes; private $subtypes;
private $datasource;
public function __construct(array $subtypes) { public function __construct(array $subtypes) {
assert_instances_of($subtypes, 'PhabricatorEditEngineSubtype'); assert_instances_of($subtypes, 'PhabricatorEditEngineSubtype');
@ -39,6 +40,19 @@ final class PhabricatorEditEngineSubtypeMap
return $this->subtypes[$subtype_key]; return $this->subtypes[$subtype_key];
} }
public function setDatasource(PhabricatorTypeaheadDatasource $datasource) {
$this->datasource = $datasource;
return $this;
}
public function newDatasource() {
if (!$this->datasource) {
throw new PhutilInvalidStateException('setDatasource');
}
return clone($this->datasource);
}
public function getCreateFormsForSubtype( public function getCreateFormsForSubtype(
PhabricatorEditEngine $edit_engine, PhabricatorEditEngine $edit_engine,
PhabricatorEditEngineSubtypeInterface $object) { PhabricatorEditEngineSubtypeInterface $object) {

View file

@ -0,0 +1,52 @@
<?php
final class PhabricatorEditEngineSubtypeHeraldField
extends HeraldField {
const FIELDCONST = 'subtype';
public function getHeraldFieldName() {
return pht('Subtype');
}
public function getFieldGroupKey() {
return HeraldSupportFieldGroup::FIELDGROUPKEY;
}
public function supportsObject($object) {
return ($object instanceof PhabricatorEditEngineSubtypeInterface);
}
public function getHeraldFieldValue($object) {
return $object->getEditEngineSubtype();
}
protected function getHeraldFieldStandardType() {
return self::STANDARD_PHID;
}
protected function getDatasource() {
$object = $this->getAdapter()->getObject();
$map = $object->newEditEngineSubtypeMap();
return $map->newDatasource();
}
protected function getDatasourceValueMap() {
$object = $this->getAdapter()->getObject();
$map = $object->newEditEngineSubtypeMap();
$result = array();
foreach ($map->getSubtypes() as $subtype) {
$result[$subtype->getKey()] = $subtype->getName();
}
return $result;
}
public function isFieldAvailable() {
$object = $this->getAdapter()->getObject();
$map = $object->newEditEngineSubtypeMap();
return ($map->getCount() > 1);
}
}