From bb2e1ad73e60e2fa90d979db04243826703b3257 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Tue, 28 Apr 2015 10:09:50 +0200 Subject: [PATCH] SONAR-6428 Use default project dashboards when user has no specific config --- .../ui/ws/ComponentNavigationAction.java | 5 +++++ .../ui/ws/ComponentNavigationActionTest.java | 17 ++++++++++++++++ .../with_default_dashboards.json | 20 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/ui/ws/ComponentNavigationActionTest/with_default_dashboards.json diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java index 59bb790d9d6..448da1e0a14 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java @@ -59,6 +59,8 @@ public class ComponentNavigationAction implements NavigationAction { private static final String PARAM_COMPONENT_KEY = "componentKey"; + private static final String ANONYMOUS = null; + private static final String PROPERTY_COMPARABLE = "comparable"; private static final String PROPERTY_CONFIGURABLE = "configurable"; private static final String PROPERTY_HAS_ROLE_POLICY = "hasRolePolicy"; @@ -136,6 +138,9 @@ public class ComponentNavigationAction implements NavigationAction { .prop("isFavorite", isFavourite(session, component, userSession)); List dashboards = activeDashboardDao.selectProjectDashboardsForUserLogin(session, userSession.login()); + if (dashboards.isEmpty()) { + dashboards = activeDashboardDao.selectProjectDashboardsForUserLogin(session, ANONYMOUS); + } writeDashboards(json, component, dashboards, userSession.locale()); if (snapshot != null) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java index 778d1ef154a..caa29df721d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java @@ -211,6 +211,23 @@ public class ComponentNavigationActionTest { wsTester.newGetRequest("api/navigation", "component").setParam("componentKey", "polop").execute().assertJson(getClass(), "with_dashboards.json"); } + @Test + public void with_default_dashboards() throws Exception { + dbClient.componentDao().insert(session, ComponentTesting.newProjectDto("abcd") + .setKey("polop").setName("Polop")); + DashboardDto dashboard = new DashboardDto().setGlobal(false).setName("Anon Dashboard").setShared(true).setColumnLayout("100%"); + dashboardDao.insert(dashboard); + activeDashboardDao.insert(new ActiveDashboardDto().setDashboardId(dashboard.getId())); + session.commit(); + + MockUserSession.set().setLogin("obiwan").addProjectUuidPermissions(UserRole.USER, "abcd"); + + wsTester = new WsTester(new NavigationWs(new ComponentNavigationAction(dbClient, activeDashboardDao, + new Views(), i18n, resourceTypes))); + + wsTester.newGetRequest("api/navigation", "component").setParam("componentKey", "polop").execute().assertJson(getClass(), "with_default_dashboards.json"); + } + @Test public void with_extensions() throws Exception { final String language = "xoo"; diff --git a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/ComponentNavigationActionTest/with_default_dashboards.json b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/ComponentNavigationActionTest/with_default_dashboards.json new file mode 100644 index 00000000000..c24d40abcf9 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/ComponentNavigationActionTest/with_default_dashboards.json @@ -0,0 +1,20 @@ +{ + "key": "polop", + "uuid": "abcd", + "name": "Polop", + "isComparable": false, + "canBeFavorite": true, + "isFavorite": false, + "dashboards": [ + { + "name": "Anon Dashboard" + } + ], + "breadcrumbs": [ + { + "key": "polop", + "name": "Polop", + "qualifier": "TRK" + } + ] +} -- 2.39.5