Give the workboard "default" workflows more modern state handling

Summary:
Depends on D20628. Ref T4900. Currently, the "Save Current Order/Filter As Default" flows on workboards duplicate some state construction, and require parameters to be passed to them explicitly.

Now that state management is separate, they can reuse a bit more code and be made to look more like other similar controllers.

Test Plan:
  - Changed the default order of a workboard.
  - Changed the default filter of a workboard.
  - Changed the order of a board to something non-default, then changed the filter, then saved the new filter as the default. Saw the modified order preserved and the modified filter removed, so I ended up in the right ("most correct") place: on the board, with my custom order in a URI parameter, and no filter URI parameter so I could see my new default filter behavior. This is an edge case that's not terribly important to get right, but we do get it right.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T4900

Differential Revision: https://secure.phabricator.com/D20629
This commit is contained in:
epriestley
2019-06-29 15:23:58 -07:00
parent 9c190d68ed
commit 9e096cd274
7 changed files with 63 additions and 43 deletions

View File

@@ -13,7 +13,7 @@ abstract class PhabricatorProjectBoardController
return $this->viewState;
}
final private function newViewState() {
private function newViewState() {
$project = $this->getProject();
$request = $this->getRequest();
@@ -22,4 +22,15 @@ abstract class PhabricatorProjectBoardController
->readFromRequest($request);
}
final protected function newBoardDialog() {
$dialog = $this->newDialog();
$state = $this->getViewState();
foreach ($state->getQueryParameters() as $key => $value) {
$dialog->addHiddenInput($key, $value);
}
return $dialog;
}
}

View File

@@ -1,25 +1,20 @@
<?php
final class PhabricatorProjectDefaultController
final class PhabricatorProjectBoardDefaultController
extends PhabricatorProjectBoardController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$project_id = $request->getURIData('projectID');
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($project_id))
->executeOne();
if (!$project) {
return new Aphront404Response();
$response = $this->loadProjectForEdit();
if ($response) {
return $response;
}
$this->setProject($project);
$project = $this->getProject();
$state = $this->getViewState();
$board_uri = $state->newWorkboardURI();
$remove_param = null;
$target = $request->getURIData('target');
switch ($target) {
@@ -31,8 +26,10 @@ final class PhabricatorProjectDefaultController
'the board.');
$button = pht('Save Default Filter');
$xaction_value = $request->getStr('filter');
$xaction_value = $state->getQueryKey();
$xaction_type = PhabricatorProjectFilterTransaction::TRANSACTIONTYPE;
$remove_param = 'filter';
break;
case 'sort':
$title = pht('Set Board Default Order');
@@ -42,8 +39,10 @@ final class PhabricatorProjectDefaultController
'the board.');
$button = pht('Save Default Order');
$xaction_value = $request->getStr('order');
$xaction_value = $state->getOrder();
$xaction_type = PhabricatorProjectSortTransaction::TRANSACTIONTYPE;
$remove_param = 'order';
break;
default:
return new Aphront404Response();
@@ -51,12 +50,6 @@ final class PhabricatorProjectDefaultController
$id = $project->getID();
$view_uri = $this->getApplicationURI("board/{$id}/");
$view_uri = new PhutilURI($view_uri);
foreach ($request->getPassthroughRequestData() as $key => $value) {
$view_uri->replaceQueryParam($key, $value);
}
if ($request->isFormPost()) {
$xactions = array();
@@ -71,20 +64,18 @@ final class PhabricatorProjectDefaultController
->setContinueOnMissingFields(true)
->applyTransactions($project, $xactions);
return id(new AphrontRedirectResponse())->setURI($view_uri);
// If the parameter we just modified is present in the query string,
// throw it away so the user is redirected back to the default view of
// the board, allowing them to see the new default behavior.
$board_uri->removeQueryParam($remove_param);
return id(new AphrontRedirectResponse())->setURI($board_uri);
}
$dialog = $this->newDialog()
return $this->newBoardDialog()
->setTitle($title)
->appendChild($body)
->setDisableWorkflowOnCancel(true)
->addCancelButton($view_uri)
->addCancelButton($board_uri)
->addSubmitButton($title);
foreach ($request->getPassthroughRequestData() as $key => $value) {
$dialog->addHiddenInput($key, $value);
}
return $dialog;
}
}

View File

@@ -797,9 +797,7 @@ final class PhabricatorProjectBoardViewController
$id = $project->getID();
$save_uri = "default/{$id}/sort/";
$save_uri = $this->getApplicationURI($save_uri);
$save_uri = $this->getURIWithState($save_uri, $force = true);
$save_uri = $state->newWorkboardURI('default/sort/');
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
@@ -842,6 +840,8 @@ final class PhabricatorProjectBoardViewController
PhabricatorApplicationSearchEngine $engine,
$query_key) {
$state = $this->getViewState();
$named = array(
'open' => pht('Open Tasks'),
'all' => pht('All Tasks'),
@@ -898,9 +898,7 @@ final class PhabricatorProjectBoardViewController
->setWorkflow(true)
->setName(pht('Advanced Filter...'));
$save_uri = "default/{$id}/filter/";
$save_uri = $this->getApplicationURI($save_uri);
$save_uri = $this->getURIWithState($save_uri, $force = true);
$save_uri = $state->newWorkboardURI('default/filter/');
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,

View File

@@ -16,6 +16,21 @@ abstract class PhabricatorProjectController extends PhabricatorController {
}
protected function loadProject() {
return $this->loadProjectWithCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
));
}
protected function loadProjectForEdit() {
return $this->loadProjectWithCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
));
}
private function loadProjectWithCapabilities(array $capabilities) {
$viewer = $this->getViewer();
$request = $this->getRequest();
@@ -35,6 +50,7 @@ abstract class PhabricatorProjectController extends PhabricatorController {
$query = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->requireCapabilities($capabilities)
->needMembers(true)
->needWatchers(true)
->needImages(true)