From: Jean-Baptiste Vilain Date: Tue, 23 Jul 2013 12:44:43 +0000 (+0200) Subject: SONAR-4451 Permission templates will be applied to all the projects matching the... X-Git-Tag: 3.7~27 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ceeccdc1109973d6572feb07f3c161bb723bea77;p=sonarqube.git SONAR-4451 Permission templates will be applied to all the projects matching the search criteria --- 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 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 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.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=] @@ -75,10 +78,16 @@ class RolesController < ApplicationController render :text => '', :status => 200 end - # GET /roles/apply_template_form?projects=&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 @@ - - - + + + + - - - - + + + + <% ['admin', 'user', 'codeviewer'].each do |permission| -%> + + <% end %> - - - - - - - - + + <% ['admin', 'user', 'codeviewer'].each do |permission| -%> + + <% end %>
PermissionUsersGroups <%= message('projects_role.admin') -%><%= message('projects_role.user') -%><%= message('projects_role.codeviewer') -%>
Administrators
Ability to perform administration functions for a project by accessing its settings.
- <%= users('admin', @project.id).map(&:name).join(', ') %> - (<%= link_to_edit_roles_permission_form(message('select'), 'admin', @project.id, 'select-admin-edit-users') %>)
-
- <%= groups('admin', @project.id).map{|g| group_name(g)}.join(', ') %> - (<%= link_to_edit_groups_permission_form(message('select'), 'admin', @project.id, 'select-admin-edit-groups') %>)
-
Users + <%= users(permission, @project.id).map(&:name).join(', ') %> + (<%= link_to_edit_roles_permission_form(message('select'), permission, @project.id, "select-#{permission}-edit-users") %>)
+
Users
Ability to navigate through every service of a project, except viewing source code and settings.
- <%= users('user', @project.id).map(&:name).join(', ') %> - (<%= link_to_edit_roles_permission_form(message('select'), 'user', @project.id, 'select-user-edit-users') %>)
-
- <%= groups('user', @project.id).map{|g| group_name(g)}.join(', ') %> - (<%= link_to_edit_groups_permission_form(message('select'), 'user', @project.id, 'select-user-edit-groups') %>)
-
Code viewers
Ability to view source code of a project.
- <%= users('codeviewer', @project.id).map(&:name).join(', ') %> - (<%= link_to_edit_roles_permission_form(message('select'), 'codeviewer', @project.id, 'select-codeviewer-edit-users') %>)
-
- <%= groups('codeviewer', @project.id).map{|g| group_name(g)}.join(', ') %> - (<%= link_to_edit_groups_permission_form(message('select'), 'codeviewer', @project.id, 'select-codeviewer-edit-groups') %>)
-
Groups + <%= groups(permission, @project.id).map{|g| group_name(g)}.join(', ') %> + (<%= link_to_edit_groups_permission_form(message('select'), permission, @project.id, "select-#{permission}-edit-groups") %>)
+
\ 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 %>