]> source.dussan.org Git - sonarqube.git/commitdiff
Sanitize PermissionTemplateDao methods
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 26 Aug 2015 10:16:22 +0000 (12:16 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 27 Aug 2015 07:52:45 +0000 (09:52 +0200)
server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
server/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java
sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java
sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java

index 8ae7d6eaaaca2d7589ac5db25703b0cc52d6adfc..e21f2d41af395b8462dd13196c11b73c39e1e217 100644 (file)
@@ -75,7 +75,7 @@ public class PermissionTemplateService {
   @CheckForNull
   public PermissionTemplate selectPermissionTemplate(String templateKey) {
     checkGlobalAdminUser(userSession);
-    PermissionTemplateDto permissionTemplateDto = permissionTemplateDao.selectPermissionTemplate(templateKey);
+    PermissionTemplateDto permissionTemplateDto = permissionTemplateDao.selectByKeyWithUserAndGroupPermissions(templateKey);
     return PermissionTemplate.create(permissionTemplateDto);
   }
 
@@ -132,7 +132,7 @@ public class PermissionTemplateService {
 
   public void deletePermissionTemplate(Long templateId) {
     checkGlobalAdminUser(userSession);
-    permissionTemplateDao.deletePermissionTemplate(templateId);
+    permissionTemplateDao.deleteById(templateId);
   }
 
   /**
index e4ceb1b718083317866015c679be9e7889e6654a..970a14d42aba437dbb947963b1cdce61e2911a01 100644 (file)
@@ -151,7 +151,7 @@ public class PermissionTemplateServiceTest {
 
     underTest.deletePermissionTemplate(1L);
 
-    verify(permissionTemplateDao, times(1)).deletePermissionTemplate(1L);
+    verify(permissionTemplateDao, times(1)).deleteById(1L);
   }
 
   @Test
@@ -177,7 +177,7 @@ public class PermissionTemplateServiceTest {
       .setUsersPermissions(usersPermissions)
       .setGroupsByPermission(groupsPermissions);
 
-    when(permissionTemplateDao.selectPermissionTemplate("my template")).thenReturn(permissionTemplateDto);
+    when(permissionTemplateDao.selectByKeyWithUserAndGroupPermissions("my template")).thenReturn(permissionTemplateDto);
 
     PermissionTemplate permissionTemplate = underTest.selectPermissionTemplate("my template");
 
index a7c2ff80497e0125c908802d19cfadd7dab7afd5..3ea563637d9666b102e3793a35cb38a6165da95a 100644 (file)
@@ -141,7 +141,7 @@ public class PermissionTemplateDao implements Dao {
   }
 
   @CheckForNull
-  public PermissionTemplateDto selectPermissionTemplate(DbSession session, String templateKey) {
+  public PermissionTemplateDto selectByKeyWithUserAndGroupPermissions(DbSession session, String templateKey) {
     PermissionTemplateDto permissionTemplate = null;
     PermissionTemplateMapper mapper = mapper(session);
     permissionTemplate = mapper.selectByKey(templateKey);
@@ -157,10 +157,10 @@ public class PermissionTemplateDao implements Dao {
   }
 
   @CheckForNull
-  public PermissionTemplateDto selectPermissionTemplate(String templateKey) {
+  public PermissionTemplateDto selectByKeyWithUserAndGroupPermissions(String templateKey) {
     DbSession session = myBatis.openSession(false);
     try {
-      return selectPermissionTemplate(session, templateKey);
+      return selectByKeyWithUserAndGroupPermissions(session, templateKey);
     } finally {
       MyBatis.closeQuietly(session);
     }
@@ -190,7 +190,7 @@ public class PermissionTemplateDao implements Dao {
     mapper(dbSession).deleteByKey(key);
   }
 
-  public void deletePermissionTemplate(Long templateId) {
+  public void deleteById(Long templateId) {
     SqlSession session = myBatis.openSession(false);
     try {
       PermissionTemplateMapper mapper = mapper(session);
@@ -328,7 +328,7 @@ public class PermissionTemplateDao implements Dao {
     if (permissionTemplateDto == null) {
       throw new IllegalArgumentException("Could not retrieve permission template with key " + templateKey);
     }
-    PermissionTemplateDto templateWithPermissions = selectPermissionTemplate(session, permissionTemplateDto.getKee());
+    PermissionTemplateDto templateWithPermissions = selectByKeyWithUserAndGroupPermissions(session, permissionTemplateDto.getKee());
     if (templateWithPermissions == null) {
       throw new IllegalArgumentException("Could not retrieve permissions for template with key " + templateKey);
     }
index 686aecd5a8459917ae72269391e50f0e7ca2c22f..526892b5c8b818dbc5f14f6135efce6602f8dec3 100644 (file)
@@ -96,7 +96,7 @@ public class PermissionTemplateDaoTest {
   public void should_select_permission_template() {
     db.prepareDbUnit(getClass(), "selectPermissionTemplate.xml");
 
-    PermissionTemplateDto permissionTemplate = underTest.selectPermissionTemplate("my_template_20130102_030405");
+    PermissionTemplateDto permissionTemplate = underTest.selectByKeyWithUserAndGroupPermissions("my_template_20130102_030405");
 
     assertThat(permissionTemplate).isNotNull();
     assertThat(permissionTemplate.getName()).isEqualTo("my template");
@@ -117,7 +117,7 @@ public class PermissionTemplateDaoTest {
   public void should_select_empty_permission_template() {
     db.prepareDbUnit(getClass(), "selectEmptyPermissionTemplate.xml");
 
-    PermissionTemplateDto permissionTemplate = underTest.selectPermissionTemplate("my_template_20130102_030405");
+    PermissionTemplateDto permissionTemplate = underTest.selectByKeyWithUserAndGroupPermissions("my_template_20130102_030405");
 
     assertThat(permissionTemplate).isNotNull();
     assertThat(permissionTemplate.getName()).isEqualTo("my template");
@@ -165,7 +165,7 @@ public class PermissionTemplateDaoTest {
   public void should_delete_permission_template() {
     db.prepareDbUnit(getClass(), "deletePermissionTemplate.xml");
 
-    underTest.deletePermissionTemplate(1L);
+    underTest.deleteById(1L);
 
     checkTemplateTables("deletePermissionTemplate-result.xml");
   }
@@ -253,7 +253,7 @@ public class PermissionTemplateDaoTest {
     PermissionTemplateDto templateWithPermissions = new PermissionTemplateDto().setKee("test_template");
     underTest = mock(PermissionTemplateDao.class);
     when(underTest.selectByKey(db.getSession(), "test_template")).thenReturn(permissionTemplateDto);
-    when(underTest.selectPermissionTemplate(db.getSession(), "test_template")).thenReturn(templateWithPermissions);
+    when(underTest.selectByKeyWithUserAndGroupPermissions(db.getSession(), "test_template")).thenReturn(templateWithPermissions);
     when(underTest.selectPermissionTemplateWithPermissions(db.getSession(), "test_template")).thenCallRealMethod();
 
     PermissionTemplateDto permissionTemplate = underTest.selectPermissionTemplateWithPermissions(db.getSession(), "test_template");