]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6428 Use default project dashboards when user has no specific config 263/head
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 28 Apr 2015 08:09:50 +0000 (10:09 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 28 Apr 2015 08:48:53 +0000 (10:48 +0200)
server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java
server/sonar-server/src/test/resources/org/sonar/server/ui/ws/ComponentNavigationActionTest/with_default_dashboards.json [new file with mode: 0644]

index 59bb790d9d67eb69e25bddbaa448d2927169f93c..448da1e0a14bc80d7245cd470a608f32f68573d9 100644 (file)
@@ -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<DashboardDto> dashboards = activeDashboardDao.selectProjectDashboardsForUserLogin(session, userSession.login());
+    if (dashboards.isEmpty()) {
+      dashboards = activeDashboardDao.selectProjectDashboardsForUserLogin(session, ANONYMOUS);
+    }
     writeDashboards(json, component, dashboards, userSession.locale());
 
     if (snapshot != null) {
index 778d1ef154a7508a0f233851c8b546f50819a70a..caa29df721d2d93472684dfa849d47d29aeba743 100644 (file)
@@ -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 (file)
index 0000000..c24d40a
--- /dev/null
@@ -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"
+    }
+  ]
+}