diff --git a/src/applications/dashboard/controller/PhabricatorDashboardPanelRenderController.php b/src/applications/dashboard/controller/PhabricatorDashboardPanelRenderController.php --- a/src/applications/dashboard/controller/PhabricatorDashboardPanelRenderController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardPanelRenderController.php @@ -34,6 +34,7 @@ $rendered_panel = id(new PhabricatorDashboardPanelRenderingEngine()) ->setViewer($viewer) ->setPanel($panel) + ->setPanelPHID($panel->getPHID()) ->setParentPanelPHIDs($parent_phids) ->setHeaderMode($request->getStr('headerMode')) ->setDashboardID($request->getInt('dashboardID')) diff --git a/src/applications/dashboard/controller/PhabricatorDashboardPanelViewController.php b/src/applications/dashboard/controller/PhabricatorDashboardPanelViewController.php --- a/src/applications/dashboard/controller/PhabricatorDashboardPanelViewController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardPanelViewController.php @@ -38,6 +38,7 @@ $rendered_panel = id(new PhabricatorDashboardPanelRenderingEngine()) ->setViewer($viewer) ->setPanel($panel) + ->setPanelPHID($panel->getPHID()) ->setParentPanelPHIDs(array()) ->renderPanel(); diff --git a/src/applications/dashboard/controller/PhabricatorDashboardRemovePanelController.php b/src/applications/dashboard/controller/PhabricatorDashboardRemovePanelController.php --- a/src/applications/dashboard/controller/PhabricatorDashboardRemovePanelController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardRemovePanelController.php @@ -20,12 +20,25 @@ 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'); - $panel = id(new PhabricatorDashboardPanelQuery()) - ->setViewer($viewer) - ->withPHIDs(array($v_panel)) - ->executeOne(); - if (!$panel) { + + $panel_on_dashboard = false; + $layout = $dashboard->getLayoutConfigObject(); + $columns = $layout->getPanelLocations(); + 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(); } @@ -43,11 +56,11 @@ ->setNewValue( array( '-' => array( - $panel->getPHID() => $panel->getPHID(), + $v_panel => $v_panel, ), )); - $layout_config->removePanel($panel->getPHID()); + $layout_config->removePanel($v_panel); $dashboard->setLayoutConfigFromObject($layout_config); $editor = id(new PhabricatorDashboardTransactionEditor()) @@ -67,7 +80,7 @@ ->appendChild(pht('Are you sure you want to remove this panel?')); return $this->newDialog() - ->setTitle(pht('Remove Panel %s', $panel->getMonogram())) + ->setTitle(pht('Remove Panel')) ->appendChild($form->buildLayoutView()) ->addCancelButton($redirect_uri) ->addSubmitButton(pht('Remove Panel')); diff --git a/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php b/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php --- a/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php +++ b/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php @@ -7,6 +7,7 @@ const HEADER_MODE_EDIT = 'edit'; private $panel; + private $panelPHID; private $viewer; private $enableAsyncRendering; private $parentPanelPHIDs; @@ -66,6 +67,15 @@ return $this->panel; } + public function setPanelPHID($panel_phid) { + $this->panelPHID = $panel_phid; + return $this; + } + + public function getPanelPHID() { + return $this->panelPHID; + } + public function renderPanel() { $panel = $this->getPanel(); $viewer = $this->getViewer(); @@ -255,32 +265,40 @@ PHUIHeaderView $header) { $panel = $this->getPanel(); - if (!$panel) { - return $header; - } - $dashboard_id = $this->getDashboardID(); - $edit_uri = id(new PhutilURI( - '/dashboard/panel/edit/'.$panel->getID().'/')); - if ($dashboard_id) { - $edit_uri->setQueryParam('dashboardID', $dashboard_id); + + if ($panel) { + $panel_id = $panel->getID(); + + $edit_uri = "/dashboard/panel/edit/{$panel_id}/"; + $edit_uri = new PhutilURI($edit_uri); + if ($dashboard_id) { + $edit_uri->setQueryParam('dashboardID', $dashboard_id); + } + + $action_edit = id(new PHUIIconView()) + ->setIcon('fa-pencil') + ->setWorkflow(true) + ->setHref((string)$edit_uri); + + $header->addActionItem($action_edit); } - $action_edit = id(new PHUIIconView()) - ->setIcon('fa-pencil') - ->setWorkflow(true) - ->setHref((string)$edit_uri); - $header->addActionItem($action_edit); if ($dashboard_id) { - $uri = id(new PhutilURI( - '/dashboard/removepanel/'.$dashboard_id.'/')) - ->setQueryParam('panelPHID', $panel->getPHID()); + $panel_phid = $this->getPanelPHID(); + + $remove_uri = "/dashboard/removepanel/{$dashboard_id}/"; + $remove_uri = id(new PhutilURI($remove_uri)) + ->setQueryParam('panelPHID', $panel_phid); + $action_remove = id(new PHUIIconView()) ->setIcon('fa-trash-o') - ->setHref((string)$uri) + ->setHref((string)$remove_uri) ->setWorkflow(true); + $header->addActionItem($action_remove); } + return $header; } diff --git a/src/applications/dashboard/engine/PhabricatorDashboardRenderingEngine.php b/src/applications/dashboard/engine/PhabricatorDashboardRenderingEngine.php --- a/src/applications/dashboard/engine/PhabricatorDashboardRenderingEngine.php +++ b/src/applications/dashboard/engine/PhabricatorDashboardRenderingEngine.php @@ -55,6 +55,7 @@ ->setViewer($viewer) ->setDashboardID($dashboard->getID()) ->setEnableAsyncRendering(true) + ->setPanelPHID($panel_phid) ->setParentPanelPHIDs(array()) ->setHeaderMode($h_mode); diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardTabsPanelType.php b/src/applications/dashboard/paneltype/PhabricatorDashboardTabsPanelType.php --- a/src/applications/dashboard/paneltype/PhabricatorDashboardTabsPanelType.php +++ b/src/applications/dashboard/paneltype/PhabricatorDashboardTabsPanelType.php @@ -91,6 +91,7 @@ ->setEnableAsyncRendering(true) ->setParentPanelPHIDs($parent_phids) ->setPanel($panel) + ->setPanelPHID($panel->getPHID()) ->setHeaderMode($no_headers) ->renderPanel(); } else { diff --git a/src/applications/dashboard/remarkup/PhabricatorDashboardRemarkupRule.php b/src/applications/dashboard/remarkup/PhabricatorDashboardRemarkupRule.php --- a/src/applications/dashboard/remarkup/PhabricatorDashboardRemarkupRule.php +++ b/src/applications/dashboard/remarkup/PhabricatorDashboardRemarkupRule.php @@ -32,6 +32,7 @@ return id(new PhabricatorDashboardPanelRenderingEngine()) ->setViewer($viewer) ->setPanel($object) + ->setPanelPHID($object->getPHID()) ->setParentPanelPHIDs($parent_phids) ->renderPanel();