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

Don't allow forms which can't create objects to be added to profile menus

Summary:
Fixes T12281. Some forms (like Settings) can't actually create new objects. Currently, though, you can select them and add them to profile menus; if you do, they fail when building an item.

Kick them out of the typeahead, and decline to render them in menus.

Test Plan:
Added "Create Settings" to a menu, no longer fatals after patch (item vanished from menu, still editable normally to get rid of it).

Tried to add another "Create Settings", no longer available in typehaead.

Added some normal stuff.

Viewed a choose-among-forms dropdown in Maniphest, which still worked normally.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12281

Differential Revision: https://secure.phabricator.com/D17372
This commit is contained in:
epriestley 2017-02-16 15:14:11 -08:00
parent b11138a16b
commit b2739710ba
4 changed files with 25 additions and 5 deletions

View file

@ -106,12 +106,14 @@ final class PhabricatorEditEngineProfileMenuItem
if (!$form) { if (!$form) {
return array(); return array();
} }
$engine = $form->getEngine();
$form_key = $form->getIdentifier();
$icon = $form->getIcon(); $icon = $form->getIcon();
$name = $this->getDisplayName($config); $name = $this->getDisplayName($config);
$href = $engine->getEditURI(null, "form/{$form_key}/");
$href = $form->getCreateURI();
if ($href === null) {
return array();
}
$item = $this->newItem() $item = $this->newItem()
->setHref($href) ->setHref($href)

View file

@ -1489,8 +1489,7 @@ abstract class PhabricatorEditEngine
); );
} else { } else {
foreach ($configs as $config) { foreach ($configs as $config) {
$form_key = $config->getIdentifier(); $config_uri = $config->getCreateURI();
$config_uri = $this->getEditURI(null, "form/{$form_key}/");
if ($parameters) { if ($parameters) {
$config_uri = (string)id(new PhutilURI($config_uri)) $config_uri = (string)id(new PhutilURI($config_uri))

View file

@ -216,6 +216,19 @@ final class PhabricatorEditEngineConfiguration
return "/transactions/editengine/{$engine_key}/view/{$key}/"; return "/transactions/editengine/{$engine_key}/view/{$key}/";
} }
public function getCreateURI() {
$form_key = $this->getIdentifier();
$engine = $this->getEngine();
try {
$create_uri = $engine->getEditURI(null, "form/{$form_key}/");
} catch (Exception $ex) {
$create_uri = null;
}
return $create_uri;
}
public function getIdentifier() { public function getIdentifier() {
$key = $this->getID(); $key = $this->getID();
if (!$key) { if (!$key) {

View file

@ -30,11 +30,17 @@ final class PhabricatorEditEngineDatasource
$forms = $this->executeQuery($query); $forms = $this->executeQuery($query);
$results = array(); $results = array();
foreach ($forms as $form) { foreach ($forms as $form) {
$create_uri = $form->getCreateURI();
if (!$create_uri) {
continue;
}
if ($form->getID()) { if ($form->getID()) {
$key = $form->getEngineKey().'/'.$form->getID(); $key = $form->getEngineKey().'/'.$form->getID();
} else { } else {
$key = $form->getEngineKey().'/'.$form->getBuiltinKey(); $key = $form->getEngineKey().'/'.$form->getBuiltinKey();
} }
$result = id(new PhabricatorTypeaheadResult()) $result = id(new PhabricatorTypeaheadResult())
->setName($form->getName()) ->setName($form->getName())
->setPHID($key) ->setPHID($key)