1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-22 19:49:02 +01:00

When editing a subtyped object, use edit forms of the same subtype

Summary:
Ref T12314. When we pick an "Edit" form for a subtyped object, only consider forms with the same subtype.

For example, editing an "Animal" uses the forms with subtype "animal" which are marked as edit forms.

This also makes "Create Subtask" carry the parent task's type.

Test Plan:
  - Edited an Animal, got an animal edit form.
  - Edited a normal task, got a normal task form.
  - Edited a paste, got the normal workflow.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12314

Differential Revision: https://secure.phabricator.com/D17445
This commit is contained in:
epriestley 2017-03-01 17:01:21 -08:00
parent 4948a21959
commit 7eab75410a
4 changed files with 44 additions and 11 deletions

View file

@ -267,7 +267,7 @@ final class ManiphestTaskDetailController extends ManiphestController {
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$edit_config = $edit_engine->loadDefaultEditConfiguration();
$edit_config = $edit_engine->loadDefaultEditConfiguration($task);
$can_create = (bool)$edit_config;
$can_reassign = $edit_engine->hasEditAccessToTransaction(

View file

@ -910,7 +910,7 @@ final class PhabricatorProjectBoardViewController
// for each column or board?
$edit_config = id(new ManiphestEditEngine())
->setViewer($viewer)
->loadDefaultEditConfiguration();
->loadDefaultEditConfiguration(new ManiphestTask());
if ($edit_config) {
$form_key = $edit_config->getIdentifier();
$create_uri = "/maniphest/task/edit/form/{$form_key}/";

View file

@ -408,11 +408,20 @@ abstract class PhabricatorEditEngine
'getCreateSortKey');
}
public function loadDefaultEditConfiguration() {
public function loadDefaultEditConfiguration($object) {
$query = $this->newConfigurationQuery()
->withIsEdit(true)
->withIsDisabled(false);
// If this object supports subtyping, we edit it with a form of the same
// subtype: so "bug" tasks get edited with "bug" forms.
if ($object instanceof PhabricatorEditEngineSubtypeInterface) {
$query->withSubtypes(
array(
$object->getEditEngineSubtype(),
));
}
return $this->loadEditEngineConfigurationWithQuery(
$query,
'getEditSortKey');
@ -891,7 +900,7 @@ abstract class PhabricatorEditEngine
}
} else {
if ($id) {
$config = $this->loadDefaultEditConfiguration();
$config = $this->loadDefaultEditConfiguration($object);
if (!$config) {
return $this->buildNoEditResponse($object);
}
@ -1370,16 +1379,16 @@ abstract class PhabricatorEditEngine
final public function hasEditAccessToTransaction($xaction_type) {
$viewer = $this->getViewer();
$config = $this->loadDefaultEditConfiguration();
if (!$config) {
return false;
}
$object = $this->getTargetObject();
if (!$object) {
$object = $this->newEditableObject();
}
$config = $this->loadDefaultEditConfiguration($object);
if (!$config) {
return false;
}
$fields = $this->buildEditFields($object);
$field = null;
@ -1535,7 +1544,7 @@ abstract class PhabricatorEditEngine
}
final public function buildEditEngineCommentView($object) {
$config = $this->loadDefaultEditConfiguration();
$config = $this->loadDefaultEditConfiguration($object);
if (!$config) {
// TODO: This just nukes the entire comment form if you don't have access
@ -1755,7 +1764,7 @@ abstract class PhabricatorEditEngine
return new Aphront400Response();
}
$config = $this->loadDefaultEditConfiguration();
$config = $this->loadDefaultEditConfiguration($object);
if (!$config) {
return new Aphront404Response();
}

View file

@ -12,6 +12,7 @@ final class PhabricatorEditEngineConfigurationQuery
private $isEdit;
private $disabled;
private $ignoreDatabaseConfigurations;
private $subtypes;
public function withIDs(array $ids) {
$this->ids = $ids;
@ -58,6 +59,11 @@ final class PhabricatorEditEngineConfigurationQuery
return $this;
}
public function withSubtypes(array $subtypes) {
$this->subtypes = $subtypes;
return $this;
}
public function newResultObject() {
return new PhabricatorEditEngineConfiguration();
}
@ -183,6 +189,17 @@ final class PhabricatorEditEngineConfigurationQuery
}
}
if ($this->subtypes !== null) {
$subtypes = array_fuse($this->subtypes);
foreach ($page as $key => $config) {
if (isset($subtypes[$config->getSubtype()])) {
continue;
}
unset($page[$key]);
}
}
return $page;
}
@ -250,6 +267,13 @@ final class PhabricatorEditEngineConfigurationQuery
$this->identifiers);
}
if ($this->subtypes !== null) {
$where[] = qsprintf(
$conn,
'subtype IN (%Ls)',
$this->subtypes);
}
return $where;
}