Differential D20629 Diff 49230 src/applications/project/controller/PhabricatorProjectBoardDefaultController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/controller/PhabricatorProjectBoardDefaultController.php
- This file was moved from src/applications/project/controller/PhabricatorProjectDefaultController.php.
<?php | <?php | ||||
final class PhabricatorProjectDefaultController | final class PhabricatorProjectBoardDefaultController | ||||
extends PhabricatorProjectBoardController { | extends PhabricatorProjectBoardController { | ||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$viewer = $request->getViewer(); | $viewer = $request->getViewer(); | ||||
$project_id = $request->getURIData('projectID'); | |||||
$project = id(new PhabricatorProjectQuery()) | $response = $this->loadProjectForEdit(); | ||||
->setViewer($viewer) | if ($response) { | ||||
->requireCapabilities( | return $response; | ||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->withIDs(array($project_id)) | |||||
->executeOne(); | |||||
if (!$project) { | |||||
return new Aphront404Response(); | |||||
} | } | ||||
$this->setProject($project); | |||||
$project = $this->getProject(); | |||||
$state = $this->getViewState(); | |||||
$board_uri = $state->newWorkboardURI(); | |||||
$remove_param = null; | |||||
$target = $request->getURIData('target'); | $target = $request->getURIData('target'); | ||||
switch ($target) { | switch ($target) { | ||||
case 'filter': | case 'filter': | ||||
$title = pht('Set Board Default Filter'); | $title = pht('Set Board Default Filter'); | ||||
$body = pht( | $body = pht( | ||||
'Make the current filter the new default filter for this board? '. | 'Make the current filter the new default filter for this board? '. | ||||
'All users will see the new filter as the default when they view '. | 'All users will see the new filter as the default when they view '. | ||||
'the board.'); | 'the board.'); | ||||
$button = pht('Save Default Filter'); | $button = pht('Save Default Filter'); | ||||
$xaction_value = $request->getStr('filter'); | $xaction_value = $state->getQueryKey(); | ||||
$xaction_type = PhabricatorProjectFilterTransaction::TRANSACTIONTYPE; | $xaction_type = PhabricatorProjectFilterTransaction::TRANSACTIONTYPE; | ||||
$remove_param = 'filter'; | |||||
break; | break; | ||||
case 'sort': | case 'sort': | ||||
$title = pht('Set Board Default Order'); | $title = pht('Set Board Default Order'); | ||||
$body = pht( | $body = pht( | ||||
'Make the current sort order the new default order for this board? '. | 'Make the current sort order the new default order for this board? '. | ||||
'All users will see the new order as the default when they view '. | 'All users will see the new order as the default when they view '. | ||||
'the board.'); | 'the board.'); | ||||
$button = pht('Save Default Order'); | $button = pht('Save Default Order'); | ||||
$xaction_value = $request->getStr('order'); | $xaction_value = $state->getOrder(); | ||||
$xaction_type = PhabricatorProjectSortTransaction::TRANSACTIONTYPE; | $xaction_type = PhabricatorProjectSortTransaction::TRANSACTIONTYPE; | ||||
$remove_param = 'order'; | |||||
break; | break; | ||||
default: | default: | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$id = $project->getID(); | $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()) { | if ($request->isFormPost()) { | ||||
$xactions = array(); | $xactions = array(); | ||||
$xactions[] = id(new PhabricatorProjectTransaction()) | $xactions[] = id(new PhabricatorProjectTransaction()) | ||||
->setTransactionType($xaction_type) | ->setTransactionType($xaction_type) | ||||
->setNewValue($xaction_value); | ->setNewValue($xaction_value); | ||||
id(new PhabricatorProjectTransactionEditor()) | id(new PhabricatorProjectTransactionEditor()) | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->setContinueOnMissingFields(true) | ->setContinueOnMissingFields(true) | ||||
->applyTransactions($project, $xactions); | ->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) | ->setTitle($title) | ||||
->appendChild($body) | ->appendChild($body) | ||||
->setDisableWorkflowOnCancel(true) | ->addCancelButton($board_uri) | ||||
->addCancelButton($view_uri) | |||||
->addSubmitButton($title); | ->addSubmitButton($title); | ||||
foreach ($request->getPassthroughRequestData() as $key => $value) { | |||||
$dialog->addHiddenInput($key, $value); | |||||
} | |||||
return $dialog; | |||||
} | } | ||||
} | } |