aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypes.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypesImpl.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java12
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ws/HomepageTypesImplTest.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ws/SetHomepageActionTest.java66
-rw-r--r--sonar-ws/src/main/protobuf/ws-users.proto1
-rw-r--r--tests/src/test/java/org/sonarqube/tests/user/SonarCloudHomepageTest.java11
7 files changed, 77 insertions, 25 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypes.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypes.java
index cd811d67f1d..2e00e41444e 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypes.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypes.java
@@ -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
*/
diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypesImpl.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypesImpl.java
index 026cc0bdc6f..7dfc2527d59 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypesImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/HomepageTypesImpl.java
@@ -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;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java
index 4765058dc95..3047f3b5be7 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java
@@ -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());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/HomepageTypesImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/HomepageTypesImplTest.java
index e6c9bf7aa77..b0a808c1fc3 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/HomepageTypesImplTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/HomepageTypesImplTest.java
@@ -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
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SetHomepageActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SetHomepageActionTest.java
index d04b170d893..968cc706da2 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SetHomepageActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SetHomepageActionTest.java
@@ -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());
@@ -193,13 +214,32 @@ public class SetHomepageActionTest {
}
@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();
userSession.logIn(user);
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();
}
diff --git a/sonar-ws/src/main/protobuf/ws-users.proto b/sonar-ws/src/main/protobuf/ws-users.proto
index cb83cede2e7..59b03221792 100644
--- a/sonar-ws/src/main/protobuf/ws-users.proto
+++ b/sonar-ws/src/main/protobuf/ws-users.proto
@@ -120,6 +120,7 @@ message CurrentWsResponse {
MY_PROJECTS = 3;
MY_ISSUES = 4;
PROJECTS = 5;
+ ISSUES = 6;
}
message Homepage {
diff --git a/tests/src/test/java/org/sonarqube/tests/user/SonarCloudHomepageTest.java b/tests/src/test/java/org/sonarqube/tests/user/SonarCloudHomepageTest.java
index 140999bf6b9..c477a1b46a0 100644
--- a/tests/src/test/java/org/sonarqube/tests/user/SonarCloudHomepageTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/user/SonarCloudHomepageTest.java
@@ -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();