diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2017-12-05 19:06:41 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk@users.noreply.github.com> | 2017-12-07 14:39:16 +0100 |
commit | ca42beccae145e371dd465cf5db2e34f1469b46c (patch) | |
tree | 797e896240e2448a088cff5139fac27436cee248 | |
parent | aafecafc4ea56a6099731ab58572e376d27bd9f9 (diff) | |
download | sonarqube-ca42beccae145e371dd465cf5db2e34f1469b46c.tar.gz sonarqube-ca42beccae145e371dd465cf5db2e34f1469b46c.zip |
SONAR-10123 UserSession#keepkeepAuthorizedComponents handles branches properly
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java | 4 | ||||
-rw-r--r-- | server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java b/server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java index 28ec0313cd2..d8722146207 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java @@ -188,12 +188,12 @@ public class ServerUserSession extends AbstractUserSession { protected List<ComponentDto> doKeepAuthorizedComponents(String permission, Collection<ComponentDto> components) { try (DbSession dbSession = dbClient.openSession(false)) { Set<String> projectUuids = components.stream() - .map(ComponentDto::projectUuid) + .map(c -> defaultIfEmpty(c.getMainBranchProjectUuid(), c.projectUuid())) .collect(MoreCollectors.toSet(components.size())); Set<String> authorizedProjectUuids = dbClient.authorizationDao().keepAuthorizedProjectUuids(dbSession, projectUuids, getUserId(), permission); return components.stream() - .filter(c -> authorizedProjectUuids.contains(c.projectUuid())) + .filter(c -> authorizedProjectUuids.contains(c.projectUuid()) || authorizedProjectUuids.contains(c.getMainBranchProjectUuid())) .collect(MoreCollectors.toList(components.size())); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java index d19500ea2e4..038cb3badd0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java @@ -40,6 +40,7 @@ import org.sonar.server.organization.TestDefaultOrganizationProvider; import org.sonar.server.organization.TestOrganizationFlags; import static com.google.common.base.Preconditions.checkState; +import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.core.permission.GlobalPermissions.PROVISIONING; import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN; @@ -448,6 +449,17 @@ public class ServerUserSessionTest { } @Test + public void keepAuthorizedComponents_on_branches() { + user = db.users().insertUser(); + db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, privateProject); + ComponentDto privateBranchProject = db.components().insertProjectBranch(privateProject); + UserSession underTest = newUserSession(user); + + assertThat(underTest.keepAuthorizedComponents(UserRole.ADMIN, asList(privateProject, privateBranchProject))) + .containsExactlyInAnyOrder(privateProject, privateBranchProject); + } + + @Test public void isSystemAdministrator_returns_true_if_org_feature_is_enabled_and_user_is_root() { organizationFlags.setEnabled(true); user = db.users().makeRoot(user); |