Differential D17314 Diff 41641 src/applications/dashboard/controller/PhabricatorDashboardRemovePanelController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/controller/PhabricatorDashboardRemovePanelController.php
Show All 14 Lines | $dashboard = id(new PhabricatorDashboardQuery()) | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
)) | )) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$dashboard) { | if (!$dashboard) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
// NOTE: If you can edit a dashboard, you can remove panels from it even | |||||
// if you don't have permission to see them or they aren't valid. We only | |||||
// require that the panel be present on the dashboard. | |||||
$v_panel = $request->getStr('panelPHID'); | $v_panel = $request->getStr('panelPHID'); | ||||
$panel = id(new PhabricatorDashboardPanelQuery()) | |||||
->setViewer($viewer) | $panel_on_dashboard = false; | ||||
->withPHIDs(array($v_panel)) | $layout = $dashboard->getLayoutConfigObject(); | ||||
->executeOne(); | $columns = $layout->getPanelLocations(); | ||||
if (!$panel) { | foreach ($columns as $column) { | ||||
foreach ($column as $column_panel_phid) { | |||||
if ($column_panel_phid == $v_panel) { | |||||
$panel_on_dashboard = true; | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
if (!$panel_on_dashboard) { | |||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$redirect_uri = $this->getApplicationURI( | $redirect_uri = $this->getApplicationURI( | ||||
'manage/'.$dashboard->getID().'/'); | 'manage/'.$dashboard->getID().'/'); | ||||
$layout_config = $dashboard->getLayoutConfigObject(); | $layout_config = $dashboard->getLayoutConfigObject(); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$xactions = array(); | $xactions = array(); | ||||
$xactions[] = id(new PhabricatorDashboardTransaction()) | $xactions[] = id(new PhabricatorDashboardTransaction()) | ||||
->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | ||||
->setMetadataValue( | ->setMetadataValue( | ||||
'edge:type', | 'edge:type', | ||||
PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST) | PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST) | ||||
->setNewValue( | ->setNewValue( | ||||
array( | array( | ||||
'-' => array( | '-' => array( | ||||
$panel->getPHID() => $panel->getPHID(), | $v_panel => $v_panel, | ||||
), | ), | ||||
)); | )); | ||||
$layout_config->removePanel($panel->getPHID()); | $layout_config->removePanel($v_panel); | ||||
$dashboard->setLayoutConfigFromObject($layout_config); | $dashboard->setLayoutConfigFromObject($layout_config); | ||||
$editor = id(new PhabricatorDashboardTransactionEditor()) | $editor = id(new PhabricatorDashboardTransactionEditor()) | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setContinueOnMissingFields(true) | ->setContinueOnMissingFields(true) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->applyTransactions($dashboard, $xactions); | ->applyTransactions($dashboard, $xactions); | ||||
return id(new AphrontRedirectResponse())->setURI($redirect_uri); | return id(new AphrontRedirectResponse())->setURI($redirect_uri); | ||||
} | } | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->addHiddenInput('confirm', true) | ->addHiddenInput('confirm', true) | ||||
->addHiddenInput('panelPHID', $v_panel) | ->addHiddenInput('panelPHID', $v_panel) | ||||
->appendChild(pht('Are you sure you want to remove this panel?')); | ->appendChild(pht('Are you sure you want to remove this panel?')); | ||||
return $this->newDialog() | return $this->newDialog() | ||||
->setTitle(pht('Remove Panel %s', $panel->getMonogram())) | ->setTitle(pht('Remove Panel')) | ||||
->appendChild($form->buildLayoutView()) | ->appendChild($form->buildLayoutView()) | ||||
->addCancelButton($redirect_uri) | ->addCancelButton($redirect_uri) | ||||
->addSubmitButton(pht('Remove Panel')); | ->addSubmitButton(pht('Remove Panel')); | ||||
} | } | ||||
} | } |