diff options
author | Benaka <diosmosis@users.noreply.github.com> | 2018-03-09 06:36:19 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2018-03-09 06:36:19 +0300 |
commit | c5f07bc6147c5a467f8ca4714e1573055a81ede3 (patch) | |
tree | 12b793b190353c131a76881c98be8986efd342d1 | |
parent | c0641ab40cc6ea3f8506689478cd35cb61cf3580 (diff) |
Allow deleting first dashboard for automation purposes. (#12607)
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | plugins/Dashboard/API.php | 9 | ||||
-rw-r--r-- | plugins/Dashboard/tests/Integration/APITest.php | 22 |
3 files changed, 28 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ba993aad8..ec11ea9583 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ The Product Changelog at **[matomo.org/changelog](https://matomo.org/changelog)* * A new JavaScript tracker method `resetUserId` has been added to allow clearing user and visitor id. * A new event `Actions.addActionTypes` has been added, to allow plugins to add their custom action types. * Dashboard API has been extended by the methods `copyDashboardToUser`, `createNewDashboardForUser`, `removeDashboard` and `resetDashboardLayout` + * It is also now possible to delete the first dashboard for a user for automation purposes. Doing so and not adding + a new first dashboard will result in buggy UX. * A new event `API.Request.intercept` has been added which allows plugins to intercept API requests to perform custom logic, overriding the original API method. * A new event `Request.shouldDisablePostProcessing` has been added which allows plugins to disable DataTable post processing for individual API requests. * A new event `SitesManager.shouldPerformEmptySiteCheck` has been added to allow plugins to disable the empty site check for individual sites. diff --git a/plugins/Dashboard/API.php b/plugins/Dashboard/API.php index de6551ca60..7ebcb84fcd 100644 --- a/plugins/Dashboard/API.php +++ b/plugins/Dashboard/API.php @@ -71,6 +71,11 @@ class API extends \Piwik\Plugin\API * * Note: Only a super user is able to remove dashboards for other users * + * Also note: It is allowed to delete the first dashboard for a user, BUT + * that will cause buggy behavior if a new dashboard is not immediately added. + * Deleting the first dashboard (with ID = 1) should only be done for automation + * purposes. + * * @param int $idDashboard id of the dashboard to be removed * @param string $login Login of the dashboard user [defaults to current user] */ @@ -80,9 +85,7 @@ class API extends \Piwik\Plugin\API Piwik::checkUserHasSuperUserAccessOrIsTheUser($login); - if ($idDashboard != 1) { - $this->model->deleteDashboardForUser($idDashboard, $login); - } + $this->model->deleteDashboardForUser($idDashboard, $login); } /** diff --git a/plugins/Dashboard/tests/Integration/APITest.php b/plugins/Dashboard/tests/Integration/APITest.php index ffb1f4c12f..1384d18d15 100644 --- a/plugins/Dashboard/tests/Integration/APITest.php +++ b/plugins/Dashboard/tests/Integration/APITest.php @@ -112,7 +112,7 @@ class APITest extends IntegrationTestCase $dashboards = $this->model->getAllDashboardsForUser('eva'); $this->assertEmpty($dashboards); - // first dashboard can't be removed + // first dashboard shouldn't be removed $this->api->createNewDashboardForUser('eva', 'name', $addDefaultWidgets = true); $id = $this->api->createNewDashboardForUser('eva', 'new name', $addDefaultWidgets = true); @@ -130,7 +130,7 @@ class APITest extends IntegrationTestCase $dashboards = $this->model->getAllDashboardsForUser('eva'); $this->assertEmpty($dashboards); - // first dashboard can't be removed + // first dashboard shouldn't be removed $this->api->createNewDashboardForUser('eva', 'name', $addDefaultWidgets = true); $id = $this->api->createNewDashboardForUser('eva', 'new name', $addDefaultWidgets = true); @@ -143,6 +143,24 @@ class APITest extends IntegrationTestCase $this->assertCount(1, $dashboards); } + public function testRemoveDashboardAllowsRemovingFirst() + { + $dashboards = $this->model->getAllDashboardsForUser('eva'); + $this->assertEmpty($dashboards); + + // we allow removing first dashboard for an automation use case, so tested here + // but if another dashboard isn't immediately added, it can cause problems. + $id = $this->api->createNewDashboardForUser('eva', 'name', $addDefaultWidgets = true); + + $dashboards = $this->model->getAllDashboardsForUser('eva'); + $this->assertCount(1, $dashboards); + + $this->api->removeDashboard($id, 'eva'); + + $dashboards = $this->model->getAllDashboardsForUser('eva'); + $this->assertEmpty($dashboards); + } + public function provideContainerConfig() { return array( |