aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-11-08 17:04:22 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-11-08 17:04:22 +0100
commit929a72a19587e5e06018e04c47ac525f033b333c (patch)
tree0a6103d769518848054fa64481842db72e0743c2 /sonar-batch
parentcee7f854a3d1403ad605c9aef560d3cbd27095eb (diff)
downloadsonarqube-929a72a19587e5e06018e04c47ac525f033b333c.tar.gz
sonarqube-929a72a19587e5e06018e04c47ac525f033b333c.zip
Grant roles when projects are created, not later during decorator phase
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java16
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java3
4 files changed, 20 insertions, 9 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java
index 4974e73cb1e..de3fdcfffb0 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java
@@ -50,6 +50,7 @@ import org.sonar.core.notification.DefaultNotificationManager;
import org.sonar.core.persistence.DaoUtils;
import org.sonar.core.persistence.DatabaseVersion;
import org.sonar.core.persistence.MyBatis;
+import org.sonar.core.resource.DefaultResourcePermissions;
import org.sonar.core.rule.CacheRuleFinder;
import org.sonar.core.user.DefaultUserFinder;
import org.sonar.jpa.dao.MeasuresDao;
@@ -85,6 +86,7 @@ public class BatchModule extends Module {
container.addSingleton(LinkPersister.class);
container.addSingleton(MeasurePersister.class);
container.addSingleton(MemoryOptimizer.class);
+ container.addSingleton(DefaultResourcePermissions.class);
container.addSingleton(DefaultResourcePersister.class);
container.addSingleton(SourcePersister.class);
container.addSingleton(MeasuresDao.class);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
index 0917fa776b2..77b97879ced 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
@@ -26,6 +26,7 @@ import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.*;
+import org.sonar.api.security.ResourcePermissions;
import org.sonar.api.utils.SonarException;
import javax.persistence.NonUniqueResultException;
@@ -40,9 +41,11 @@ public final class DefaultResourcePersister implements ResourcePersister {
private DatabaseSession session;
private Map<Resource, Snapshot> snapshotsByResource = Maps.newHashMap();
+ private ResourcePermissions permissions;
- public DefaultResourcePersister(DatabaseSession session) {
+ public DefaultResourcePersister(DatabaseSession session, ResourcePermissions permissions) {
this.session = session;
+ this.permissions = permissions;
}
public Snapshot saveProject(Project project, Project parent) {
@@ -84,6 +87,9 @@ public final class DefaultResourcePersister implements ResourcePersister {
snapshot.setBuildDate(new Date());
snapshot = session.save(snapshot);
session.commit();
+
+ permissions.grantDefaultRoles(project);
+
return snapshot;
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
index 21cd76173d4..3d35e195e0a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
@@ -27,6 +27,7 @@ import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.JavaPackage;
import org.sonar.api.resources.Library;
import org.sonar.api.resources.Project;
+import org.sonar.api.security.ResourcePermissions;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.text.ParseException;
@@ -36,6 +37,7 @@ import static org.fest.assertions.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.Mockito.mock;
public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
@@ -67,7 +69,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
public void shouldSaveNewProject() {
setupData("shared");
- ResourcePersister persister = new DefaultResourcePersister(getSession());
+ ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourcePermissions.class));
persister.saveProject(singleProject, null);
checkTables("shouldSaveNewProject", new String[] {"build_date", "created_at"}, "projects", "snapshots");
@@ -81,7 +83,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
public void shouldSaveNewMultiModulesProject() {
setupData("shared");
- ResourcePersister persister = new DefaultResourcePersister(getSession());
+ ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourcePermissions.class));
persister.saveProject(multiModuleProject, null);
persister.saveProject(moduleA, multiModuleProject);
persister.saveProject(moduleB, multiModuleProject);
@@ -94,7 +96,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
public void shouldSaveNewDirectory() {
setupData("shared");
- ResourcePersister persister = new DefaultResourcePersister(getSession());
+ ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourcePermissions.class));
persister.saveProject(singleProject, null);
persister.saveResource(singleProject, new JavaPackage("org.foo").setEffectiveKey("foo:org.foo"));
@@ -105,7 +107,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
public void shouldSaveNewLibrary() {
setupData("shared");
- ResourcePersister persister = new DefaultResourcePersister(getSession());
+ ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourcePermissions.class));
persister.saveProject(singleProject, null);
persister.saveResource(singleProject, new Library("junit:junit", "4.8.2").setEffectiveKey("junit:junit"));
persister.saveResource(singleProject, new Library("junit:junit", "4.8.2").setEffectiveKey("junit:junit"));// do nothing, already saved
@@ -118,7 +120,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
public void shouldClearResourcesExceptProjects() {
setupData("shared");
- DefaultResourcePersister persister = new DefaultResourcePersister(getSession());
+ DefaultResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourcePermissions.class));
persister.saveProject(multiModuleProject, null);
persister.saveProject(moduleA, multiModuleProject);
persister.saveResource(moduleA, new JavaPackage("org.foo").setEffectiveKey("a:org.foo"));
@@ -134,7 +136,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
public void shouldUpdateExistingResource() {
setupData("shouldUpdateExistingResource");
- ResourcePersister persister = new DefaultResourcePersister(getSession());
+ ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourcePermissions.class));
singleProject.setName("new name");
singleProject.setDescription("new description");
persister.saveProject(singleProject, null);
@@ -147,7 +149,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
public void shouldRemoveRootIndexIfResourceIsProject() {
setupData("shouldRemoveRootIndexIfResourceIsProject");
- ResourcePersister persister = new DefaultResourcePersister(getSession());
+ ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourcePermissions.class));
persister.saveProject(singleProject, null);
checkTables("shouldRemoveRootIndexIfResourceIsProject", new String[] {"build_date", "created_at"}, "projects", "snapshots");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
index 923eb3a98ce..f355311bce3 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
@@ -23,6 +23,7 @@ import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.security.ResourcePermissions;
import org.sonar.batch.bootstrap.ServerClient;
import org.sonar.batch.index.DefaultResourcePersister;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
@@ -52,7 +53,7 @@ public class UpdateStatusJobTest extends AbstractDbUnitTestCase {
setupData("sharedFixture", fixture);
DatabaseSession session = getSession();
- UpdateStatusJob sensor = new UpdateStatusJob(new Settings(), mock(ServerClient.class), session, new DefaultResourcePersister(session), loadSnapshot(snapshotId));
+ UpdateStatusJob sensor = new UpdateStatusJob(new Settings(), mock(ServerClient.class), session, new DefaultResourcePersister(session, mock(ResourcePermissions.class)), loadSnapshot(snapshotId));
sensor.execute();
checkTables(fixture, "snapshots");