Differential D20408 Diff 48715 src/applications/dashboard/controller/panel/PhabricatorDashboardPanelEditController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/controller/panel/PhabricatorDashboardPanelEditController.php
<?php | <?php | ||||
final class PhabricatorDashboardPanelEditController | final class PhabricatorDashboardPanelEditController | ||||
extends PhabricatorDashboardController { | extends PhabricatorDashboardController { | ||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$engine = id(new PhabricatorDashboardPanelEditEngine()) | $engine = id(new PhabricatorDashboardPanelEditEngine()) | ||||
->setController($this); | ->setController($this); | ||||
// We can create or edit a panel in the context of a dashboard. If we | // We can create or edit a panel in the context of a dashboard or | ||||
// started on a dashboard, we want to return to that dashboard when we're | // container panel, like a tab panel. If we started this flow on some | ||||
// done editing. | // container object, we want to return to that container when we're done | ||||
$dashboard_id = $request->getStr('dashboardID'); | // editing. | ||||
if (strlen($dashboard_id)) { | |||||
$dashboard = id(new PhabricatorDashboardQuery()) | $context_phid = $request->getStr('contextPHID'); | ||||
if (strlen($context_phid)) { | |||||
$context = id(new PhabricatorObjectQuery()) | |||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIDs(array($dashboard_id)) | ->withPHIDs(array($context_phid)) | ||||
->requireCapabilities( | ->requireCapabilities( | ||||
array( | array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
)) | )) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$dashboard) { | if (!$context) { | ||||
return new Aphront404Response(); | |||||
} | |||||
if (!($context instanceof PhabricatorDashboardPanelContainerInterface)) { | |||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$engine | $engine | ||||
->setDashboard($dashboard) | ->setContextObject($context) | ||||
->addContextParameter('dashboardID', $dashboard_id); | ->addContextParameter('contextPHID', $context_phid); | ||||
} else { | } else { | ||||
$dashboard = null; | $context = null; | ||||
} | } | ||||
$id = $request->getURIData('id'); | $id = $request->getURIData('id'); | ||||
if (!$id) { | if (!$id) { | ||||
$column_id = $request->getStr('columnID'); | $column_key = $request->getStr('columnKey'); | ||||
if ($dashboard) { | if ($context) { | ||||
$cancel_uri = $dashboard->getURI(); | $cancel_uri = $context->getURI(); | ||||
} else { | } else { | ||||
$cancel_uri = $this->getApplicationURI('panel/'); | $cancel_uri = $this->getApplicationURI('panel/'); | ||||
} | } | ||||
$panel_type = $request->getStr('panelType'); | $panel_type = $request->getStr('panelType'); | ||||
$panel_types = PhabricatorDashboardPanelType::getAllPanelTypes(); | $panel_types = PhabricatorDashboardPanelType::getAllPanelTypes(); | ||||
if (empty($panel_types[$panel_type])) { | if (empty($panel_types[$panel_type])) { | ||||
return $this->buildPanelTypeResponse($cancel_uri); | return $this->buildPanelTypeResponse($cancel_uri); | ||||
} | } | ||||
$engine | $engine | ||||
->addContextParameter('panelType', $panel_type) | ->addContextParameter('panelType', $panel_type) | ||||
->addContextParameter('columnID', $column_id) | ->addContextParameter('columnKey', $column_key) | ||||
->setPanelType($panel_type) | ->setPanelType($panel_type) | ||||
->setColumnID($column_id); | ->setColumnKey($column_key); | ||||
} | } | ||||
return $engine->buildResponse(); | return $engine->buildResponse(); | ||||
} | } | ||||
private function buildPanelTypeResponse($cancel_uri) { | private function buildPanelTypeResponse($cancel_uri) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
Show All 33 Lines |