From 6e030b62056c9383679545ba95db0d141c34e402 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Vilain Date: Wed, 17 Jul 2013 16:07:36 +0200 Subject: [PATCH] SONAR-4466 Moved the default templates selection to a dedicated modal window --- .../permission_templates_controller.rb | 70 ++++++++++++++----- .../_default_templates_form.html.erb | 35 ++++++++++ .../views/permission_templates/index.html.erb | 25 ++----- 3 files changed, 94 insertions(+), 36 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_default_templates_form.html.erb 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 0e1017e1907..d2a2bceff5d 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 @@ -37,24 +37,16 @@ class PermissionTemplatesController < ApplicationController # GET # def index - templates_names = Internal.permission_templates.selectAllPermissionTemplates.collect {|t| t.name} - @permission_templates = [] - @permission_templates_options = [] - templates_names.each do |template_name| - permission_template = Internal.permission_templates.selectPermissionTemplate(template_name) - @permission_templates << permission_template - @permission_templates_options << [permission_template.name, permission_template.key] - end - @root_qualifiers = get_root_qualifiers + all_templates = Internal.permission_templates.selectAllPermissionTemplates - @default_templates = {} - default_template_property = Property.by_key("sonar.permission.template.default") - @root_qualifiers.each do |qualifier| - qualifier_template = Property.by_key("sonar.permission.template.#{qualifier}.default") - @default_templates[qualifier] = qualifier_template ? qualifier_template.text_value : default_template_property.text_value - end + @permission_templates = get_templates_and_permissions(all_templates) + @root_qualifiers = get_root_qualifiers + @default_templates = get_default_templates_per_qualifier(@root_qualifiers) end + # + # GET (modal form) + # def edit_users @permission = params[:permission] @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name]) @@ -64,6 +56,9 @@ class PermissionTemplatesController < ApplicationController render :partial => 'permission_templates/edit_users' end + # + # GET (modal form) + # def edit_groups @permission = params[:permission] @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name]) @@ -129,7 +124,9 @@ class PermissionTemplatesController < ApplicationController redirect_to :action => 'index' end - + # + # GET (modal form) + # def create_form render :partial => 'permission_templates/permission_template_form', :locals => {:form_action => 'create', :message_title => 'new_template', :message_submit => 'create_template'} @@ -144,6 +141,9 @@ class PermissionTemplatesController < ApplicationController redirect_to :action => 'index' end + # + # GET (modal form) + # def edit_form @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name]) render :partial => 'permission_templates/permission_template_form', @@ -160,6 +160,9 @@ class PermissionTemplatesController < ApplicationController redirect_to :action => 'index' end + # + # GET (modal form) + # def delete_form @permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name]) render :partial => 'permission_templates/delete_form' @@ -175,10 +178,23 @@ class PermissionTemplatesController < ApplicationController redirect_to :action => 'index' end + # + # GET (modal form) + # + def default_templates_form + all_templates = Internal.permission_templates.selectAllPermissionTemplates + + @permission_templates_options = all_templates.collect {|t| [t.name, t.key]} + @root_qualifiers = get_root_qualifiers + @default_templates = get_default_templates_per_qualifier(@root_qualifiers) + + render :partial => 'permission_templates/default_templates_form' + end + # # POST # - def set_default_template + def update_default_templates verify_post_request get_root_qualifiers.each do |qualifier| Property.set("sonar.permission.template.#{qualifier}.default", params["default_template_#{qualifier}"]) @@ -189,10 +205,30 @@ class PermissionTemplatesController < ApplicationController redirect_to :action => 'index' end + private def get_root_qualifiers Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceRootTypes().map {|type| type.getQualifier()} end + def get_default_templates_per_qualifier(root_qualifiers) + default_templates = {} + default_template_property = Property.by_key("sonar.permission.template.default") + root_qualifiers.each do |qualifier| + qualifier_template = Property.by_key("sonar.permission.template.#{qualifier}.default") + default_templates[qualifier] = qualifier_template ? qualifier_template.text_value : default_template_property.text_value + end + default_templates + end + + def get_templates_and_permissions(permission_templates) + templates_names = permission_templates.collect {|t| t.name} + permission_templates = [] + templates_names.each do |template_name| + permission_templates << Internal.permission_templates.selectPermissionTemplate(template_name) + end + permission_templates + end + end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_default_templates_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_default_templates_form.html.erb new file mode 100644 index 00000000000..71b471a9bf0 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/permission_templates/_default_templates_form.html.erb @@ -0,0 +1,35 @@ +
+
+ +
+
+ + + 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 7b7f25ff923..fd8d4c24c7f 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 @@ -1,26 +1,13 @@ <%= render :partial => 'roles/tabs', :locals => {:selected_tab=>'Permission templates'} %>
-

Default templates

-
-

- This section allows you to configure the default permission templates that will be applied by SonarQube while analysing your projects. -

- <% form_tag(:controller => 'permission_templates', :action => 'set_default_template') do %> - - <% @root_qualifiers.each do |qualifier| %> - <%= label_tag("default_template_#{qualifier}", "Default permission template for #{message('qualifier.' + qualifier)}:") %> - <%= select_tag("default_template_#{qualifier}", options_for_select(@permission_templates_options, @default_templates[qualifier])) %>   - <% end %> -
-
- <%= submit_tag "Save" %> - <% end %> -
-

Available templates

@@ -91,7 +78,7 @@ end if qualifiers.length > 0 %> - <%= image_tag 'tick.png', :id => "is_active_#{u permission_template.name}" %>(Default for <%= qualifiers.collect {|q| message('qualifier.' + q)}.join(',') %>) + <%= image_tag 'tick.png', :id => "is_active_#{u permission_template.name}" %>(Default for <%= qualifiers.collect {|q| message('qualifier.' + q)}.join(', ') %>) <% end %> -- 2.39.5