From be8a52af8539dd972b081202aa569ccdc33dac40 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 25 Sep 2012 11:57:56 +0200 Subject: [PATCH] Reformat profiles_controller.rb --- .../app/controllers/profiles_controller.rb | 121 +++++++----------- 1 file changed, 46 insertions(+), 75 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb index e580d0d152a..d380dbff837 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb @@ -21,26 +21,18 @@ class ProfilesController < ApplicationController SECTION=Navigation::SECTION_CONFIGURATION # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) - verify :method => :post, :only => ['create', 'delete', 'copy', 'set_as_default', 'restore', 'set_projects', 'rename', 'change_parent'], :redirect_to => { :action => 'index' } + verify :method => :post, :only => ['create', 'delete', 'copy', 'set_as_default', 'restore', 'set_projects', 'rename', 'change_parent'], :redirect_to => {:action => 'index'} # the backup action is allow to non-admin users : see http://jira.codehaus.org/browse/SONAR-2039 before_filter :admin_required, :only => ['create', 'delete', 'set_as_default', 'copy', 'restore', 'change_parent', 'set_projects', 'rename_form', 'rename'] - # - # # GET /profiles/index - # - # def index @profiles = Profile.find(:all, :conditions => ['enabled=?', true], :order => 'name') end - # - # # GET /profiles/show/ - # - # def show @profile = Profile.find(params[:id]) end @@ -54,11 +46,7 @@ class ProfilesController < ApplicationController render :partial => 'profiles/create_form', :locals => {:language_key => language} end - # - # # POST /profiles/create?name=&language=&[backup=] - # - # def create profile_name=params[:name] language=params[:language] @@ -85,11 +73,7 @@ class ProfilesController < ApplicationController end - # - # # POST /profiles/delete/ - # - # def delete @profile = Profile.find(params[:id]) if @profile && @profile.deletable? @@ -99,11 +83,7 @@ class ProfilesController < ApplicationController end - # - # # POST /profiles/set_as_default/ - # - # def set_as_default profile = Profile.find(params[:id]) profile.set_as_default @@ -112,16 +92,13 @@ class ProfilesController < ApplicationController end + # GET /profiles/copy_form/ def copy_form @profile = Profile.find(params[:id]) render :partial => 'profiles/copy_form' end - # - # # POST /profiles/copy/?name= - # - # def copy render :text => 'Not an ajax request', :status => '400' unless request.xhr? @@ -140,12 +117,7 @@ class ProfilesController < ApplicationController end - - # - # # POST /profiles/backup/ - # - # def backup profile = Profile.find(params[:id]) xml = java_facade.backupProfile(profile.id) @@ -155,11 +127,12 @@ class ProfilesController < ApplicationController # Modal window to restore profile backup + # GET /profiles/restore_form/ def restore_form render :partial => 'profiles/restore_form' end - # POST /profiles/restore/ + # POST /profiles/restore?backup= def restore if params[:backup].blank? flash[:warning]=message('quality_profiles.please_upload_backup_file') @@ -171,12 +144,7 @@ class ProfilesController < ApplicationController end - - # - # # GET /profiles/export?name=&language=&format - # - # def export language = params[:language] if (params[:name].blank?) @@ -206,7 +174,7 @@ class ProfilesController < ApplicationController @profile = Profile.find(params[:id]) profiles=Profile.find(:all, :conditions => ['language=? and id<>? and (parent_name is null or parent_name<>?) and enabled=?', @profile.language, @profile.id, @profile.name, true], :order => 'name') - @select_parent = [[message('none'), nil]] + profiles.collect{ |profile| [profile.name, profile.name] } + @select_parent = [[message('none'), nil]] + profiles.collect { |profile| [profile.name, profile.name] } end # @@ -218,7 +186,7 @@ class ProfilesController < ApplicationController @profile = Profile.find(params[:id]) versions = ActiveRuleChange.find(:all, :select => 'profile_version, MAX(change_date) AS change_date', :conditions => ['profile_id=?', @profile.id], :group => 'profile_version') - versions.sort! { |a,b| b.profile_version <=> a.profile_version } + versions.sort! { |a, b| b.profile_version <=> a.profile_version } if !versions.empty? last_version = versions[0].profile_version @@ -237,7 +205,7 @@ class ProfilesController < ApplicationController end @changes = ActiveRuleChange.find(:all, :conditions => ['profile_id=? and ? 'id desc') - @select_versions = versions.map {|u| [ message(u.profile_version == last_version ? 'quality_profiles.last_version_x_with_date' : 'quality_profiles.version_x_with_date', :params => [u.profile_version.to_s, l(u.change_date)]), u.profile_version ]} | [[message('quality_profiles.no_version'), 0]]; + @select_versions = versions.map { |u| [message(u.profile_version == last_version ? 'quality_profiles.last_version_x_with_date' : 'quality_profiles.version_x_with_date', :params => [u.profile_version.to_s, l(u.change_date)]), u.profile_version] } | [[message('quality_profiles.no_version'), 0]]; end end @@ -278,14 +246,13 @@ class ProfilesController < ApplicationController def projects @profile = Profile.find(params[:id]) @available_projects=Project.find(:all, - :include => ['profile','snapshots'], - :conditions => ['projects.qualifier=? AND projects.scope=? AND snapshots.islast=?', Project::QUALIFIER_PROJECT, Project::SCOPE_SET, true], - :order => 'projects.name asc') + :include => ['profile', 'snapshots'], + :conditions => ['projects.qualifier=? AND projects.scope=? AND snapshots.islast=?', Project::QUALIFIER_PROJECT, Project::SCOPE_SET, true], + :order => 'projects.name asc') @available_projects-=@profile.projects end - # # # POST /profiles/set_projects/?projects= @@ -352,9 +319,9 @@ class ProfilesController < ApplicationController @profile2 = Profile.find(params[:id2]) arules1 = ActiveRule.find(:all, :include => [{:active_rule_parameters => :rules_parameter}, :rule], - :conditions => ['active_rules.profile_id=?', @profile1.id]) + :conditions => ['active_rules.profile_id=?', @profile1.id]) arules2 = ActiveRule.find(:all, :order => 'rules.plugin_name, rules.plugin_rule_key', :include => [{:active_rule_parameters => :rules_parameter}, :rule], - :conditions => ['active_rules.profile_id=?', @profile2.id]) + :conditions => ['active_rules.profile_id=?', @profile2.id]) diffs_by_rule={} arules1.each do |arule1| @@ -371,10 +338,14 @@ class ProfilesController < ApplicationController @sames=[] diffs_by_rule.values.sort.each do |diff| case diff.status - when DIFF_IN1 then @in1<(other) @@ -466,9 +437,9 @@ class ProfilesController < ApplicationController added = added +1 else rule = active_rule1.rule # = active_rule2.rule - #compare severity + #compare severity diff = true if active_rule1.priority != active_rule2.priority - #compare parameters + #compare parameters rule.parameters.each do |param| diff = true if active_rule1.value(param.id) != active_rule2.value(param.id) end -- 2.39.5