aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-06-01 10:51:30 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-06-01 10:56:17 +0200
commit95d5833985ba0755053fd9408e0a7aeda010b8d9 (patch)
tree85af44ee7c17e1423d4051905cdd60f1eb0101aa /sonar-core
parent398dd7329e025be2c72cca994ae43f834a4ec407 (diff)
downloadsonarqube-95d5833985ba0755053fd9408e0a7aeda010b8d9.tar.gz
sonarqube-95d5833985ba0755053fd9408e0a7aeda010b8d9.zip
SONAR-6259 Grant project permission on the compute engine
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java17
-rw-r--r--sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java5
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/fail_when_no_default_template_is_defined.xml5
3 files changed, 15 insertions, 12 deletions
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 @@
+<dataset>
+
+ <projects id="123" kee="project"/>
+
+</dataset>