mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-28 09:42:41 +01:00
2f8e409876
Summary: Ref T9132. Ref T9908. This attempts to move us forward on answering this question: > Which form gets used when a user clicks "Edit Task"? One answer is "the same form that was used to create the task". There are several problems with that: - The form might not exist anymore. - The user might not have permission to see it. - Some of the fields might be hidden, essentially preventing them from being edited. - We have to store the value somewhere and old tasks won't have a value. - Any instructions on the form probably don't apply to edits. One answer is "force the default, full form". That's not as problematic, but it means we have no ability to create limited access users who see fewer fields. The answer in this diff is: - Forms can be marked as "edit forms". - We take the user to the first edit form they have permission to see, from a master list. This allows you to create several forms like: - Advanced Edit Form (say, all fields -- visible to administrators). - Basic Edit Form (say, no policies -- visible to trusted users). - Noob Edit Form (say, no policies, priorities, or status -- visible to everyone). Then you can give everyone access to "noob", some people access to "basic", and a few people access to "advanced". This might only be part of the answer. In particular, you can still //use// any edit form you can see, so we could do these things in the future: - Give you an option to switch to a different form if you want. - Save the form the task was created with, and use that form by default. If we do pursue those, we can fall back to this behavior if there's a problem with them (e.g., original form doesn't exist or wasn't recorded). There's also no "reorder" UI yet, that'll be coming in the next diff. I'm also going to try to probably make the "create" and "edit" stuff a little more consistent / less weird in a bit. Test Plan: Marked various forms as edit forms or not edit forms, made edits, hit permissions errors, etc. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9132, T9908 Differential Revision: https://secure.phabricator.com/D14702
145 lines
3.5 KiB
PHP
145 lines
3.5 KiB
PHP
<?php
|
|
|
|
final class PhabricatorEditEngineConfigurationSearchEngine
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
private $engineKey;
|
|
|
|
public function setEngineKey($engine_key) {
|
|
$this->engineKey = $engine_key;
|
|
return $this;
|
|
}
|
|
|
|
public function getEngineKey() {
|
|
return $this->engineKey;
|
|
}
|
|
|
|
public function canUseInPanelContext() {
|
|
return false;
|
|
}
|
|
|
|
public function getResultTypeDescription() {
|
|
return pht('Forms');
|
|
}
|
|
|
|
public function getApplicationClassName() {
|
|
return 'PhabricatorTransactionsApplication';
|
|
}
|
|
|
|
public function newQuery() {
|
|
return id(new PhabricatorEditEngineConfigurationQuery())
|
|
->withEngineKeys(array($this->getEngineKey()));
|
|
}
|
|
|
|
protected function buildQueryFromParameters(array $map) {
|
|
$query = $this->newQuery();
|
|
|
|
$is_create = $map['isCreate'];
|
|
if ($is_create !== null) {
|
|
$query->withIsDefault($is_create);
|
|
}
|
|
|
|
$is_edit = $map['isEdit'];
|
|
if ($is_edit !== null) {
|
|
$query->withIsEdit($is_edit);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
protected function buildCustomSearchFields() {
|
|
return array(
|
|
id(new PhabricatorSearchThreeStateField())
|
|
->setLabel(pht('Create'))
|
|
->setKey('isCreate')
|
|
->setOptions(
|
|
pht('Show All'),
|
|
pht('Hide Create Forms'),
|
|
pht('Show Only Create Forms')),
|
|
id(new PhabricatorSearchThreeStateField())
|
|
->setLabel(pht('Edit'))
|
|
->setKey('isEdit')
|
|
->setOptions(
|
|
pht('Show All'),
|
|
pht('Hide Edit Forms'),
|
|
pht('Show Only Edit Forms')),
|
|
);
|
|
}
|
|
|
|
protected function getDefaultFieldOrder() {
|
|
return array();
|
|
}
|
|
|
|
protected function getURI($path) {
|
|
return '/transactions/editengine/'.$this->getEngineKey().'/'.$path;
|
|
}
|
|
|
|
protected function getBuiltinQueryNames() {
|
|
$names = array(
|
|
'all' => pht('All Forms'),
|
|
'create' => pht('Create Forms'),
|
|
'modify' => pht('Edit Forms'),
|
|
);
|
|
|
|
return $names;
|
|
}
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
$query = $this->newSavedQuery();
|
|
$query->setQueryKey($query_key);
|
|
|
|
switch ($query_key) {
|
|
case 'all':
|
|
return $query;
|
|
case 'create':
|
|
return $query->setParameter('isCreate', true);
|
|
case 'modify':
|
|
return $query->setParameter('isEdit', true);
|
|
}
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
}
|
|
|
|
protected function renderResultList(
|
|
array $configs,
|
|
PhabricatorSavedQuery $query,
|
|
array $handles) {
|
|
assert_instances_of($configs, 'PhabricatorEditEngineConfiguration');
|
|
$viewer = $this->requireViewer();
|
|
$engine_key = $this->getEngineKey();
|
|
|
|
$list = id(new PHUIObjectItemListView())
|
|
->setUser($viewer);
|
|
foreach ($configs as $config) {
|
|
$item = id(new PHUIObjectItemView())
|
|
->setHeader($config->getDisplayName());
|
|
|
|
$id = $config->getID();
|
|
if ($id) {
|
|
$item->setObjectName(pht('Form %d', $id));
|
|
$key = $id;
|
|
} else {
|
|
$item->setObjectName(pht('Builtin'));
|
|
$key = $config->getBuiltinKey();
|
|
}
|
|
$item->setHref("/transactions/editengine/{$engine_key}/view/{$key}/");
|
|
|
|
if ($config->getIsDefault()) {
|
|
$item->addIcon('fa-plus', pht('Default'));
|
|
}
|
|
|
|
if ($config->getIsEdit()) {
|
|
$item->addIcon('fa-pencil', pht('Edit Form'));
|
|
}
|
|
|
|
if ($config->getIsDisabled()) {
|
|
$item->addIcon('fa-ban', pht('Disabled'));
|
|
}
|
|
|
|
$list->addItem($item);
|
|
}
|
|
|
|
return id(new PhabricatorApplicationSearchResultView())
|
|
->setObjectList($list);
|
|
}
|
|
}
|