]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4451 Permission templates will be applied to all the projects matching the...
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Tue, 23 Jul 2013 12:44:43 +0000 (14:44 +0200)
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Tue, 23 Jul 2013 12:44:43 +0000 (14:44 +0200)
sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java
sonar-core/src/main/java/org/sonar/core/permission/ComponentPermissionFacade.java
sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/permission_templates_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/roles_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/project_roles/index.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/roles/_apply_template_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/roles/projects.html.erb

index a886424f24710161c4407452bcbae444ac1bddb3..1043ad3ca61995e420a2732438396093cd031c68 100644 (file)
@@ -23,11 +23,21 @@ import org.sonar.api.component.Component;
 
 public class ComponentDto implements Component {
 
+  private Long id;
   private String key;
   private String name;
   private String longName;
   private String qualifier;
 
+  public Long getId() {
+    return id;
+  }
+
+  public ComponentDto setId(Long id) {
+    this.id = id;
+    return this;
+  }
+
   @Override
   public String key() {
     return key;
index b455aa61679a474368a4da31b1f44acebe0d2216..f681635865a52d75a2b76dd3342d070c50a39fa9 100644 (file)
@@ -141,7 +141,6 @@ public class ComponentPermissionFacade implements TaskComponent, ServerComponent
       if(usersPermissions != null) {
         for (PermissionTemplateUserDto userPermission : usersPermissions) {
           addUserPermission(resourceId, userPermission.getUserLogin(), userPermission.getPermission(), session);
-
         }
       }
       List<PermissionTemplateGroupDto> groupsPermissions = permissionTemplate.getGroupsPermissions();
index 18bb0ec788c0d919b2799fea8d785db88ae99d59..6d68359fe07a61ea4735be3bb3c7686f9f74b89a 100644 (file)
@@ -220,6 +220,7 @@ public class ResourceDao {
 
   public static ComponentDto toComponent(ResourceDto resourceDto){
     return new ComponentDto()
+      .setId(resourceDto.getId())
       .setKey(resourceDto.getKey())
       .setLongName(resourceDto.getLongName())
       .setName(resourceDto.getName())
index 11a7edcd71ed1111ae4e497049ec18f75cfe44ae..2b38ad2e31f23429bb293877a74a28f6fab157b0 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.Test;
 import org.sonar.api.component.Component;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.Scopes;
+import org.sonar.core.component.ComponentDto;
 import org.sonar.core.persistence.AbstractDaoTestCase;
 
 import java.util.Collection;
@@ -316,6 +317,7 @@ public class ResourceDaoTest extends AbstractDaoTestCase {
     List<Component> components = dao.selectComponentsByQualifiers(newArrayList("TRK"));
     assertThat(components).hasSize(1);
     assertThat(components.get(0).key()).isEqualTo("org.struts:struts");
+    assertThat(((ComponentDto)components.get(0)).getId()).isEqualTo(1L);
 
     assertThat(dao.selectComponentsByQualifiers(newArrayList("unknown"))).isEmpty();
     assertThat(dao.selectComponentsByQualifiers(Collections.<String>emptyList())).isEmpty();
index 5b4b517a7a460e67e2a131c8b9f848332908e096..6a0c388d1ef518050cb4a74feffcb8c13061edd2 100644 (file)
@@ -209,7 +209,7 @@ class PermissionTemplatesController < ApplicationController
   private
 
   def get_root_qualifiers
-    Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceRootTypes().map {|type| type.getQualifier()}
+    Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceRootTypes().map {|type| type.getQualifier()}.sort
   end
 
   def get_default_templates_per_qualifier(root_qualifiers)
index c9db2eba7bb01017960d2b8a67131c5198e0e8db..b981e0b726eeeed6065d19a2b19304b976db9cd3 100644 (file)
@@ -45,6 +45,9 @@ class RolesController < ApplicationController
         # Even if components are already sorted, we must sort them again as this SQL query will not keep order
         :order => 'name'
     )
+    @components_names = params[:names]
+    @components_keys = params[:keys]
+    @components_qualifiers = params[:qualifiers]
   end
 
   # GET /roles/edit_users[?resource=<resource>]
@@ -75,10 +78,16 @@ class RolesController < ApplicationController
     render :text => '', :status => 200
   end
 
-  # GET /roles/apply_template_form?projects=<projects>&qualifier=<qualifier>
+  # GET /roles/apply_template_form?criteria
   def apply_template_form
     @permission_templates = Internal.permission_templates.selectAllPermissionTemplates().sort_by {|t| t.name.downcase}.collect {|pt| [pt.name, pt.key]}
-    render :partial => 'apply_template_form', :locals => {:components => params[:projects], :project_name => params[:project_name], :qualifier => params[:qualifier] || 'TRK'}
+
+    params['qualifiers'] ||= 'TRK'
+    @query_result = Internal.component_api.find(params).components().to_a
+    @projects_ids = @query_result.collect{|component| component.getId()}
+
+    render :partial => 'apply_template_form',
+           :locals => {:components => @projects_ids, :project_name => @query_result.size == 1 ? @query_result[0].name : nil, :qualifier => params[:qualifiers]}
   end
 
   # POST /roles/apply_template?criteria
index 874e7cdbac523f9278997719ba3efd50731598b6..be1287364fccae6d6405b1581446db6d99b45be5 100644 (file)
@@ -2,44 +2,31 @@
 <table class="data width100">
   <thead>
   <tr>
-    <th>Permission</th>
-    <th width="35%">Users</th>
-    <th width="35%">Groups</th>
+    <th>&nbsp;</th>
+    <th><%= message('projects_role.admin') -%></th>
+    <th><%= message('projects_role.user') -%></th>
+    <th><%= message('projects_role.codeviewer') -%></th>
   </tr>
   </thead>
   <tbody>
-  <tr class="even" >
-    <td valign="top"><b>Administrators</b><br/><span class="small gray">Ability to perform administration functions for a project by accessing its settings.</span></td>
-    <td valign="top" style="word-break:break-all;width:35%;">
-      <span id="admin-role-users"><%= users('admin', @project.id).map(&:name).join(', ') %></span>
-      (<%= link_to_edit_roles_permission_form(message('select'), 'admin', @project.id, 'select-admin-edit-users') %>)<br/>
-    </td>
-    <td valign="top" style="word-break:break-all;width:35%;">
-      <span id="admin-role-groups"><%= groups('admin', @project.id).map{|g| group_name(g)}.join(', ') %></span>
-      (<%= link_to_edit_groups_permission_form(message('select'), 'admin', @project.id, 'select-admin-edit-groups') %>)<br/>
-    </td>
+  <tr class="even">
+    <td valign="top"><b>Users</b></td>
+
+    <% ['admin', 'user', 'codeviewer'].each do |permission| -%>
+      <td valign="top">
+        <span class="nowrap" id="<%= permission -%>-role-users"><%= users(permission, @project.id).map(&:name).join(', ') %></span>
+        (<%= link_to_edit_roles_permission_form(message('select'), permission, @project.id, "select-#{permission}-edit-users") %>)<br/>
+      </td>
+    <% end %>
   </tr>
   <tr class="odd">
-    <td valign="top"><b>Users</b><br/><span class="small gray">Ability to navigate through every service of a project, except viewing source code and settings.</span></td>
-    <td valign="top" style="word-break:break-all;width:35%;">
-      <span id="user-role-users"><%= users('user', @project.id).map(&:name).join(', ') %></span>
-      (<%= link_to_edit_roles_permission_form(message('select'), 'user', @project.id, 'select-user-edit-users') %>)<br/>
-    </td>
-    <td valign="top" style="word-break:break-all;width:35%;">
-      <span id="user-role-groups"><%= groups('user', @project.id).map{|g| group_name(g)}.join(', ') %></span>
-      (<%= link_to_edit_groups_permission_form(message('select'), 'user', @project.id, 'select-user-edit-groups') %>)<br/>
-    </td>
-  </tr>
-  <tr class="even" >
-    <td valign="top"><b>Code viewers</b><br/><span class="small gray">Ability to view source code of a project.</span></td>
-    <td valign="top" style="word-break:break-all;width:35%;">
-      <span id="codeviewer-role-users"><%= users('codeviewer', @project.id).map(&:name).join(', ') %></span>
-      (<%= link_to_edit_roles_permission_form(message('select'), 'codeviewer', @project.id, 'select-codeviewer-edit-users') %>)<br/>
-    </td>
-    <td valign="top" style="word-break:break-all;width:35%;">
-      <span id="codeviewer-role-groups"><%= groups('codeviewer', @project.id).map{|g| group_name(g)}.join(', ') %></span>
-      (<%= link_to_edit_groups_permission_form(message('select'), 'codeviewer', @project.id, 'select-codeviewer-edit-groups') %>)<br/>
-    </td>
+    <td valign="top"><b>Groups</b></td>
+    <% ['admin', 'user', 'codeviewer'].each do |permission| -%>
+      <td valign="top">
+        <span class="nowrap" id="<%= permission -%>-role-groups"><%= groups(permission, @project.id).map{|g| group_name(g)}.join(', ') %></span>
+        (<%= link_to_edit_groups_permission_form(message('select'), permission, @project.id, "select-#{permission}-edit-groups") %>)<br/>
+      </td>
+    <% end %>
   </tr>
   </tbody>
 </table>
\ No newline at end of file
index bab848223da398830cb6ea23e82a34335946e6fa..338e287b279a30748c57ab3aa5331d8bac645f8c 100644 (file)
@@ -4,8 +4,8 @@
   <% end %>
   <fieldset>
     <div class="modal-head">
-    <% if params[:project_name] %>
-      <h2><%= message('projects_role.apply_template_to_xxx', :params => params[:project_name]) -%></h2>
+    <% if project_name %>
+      <h2><%= message('projects_role.apply_template_to_xxx', :params => project_name) -%></h2>
     <% else %>
       <h2><%= message('projects_role.apply_template') -%></h2>
     <% end %>
@@ -21,7 +21,7 @@
         <div class="modal-field">
           <%= label_tag 'template_key', 'Permission Template' %>
           <%= select_tag('template_key', options_for_select(@permission_templates, -1), :style => 'width: 250px;') %>
-          <% unless params[:project_name] %>
+          <% unless project_name %>
             <span style="float:right" class="note">(<%= "#{components.size} #{message('qualifier.' + qualifier)}s" %>)</span><br/>
           <% end %>
         </div>
index 2a37157af768cbc0cc6b3eecb13cd49fdb2901f0..9ce4a13c7cf78b0956ce800931b4ad3d24feaaba 100644 (file)
@@ -33,7 +33,8 @@
 <div id="project-roles-operations" style="float: right;">
   <ul class="operations">
     <li class="last">
-      <%= link_to message('projects_role.bulk_change'), {:action => :apply_template_form, :projects => @projects.collect {|proj| proj.id}, :qualifier => @qualifier},
+      <%= link_to message('projects_role.bulk_change'), {:action => :apply_template_form, :names => @components_names,
+                                                         :keys => @components_keys, :qualifiers => @components_qualifiers},
                    :id => 'apply-template-modal', :class => 'open-modal link-action' %>
     </li>
   </ul>
@@ -81,7 +82,7 @@
         </td>
       <% end %>
       <td align="right">
-        <%= link_to message('projects_role.apply_template'), {:action => :apply_template_form, :projects => [project.id], :project_name => project.name, :qualifier => @qualifier},
+        <%= link_to message('projects_role.apply_template'), {:action => :apply_template_form, :names => project.name},
                     :id => "apply-template-#{u project.kee}", :class => 'open-modal link-action' %>
       </td>
     </tr>