diff options
author | Zipeng WU <zipeng.wu@sonarsource.com> | 2024-11-22 11:34:23 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-11-29 20:03:07 +0000 |
commit | b85729ae76a2b00d324f8f2460cdc47579582594 (patch) | |
tree | 1cb8c3d735dd1b940fab052249ec027f52fe3b88 /server/sonar-webserver-webapi | |
parent | 1553847b42c26843c1503fdd8716fe3d9dbee726 (diff) | |
download | sonarqube-b85729ae76a2b00d324f8f2460cdc47579582594.tar.gz sonarqube-b85729ae76a2b00d324f8f2460cdc47579582594.zip |
SONAR-23619 Remove quality gate project’s assignment restrictions
Diffstat (limited to 'server/sonar-webserver-webapi')
4 files changed, 12 insertions, 91 deletions
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/DeselectActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/DeselectActionIT.java index 5f33072d2a7..74c35e63ffe 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/DeselectActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/DeselectActionIT.java @@ -20,7 +20,6 @@ package org.sonar.server.qualitygate.ws; import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.sonar.api.server.ws.Change; @@ -32,25 +31,18 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ProjectData; import org.sonar.db.project.ProjectDto; import org.sonar.db.qualitygate.QualityGateDto; -import org.sonar.server.ai.code.assurance.AiCodeAssuranceVerifier; import org.sonar.server.component.ComponentFinder; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; -import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.WsActionTester; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.tuple; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.sonar.api.web.UserRole.ADMIN; import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES; import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES; -import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_GATE_NAME; class DeselectActionIT { @@ -61,16 +53,10 @@ class DeselectActionIT { private final DbClient dbClient = db.getDbClient(); private final ComponentFinder componentFinder = TestComponentFinder.from(db); - private final AiCodeAssuranceVerifier aiCodeAssuranceVerifier = mock(AiCodeAssuranceVerifier.class); private final DeselectAction underTest = new DeselectAction(dbClient, new QualityGatesWsSupport(db.getDbClient(), userSession, - componentFinder), aiCodeAssuranceVerifier); + componentFinder)); private final WsActionTester ws = new WsActionTester(underTest); - @BeforeEach - void setUp() { - when(aiCodeAssuranceVerifier.isAiCodeAssured(any())).thenReturn(false); - } - @Test void deselect_by_key() { userSession.addPermission(ADMINISTER_QUALITY_GATES); @@ -185,7 +171,8 @@ class DeselectActionIT { assertThat(def.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder( tuple("6.6", "The parameter 'gateId' was removed"), tuple("8.3", "The parameter 'projectId' was removed"), - tuple("10.7", "It is not possible anymore to change the Quality Gate of a project flagged as containing AI code.")); + tuple("10.7", "It is not possible anymore to change the Quality Gate of a project flagged as containing AI code."), + tuple("10.8", "Allow to change the Quality Gate of a project flagged as containing AI code.")); assertThat(def.params()) .extracting(WebService.Param::key, WebService.Param::isRequired) @@ -193,23 +180,6 @@ class DeselectActionIT { tuple("projectKey", true)); } - @Test - void whenAiCodeAssuranceIsSet_failIfEditionIsDeveloperOrHigher() { - QualityGateDto qualityGate = db.qualityGates().insertQualityGate(); - ProjectDto projectDto = db.components().insertProjectWithAiCode().getProjectDto(); - when(aiCodeAssuranceVerifier.isAiCodeAssured(projectDto)).thenReturn(true); - - userSession.logIn().addProjectPermission(ADMIN, projectDto); - - TestRequest request = ws.newRequest() - .setParam(PARAM_GATE_NAME, qualityGate.getName()) - .setParam("projectKey", projectDto.getKey()); - - assertThatThrownBy(request::execute) - .isInstanceOf(ForbiddenException.class) - .hasMessage("Quality gate cannot be changed for project with AI Code Assurance enabled."); - } - private void associateProjectToQualityGate(ProjectDto project, QualityGateDto qualityGate) { db.qualityGates().associateProjectToQualityGate(project, qualityGate); db.commit(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/SelectActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/SelectActionIT.java index 1a2a0843b85..0c5b6b4bdb6 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/SelectActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/SelectActionIT.java @@ -20,7 +20,6 @@ package org.sonar.server.qualitygate.ws; import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.sonar.db.DbClient; @@ -29,20 +28,15 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ProjectData; import org.sonar.db.project.ProjectDto; import org.sonar.db.qualitygate.QualityGateDto; -import org.sonar.server.ai.code.assurance.AiCodeAssuranceVerifier; import org.sonar.server.component.ComponentFinder; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; -import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.WsActionTester; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import static org.sonar.api.web.UserRole.ADMIN; import static org.sonar.api.web.UserRole.ISSUE_ADMIN; import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES; @@ -57,16 +51,10 @@ class SelectActionIT { private final DbClient dbClient = db.getDbClient(); private final ComponentFinder componentFinder = TestComponentFinder.from(db); - private final AiCodeAssuranceVerifier aiCodeAssuranceVerifier = mock(AiCodeAssuranceVerifier.class); private final SelectAction underTest = new SelectAction(dbClient, - new QualityGatesWsSupport(db.getDbClient(), userSession, componentFinder), aiCodeAssuranceVerifier); + new QualityGatesWsSupport(db.getDbClient(), userSession, componentFinder)); private final WsActionTester ws = new WsActionTester(underTest); - @BeforeEach - void setUp() { - when(aiCodeAssuranceVerifier.isAiCodeAssured(any())).thenReturn(false); - } - @Test void select_by_key() { userSession.addPermission(ADMINISTER_QUALITY_GATES); @@ -211,23 +199,6 @@ class SelectActionIT { .isInstanceOf(ForbiddenException.class); } - @Test - void whenAiCodeAssuranceIsSet_failIfEditionIsDeveloperOrHigher() { - QualityGateDto qualityGate = db.qualityGates().insertQualityGate(); - ProjectDto projectDto = db.components().insertProjectWithAiCode().getProjectDto(); - when(aiCodeAssuranceVerifier.isAiCodeAssured(projectDto)).thenReturn(true); - - userSession.logIn().addProjectPermission(ADMIN, projectDto); - - TestRequest request = ws.newRequest() - .setParam(PARAM_GATE_NAME, qualityGate.getName()) - .setParam("projectKey", projectDto.getKey()); - - assertThatThrownBy(request::execute) - .isInstanceOf(ForbiddenException.class) - .hasMessage("Quality gate cannot be changed for project with AI Code Assurance enabled."); - } - private void assertSelected(QualityGateDto qualityGate, ProjectDto project) { Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByProjectUuid(project.getUuid()); assertThat(qGateUuid) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java index a9c008f3f17..b5a9343505c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java @@ -26,8 +26,6 @@ import org.sonar.api.server.ws.WebService; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.project.ProjectDto; -import org.sonar.server.ai.code.assurance.AiCodeAssuranceVerifier; -import org.sonar.server.exceptions.ForbiddenException; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PROJECT_KEY; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; @@ -36,12 +34,10 @@ public class DeselectAction implements QualityGatesWsAction { private final DbClient dbClient; private final QualityGatesWsSupport wsSupport; - private final AiCodeAssuranceVerifier aiCodeAssuranceVerifier; - public DeselectAction(DbClient dbClient, QualityGatesWsSupport wsSupport, AiCodeAssuranceVerifier aiCodeAssuranceVerifier) { + public DeselectAction(DbClient dbClient, QualityGatesWsSupport wsSupport) { this.wsSupport = wsSupport; this.dbClient = dbClient; - this.aiCodeAssuranceVerifier = aiCodeAssuranceVerifier; } @Override @@ -57,9 +53,10 @@ public class DeselectAction implements QualityGatesWsAction { .setSince("4.3") .setHandler(this) .setChangelog( + new Change("10.8", "Allow to change the Quality Gate of a project flagged as containing AI code."), new Change("10.7", "It is not possible anymore to change the Quality Gate of a project flagged as containing AI code."), - new Change("8.3", "The parameter 'projectId' was removed"), - new Change("6.6", "The parameter 'gateId' was removed")); + new Change("6.6", "The parameter 'gateId' was removed"), + new Change("8.3", "The parameter 'projectId' was removed")); action.createParam(PARAM_PROJECT_KEY) .setRequired(true) @@ -78,15 +75,8 @@ public class DeselectAction implements QualityGatesWsAction { } private void dissociateProject(DbSession dbSession, ProjectDto project) { - checkProjectQGCanChange(project); + wsSupport.checkCanAdminProject(project); dbClient.projectQgateAssociationDao().deleteByProjectUuid(dbSession, project.getUuid()); dbSession.commit(); } - - private void checkProjectQGCanChange(ProjectDto project) { - wsSupport.checkCanAdminProject(project); - if (aiCodeAssuranceVerifier.isAiCodeAssured(project)) { - throw new ForbiddenException("Quality gate cannot be changed for project with AI Code Assurance enabled."); - } - } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java index b6390f3a7bc..47f262c68b6 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java @@ -27,8 +27,6 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.project.ProjectDto; import org.sonar.db.qualitygate.QualityGateDto; -import org.sonar.server.ai.code.assurance.AiCodeAssuranceVerifier; -import org.sonar.server.exceptions.ForbiddenException; import static org.sonar.server.qualitygate.ws.CreateAction.NAME_MAXIMUM_LENGTH; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.ACTION_SELECT; @@ -39,12 +37,10 @@ import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; public class SelectAction implements QualityGatesWsAction { private final DbClient dbClient; private final QualityGatesWsSupport wsSupport; - private final AiCodeAssuranceVerifier aiCodeAssuranceVerifier; - public SelectAction(DbClient dbClient, QualityGatesWsSupport wsSupport, AiCodeAssuranceVerifier aiCodeAssuranceVerifier) { + public SelectAction(DbClient dbClient, QualityGatesWsSupport wsSupport) { this.dbClient = dbClient; this.wsSupport = wsSupport; - this.aiCodeAssuranceVerifier = aiCodeAssuranceVerifier; } @Override @@ -60,6 +56,7 @@ public class SelectAction implements QualityGatesWsAction { .setSince("4.3") .setHandler(this) .setChangelog( + new Change("10.8", "Allow to change the Quality Gate of a project flagged as containing AI code."), new Change("10.7", "It is not possible anymore to change the Quality Gate of a project flagged as containing AI code."), new Change("10.0", "Parameter 'gateId' is removed. Use 'gateName' instead."), new Change("8.4", "Parameter 'gateName' added"), @@ -90,7 +87,7 @@ public class SelectAction implements QualityGatesWsAction { QualityGateDto qualityGate; qualityGate = wsSupport.getByName(dbSession, gateName); ProjectDto project = wsSupport.getProject(dbSession, projectKey); - checkProjectQGCanChange(project); + wsSupport.checkCanAdminProject(project); QualityGateDto currentQualityGate = dbClient.qualityGateDao().selectByProjectUuid(dbSession, project.getUuid()); if (currentQualityGate == null) { @@ -106,11 +103,4 @@ public class SelectAction implements QualityGatesWsAction { } response.noContent(); } - - private void checkProjectQGCanChange(ProjectDto project) { - wsSupport.checkCanAdminProject(project); - if (aiCodeAssuranceVerifier.isAiCodeAssured(project)) { - throw new ForbiddenException("Quality gate cannot be changed for project with AI Code Assurance enabled."); - } - } } |