]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8354 Remove dashboards from api/navigation/global WS
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 7 Nov 2016 14:53:48 +0000 (15:53 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 9 Nov 2016 15:47:34 +0000 (16:47 +0100)
server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalNavigationAction.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalNavigationActionTest.java
server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/admin.json
server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/anonymous.json
server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/empty.json
server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/only_logo.json
server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/user.json
server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/with_qualifiers.json

index 83cdea298103e87e3fdb89961ff14a61d55c1a55..11f719b0647c545a5d1010139fe7bc1cfb3b0b2d 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.ui.ws;
 
-import java.util.List;
 import org.sonar.api.config.Settings;
 import org.sonar.api.resources.ResourceType;
 import org.sonar.api.resources.ResourceTypes;
@@ -29,28 +28,19 @@ import org.sonar.api.server.ws.WebService.NewController;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.api.web.NavigationSection;
 import org.sonar.api.web.Page;
-import org.sonar.db.dashboard.ActiveDashboardDao;
-import org.sonar.db.dashboard.DashboardDto;
 import org.sonar.server.ui.ViewProxy;
 import org.sonar.server.ui.Views;
-import org.sonar.server.user.UserSession;
 
 public class GlobalNavigationAction implements NavigationWsAction {
 
-  private static final String ANONYMOUS = null;
-
-  private final ActiveDashboardDao activeDashboardDao;
   private final Views views;
   private final Settings settings;
   private final ResourceTypes resourceTypes;
-  private final UserSession userSession;
 
-  public GlobalNavigationAction(ActiveDashboardDao activeDashboardDao, Views views, Settings settings, ResourceTypes resourceTypes, UserSession userSession) {
-    this.activeDashboardDao = activeDashboardDao;
+  public GlobalNavigationAction(Views views, Settings settings, ResourceTypes resourceTypes) {
     this.views = views;
     this.settings = settings;
     this.resourceTypes = resourceTypes;
-    this.userSession = userSession;
   }
 
   @Override
@@ -65,30 +55,13 @@ public class GlobalNavigationAction implements NavigationWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    List<DashboardDto> dashboards = activeDashboardDao.selectGlobalDashboardsForUserLogin(userSession.getLogin());
-    if (dashboards.isEmpty()) {
-      dashboards = activeDashboardDao.selectGlobalDashboardsForUserLogin(ANONYMOUS);
-    }
-
     JsonWriter json = response.newJsonWriter().beginObject();
-    writeDashboards(json, dashboards);
     writePages(json);
     writeLogoProperties(json);
     writeQualifiers(json);
     json.endObject().close();
   }
 
-  private static void writeDashboards(JsonWriter json, List<DashboardDto> dashboards) {
-    json.name("globalDashboards").beginArray();
-    for (DashboardDto dashboard : dashboards) {
-      json.beginObject()
-        .prop("key", dashboard.getKey())
-        .prop("name", dashboard.getName())
-        .endObject();
-    }
-    json.endArray();
-  }
-
   private void writePages(JsonWriter json) {
     json.name("globalPages").beginArray();
     for (ViewProxy<Page> page : views.getPages(NavigationSection.HOME)) {
index 6a2cf972ade596f771737cad50d78c081f7e3998..fbcf9eb4851eb4119e78917dad57a69e658ccbaf 100644 (file)
  */
 package org.sonar.server.ui.ws;
 
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.config.Settings;
 import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.Settings;
 import org.sonar.api.resources.ResourceType;
 import org.sonar.api.resources.ResourceTypeTree;
 import org.sonar.api.resources.ResourceTypes;
@@ -34,21 +32,12 @@ import org.sonar.api.web.Page;
 import org.sonar.api.web.UserRole;
 import org.sonar.api.web.View;
 import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.dashboard.ActiveDashboardDao;
-import org.sonar.db.dashboard.ActiveDashboardDto;
-import org.sonar.db.dashboard.DashboardDao;
-import org.sonar.db.dashboard.DashboardDto;
-import org.sonar.db.user.UserDao;
-import org.sonar.db.user.UserDto;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ui.Views;
 import org.sonar.server.ws.WsTester;
 
-import static org.mockito.Mockito.mock;
-
 public class GlobalNavigationActionTest {
 
   @Rule
@@ -56,35 +45,13 @@ public class GlobalNavigationActionTest {
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
 
-  private DbSession session;
+  private DbSession session = dbTester.getSession();
 
   private WsTester wsTester;
 
-  private UserDao userDao;
-
-  private DashboardDao dashboardDao;
-
-  private ActiveDashboardDao activeDashboardDao;
-
-  @Before
-  public void before() {
-    userDao = new UserDao(dbTester.myBatis(), mock(System2.class));
-    dashboardDao = new DashboardDao(dbTester.myBatis());
-    activeDashboardDao = new ActiveDashboardDao(dbTester.myBatis());
-    DbClient dbClient = new DbClient(
-      dbTester.database(), dbTester.myBatis(), userDao, dashboardDao, activeDashboardDao);
-
-    session = dbClient.openSession(false);
-  }
-
-  @After
-  public void after() {
-    session.close();
-  }
-
   @Test
   public void empty_call() throws Exception {
-    wsTester = new WsTester(new NavigationWs(new GlobalNavigationAction(activeDashboardDao, new Views(userSessionRule), new MapSettings(), new ResourceTypes(), userSessionRule)));
+    wsTester = new WsTester(new NavigationWs(new GlobalNavigationAction(new Views(userSessionRule), new MapSettings(), new ResourceTypes())));
 
     wsTester.newGetRequest("api/navigation", "global").execute().assertJson(getClass(), "empty.json");
   }
@@ -104,18 +71,18 @@ public class GlobalNavigationActionTest {
           .addRelations("PAL", "LAP")
           .build()
       });
-    wsTester = new WsTester(new NavigationWs(new GlobalNavigationAction(activeDashboardDao, new Views(userSessionRule), new MapSettings(), resourceTypes, userSessionRule)));
+    wsTester = new WsTester(new NavigationWs(new GlobalNavigationAction(new Views(userSessionRule), new MapSettings(), resourceTypes)));
 
     wsTester.newGetRequest("api/navigation", "global").execute().assertJson(getClass(), "with_qualifiers.json");
   }
 
   @Test
   public void only_logo() throws Exception {
-    wsTester = new WsTester(new NavigationWs(new GlobalNavigationAction(activeDashboardDao, new Views(userSessionRule),
+    wsTester = new WsTester(new NavigationWs(new GlobalNavigationAction(new Views(userSessionRule),
       new MapSettings()
         .setProperty("sonar.lf.logoUrl", "http://some-server.tld/logo.png")
         .setProperty("sonar.lf.logoWidthPx", "123"),
-      new ResourceTypes(), userSessionRule)));
+      new ResourceTypes())));
 
     wsTester.newGetRequest("api/navigation", "global").execute().assertJson(getClass(), "only_logo.json");
   }
@@ -155,50 +122,12 @@ public class GlobalNavigationActionTest {
   }
 
   private void nominalSetup() {
-    createAndConfigureDashboardForUser();
-    createAndConfigureDashboardForAnonymous();
-
     session.commit();
 
     Settings settings = new MapSettings()
       .setProperty("sonar.lf.logoUrl", "http://some-server.tld/logo.png")
       .setProperty("sonar.lf.logoWidthPx", "123");
-    wsTester = new WsTester(new NavigationWs(new GlobalNavigationAction(activeDashboardDao, createViews(), settings, new ResourceTypes(), userSessionRule)));
-  }
-
-  private void createAndConfigureDashboardForUser() {
-    UserDto user = createUser("obiwan", 42L);
-    userDao.insert(session, user);
-    DashboardDto defaultDashboardForUser = createDashboard(1L, "Default Dashboard for User");
-    dashboardDao.insert(defaultDashboardForUser);
-    activeDashboardDao.insert(createActiveDashboard(user.getId(), defaultDashboardForUser.getId(), 1));
-  }
-
-  private void createAndConfigureDashboardForAnonymous() {
-    DashboardDto defaultDashboardForAnonymous = createDashboard(2L, "Default Dashboard for Anonymous");
-    dashboardDao.insert(defaultDashboardForAnonymous);
-    activeDashboardDao.insert(createActiveDashboard(null, defaultDashboardForAnonymous.getId(), 1));
-  }
-
-  private UserDto createUser(String login, Long userId) {
-    return new UserDto()
-      .setActive(true)
-      .setId(userId)
-      .setLogin(login);
-  }
-
-  private DashboardDto createDashboard(long id, String name) {
-    return new DashboardDto()
-      .setId(id)
-      .setName(name)
-      .setShared(true);
-  }
-
-  private ActiveDashboardDto createActiveDashboard(Long userId, Long dashboardId, int orderIndex) {
-    return new ActiveDashboardDto()
-      .setOrderIndex(orderIndex)
-      .setDashboardId(dashboardId)
-      .setUserId(userId);
+    wsTester = new WsTester(new NavigationWs(new GlobalNavigationAction(createViews(), settings, new ResourceTypes())));
   }
 
   private Views createViews() {
@@ -207,6 +136,7 @@ public class GlobalNavigationActionTest {
       public String getTitle() {
         return "My Plugin Page";
       }
+
       @Override
       public String getId() {
         return "my_plugin_page";
@@ -218,6 +148,7 @@ public class GlobalNavigationActionTest {
       public String getTitle() {
         return "My Rails App";
       }
+
       @Override
       public String getId() {
         return "/my_rails_app";
index abd48e7adac76274598843ae0c426eb391e2d308..1ad7b80b0916ba3478cf7539c163d42e3d732b8e 100644 (file)
@@ -1,9 +1,4 @@
 {
-  "globalDashboards": [
-    {
-      "name": "Default Dashboard for User"
-    }
-  ],
   "globalPages": [
     {
       "name": "My Plugin Page",
index d6877e59d2abbf3f049262b977854658ccb8e527..4bb69ea6b3d52993ebf286fe4e0329de8eb46ce8 100644 (file)
@@ -1,9 +1,4 @@
 {
-  "globalDashboards": [
-    {
-      "name": "Default Dashboard for Anonymous"
-    }
-  ],
   "globalPages": [
     {
       "name": "My Plugin Page",
index eb0242c10fc850391447c9cd8b0726d196949659..4bb69ea6b3d52993ebf286fe4e0329de8eb46ce8 100644 (file)
@@ -1,9 +1,4 @@
 {
-  "globalDashboards": [
-    {
-      "name": "Default Dashboard for User"
-    }
-  ],
   "globalPages": [
     {
       "name": "My Plugin Page",