aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>2013-07-05 11:22:15 +0200
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>2013-07-05 11:22:15 +0200
commit84c173736bd43b7b7aa546e6b84d2d52089c68c1 (patch)
tree4dbc1b7b1fd909796f650662e2cd7bd39617a01e
parentea30368b73c1cc3d3535097e90b2844a360d594c (diff)
downloadsonarqube-84c173736bd43b7b7aa546e6b84d2d52089c68c1.tar.gz
sonarqube-84c173736bd43b7b7aa546e6b84d2d52089c68c1.zip
SONAR-4463 Added binding in internal rb class for new permission template operations
-rw-r--r--sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java1
-rw-r--r--sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java31
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/Platform.java2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb4
-rw-r--r--sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java16
5 files changed, 45 insertions, 9 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java b/sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java
index ed8967b2959..9f99630b65f 100644
--- a/sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java
@@ -65,6 +65,7 @@ public class PermissionDao implements TaskExtension, ServerExtension {
return permissionTemplate;
}
+ @CheckForNull
public List<PermissionTemplateDto> selectAllPermissionTemplates() {
SqlSession session = myBatis.openSession();
try {
diff --git a/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java b/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java
index e996b13403c..7be63ada0cf 100644
--- a/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java
+++ b/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java
@@ -20,6 +20,7 @@
package org.sonar.server.permission;
+import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
@@ -45,11 +46,30 @@ public class InternalPermissionTemplateService implements ServerComponent {
this.userDao = userDao;
}
+ @CheckForNull
+ public PermissionTemplate selectPermissionTemplate(String templateName) {
+ PermissionTemplateUpdater.checkUserCredentials();
+ PermissionTemplateDto permissionTemplateDto = permissionDao.selectPermissionTemplate(templateName);
+ return PermissionTemplate.create(permissionTemplateDto);
+ }
+
+ public List<PermissionTemplate> selectAllPermissionTemplates() {
+ PermissionTemplateUpdater.checkUserCredentials();
+ List<PermissionTemplate> permissionTemplates = Lists.newArrayList();
+ List<PermissionTemplateDto> permissionTemplateDtos = permissionDao.selectAllPermissionTemplates();
+ if(permissionTemplateDtos != null) {
+ for (PermissionTemplateDto permissionTemplateDto : permissionTemplateDtos) {
+ permissionTemplates.add(PermissionTemplate.create(permissionTemplateDto));
+ }
+ }
+ return permissionTemplates;
+ }
+
public PermissionTemplate createPermissionTemplate(String name, String description) {
PermissionTemplateUpdater.checkUserCredentials();
- PermissionTemplateDto permissionTemplateDto = permissionDao.createPermissionTemplate(name, description);
checkThatTemplateNameIsUnique(name);
- if(permissionTemplateDto == null) {
+ PermissionTemplateDto permissionTemplateDto = permissionDao.createPermissionTemplate(name, description);
+ if(permissionTemplateDto.getId() == null) {
String errorMsg = "Template creation failed";
LOG.error(errorMsg);
throw new ServerErrorException(errorMsg);
@@ -57,13 +77,6 @@ public class InternalPermissionTemplateService implements ServerComponent {
return PermissionTemplate.create(permissionTemplateDto);
}
- @CheckForNull
- public PermissionTemplate selectPermissionTemplate(String templateName) {
- PermissionTemplateUpdater.checkUserCredentials();
- PermissionTemplateDto permissionTemplateDto = permissionDao.selectPermissionTemplate(templateName);
- return PermissionTemplate.create(permissionTemplateDto);
- }
-
public void deletePermissionTemplate(String templateName) {
PermissionTemplateUpdater.checkUserCredentials();
PermissionTemplateDto permissionTemplateDto = permissionDao.selectTemplateByName(templateName);
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
index 2d7014b3728..be04a975fb3 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
@@ -78,6 +78,7 @@ import org.sonar.server.issue.*;
import org.sonar.server.notifications.NotificationCenter;
import org.sonar.server.notifications.NotificationService;
import org.sonar.server.permission.InternalPermissionService;
+import org.sonar.server.permission.InternalPermissionTemplateService;
import org.sonar.server.plugins.*;
import org.sonar.server.qualitymodel.DefaultModelManager;
import org.sonar.server.rule.RubyRuleService;
@@ -257,6 +258,7 @@ public final class Platform {
servicesContainer.addSingleton(DefaultUserFinder.class);
servicesContainer.addSingleton(DefaultUserService.class);
servicesContainer.addSingleton(InternalPermissionService.class);
+ servicesContainer.addSingleton(InternalPermissionTemplateService.class);
// components
servicesContainer.addSingleton(DefaultRubyComponentService.class);
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb
index 912991a77fc..ded7ff05eca 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb
@@ -50,6 +50,10 @@ class Internal
component(Java::OrgSonarServerPermission::InternalPermissionService.java_class)
end
+ def self.permission_templates
+ component(Java::OrgSonarServierPermission::InternalPermissionTemplateService.java_class)
+ end
+
private
def self.component(component_java_class)
Java::OrgSonarServerPlatform::Platform.component(component_java_class)
diff --git a/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java b/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java
index 7abe57e7496..d7e9bf89028 100644
--- a/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java
@@ -133,6 +133,22 @@ public class InternalPermissionTemplateServiceTest {
}
@Test
+ public void should_retrieve_all_permission_templates() throws Exception {
+ PermissionTemplateDto template1 =
+ new PermissionTemplateDto().setId(1L).setName("template1").setDescription("template1");
+ PermissionTemplateDto template2 =
+ new PermissionTemplateDto().setId(2L).setName("template2").setDescription("template2");
+ when(permissionDao.selectAllPermissionTemplates()).thenReturn(Lists.newArrayList(template1, template2));
+
+ List<PermissionTemplate> templates = permissionTemplateService.selectAllPermissionTemplates();
+
+ assertThat(templates).hasSize(2);
+ assertThat(templates).onProperty("id").containsOnly(1L, 2L);
+ assertThat(templates).onProperty("name").containsOnly("template1", "template2");
+ assertThat(templates).onProperty("description").containsOnly("template1", "template2");
+ }
+
+ @Test
public void should_add_user_permission() throws Exception {
UserDto userDto = new UserDto().setId(1L).setLogin("user").setName("user");
when(userDao.selectActiveUserByLogin("user")).thenReturn(userDto);