]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4466 Provision the logical key in the model objects used by the views
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Mon, 15 Jul 2013 16:46:24 +0000 (18:46 +0200)
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Mon, 15 Jul 2013 16:46:24 +0000 (18:46 +0200)
sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml
sonar-core/src/test/java/org/sonar/core/permission/PermissionDaoTest.java
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectAllPermissionTemplates.xml
sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplate.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/permission_templates_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/index.html.erb
sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateTest.java

index 0ca7a418f637a0e4df129d2728b4af545d3e597c..5999d29729da115ee87d8cf8ff9ae60e0e988467 100644 (file)
   </select>
 
   <select id="selectByName" parameterType="String" resultType="PermissionTemplate">
-    SELECT id, name, description, created_at AS createdAt, updated_at AS updatedAt
+    SELECT id, name, kee, description, created_at AS createdAt, updated_at AS updatedAt
     FROM permission_templates
     WHERE name = #{templateName}
   </select>
 
   <select id="selectAllPermissionTemplates" resultType="PermissionTemplate">
-    SELECT id, name, description, created_at AS createdAt, updated_at AS updatedAt
+    SELECT id, name, kee, description, created_at AS createdAt, updated_at AS updatedAt
     FROM permission_templates
   </select>
 
index 57d312aceb9c2777fa29405a9a16ec7e0802f9af..424943b66adc2e924b1e0ab371dac1380338235e 100644 (file)
@@ -93,6 +93,7 @@ public class PermissionDaoTest extends AbstractDaoTestCase {
 
     assertThat(permissionTemplate).isNotNull();
     assertThat(permissionTemplate.getName()).isEqualTo("my template");
+    assertThat(permissionTemplate.getKee()).isEqualTo("my_template_20130102_030405");
     assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
     assertThat(permissionTemplate.getUsersPermissions()).hasSize(3);
     assertThat(permissionTemplate.getUsersPermissions()).onProperty("userId").containsOnly(1L, 2L, 1L);
@@ -126,11 +127,12 @@ public class PermissionDaoTest extends AbstractDaoTestCase {
     assertThat(permissionTemplate).isNotNull();
     assertThat(permissionTemplate.getId()).isEqualTo(1L);
     assertThat(permissionTemplate.getName()).isEqualTo("my template");
+    assertThat(permissionTemplate.getKee()).isEqualTo("my_template_20130102_030405");
     assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
   }
 
   @Test
-  public void should_select_permission_template_by_id() throws Exception {
+  public void should_select_permission_template_by_key() throws Exception {
     setupData("selectPermissionTemplate");
 
     PermissionTemplateDto permissionTemplate = permissionDao.selectTemplateByKey("my_template_20130102_030405");
@@ -138,6 +140,7 @@ public class PermissionDaoTest extends AbstractDaoTestCase {
     assertThat(permissionTemplate).isNotNull();
     assertThat(permissionTemplate.getId()).isEqualTo(1L);
     assertThat(permissionTemplate.getName()).isEqualTo("my template");
+    assertThat(permissionTemplate.getKee()).isEqualTo("my_template_20130102_030405");
     assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
   }
 
@@ -150,6 +153,7 @@ public class PermissionDaoTest extends AbstractDaoTestCase {
     assertThat(permissionTemplates).hasSize(3);
     assertThat(permissionTemplates).onProperty("id").containsOnly(1L, 2L, 3L);
     assertThat(permissionTemplates).onProperty("name").containsOnly("template1", "template2", "template3");
+    assertThat(permissionTemplates).onProperty("kee").containsOnly("template1_20130102_030405", "template2_20130102_030405", "template3_20130102_030405");
     assertThat(permissionTemplates).onProperty("description").containsOnly("description1", "description2", "description3");
   }
 
index 1fa43bea18c0c89193761e0696d8af06f8c52495..65a68bb4b4b2f127201b4b99a7f0bc48f4a2fcf5 100644 (file)
@@ -1,5 +1,5 @@
 <dataset>
-  <permission_templates id="1" name="template1" kee="my_template_20130102_030405" description="description1" created_at="[null]" updated_at="[null]"/>
-  <permission_templates id="2" name="template2" kee="my_template_20130102_030405" description="description2" created_at="[null]" updated_at="[null]"/>
-  <permission_templates id="3" name="template3" kee="my_template_20130102_030405" description="description3" created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="1" name="template1" kee="template1_20130102_030405" description="description1" created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="2" name="template2" kee="template2_20130102_030405" description="description2" created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="3" name="template3" kee="template3_20130102_030405" description="description3" created_at="[null]" updated_at="[null]"/>
 </dataset>
\ No newline at end of file
index a88bf35d11f71e4ff6cb63a74338e5e9145e907c..0d6bbf66fe41009e0a3aa0902fef9ccb13e3782a 100644 (file)
@@ -34,13 +34,15 @@ public class PermissionTemplate {
 
   private final Long id;
   private final String name;
+  private final String key;
   private final String description;
   private Multimap<String, PermissionTemplateUser> usersByPermission;
   private Multimap<String, PermissionTemplateGroup> groupsByPermission;
 
-  private PermissionTemplate(Long id, String name, String description) {
+  private PermissionTemplate(Long id, String name, String key, String description) {
     this.id = id;
     this.name = name;
+    this.key = key;
     this.description = description;
     usersByPermission = HashMultimap.create();
     groupsByPermission = HashMultimap.create();
@@ -50,8 +52,8 @@ public class PermissionTemplate {
     if(permissionTemplateDto == null) {
       return null;
     }
-    PermissionTemplate permissionTemplate =
-      new PermissionTemplate(permissionTemplateDto.getId(), permissionTemplateDto.getName(), permissionTemplateDto.getDescription());
+    PermissionTemplate permissionTemplate = new PermissionTemplate(
+      permissionTemplateDto.getId(), permissionTemplateDto.getName(), permissionTemplateDto.getKee(), permissionTemplateDto.getDescription());
 
     List<PermissionTemplateUserDto> usersPermissions = permissionTemplateDto.getUsersPermissions();
     if(usersPermissions != null) {
@@ -83,6 +85,10 @@ public class PermissionTemplate {
     return description;
   }
 
+  public String getKey() {
+    return key;
+  }
+
   public List<PermissionTemplateUser> getUsersForPermission(String permission) {
     return ImmutableList.copyOf(usersByPermission.get(permission));
   }
index 5447ccd6b6733214b1327e9208696ab38d2453fc..93b0b2d29b3a7391a9cb0311b2e8161db649b51a 100644 (file)
@@ -84,7 +84,7 @@ public class RegisterPermissionTemplates {
     } else {
       GroupDto groupDto = userDao.selectGroupByName(groupName);
       if(groupDto != null) {
-        groupId = userDao.selectGroupByName(groupName).getId();
+        groupId = groupDto.getId();
       } else {
         throw new IllegalArgumentException("Cannot setup default permission for group: " + groupName);
       }
index b9a99cb8fb078ee22ad56890bf9eb339f80a3f1c..1d9aa4a1bbbf7f6b18da1a9d45c9d9445c5526af 100644 (file)
@@ -43,7 +43,7 @@ class PermissionTemplatesController < ApplicationController
     templates_names.each do |template_name|
       permission_template = Internal.permission_templates.selectPermissionTemplate(template_name)
       @permission_templates << permission_template
-      @permission_templates_options << [permission_template.name, permission_template.id.to_s]
+      @permission_templates_options << [permission_template.name, permission_template.key]
     end
     @root_qualifiers = get_root_qualifiers
 
@@ -78,7 +78,7 @@ class PermissionTemplatesController < ApplicationController
   #
   def update_users_permissions
     verify_post_request
-    require_parameters :id, :name, :permission
+    require_parameters :name, :permission
 
     @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
 
@@ -106,7 +106,7 @@ class PermissionTemplatesController < ApplicationController
   #
   def update_groups_permissions
     verify_post_request
-    require_parameters :id, :name, :permission
+    require_parameters :name, :permission
 
     @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
 
index 2ab96d108670a3d2da39c3f257d21d8df82cd8e5..7b7f25ff9231f6a322e707749d40dcac25ac02cf 100644 (file)
                      :id => "selectg-codeviewer-#{u permission_template.name}", :class => 'open-modal link-action', 'modal-width' => '760px' %>)
       </td>
       <td>
-        <% if @default_templates.values.include?(permission_template.id.to_s)
-              qualifier = @default_templates.invert[permission_template.id.to_s]
+        <% qualifiers = []
+           @default_templates.each_pair do |q, t|
+             qualifiers << q if t == permission_template.key
+           end
+           if qualifiers.length > 0
         %>
-          <%= image_tag 'tick.png', :id => "is_active_#{u permission_template.name}" %><span class="small gray">(Default for <%= message('qualifier.' + qualifier) %>)</span>
+          <%= image_tag 'tick.png', :id => "is_active_#{u permission_template.name}" %><span class="small gray">(Default for <%= qualifiers.collect {|q| message('qualifier.' + q)}.join(',') %>)</span>
         <% end %>
       </td>
       <td align="right">
@@ -96,7 +99,7 @@
                     :id => "edit-template-#{u permission_template.name}", :class => 'open-modal link-action' %>
       </td>
       <td align="right">
-        <% unless @default_templates.values.include?(permission_template.id.to_s) %>
+        <% unless @default_templates.values.include?(permission_template.key) %>
           <%= link_to message('delete'), {:action => :delete_form, :name => permission_template.name},
                       :id => "delete-template-#{u permission_template.name}", :class => 'open-modal link-action link-red' %>
         <% end %>
index 69a11a8a2ca3136308f669f923c2e93dbe4be21b..5cfa33b23c45e959b20c900e20595d3641cc9918 100644 (file)
@@ -36,6 +36,7 @@ public class PermissionTemplateTest {
     PermissionTemplateDto permissionTemplateDto = new PermissionTemplateDto()
       .setId(1L)
       .setName("name")
+      .setKee("key")
       .setDescription("description")
       .setUsersPermissions(Lists.newArrayList(
         new PermissionTemplateUserDto().setId(1L).setUserId(1L).setUserName("user1").setUserLogin("login1").setPermission("permission1"),
@@ -52,6 +53,7 @@ public class PermissionTemplateTest {
 
     assertThat(permissionTemplate.getId()).isEqualTo(1L);
     assertThat(permissionTemplate.getName()).isEqualTo("name");
+    assertThat(permissionTemplate.getKey()).isEqualTo("key");
     assertThat(permissionTemplate.getDescription()).isEqualTo("description");
     assertThat(permissionTemplate.getUsersForPermission("unmatchedPermission")).isEmpty();
     assertThat(permissionTemplate.getUsersForPermission("permission1")).onProperty("userName").containsOnly("user1", "user2");