]> source.dussan.org Git - sonarqube.git/commitdiff
Some ruby refactoring in user and group consoles
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 21 Oct 2013 08:19:28 +0000 (10:19 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 21 Oct 2013 08:19:28 +0000 (10:19 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb

index f24b4314c3773e58bd538b3c9d28bfc96127d341..d2a3b1855229fb03a0da4676e00a6477142003d7 100644 (file)
@@ -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)
 
index 93a7e4aa67c1c37be5831478ca48290423a30486..7b50c3407336f5c41f06f7fa62ec0e5c2ac8560b 100644 (file)
@@ -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("<br/>\n")
-    end
 
+  private
+
+  def to_index(errors, id)
+    flash[:error] = errors.full_messages.join("<br/>\n") unless errors.empty?
     redirect_to(:action => 'index', :id => id)
   end
 
index d5be18b9f37bc76870a0042b06279fe7a3b97c1b..13b4c2ce774f16748ae665d4af027d5930000b08 100644 (file)
@@ -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