diff options
9 files changed, 51 insertions, 42 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java b/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java index a886424f247..1043ad3ca61 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java +++ b/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java @@ -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; diff --git a/sonar-core/src/main/java/org/sonar/core/permission/ComponentPermissionFacade.java b/sonar-core/src/main/java/org/sonar/core/permission/ComponentPermissionFacade.java index b455aa61679..f681635865a 100644 --- a/sonar-core/src/main/java/org/sonar/core/permission/ComponentPermissionFacade.java +++ b/sonar-core/src/main/java/org/sonar/core/permission/ComponentPermissionFacade.java @@ -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(); diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java index 18bb0ec788c..6d68359fe07 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java @@ -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()) diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java index 11a7edcd71e..2b38ad2e31f 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java @@ -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(); diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/permission_templates_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/permission_templates_controller.rb index 5b4b517a7a4..6a0c388d1ef 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/permission_templates_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/permission_templates_controller.rb @@ -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) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/roles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/roles_controller.rb index c9db2eba7bb..b981e0b726e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/roles_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/roles_controller.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project_roles/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project_roles/index.html.erb index 874e7cdbac5..be1287364fc 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/project_roles/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project_roles/index.html.erb @@ -2,44 +2,31 @@ <table class="data width100"> <thead> <tr> - <th>Permission</th> - <th width="35%">Users</th> - <th width="35%">Groups</th> + <th> </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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/roles/_apply_template_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/roles/_apply_template_form.html.erb index bab848223da..338e287b279 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/roles/_apply_template_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/roles/_apply_template_form.html.erb @@ -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> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/roles/projects.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/roles/projects.html.erb index 2a37157af76..9ce4a13c7cf 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/roles/projects.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/roles/projects.html.erb @@ -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> |