Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenaka <diosmosis@users.noreply.github.com>2018-03-09 06:36:19 +0300
committerMatthieu Aubry <mattab@users.noreply.github.com>2018-03-09 06:36:19 +0300
commitc5f07bc6147c5a467f8ca4714e1573055a81ede3 (patch)
tree12b793b190353c131a76881c98be8986efd342d1 /plugins/Dashboard
parentc0641ab40cc6ea3f8506689478cd35cb61cf3580 (diff)
Allow deleting first dashboard for automation purposes. (#12607)
Diffstat (limited to 'plugins/Dashboard')
-rw-r--r--plugins/Dashboard/API.php9
-rw-r--r--plugins/Dashboard/tests/Integration/APITest.php22
2 files changed, 26 insertions, 5 deletions
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(