mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-11 15:21:03 +01:00
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:
parent
128a9d13fc
commit
5556f0e45a
1 changed files with 12 additions and 3 deletions
|
@ -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'))
|
||||||
|
|
Loading…
Reference in a new issue