From 65c729ebd24a5f1dc7e076b866aadf701556e9d2 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 5 Jun 2013 13:04:15 +0200 Subject: [PATCH] SONAR-3755 Fix issue on SQL to retrieve root project --- .../org/sonar/core/resource/ResourceMapper.xml | 11 ++++++----- .../sonar/core/resource/ResourceDaoTest/fixture.xml | 11 +++++++++++ .../java/org/sonar/server/issue/IssueService.java | 4 ++-- .../java/org/sonar/server/issue/IssueServiceTest.java | 4 ++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml index 41de56b6931..0b6d58823bb 100644 --- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml @@ -103,20 +103,21 @@ diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml index 6445d143ed7..0c72a978001 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml @@ -13,6 +13,15 @@ period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path=""/> + + + diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java b/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java index f6a9e846b0a..14ade9f87e4 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java @@ -203,14 +203,14 @@ public class IssueService implements ServerComponent { // must be logged throw new IllegalStateException("User is not logged in"); } - if (!authorizationDao.isAuthorizedComponentId(findProject(issue.componentKey()).getId(), userSession.userId(), requiredRole)) { + if (!authorizationDao.isAuthorizedComponentId(findRootProject(issue.componentKey()).getId(), userSession.userId(), requiredRole)) { // TODO throw unauthorized throw new IllegalStateException("User does not have the required role"); } } @VisibleForTesting - ResourceDto findProject(String componentKey) { + ResourceDto findRootProject(String componentKey) { ResourceDto resourceDto = resourceDao.getRootProjectByComponentKey(componentKey); if (resourceDto == null) { // TODO throw 404 diff --git a/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceTest.java b/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceTest.java index 584c217ad06..bfeec5cbfc1 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceTest.java @@ -411,14 +411,14 @@ public class IssueServiceTest { public void should_find_project() { ResourceDto project = new ResourceDto().setKey("org.sonar.Sample").setId(1l); when(resourceDao.getRootProjectByComponentKey(anyString())).thenReturn(project); - assertThat(issueService.findProject("org.sonar.Sample")).isEqualTo(project); + assertThat(issueService.findRootProject("org.sonar.Sample")).isEqualTo(project); } @Test public void should_fail_to_find_project() { when(resourceDao.getRootProjectByComponentKey(anyString())).thenReturn(null); try { - issueService.findProject("org.sonar.Sample"); + issueService.findRootProject("org.sonar.Sample"); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Component 'org.sonar.Sample' does not exists."); -- 2.39.5