]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10426 Allow homepage on Projects and on Issues in SonarQube
authorGuillaume Jambet <guillaume.jambet@sonarsource.com>
Tue, 20 Feb 2018 16:00:30 +0000 (17:00 +0100)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Fri, 2 Mar 2018 12:17:32 +0000 (13:17 +0100)
server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypes.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypesImpl.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/HomepageTypesImplTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/SetHomepageActionTest.java
sonar-ws/src/main/protobuf/ws-users.proto
tests/src/test/java/org/sonarqube/tests/user/SonarCloudHomepageTest.java

index cd811d67f1dda5306ccb5cda312900f99340c094..2e00e41444e2408c38086b68c90d339e41e3d4ec 100644 (file)
@@ -26,9 +26,9 @@ public interface HomepageTypes {
   enum Type {
     PROJECT,
     /**
-     * This type in only available on SonarQube
+     * These types in only available on SonarQube
      */
-    PROJECTS,
+    PROJECTS, ISSUES,
     /**
      * These types are only available on SonarCloud
      */
index 026cc0bdc6f06c6dd6e53143e5473c6957e0006c..7dfc2527d59178603eb26f2f0419d02cfe638f7f 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.server.organization.OrganizationFlags;
 import static com.google.common.base.Preconditions.checkState;
 import static java.util.Arrays.stream;
 import static java.util.stream.Collectors.toList;
+import static org.sonar.server.user.ws.HomepageTypes.Type.ISSUES;
 import static org.sonar.server.user.ws.HomepageTypes.Type.MY_ISSUES;
 import static org.sonar.server.user.ws.HomepageTypes.Type.MY_PROJECTS;
 import static org.sonar.server.user.ws.HomepageTypes.Type.ORGANIZATION;
@@ -41,7 +42,7 @@ import static org.sonar.server.user.ws.HomepageTypes.Type.values;
 
 public class HomepageTypesImpl implements HomepageTypes, Startable {
 
-  private static final EnumSet<Type> ON_SONARQUBE = EnumSet.of(PROJECTS, PROJECT, ORGANIZATION);
+  private static final EnumSet<Type> ON_SONARQUBE = EnumSet.of(PROJECTS, PROJECT, ISSUES, ORGANIZATION);
   private static final EnumSet<Type> ON_SONARCLOUD = EnumSet.of(PROJECT, MY_PROJECTS, MY_ISSUES, ORGANIZATION);
 
   private final Configuration configuration;
index 4765058dc95f847a798a31845bc63edb544b60b9..3047f3b5be7f859d56632741b9740a886028a7cb 100644 (file)
@@ -46,7 +46,7 @@ public class SetHomepageAction implements UsersWsAction {
 
   private static final String ACTION = "set_homepage";
 
-  private static final String PARAM_TYPE = "type";
+  public static final String PARAM_TYPE = "type";
   private static final String PARAM_ORGANIZATION = "organization";
   private static final String PARAM_COMPONENT = "component";
   private static final String PARAM_BRANCH = "branch";
@@ -54,13 +54,11 @@ public class SetHomepageAction implements UsersWsAction {
   private final UserSession userSession;
   private final DbClient dbClient;
   private final ComponentFinder componentFinder;
-  private HomepageTypes homepageTypes;
 
-  public SetHomepageAction(UserSession userSession, DbClient dbClient, ComponentFinder componentFinder, HomepageTypes homepageTypes) {
+  public SetHomepageAction(UserSession userSession, DbClient dbClient, ComponentFinder componentFinder) {
     this.userSession = userSession;
     this.dbClient = dbClient;
     this.componentFinder = componentFinder;
-    this.homepageTypes = homepageTypes;
   }
 
   @Override
@@ -77,12 +75,11 @@ public class SetHomepageAction implements UsersWsAction {
     action.createParam(PARAM_TYPE)
       .setDescription("Type of the requested page")
       .setRequired(true)
-      .setPossibleValues(homepageTypes.getTypes());
+      .setPossibleValues(HomepageTypes.Type.values());
 
     action.createParam(PARAM_ORGANIZATION)
       .setDescription("Organization key. It should only be used when parameter '%s' is set to '%s'", PARAM_TYPE, ORGANIZATION)
       .setSince("7.1")
-      .setInternal(false)
       .setExampleValue("my-org");
 
     action.createParam(PARAM_COMPONENT)
@@ -93,7 +90,6 @@ public class SetHomepageAction implements UsersWsAction {
     action.createParam(PARAM_BRANCH)
       .setDescription("Branch key. It can only be used when parameter '%s' is set to '%s'", PARAM_TYPE, PROJECT)
       .setExampleValue(KEY_BRANCH_EXAMPLE_001)
-      .setInternal(true)
       .setSince("7.1");
   }
 
@@ -131,6 +127,8 @@ public class SetHomepageAction implements UsersWsAction {
         return dbClient.organizationDao().selectByKey(dbSession, organizationParameter)
           .orElseThrow(() -> new NotFoundException(format("No organizationDto with key '%s'", organizationParameter)))
           .getUuid();
+      case PROJECTS:
+      case ISSUES:
       case MY_PROJECTS:
       case MY_ISSUES:
         checkArgument(isBlank(componentParameter), "Parameter '%s' must not be provided when type is '%s'", PARAM_COMPONENT, type.name());
index e6c9bf7aa778f99b1a66f8bffeb756f60c356eb9..b0a808c1fc33e880ed170ca3fe59da55dd59d890 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.db.DbTester;
 import org.sonar.server.organization.TestOrganizationFlags;
 
 import static org.assertj.core.api.Java6Assertions.assertThat;
+import static org.sonar.server.user.ws.HomepageTypes.Type.ISSUES;
 import static org.sonar.server.user.ws.HomepageTypes.Type.MY_ISSUES;
 import static org.sonar.server.user.ws.HomepageTypes.Type.MY_PROJECTS;
 import static org.sonar.server.user.ws.HomepageTypes.Type.ORGANIZATION;
@@ -70,7 +71,7 @@ public class HomepageTypesImplTest {
 
     underTest.start();
 
-    assertThat(underTest.getTypes()).containsExactlyInAnyOrder(PROJECT, PROJECTS);
+    assertThat(underTest.getTypes()).containsExactlyInAnyOrder(PROJECT, PROJECTS, ISSUES);
   }
 
   @Test
@@ -80,7 +81,7 @@ public class HomepageTypesImplTest {
 
     underTest.start();
 
-    assertThat(underTest.getTypes()).containsExactlyInAnyOrder(PROJECT, PROJECTS, ORGANIZATION);
+    assertThat(underTest.getTypes()).containsExactlyInAnyOrder(PROJECT, PROJECTS, ISSUES, ORGANIZATION);
   }
 
   @Test
index d04b170d8939c96814eb8c29fb7916ea0d5be351..968cc706da2b857a7d1efbe41bb1270df6d55332 100644 (file)
@@ -40,10 +40,13 @@ import static org.apache.http.HttpStatus.SC_NO_CONTENT;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.sonar.server.user.ws.HomepageTypes.Type.ISSUES;
 import static org.sonar.server.user.ws.HomepageTypes.Type.MY_ISSUES;
 import static org.sonar.server.user.ws.HomepageTypes.Type.MY_PROJECTS;
 import static org.sonar.server.user.ws.HomepageTypes.Type.ORGANIZATION;
 import static org.sonar.server.user.ws.HomepageTypes.Type.PROJECT;
+import static org.sonar.server.user.ws.HomepageTypes.Type.PROJECTS;
+import static org.sonar.server.user.ws.SetHomepageAction.PARAM_TYPE;
 
 public class SetHomepageActionTest {
 
@@ -64,7 +67,7 @@ public class SetHomepageActionTest {
   @Before
   public void setUp() {
     when(homepageTypes.getTypes()).thenReturn(asList(PROJECT, ORGANIZATION, MY_ISSUES, MY_PROJECTS));
-    ws = new WsActionTester(new SetHomepageAction(userSession, dbClient, TestComponentFinder.from(db), homepageTypes));
+    ws = new WsActionTester(new SetHomepageAction(userSession, dbClient, TestComponentFinder.from(db)));
   }
 
   @Test
@@ -81,7 +84,6 @@ public class SetHomepageActionTest {
     WebService.Param typeParam = action.param("type");
     assertThat(typeParam.isRequired()).isTrue();
     assertThat(typeParam.description()).isEqualTo("Type of the requested page");
-    assertThat(typeParam.possibleValues()).containsExactlyInAnyOrder("PROJECT", "ORGANIZATION", "MY_PROJECTS", "MY_ISSUES");
 
     WebService.Param componentParam = action.param("component");
     assertThat(componentParam.isRequired()).isFalse();
@@ -90,7 +92,6 @@ public class SetHomepageActionTest {
 
     WebService.Param branchParam = action.param("branch");
     assertThat(branchParam.isRequired()).isFalse();
-    assertThat(branchParam.isInternal()).isTrue();
     assertThat(branchParam.description()).isEqualTo("Branch key. It can only be used when parameter 'type' is set to 'PROJECT'");
     assertThat(branchParam.since()).isEqualTo("7.1");
 
@@ -110,7 +111,7 @@ public class SetHomepageActionTest {
 
     ws.newRequest()
       .setMethod("POST")
-      .setParam("type", "PROJECT")
+      .setParam(PARAM_TYPE, "PROJECT")
       .setParam("component", project.getKey())
       .execute();
 
@@ -130,7 +131,7 @@ public class SetHomepageActionTest {
 
     ws.newRequest()
       .setMethod("POST")
-      .setParam("type", "PROJECT")
+      .setParam(PARAM_TYPE, "PROJECT")
       .setParam("component", branch.getKey())
       .setParam("branch", branch.getBranch())
       .execute();
@@ -150,7 +151,7 @@ public class SetHomepageActionTest {
 
     ws.newRequest()
       .setMethod("POST")
-      .setParam("type", "ORGANIZATION")
+      .setParam(PARAM_TYPE, "ORGANIZATION")
       .setParam("organization", organization.getKey())
       .execute();
 
@@ -161,13 +162,13 @@ public class SetHomepageActionTest {
   }
 
   @Test
-  public void set_my_issues_homepage() {
+  public void set_sonarcloud_my_issues_homepage() {
     UserDto user = db.users().insertUser();
     userSession.logIn(user);
 
     ws.newRequest()
       .setMethod("POST")
-      .setParam("type", "MY_ISSUES")
+      .setParam(PARAM_TYPE, "MY_ISSUES")
       .execute();
 
     UserDto actual = db.getDbClient().userDao().selectByLogin(db.getSession(), user.getLogin());
@@ -177,13 +178,33 @@ public class SetHomepageActionTest {
   }
 
   @Test
-  public void set_my_projects_homepage() {
+  public void set_sonarqube_issues_homepage() {
+
+    when(homepageTypes.getTypes()).thenReturn(asList(PROJECT, ORGANIZATION, ISSUES, PROJECTS));
+    ws = new WsActionTester(new SetHomepageAction(userSession, dbClient, TestComponentFinder.from(db)));
+
+    UserDto user = db.users().insertUser();
+    userSession.logIn(user);
+
+    ws.newRequest()
+      .setMethod("POST")
+      .setParam(PARAM_TYPE, "ISSUES")
+      .execute();
+
+    UserDto actual = db.getDbClient().userDao().selectByLogin(db.getSession(), user.getLogin());
+    assertThat(actual).isNotNull();
+    assertThat(actual.getHomepageType()).isEqualTo("ISSUES");
+    assertThat(actual.getHomepageParameter()).isNullOrEmpty();
+  }
+
+  @Test
+  public void set_sonarcloud_my_projects_homepage() {
     UserDto user = db.users().insertUser();
     userSession.logIn(user);
 
     ws.newRequest()
       .setMethod("POST")
-      .setParam("type", "MY_PROJECTS")
+      .setParam(PARAM_TYPE, "MY_PROJECTS")
       .execute();
 
     UserDto actual = db.getDbClient().userDao().selectByLogin(db.getSession(), user.getLogin());
@@ -192,6 +213,25 @@ public class SetHomepageActionTest {
     assertThat(actual.getHomepageParameter()).isNullOrEmpty();
   }
 
+  @Test
+  public void set_sonarqube_projects_homepage() {
+    when(homepageTypes.getTypes()).thenReturn(asList(PROJECT, ORGANIZATION, ISSUES, PROJECTS));
+    ws = new WsActionTester(new SetHomepageAction(userSession, dbClient, TestComponentFinder.from(db)));
+
+    UserDto user = db.users().insertUser();
+    userSession.logIn(user);
+
+    ws.newRequest()
+      .setMethod("POST")
+      .setParam(PARAM_TYPE, "PROJECTS")
+      .execute();
+
+    UserDto actual = db.getDbClient().userDao().selectByLogin(db.getSession(), user.getLogin());
+    assertThat(actual).isNotNull();
+    assertThat(actual.getHomepageType()).isEqualTo("PROJECTS");
+    assertThat(actual.getHomepageParameter()).isNullOrEmpty();
+  }
+
   @Test
   public void response_has_no_content() {
     UserDto user = db.users().insertUser();
@@ -199,7 +239,7 @@ public class SetHomepageActionTest {
 
     TestResponse response = ws.newRequest()
       .setMethod("POST")
-      .setParam("type", "MY_PROJECTS")
+      .setParam(PARAM_TYPE, "MY_PROJECTS")
       .execute();
 
     assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
@@ -216,7 +256,7 @@ public class SetHomepageActionTest {
 
     ws.newRequest()
       .setMethod("POST")
-      .setParam("type", "PROJECT")
+      .setParam(PARAM_TYPE, "PROJECT")
       .execute();
 
   }
@@ -231,7 +271,7 @@ public class SetHomepageActionTest {
 
     ws.newRequest()
       .setMethod("POST")
-      .setParam("type", "ORGANIZATION")
+      .setParam(PARAM_TYPE, "ORGANIZATION")
       .execute();
   }
 
index cb83cede2e768ede14ec8de1fde2f8964b06a9c1..59b03221792fc871dc4ca935c175610c9e6c2afd 100644 (file)
@@ -120,6 +120,7 @@ message CurrentWsResponse {
     MY_PROJECTS = 3;
     MY_ISSUES = 4;
     PROJECTS = 5;
+    ISSUES = 6;
   }
 
   message Homepage {
index 140999bf6b97c38218bbe08cf4c66abe1eecf5fa..c477a1b46a0e2ed046d7d44e15b7cc503063f0e3 100644 (file)
@@ -66,6 +66,17 @@ public class SonarCloudHomepageTest {
     checkHomepage(user, MY_ISSUES, null, null);
   }
 
+
+  @Test
+  public void set_and_get_homepage_on_organizations() {
+    Organization organization = tester.organizations().generate();
+    User user = tester.users().generateMember(organization);
+
+    setHomepage(user, "ORGANIZATION", organization.getKey(), null);
+
+    checkHomepage(user, ORGANIZATION, organization, null);
+  }
+
   @Test
   public void fallback_to_my_projects_when_homepage_was_set_to_a_removed_project() {
     Organization organization = tester.organizations().generate();