@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+63 -43
+2 -2
src/__phutil_library_map__.php
··· 4158 4158 'PhabricatorProjectArchiveController' => 'applications/project/controller/PhabricatorProjectArchiveController.php', 4159 4159 'PhabricatorProjectBoardBackgroundController' => 'applications/project/controller/PhabricatorProjectBoardBackgroundController.php', 4160 4160 'PhabricatorProjectBoardController' => 'applications/project/controller/PhabricatorProjectBoardController.php', 4161 + 'PhabricatorProjectBoardDefaultController' => 'applications/project/controller/PhabricatorProjectBoardDefaultController.php', 4161 4162 'PhabricatorProjectBoardDisableController' => 'applications/project/controller/PhabricatorProjectBoardDisableController.php', 4162 4163 'PhabricatorProjectBoardImportController' => 'applications/project/controller/PhabricatorProjectBoardImportController.php', 4163 4164 'PhabricatorProjectBoardManageController' => 'applications/project/controller/PhabricatorProjectBoardManageController.php', ··· 4207 4208 'PhabricatorProjectCustomFieldStringIndex' => 'applications/project/storage/PhabricatorProjectCustomFieldStringIndex.php', 4208 4209 'PhabricatorProjectDAO' => 'applications/project/storage/PhabricatorProjectDAO.php', 4209 4210 'PhabricatorProjectDatasource' => 'applications/project/typeahead/PhabricatorProjectDatasource.php', 4210 - 'PhabricatorProjectDefaultController' => 'applications/project/controller/PhabricatorProjectDefaultController.php', 4211 4211 'PhabricatorProjectDescriptionField' => 'applications/project/customfield/PhabricatorProjectDescriptionField.php', 4212 4212 'PhabricatorProjectDetailsProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectDetailsProfileMenuItem.php', 4213 4213 'PhabricatorProjectDropEffect' => 'applications/project/icon/PhabricatorProjectDropEffect.php', ··· 10422 10422 'PhabricatorProjectArchiveController' => 'PhabricatorProjectController', 10423 10423 'PhabricatorProjectBoardBackgroundController' => 'PhabricatorProjectBoardController', 10424 10424 'PhabricatorProjectBoardController' => 'PhabricatorProjectController', 10425 + 'PhabricatorProjectBoardDefaultController' => 'PhabricatorProjectBoardController', 10425 10426 'PhabricatorProjectBoardDisableController' => 'PhabricatorProjectBoardController', 10426 10427 'PhabricatorProjectBoardImportController' => 'PhabricatorProjectBoardController', 10427 10428 'PhabricatorProjectBoardManageController' => 'PhabricatorProjectBoardController', ··· 10484 10485 'PhabricatorProjectCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage', 10485 10486 'PhabricatorProjectDAO' => 'PhabricatorLiskDAO', 10486 10487 'PhabricatorProjectDatasource' => 'PhabricatorTypeaheadDatasource', 10487 - 'PhabricatorProjectDefaultController' => 'PhabricatorProjectBoardController', 10488 10488 'PhabricatorProjectDescriptionField' => 'PhabricatorProjectStandardCustomField', 10489 10489 'PhabricatorProjectDetailsProfileMenuItem' => 'PhabricatorProfileMenuItem', 10490 10490 'PhabricatorProjectDropEffect' => 'Phobject',
+2 -2
src/applications/project/application/PhabricatorProjectApplication.php
··· 90 90 => 'PhabricatorProjectBoardManageController', 91 91 'background/' 92 92 => 'PhabricatorProjectBoardBackgroundController', 93 + 'default/(?P<target>[^/]+)/' 94 + => 'PhabricatorProjectBoardDefaultController', 93 95 ), 94 96 'column/' => array( 95 97 'remove/(?P<id>\d+)/' => ··· 112 114 => 'PhabricatorProjectSilenceController', 113 115 'warning/(?P<id>[1-9]\d*)/' 114 116 => 'PhabricatorProjectSubprojectWarningController', 115 - 'default/(?P<projectID>[1-9]\d*)/(?P<target>[^/]+)/' 116 - => 'PhabricatorProjectDefaultController', 117 117 ), 118 118 '/tag/' => array( 119 119 '(?P<slug>[^/]+)/' => 'PhabricatorProjectViewController',
+12 -1
src/applications/project/controller/PhabricatorProjectBoardController.php
··· 13 13 return $this->viewState; 14 14 } 15 15 16 - final private function newViewState() { 16 + private function newViewState() { 17 17 $project = $this->getProject(); 18 18 $request = $this->getRequest(); 19 19 20 20 return id(new PhabricatorWorkboardViewState()) 21 21 ->setProject($project) 22 22 ->readFromRequest($request); 23 + } 24 + 25 + final protected function newBoardDialog() { 26 + $dialog = $this->newDialog(); 27 + 28 + $state = $this->getViewState(); 29 + foreach ($state->getQueryParameters() as $key => $value) { 30 + $dialog->addHiddenInput($key, $value); 31 + } 32 + 33 + return $dialog; 23 34 } 24 35 25 36 }
+4 -6
src/applications/project/controller/PhabricatorProjectBoardViewController.php
··· 797 797 798 798 $id = $project->getID(); 799 799 800 - $save_uri = "default/{$id}/sort/"; 801 - $save_uri = $this->getApplicationURI($save_uri); 802 - $save_uri = $this->getURIWithState($save_uri, $force = true); 800 + $save_uri = $state->newWorkboardURI('default/sort/'); 803 801 804 802 $can_edit = PhabricatorPolicyFilter::hasCapability( 805 803 $viewer, ··· 841 839 $custom_query, 842 840 PhabricatorApplicationSearchEngine $engine, 843 841 $query_key) { 842 + 843 + $state = $this->getViewState(); 844 844 845 845 $named = array( 846 846 'open' => pht('Open Tasks'), ··· 898 898 ->setWorkflow(true) 899 899 ->setName(pht('Advanced Filter...')); 900 900 901 - $save_uri = "default/{$id}/filter/"; 902 - $save_uri = $this->getApplicationURI($save_uri); 903 - $save_uri = $this->getURIWithState($save_uri, $force = true); 901 + $save_uri = $state->newWorkboardURI('default/filter/'); 904 902 905 903 $can_edit = PhabricatorPolicyFilter::hasCapability( 906 904 $viewer,
+16
src/applications/project/controller/PhabricatorProjectController.php
··· 16 16 } 17 17 18 18 protected function loadProject() { 19 + return $this->loadProjectWithCapabilities( 20 + array( 21 + PhabricatorPolicyCapability::CAN_VIEW, 22 + )); 23 + } 24 + 25 + protected function loadProjectForEdit() { 26 + return $this->loadProjectWithCapabilities( 27 + array( 28 + PhabricatorPolicyCapability::CAN_VIEW, 29 + PhabricatorPolicyCapability::CAN_EDIT, 30 + )); 31 + } 32 + 33 + private function loadProjectWithCapabilities(array $capabilities) { 19 34 $viewer = $this->getViewer(); 20 35 $request = $this->getRequest(); 21 36 ··· 35 50 36 51 $query = id(new PhabricatorProjectQuery()) 37 52 ->setViewer($viewer) 53 + ->requireCapabilities($capabilities) 38 54 ->needMembers(true) 39 55 ->needWatchers(true) 40 56 ->needImages(true)
+23 -32
src/applications/project/controller/PhabricatorProjectDefaultController.php src/applications/project/controller/PhabricatorProjectBoardDefaultController.php
··· 1 1 <?php 2 2 3 - final class PhabricatorProjectDefaultController 3 + final class PhabricatorProjectBoardDefaultController 4 4 extends PhabricatorProjectBoardController { 5 5 6 6 public function handleRequest(AphrontRequest $request) { 7 7 $viewer = $request->getViewer(); 8 - $project_id = $request->getURIData('projectID'); 9 8 10 - $project = id(new PhabricatorProjectQuery()) 11 - ->setViewer($viewer) 12 - ->requireCapabilities( 13 - array( 14 - PhabricatorPolicyCapability::CAN_VIEW, 15 - PhabricatorPolicyCapability::CAN_EDIT, 16 - )) 17 - ->withIDs(array($project_id)) 18 - ->executeOne(); 19 - if (!$project) { 20 - return new Aphront404Response(); 9 + $response = $this->loadProjectForEdit(); 10 + if ($response) { 11 + return $response; 21 12 } 22 - $this->setProject($project); 13 + 14 + $project = $this->getProject(); 15 + $state = $this->getViewState(); 16 + $board_uri = $state->newWorkboardURI(); 17 + $remove_param = null; 23 18 24 19 $target = $request->getURIData('target'); 25 20 switch ($target) { ··· 31 26 'the board.'); 32 27 $button = pht('Save Default Filter'); 33 28 34 - $xaction_value = $request->getStr('filter'); 29 + $xaction_value = $state->getQueryKey(); 35 30 $xaction_type = PhabricatorProjectFilterTransaction::TRANSACTIONTYPE; 31 + 32 + $remove_param = 'filter'; 36 33 break; 37 34 case 'sort': 38 35 $title = pht('Set Board Default Order'); ··· 42 39 'the board.'); 43 40 $button = pht('Save Default Order'); 44 41 45 - $xaction_value = $request->getStr('order'); 42 + $xaction_value = $state->getOrder(); 46 43 $xaction_type = PhabricatorProjectSortTransaction::TRANSACTIONTYPE; 44 + 45 + $remove_param = 'order'; 47 46 break; 48 47 default: 49 48 return new Aphront404Response(); 50 49 } 51 50 52 51 $id = $project->getID(); 53 - 54 - $view_uri = $this->getApplicationURI("board/{$id}/"); 55 - $view_uri = new PhutilURI($view_uri); 56 - foreach ($request->getPassthroughRequestData() as $key => $value) { 57 - $view_uri->replaceQueryParam($key, $value); 58 - } 59 52 60 53 if ($request->isFormPost()) { 61 54 $xactions = array(); ··· 71 64 ->setContinueOnMissingFields(true) 72 65 ->applyTransactions($project, $xactions); 73 66 74 - return id(new AphrontRedirectResponse())->setURI($view_uri); 67 + // If the parameter we just modified is present in the query string, 68 + // throw it away so the user is redirected back to the default view of 69 + // the board, allowing them to see the new default behavior. 70 + $board_uri->removeQueryParam($remove_param); 71 + 72 + return id(new AphrontRedirectResponse())->setURI($board_uri); 75 73 } 76 74 77 - $dialog = $this->newDialog() 75 + return $this->newBoardDialog() 78 76 ->setTitle($title) 79 77 ->appendChild($body) 80 - ->setDisableWorkflowOnCancel(true) 81 - ->addCancelButton($view_uri) 78 + ->addCancelButton($board_uri) 82 79 ->addSubmitButton($title); 83 - 84 - foreach ($request->getPassthroughRequestData() as $key => $value) { 85 - $dialog->addHiddenInput($key, $value); 86 - } 87 - 88 - return $dialog; 89 80 } 90 81 }
+4
src/applications/project/state/PhabricatorWorkboardViewState.php
··· 147 147 return 'open'; 148 148 } 149 149 150 + public function getQueryParameters() { 151 + return $this->requestState; 152 + } 153 + 150 154 }