diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-05-12 14:41:23 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-05-12 14:41:23 +0200 |
commit | e0eaacef1ec9c6398975c309624d28031814e8ec (patch) | |
tree | 08ae47f75214cd4c3ce5f5a27d1aaf14ad3cdffd | |
parent | 1fec4af1dbf266ac5e0ca3b04b4a987ad50e052d (diff) | |
download | sonarqube-e0eaacef1ec9c6398975c309624d28031814e8ec.tar.gz sonarqube-e0eaacef1ec9c6398975c309624d28031814e8ec.zip |
SONAR-1884 Use explicit method on root component keys for authorization on profile projects page
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java | 10 | ||||
-rw-r--r-- | sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileProjectLookupTest.java | 4 |
2 files changed, 7 insertions, 7 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java index e286088d260..5dd735c852e 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java @@ -34,6 +34,7 @@ import org.sonar.server.user.UserSession; import javax.annotation.CheckForNull; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -63,10 +64,11 @@ public class QProfileProjectLookup implements ServerComponent { UserSession userSession = UserSession.get(); List<Component> result = Lists.newArrayList(); - for (String key: authorizationDao.keepAuthorizedComponentKeys( - componentsByKeys.keySet(), userSession.userId(), UserRole.USER - )) { - result.add(componentsByKeys.get(key)); + Collection<String> authorizedProjectKeys = authorizationDao.selectAuthorizedRootProjectsKeys(userSession.userId(), UserRole.USER); + for (String key: componentsByKeys.keySet()) { + if (authorizedProjectKeys.contains(key)) { + result.add(componentsByKeys.get(key)); + } } return result; diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileProjectLookupTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileProjectLookupTest.java index f618d00c389..e4e9c747669 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileProjectLookupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileProjectLookupTest.java @@ -40,8 +40,6 @@ import org.sonar.server.user.MockUserSession; import static com.google.common.collect.Lists.newArrayList; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; -import static org.mockito.Matchers.anySet; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -83,7 +81,7 @@ public class QProfileProjectLookupTest { new ComponentDto().setId(1L).setKey(key1).setName("SonarQube One"), new ComponentDto().setId(1L).setKey(key2).setName("SonarQube Two"))); - when(authorizationDao.keepAuthorizedComponentKeys(anySet(), eq(userId), eq(UserRole.USER))).thenReturn(Sets.newHashSet(key1)); + when(authorizationDao.selectAuthorizedRootProjectsKeys(userId, UserRole.USER)).thenReturn(Sets.newHashSet(key1)); assertThat(lookup.projects(1)).hasSize(1); } |