From b16eba0f89bbdcbe057e03b0e7b955f1d4cc8687 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 16 Jul 2013 22:18:08 +0200 Subject: [PATCH] SONAR-4498 Use modal windows in the "Projects Permission" page of project settings to select groups/users --- .../app/controllers/issues_controller.rb | 2 +- .../controllers/project_roles_controller.rb | 31 +--------- .../app/controllers/roles_controller.rb | 58 +++++++------------ .../WEB-INF/app/helpers/roles_helper.rb | 10 ++-- .../views/project_roles/edit_groups.html.erb | 51 ---------------- .../views/project_roles/edit_users.html.erb | 50 ---------------- .../app/views/project_roles/index.html.erb | 20 ++++--- .../app/views/roles/_edit_groups.html.erb | 7 ++- .../app/views/roles/_edit_users.html.erb | 7 ++- 9 files changed, 48 insertions(+), 188 deletions(-) delete mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/project_roles/edit_groups.html.erb delete mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/project_roles/edit_users.html.erb diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb index d14d11f2003..61d477a205c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb @@ -158,7 +158,7 @@ class IssuesController < ApplicationController render :partial => 'issues/bulk_change_form' end - # POST /issues/bulk_change + # POST /issues/bulk_change?criteria def bulk_change verify_post_request Internal.issues.bulkChange(params, params[:comment]) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_roles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_roles_controller.rb index f7d4292b390..3ada58fecef 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_roles_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_roles_controller.rb @@ -22,39 +22,10 @@ class ProjectRolesController < ApplicationController SECTION=Navigation::SECTION_RESOURCE - verify :method => :post, :only => [:grant_users, :grant_groups ], :redirect_to => { :action => 'index' } - + # GET /project_roles/@project def index @project=Project.by_key(params[:id]) access_denied unless is_admin?(@project) end - def edit_users - @project=Project.by_key(params[:id]) - access_denied unless is_admin?(@project) - @role = params[:role] - end - - def edit_groups - @project=Project.by_key(params[:id]) - access_denied unless is_admin?(@project) - @role = params[:role] - end - - def grant_users - project=Project.by_key(params[:id]) - access_denied unless is_admin?(project) - - UserRole.grant_users(params[:users], params[:role], project.id) - redirect_to(:action => 'index', :id => project.id) - end - - def grant_groups - project=Project.by_key(params[:id]) - access_denied unless is_admin?(project) - - GroupRole.grant_groups(params[:groups], params[:role], project.id) - redirect_to(:action => 'index', :id => project.id) - end - end 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 a7b55db8ebc..b0eb5c091d4 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 @@ -23,14 +23,14 @@ class RolesController < ApplicationController SECTION=Navigation::SECTION_CONFIGURATION before_filter :admin_required - verify :method => :post, :only => [:set_users, :set_groups, :set_default_project_groups, :set_default_project_users], :redirect_to => {:action => 'global'} + verify :method => :post, :only => [:set_users, :set_groups], :redirect_to => {:action => 'global'} - # GET REQUESTS - + # GET /roles/global def global end + # GET /roles/projects def projects params['pageSize'] = 25 params['qualifiers'] ||= 'TRK' @@ -47,54 +47,42 @@ class RolesController < ApplicationController ) end + # GET /roles/edit_users[?resource=] def edit_users @project=Project.by_key(params[:resource]) if params[:resource].present? @role = params[:role] render :partial => 'edit_users' end - def edit_groups - @project=Project.by_key(params[:resource]) if params[:resource].present? - @role = params[:role] - render :partial => 'edit_groups' - end - - def apply_template_form - bad_request('There are currently no results to apply the permission template to') if params[:projects].blank? - @permission_templates = Internal.permission_templates.selectAllPermissionTemplates().collect {|pt| [pt.name, pt.key]} - render :partial => 'apply_template_form', :locals => {:components => params[:projects], :qualifier => params[:qualifier] || 'TRK'} - end - - # POST REQUESTS - + # POST /roles/set_users?users=&role=[&resource=] def set_users bad_request('Missing role') if params[:role].blank? UserRole.grant_users(params[:users], params[:role], params[:resource]) render :text => '', :status => 200 end - def set_groups - bad_request('Missing role') if params[:role].blank? - GroupRole.grant_groups(params[:groups], params[:role], params[:resource]) - redirect + # GET /roles/edit_groups[?resource=] + def edit_groups + @project=Project.by_key(params[:resource]) if params[:resource].present? + @role = params[:role] + render :partial => 'edit_groups' end - def set_default_project_groups + # POST /roles/set_groups?users=&role=[&resource=] + def set_groups bad_request('Missing role') if params[:role].blank? - bad_request('Missing qualifier') if params[:qualifier].blank? - group_names = params[:groups] || [] - Property.set("sonar.role.#{params[:role]}.#{params[:qualifier]}.defaultGroups", group_names.join(',')) - redirect + GroupRole.grant_groups(params[:groups], params[:role], params[:resource]) + render :text => '', :status => 200 end - def set_default_project_users - bad_request('Missing role') if params[:role].blank? - bad_request('Missing qualifier') if params[:qualifier].blank? - logins = params[:logins] || [] - Property.set("sonar.role.#{params[:role]}.#{params[:qualifier]}.defaultUsers", logins.join(',')) - redirect + # GET /roles/apply_template_form?projects=&qualifier= + def apply_template_form + bad_request('There are currently no results to apply the permission template to') if params[:projects].blank? + @permission_templates = Internal.permission_templates.selectAllPermissionTemplates().collect {|pt| [pt.name, pt.key]} + render :partial => 'apply_template_form', :locals => {:components => params[:projects], :qualifier => params[:qualifier] || 'TRK'} end + # POST /roles/apply_template?criteria def apply_template verify_post_request require_parameters :template_key @@ -102,10 +90,4 @@ class RolesController < ApplicationController redirect_to :action => 'projects' end - private - - def redirect - redirect_to(:action => params['redirect'] || 'global', :q => params[:q], :qualifier => params[:qualifier], :page => params[:page]) - end - end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/roles_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/roles_helper.rb index 681eee71547..869e4d616f8 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/roles_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/roles_helper.rb @@ -21,19 +21,19 @@ module RolesHelper def users(role, resource_id=nil) resource_id=(resource_id.blank? ? nil : resource_id.to_i) - user_roles=UserRole.find(:all, :include => 'user', :conditions => {:role => role, :resource_id => resource_id, :users => {:active => true}}) + user_roles=UserRole.all(:include => 'user', :conditions => {:role => role, :resource_id => resource_id, :users => {:active => true}}) users = user_roles.map { |ur| ur.user } Api::Utils.insensitive_sort(users) { |user| user.name } end def all_users - users = User.find(:all, :conditions => ["active=?", true]) + users = User.all(:conditions => ["active=?", true]) Api::Utils.insensitive_sort(users) { |user| user.name } end def groups(role, resource_id=nil) resource_id=(resource_id.blank? ? nil : resource_id.to_i) - group_roles=GroupRole.find(:all, :include => 'group', :conditions => {:role => role, :resource_id => resource_id}) + group_roles=GroupRole.all(:include => 'group', :conditions => {:role => role, :resource_id => resource_id}) groups = group_roles.map { |ur| ur.group } Api::Utils.insensitive_sort(groups) { |group| group ? group.name : '' } end @@ -56,7 +56,7 @@ module RolesHelper # verify that groups still exist result = [] if group_names.size>0 - groups = Group.find(:all, :conditions => ['name in (?)', group_names]) + groups = Group.all(:conditions => ['name in (?)', group_names]) result = Api::Utils.insensitive_sort(groups.map{|g| g.name}) result = ['Anyone'].concat(result) if group_names.include? 'Anyone' end @@ -65,7 +65,7 @@ module RolesHelper def default_project_users(role, qualifier) logins=(controller.java_facade.getConfigurationValue("sonar.role.#{role}.#{qualifier}.defaultUsers") || '').split(',') - users = User.find(:all, :conditions => ['login in (?) and active=?', logins, true]) + users = User.all(:conditions => ['login in (?) and active=?', logins, true]) Api::Utils.insensitive_sort(users) { |user| user.name } end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project_roles/edit_groups.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project_roles/edit_groups.html.erb deleted file mode 100644 index 5fb122b945c..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/project_roles/edit_groups.html.erb +++ /dev/null @@ -1,51 +0,0 @@ -<% - granted_groups=groups(@role, @project.id) - ungranted_groups=all_groups - granted_groups -%> -
» Back
-

Role Membership Of <%= h(@project.name) %>

-
-
-
- - - - - - - - - - -
-

Add Groups

- -
-
-

-
- -
-

Role: <%= role_name(@role) -%>

- -
- - -
-
- -
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project_roles/edit_users.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project_roles/edit_users.html.erb deleted file mode 100644 index 337c5f491de..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/project_roles/edit_users.html.erb +++ /dev/null @@ -1,50 +0,0 @@ -<% - granted_users=users(@role, params[:id]) - ungranted_users=all_users - granted_users -%> -
» Back
-

Role Membership Of <%= h(@project.name) %>

-
-
-
- - - - - - - - - - - -
-

Add Users

- -
-
-

-
- -
-

Role: <%= role_name(@role) -%>

- -
- - -
-
- -
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 6af2dc4a534..adfd367db30 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 @@ -12,34 +12,40 @@ Administrators
Ability to perform administration functions for a project by accessing its settings. <%= users('admin', @project.id).map(&:name).join(', ') %> - (<%= link_to "select", {:action => 'edit_users', :id => @project.id, :role => 'admin'}, {:id => 'select-admin-edit-users', :class => 'link-action'} %>) + (<%= link_to message('select'), {:controller => :roles, :action => :edit_users, :role => 'admin', :resource => @project.id}, + :id => 'select-admin-edit-users', :class => 'open-modal link-action', 'modal-width' => '760px' %>) <%= groups('admin', @project.id).map{|g| group_name(g)}.join(', ') %> - (<%= link_to "select", {:action => 'edit_groups', :id => @project.id, :role => 'admin'}, {:id => 'select-admin-edit-groups', :class => 'link-action'} %>) + (<%= link_to message('select'), {:controller => :roles, :action => :edit_groups, :role => 'admin', :resource => @project.id}, + :id => 'select-admin-edit-groups', :class => 'open-modal link-action', 'modal-width' => '760px' %>) 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 "select", {:action => 'edit_users', :id => @project.id, :role => 'user'}, {:id => 'select-user-edit-users', :class => 'link-action'} %>) + (<%= link_to message('select'), {:controller => :roles, :action => :edit_users, :role => 'user', :resource => @project.id}, + :id => 'select-user-edit-users', :class => 'open-modal link-action', 'modal-width' => '760px' %>) <%= groups('user', @project.id).map{|g| group_name(g)}.join(', ') %> - (<%= link_to "select", {:action => 'edit_groups', :id => @project.id, :role => 'user'}, {:id => 'select-user-edit-groups', :class => 'link-action'} %>) + (<%= link_to message('select'), {:controller => :roles, :action => :edit_groups, :role => 'user', :resource => @project.id}, + :id => 'select-user-edit-groups', :class => 'open-modal link-action', 'modal-width' => '760px' %>) Code viewers
Ability to view source code of a project. <%= users('codeviewer', @project.id).map(&:name).join(', ') %> - (<%= link_to "select", {:action => 'edit_users', :id => @project.id, :role => 'codeviewer'}, {:id => 'select-codeviewer-edit-users', :class => 'link-action'} %>) + (<%= link_to message('select'), {:controller => :roles, :action => :edit_users, :role => 'codeviewer', :resource => @project.id}, + :id => 'select-codeviewer-edit-users', :class => 'open-modal link-action', 'modal-width' => '760px' %>)
<%= groups('codeviewer', @project.id).map{|g| group_name(g)}.join(', ') %> - (<%= link_to "select", {:action => 'edit_groups', :id => @project.id, :role => 'codeviewer'}, {:id => 'select-codeviewer-edit-groups', :class => 'link-action'} %>) - + (<%= link_to message('select'), {:controller => :roles, :action => :edit_groups, :role => 'codeviewer', :resource => @project.id}, + :id => 'select-codeviewer-edit-groups', :class => 'open-modal link-action', 'modal-width' => '760px' %>) + \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/roles/_edit_groups.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/roles/_edit_groups.html.erb index d1d58d4299f..603ec1b5613 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/roles/_edit_groups.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/roles/_edit_groups.html.erb @@ -1,10 +1,11 @@ <% - granted_groups=groups(@role, params[:resource]) + project_id = @project ? @project.id : nil + granted_groups=groups(@role, project_id) ungranted_groups=all_groups - granted_groups %>
-
- + +