From: Simon Brandhof Date: Mon, 21 Oct 2013 08:19:28 +0000 (+0200) Subject: Some ruby refactoring in user and group consoles X-Git-Tag: 4.0~45 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=eb321c1da9949532872a6a7c64be6d51e11affe4;p=sonarqube.git Some ruby refactoring in user and group consoles --- diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb index f24b4314c37..d2a3b185522 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb @@ -252,10 +252,12 @@ class ApplicationController < ActionController::Base # # SETTINGS # + # TODO - remove from ApplicationController def by_category_name(categories) Api::Utils.insensitive_sort(categories) { |category| category_name(category) } end + # TODO - remove from ApplicationController def by_subcategory_name(category, subcategories) Api::Utils.insensitive_sort(subcategories) { |subcategory| if (subcategory == category) @@ -267,11 +269,13 @@ class ApplicationController < ActionController::Base } end + # TODO - remove from ApplicationController def category_name(category) # Try with lowercase key then with original key for backward compatibility message("property.category.#{category.key}", :default => message("property.category.#{category.originalKey}", :default => category.originalKey)) end + # TODO - remove from ApplicationController def subcategory_name(category, subcategory) if (category.key == subcategory.key) # If subcategory == category then it is the default one @@ -283,6 +287,7 @@ class ApplicationController < ActionController::Base end end + # TODO - remove from ApplicationController def processProperties(definitions_per_category) @categories = by_category_name(definitions_per_category.keys) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb index 93a7e4aa67c..7b50c340733 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb @@ -32,8 +32,8 @@ class GroupsController < ApplicationController end def create_form - @groups = Group.find(:all, :order => 'name') if params[:id] + # TODO is it used ? @group = Group.find(params[:id]) else @group = Group.new @@ -45,12 +45,14 @@ class GroupsController < ApplicationController if params[:id] @group = Group.find(params[:id]) else + # TODO is it used ? @group = Group.new end render :partial => 'groups/edit_form' end def create + verify_post_request group = Group.new(params[:group]) if group.save flash[:notice] = 'The new group is created.' @@ -64,6 +66,7 @@ class GroupsController < ApplicationController end def update + verify_post_request group = Group.find(params[:id]) if group.update_attributes(params[:group]) flash[:notice] = 'Group is updated.' @@ -77,6 +80,7 @@ class GroupsController < ApplicationController end def delete + verify_post_request group = Group.find(params[:id]) if group.destroy flash[:notice] = 'Group is deleted.' @@ -97,11 +101,11 @@ class GroupsController < ApplicationController redirect_to(:action => 'index') end - def to_index(errors, id) - if !errors.empty? - flash[:error] = errors.full_messages.join("
\n") - end + private + + def to_index(errors, id) + flash[:error] = errors.full_messages.join("
\n") unless errors.empty? redirect_to(:action => 'index', :id => id) end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb index d5be18b9f37..13b4c2ce774 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb @@ -83,8 +83,8 @@ class UsersController < ApplicationController end def create_form - init_users_list if params[:id] + # TODO is it really used ? @user = User.find(params[:id]) else @user = User.new @@ -93,7 +93,6 @@ class UsersController < ApplicationController end def reactivate_form - init_users_list if params[:id] @user = User.find(params[:id]) else @@ -107,14 +106,12 @@ class UsersController < ApplicationController end def edit_form - init_users_list @user = User.find(params[:id]) render :partial => 'users/edit_form', :status => 200 end def change_password_form - init_users_list @user = User.find(params[:id]) render :partial => 'users/change_password_form', :status => 200 end