From: Julien Lancelot Date: Thu, 18 Jul 2013 14:59:10 +0000 (+0200) Subject: Add a common way to generate edit permission link X-Git-Tag: 3.7~53 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fffe0ffa7c391fdd0ddefade1a01c9dab95fcbec;p=sonarqube.git Add a common way to generate edit permission link --- 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 869e4d616f8..a774e513a01 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 @@ -86,4 +86,14 @@ module RolesHelper message("global_permissions.#{role}", :default => role) end + def link_to_edit_roles_permission_form(label, role, resource_id, html_id) + link_to message(label), {:controller => :roles, :action => :edit_users, :role => role, :resource => resource_id}, + :id => html_id, :class => 'open-modal link-action', 'modal-width' => '780px' + end + + def link_to_edit_groups_permission_form(label, role, resource_id, html_id) + link_to message(label), {:controller => :roles, :action => :edit_groups, :role => role, :resource => resource_id}, + :id => html_id, :class => 'open-modal link-action', 'modal-width' => '780px' + end + end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_groups.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_groups.html.erb index fce1c839136..eb9e147f375 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_groups.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_groups.html.erb @@ -20,7 +20,7 @@ <% end %> - +



diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_users.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_users.html.erb index 9125985ed90..e4cd1477aec 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_users.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_edit_users.html.erb @@ -20,7 +20,7 @@ <% end %> - +



diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/index.html.erb index ebf45b3f708..4a3c0d0499c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/index.html.erb @@ -35,42 +35,20 @@ <%= h permission_template.name %>
<%= h permission_template.description -%> - - <% - users=Api::Utils.insensitive_sort(permission_template.getUsersForPermission('admin').collect {|u| u.userName}) - groups=Api::Utils.insensitive_sort(permission_template.getGroupsForPermission('admin').collect {|g| g.groupName.blank? ? 'Anyone' : g.groupName}) - %> - <%= users.join(', ') %> - (<%= link_to message('select users'), {:action => :edit_users, :name => permission_template.name, :permission => 'admin'}, - :id => "selectu-admin-#{u permission_template.name}", :class => 'open-modal link-action', 'modal-width' => '760px' %>)
- <%= groups.join(', ') %> - (<%= link_to message('select groups'), {:action => :edit_groups, :name => permission_template.name, :permission => 'admin'}, - :id => "selectg-admin-#{u permission_template.name}", :class => 'open-modal link-action', 'modal-width' => '760px' %>) - - - <% - users=Api::Utils.insensitive_sort(permission_template.getUsersForPermission('user').collect {|u| u.userName}) - groups=Api::Utils.insensitive_sort(permission_template.getGroupsForPermission('user').collect {|g| g.groupName.blank? ? 'Anyone' : g.groupName}) - %> - <%= users.join(', ') %> - (<%= link_to message('select users'), {:action => :edit_users, :name => permission_template.name, :permission => 'user'}, - :id => "selectu-user-#{u permission_template.name}", :class => 'open-modal link-action', 'modal-width' => '760px' %>)
- <%= groups.join(', ') %> - (<%= link_to message('select groups'), {:action => :edit_groups, :name => permission_template.name, :permission => 'user'}, - :id => "selectg-user-#{u permission_template.name}", :class => 'open-modal link-action', 'modal-width' => '760px' %>) - - - <% - users=Api::Utils.insensitive_sort(permission_template.getUsersForPermission('codeviewer').collect {|u| u.userName}) - groups=Api::Utils.insensitive_sort(permission_template.getGroupsForPermission('codeviewer').collect {|g| g.groupName.blank? ? 'Anyone' : g.groupName}) - %> - <%= users.join(', ') %> - (<%= link_to message('select users'), {:action => :edit_users, :name => permission_template.name, :permission => 'codeviewer'}, - :id => "selectu-codeviewer-#{u permission_template.name}", :class => 'open-modal link-action', 'modal-width' => '760px' %>)
- <%= groups.join(', ') %> - (<%= link_to message('select groups'), {:action => :edit_groups, :name => permission_template.name, :permission => 'codeviewer'}, - :id => "selectg-codeviewer-#{u permission_template.name}", :class => 'open-modal link-action', 'modal-width' => '760px' %>) - + <% ['admin', 'user', 'codeviewer'].each do |permission| -%> + + <% + users=Api::Utils.insensitive_sort(permission_template.getUsersForPermission(permission).collect {|u| u.userName}) + groups=Api::Utils.insensitive_sort(permission_template.getGroupsForPermission(permission).collect {|g| g.groupName.blank? ? 'Anyone' : g.groupName}) + %> + <%= users.join(', ') %> + (<%= link_to message('select users'), {:action => :edit_users, :name => permission_template.name, :permission => permission}, + :id => "selectu-#{permission}-#{u permission_template.name}", :class => 'open-modal link-action', 'modal-width' => '780px' %>)
+ <%= groups.join(', ') %> + (<%= link_to message('select groups'), {:action => :edit_groups, :name => permission_template.name, :permission => permission}, + :id => "selectg-#{permission}-#{u permission_template.name}", :class => 'open-modal link-action', 'modal-width' => '780px' %>)
+ + <% end %> <% qualifiers = [] @default_templates.each_pair do |q, t| 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 f4f9ade6a51..874e7cdbac5 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,40 +12,34 @@ Administrators
Ability to perform administration functions for a project by accessing its settings. <%= users('admin', @project.id).map(&:name).join(', ') %> - (<%= 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' %>) + (<%= 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 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' %>) + (<%= link_to_edit_groups_permission_form(message('select'), 'admin', @project.id, 'select-admin-edit-groups') %>)
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 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' %>) + (<%= 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 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' %>) + (<%= 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 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' %>)
+ (<%= 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 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' %>) - + (<%= link_to_edit_groups_permission_form(message('select'), 'codeviewer', @project.id, 'select-codeviewer-edit-groups') %>)
+ \ 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 603ec1b5613..64dc2d6d354 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 @@ -24,7 +24,7 @@ <% end %> - +



diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/roles/_edit_users.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/roles/_edit_users.html.erb index bb44aadefc1..4e1f7a95060 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/roles/_edit_users.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/roles/_edit_users.html.erb @@ -23,7 +23,7 @@ <% end %> - +



diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/roles/global.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/roles/global.html.erb index de6f010ae2f..b9d130f0530 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/roles/global.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/roles/global.html.erb @@ -16,13 +16,11 @@ <%= message('global_permissions.' + global_permission_key + '.desc') -%> <%= users(global_permission_key).map(&:name).join(', ') -%> - (<%= link_to message('select'), {:action => :edit_users, :role => global_permission_key}, - :id => "select-users-#{global_permission_key}", :class => 'open-modal link-action', 'modal-width' => '760px' %>)
+ (<%= link_to_edit_roles_permission_form(message('select'), global_permission_key, nil, "select-users-#{global_permission_key}") %>)
<%= groups(global_permission_key).map{|g| group_name(g)}.join(', ') %> - (<%= link_to message('select'), {:action => :edit_groups, :role => global_permission_key}, - :id => "select-groups-#{global_permission_key}", :class => 'open-modal link-action', 'modal-width' => '760px' %>)
+ (<%= link_to_edit_groups_permission_form(message('select'), global_permission_key, nil, "select-groups-#{global_permission_key}") %>)
<% end %> 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 ecc74d213df..c7d5f586037 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 @@ -66,42 +66,18 @@ <%= h project.name %>
<%= h project.key -%> - - <% - users=Api::Utils.insensitive_sort(project.user_roles.select { |ur| ur.role=='admin' }.map { |ur| ur.user.name }) - groups=Api::Utils.insensitive_sort(project.group_roles.select { |gr| gr.role=='admin' }.map { |gr| group_name(gr.group) }) - %> - <%= users.join(', ') %> - (<%= link_to message('select users'), {:action => :edit_users, :role => 'admin', :resource => project.id}, - :id => "selectu-admin-#{u project.kee}", :class => 'open-modal link-action', 'modal-width' => '760px' %>)
- <%= groups.join(', ') %> - (<%= link_to message('select groups'), {:action => :edit_groups, :role => 'admin', :resource => project.id}, - :id => "selectg-admin-#{u project.kee}", :class => 'open-modal link-action', 'modal-width' => '760px' %>)
- - - <% - users=Api::Utils.insensitive_sort(project.user_roles.select { |ur| ur.role=='user' }.map { |ur| ur.user.name }) - groups=Api::Utils.insensitive_sort(project.group_roles.select { |gr| gr.role=='user' }.map { |gr| group_name(gr.group) }) - %> - <%= users.join(', ') %> - (<%= link_to message('select users'), {:action => :edit_users, :role => 'user', :resource => project.id}, - :id => "selectu-user-#{u project.kee}", :class => 'open-modal link-action', 'modal-width' => '760px' %>)
- <%= groups.join(', ') %> - (<%= link_to message('select groups'), {:action => :edit_groups, :role => 'user', :resource => project.id}, - :id => "selectg-user-#{u project.kee}", :class => 'open-modal link-action', 'modal-width' => '760px' %>)
- - - <% - users=Api::Utils.insensitive_sort(project.user_roles.select { |ur| ur.role=='codeviewer' }.map { |ur| ur.user.name }) - groups=Api::Utils.insensitive_sort(project.group_roles.select { |gr| gr.role=='codeviewer' }.map { |gr| group_name(gr.group) }) - %> - <%= users.join(', ') %> - (<%= link_to message('select users'), {:action => :edit_users, :role => 'codeviewer', :resource => project.id}, - :id => "selectu-codeviewer-#{u project.kee}", :class => 'open-modal link-action', 'modal-width' => '760px' %>)
- <%= groups.join(', ') %> - (<%= link_to message('select groups'), {:action => :edit_groups, :role => 'codeviewer', :resource => project.id}, - :id => "selectg-codeviewer-#{u project.kee}", :class => 'open-modal link-action', 'modal-width' => '760px' %>)
- + <% ['admin', 'user', 'codeviewer'].each do |permission| -%> + + <% + users=Api::Utils.insensitive_sort(project.user_roles.select { |ur| ur.role==permission }.map { |ur| ur.user.name }) + groups=Api::Utils.insensitive_sort(project.group_roles.select { |gr| gr.role==permission }.map { |gr| group_name(gr.group) }) + %> + <%= users.join(', ') %> + (<%= link_to_edit_roles_permission_form(message('select users'), permission, project.id, "selectu-#{permission}-#{u project.kee}") %>)
+ <%= groups.join(', ') %> + (<%= link_to_edit_groups_permission_form(message('select groups'), permission, project.id, "selectg-#{permission}-#{u project.kee}") %>)
+ + <% end %> <%= link_to message('projects_role.apply_template'), {:action => :apply_template_form, :projects => [project.id], :project_name => project.name, :qualifier => @qualifier}, :id => "apply-template-modal-#{project.id}", :class => 'open-modal link-action' %>