Don't allow duplicate panels on dashboards
Summary: Fixes T10145. I went with "don't add two panels", since panels are easy to create, I expect this to be a reasonable limit until we have better use cases. Test Plan: Try to add the same panel twice, get error. Add panel normally fine, move panels fine, edit panels fine. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T10145 Differential Revision: https://secure.phabricator.com/D17351
This commit is contained in:
@@ -10,6 +10,7 @@ final class PhabricatorDashboardAddPanelController
|
|||||||
$dashboard = id(new PhabricatorDashboardQuery())
|
$dashboard = id(new PhabricatorDashboardQuery())
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->withIDs(array($id))
|
->withIDs(array($id))
|
||||||
|
->needPanels(true)
|
||||||
->requireCapabilities(
|
->requireCapabilities(
|
||||||
array(
|
array(
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
@@ -33,9 +34,18 @@ final class PhabricatorDashboardAddPanelController
|
|||||||
->withIDs(array($v_panel))
|
->withIDs(array($v_panel))
|
||||||
->executeOne();
|
->executeOne();
|
||||||
if (!$panel) {
|
if (!$panel) {
|
||||||
$errors[] = pht('No such panel!');
|
$errors[] = pht('Not a valid panel.');
|
||||||
$e_panel = pht('Invalid');
|
$e_panel = pht('Invalid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$on_dashboard = $dashboard->getPanels();
|
||||||
|
$on_ids = mpull($on_dashboard, null, 'getID');
|
||||||
|
if (array_key_exists($v_panel, $on_ids)) {
|
||||||
|
$p_name = $panel->getName();
|
||||||
|
$errors[] = pht('Panel "%s" already exists on dashboard.', $p_name);
|
||||||
|
$e_panel = pht('Invalid');
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$errors[] = pht('Select a panel to add.');
|
$errors[] = pht('Select a panel to add.');
|
||||||
$e_panel = pht('Required');
|
$e_panel = pht('Required');
|
||||||
@@ -81,8 +91,7 @@ final class PhabricatorDashboardAddPanelController
|
|||||||
->setDatasource(new PhabricatorDashboardPanelDatasource())
|
->setDatasource(new PhabricatorDashboardPanelDatasource())
|
||||||
->setLimit(1)
|
->setLimit(1)
|
||||||
->setName('panel')
|
->setName('panel')
|
||||||
->setLabel(pht('Panel'))
|
->setLabel(pht('Panel')));
|
||||||
->setValue($v_panel));
|
|
||||||
|
|
||||||
return $this->newDialog()
|
return $this->newDialog()
|
||||||
->setTitle(pht('Add Panel'))
|
->setTitle(pht('Add Panel'))
|
||||||
|
|||||||
Reference in New Issue
Block a user