From 95d5833985ba0755053fd9408e0a7aeda010b8d9 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 1 Jun 2015 10:51:30 +0200 Subject: SONAR-6259 Grant project permission on the compute engine --- .../org/sonar/core/permission/PermissionFacade.java | 17 ++++++----------- .../core/resource/DefaultResourcePermissionsTest.java | 5 ++++- .../fail_when_no_default_template_is_defined.xml | 5 +++++ 3 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/fail_when_no_default_template_is_defined.xml (limited to 'sonar-core') diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java index ac2d768ef1c..b4a0c68c6cf 100644 --- a/sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java +++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java @@ -21,11 +21,16 @@ package org.sonar.core.permission; import com.google.common.annotations.VisibleForTesting; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.BatchSide; -import org.sonar.api.server.ServerSide; import org.sonar.api.config.Settings; import org.sonar.api.security.DefaultGroups; +import org.sonar.api.server.ServerSide; import org.sonar.core.persistence.DbSession; import org.sonar.core.resource.ResourceDao; import org.sonar.core.resource.ResourceDto; @@ -35,13 +40,6 @@ import org.sonar.core.user.RoleDao; import org.sonar.core.user.UserDao; import org.sonar.core.user.UserRoleDto; -import javax.annotation.Nullable; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - /** * This facade wraps db operations related to permissions * @@ -201,9 +199,6 @@ public class PermissionFacade { public void grantDefaultRoles(DbSession session, Long componentId, String qualifier) { ResourceDto resource = resourceDao.getResource(componentId, session); - if (resource == null) { - throw new IllegalStateException("Unable to find resource with id " + componentId); - } String applicablePermissionTemplateKey = getApplicablePermissionTemplateKey(session, resource.getKey(), qualifier); applyPermissionTemplate(session, applicablePermissionTemplateKey, componentId); } diff --git a/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java b/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java index a3f75efac0b..0ccbedaadda 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java @@ -224,8 +224,11 @@ public class DefaultResourcePermissionsTest extends AbstractDaoTestCase { } @Test - public void should_fail_when_no_default_template_is_defined() { + public void fail_when_no_default_template_is_defined() { throwable.expect(IllegalStateException.class); + throwable.expectMessage("At least one default permission template should be defined"); + + setupData("fail_when_no_default_template_is_defined"); permissions.grantDefaultRoles(project); } diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/fail_when_no_default_template_is_defined.xml b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/fail_when_no_default_template_is_defined.xml new file mode 100644 index 00000000000..1fffc1facb2 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/fail_when_no_default_template_is_defined.xml @@ -0,0 +1,5 @@ + + + + + -- cgit v1.2.3