From: Julien Lancelot Date: Tue, 13 Nov 2018 10:32:58 +0000 (+0100) Subject: SONAR-11249 Fix display of quality gate on long-lived branch prj page X-Git-Tag: 6.7.6~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F3185%2Fhead;p=sonarqube.git SONAR-11249 Fix display of quality gate on long-lived branch prj page --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java index a55d2ebcfe8..dac671c6b03 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java @@ -140,6 +140,7 @@ public class ComponentAction implements NavigationWsAction { !userSession.isSystemAdministrator()) { throw insufficientPrivilegesException(); } + ComponentDto project = component.getMainBranchProjectUuid() == null ? component : componentFinder.getByUuid(session, component.getMainBranchProjectUuid()); OrganizationDto org = componentFinder.getOrganization(session, component); Optional analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, component.projectUuid()); @@ -147,7 +148,7 @@ public class ComponentAction implements NavigationWsAction { json.beginObject(); writeComponent(json, session, component, org, analysis.orElse(null)); writeProfiles(json, session, component); - writeQualityGate(json, session, component); + writeQualityGate(json, session, project); if (userSession.hasComponentPermission(ADMIN, component) || userSession.hasPermission(ADMINISTER_QUALITY_PROFILES, org) || userSession.hasPermission(ADMINISTER_QUALITY_GATES, org)) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java index 536795e12b1..7966b9a8ae5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java @@ -71,6 +71,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.api.measures.CoreMetrics.QUALITY_PROFILES_KEY; import static org.sonar.api.web.page.Page.Scope.COMPONENT; +import static org.sonar.db.component.BranchType.LONG; import static org.sonar.db.component.ComponentTesting.newDirectory; import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newModuleDto; @@ -291,6 +292,25 @@ public class ComponentActionTest { executeAndVerify(project.getDbKey(), "return_quality_gate.json"); } + @Test + public void quality_gate_for_a_long_living_branch() { + dbTester.qualityGates().createDefaultQualityGate("Default"); + ComponentDto project = dbTester.components().insertPrivateProject(); + ComponentDto longLivingBranch = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(LONG)); + QualityGateDto qualityGateDto = dbTester.qualityGates().insertQualityGate("Sonar way"); + dbTester.qualityGates().associateProjectToQualityGate(project, qualityGateDto); + userSession.addProjectPermission(UserRole.USER, project); + init(); + + String json = ws.newRequest() + .setParam("componentKey", longLivingBranch.getKey()) + .setParam("branch", longLivingBranch.getBranch()) + .execute() + .getInput(); + + verify(json, "return_quality_gate.json"); + } + @Test public void return_default_quality_gate() throws Exception { init();