From a6a9e784a3ebc96723fe21c7e18a67d44b67ae10 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 8 Feb 2017 21:29:37 +0100 Subject: [PATCH] Fix Quality flaws --- .../src/main/java/org/sonar/server/ce/ws/TaskAction.java | 7 ++++--- .../src/main/java/org/sonar/server/user/UserSession.java | 2 +- .../test/java/org/sonar/db/component/ComponentDaoTest.java | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/TaskAction.java b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/TaskAction.java index 4318f5910bf..48d3b44c1ce 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/TaskAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/TaskAction.java @@ -31,7 +31,6 @@ import javax.annotation.Nullable; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; -import org.sonar.core.permission.GlobalPermissions; import org.sonar.core.util.Uuids; import org.sonar.core.util.stream.Collectors; import org.sonar.db.DbClient; @@ -44,6 +43,7 @@ import org.sonar.server.user.UserSession; import org.sonarqube.ws.WsCe; import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION; +import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN; import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException; import static org.sonar.server.ws.WsUtils.writeProtobuf; @@ -122,8 +122,9 @@ public class TaskAction implements CeWsAction { private void checkPermission(Optional component) { if (component.isPresent()) { - if (!userSession.hasOrganizationPermission(component.get().getOrganizationUuid(), GlobalPermissions.SYSTEM_ADMIN) && - !userSession.hasOrganizationPermission(component.get().getOrganizationUuid(), GlobalPermissions.SCAN_EXECUTION) && + String orgUuid = component.get().getOrganizationUuid(); + if (!userSession.hasOrganizationPermission(orgUuid, SYSTEM_ADMIN) && + !userSession.hasOrganizationPermission(orgUuid, SCAN_EXECUTION) && !userSession.hasComponentPermission(SCAN_EXECUTION, component.get())) { throw insufficientPrivilegesException(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/UserSession.java b/server/sonar-server/src/main/java/org/sonar/server/user/UserSession.java index 4198fe6cd15..c95449fb063 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/UserSession.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/UserSession.java @@ -34,7 +34,7 @@ public interface UserSession { String getLogin(); /** - * NAme of the authenticated user. Returns {@code null} + * Name of the authenticated user. Returns {@code null} * if {@link #isLoggedIn()} is {@code false}. */ @CheckForNull diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java index 23f0afc361d..93f36f1e21b 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -541,8 +541,7 @@ public class ComponentDaoTest { public void select_provisioned() { OrganizationDto organization = db.organizations().insert(); ComponentDto provisionedProject = db.components().insertComponent(newProjectDto(organization).setKey("provisioned.project").setName("Provisioned Project")); - ComponentDto provisionedView = db.components().insertView(organization, (dto) -> { - }); + ComponentDto provisionedView = db.components().insertView(organization); String projectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization)).getComponentUuid(); String disabledProjectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization).setEnabled(false)).getComponentUuid(); String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid(); -- 2.39.5