diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2012-02-14 11:01:58 +0100 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2012-02-14 11:46:58 +0100 |
commit | 0e10dd4728b124717469508a9ab99dcaa62fc1f3 (patch) | |
tree | 3c2d76e516b88f810ce5c6886bc5379355876aca | |
parent | fa26409fef5ab3093e926ef2b02b2ae9c9a3fa58 (diff) | |
download | sonarqube-0e10dd4728b124717469508a9ab99dcaa62fc1f3.tar.gz sonarqube-0e10dd4728b124717469508a9ab99dcaa62fc1f3.zip |
SONAR-3258 Add feedback from Freddy
5 files changed, 28 insertions, 26 deletions
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 850a3308e90..30b06744cf3 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 @@ -30,12 +30,16 @@ class UsersController < ApplicationController user = User.find_by_login(params[:user][:login]) if user && !user.active - # users was deleted, a message must be displayed to ask wether to override it or not - @user = user - @user.name = params[:user][:name] - @user.email = params[:user][:email] - @users = User.find(:all, :conditions => ["active=?", true], :include => 'groups') - render :index + # users is deativated, this is a special case: + # 1- first, we save the given information, in case the user is reactivated (to not ask for it twice) + if user.update_attributes(params[:user]) + # 2- if info correctly saved, then we display a message to ask wether the user should be reactivated or not + @user = user + @users = User.find(:all, :conditions => ["active=?", true], :include => 'groups') + render :index + else + to_index(user.errors, nil) + end else user=prepare_user if user.save @@ -110,12 +114,8 @@ class UsersController < ApplicationController def reactivate user = User.find_by_login(params[:user][:login]) - if user - user.name = params[:user][:name] - user.email = params[:user][:email] - user.password = params[:user][:password] - user.password_confirmation = params[:user][:password_confirmation] - user.active = true + if user + user.reactivate(java_facade.getSettings().getString('sonar.defaultGroup')) user.save! flash[:notice] = 'User was successfully reactivated.' else @@ -169,7 +169,7 @@ class UsersController < ApplicationController end def autocomplete - @users = User.find(:all, :conditions => ["UPPER(name) like ?", params[:user_name_start].clone.upcase+"%"]) + @users = User.find(:all, :conditions => ["UPPER(name) like ? AND active=?", params[:user_name_start].clone.upcase+"%", true]) @char_count = params[:user_name_start].size render :partial => 'autocomplete' end 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 8ad5e3e757c..55936a07bfe 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 @@ -26,7 +26,7 @@ module RolesHelper end def all_users - User.find(:all, :order => 'name') + User.find(:all, :conditions => ["active=?", true], :order => 'name') end def groups(role, resource_id=nil) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/group.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/group.rb index 48f26531360..8537c5d4224 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/group.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/group.rb @@ -29,7 +29,7 @@ class Group < ActiveRecord::Base # all the users that are NOT members of this group def available_users - User.find(:all, :order => 'name') - users + User.find(:all, :conditions => ["active=?", true], :order => 'name') - users end def set_users(new_users=[]) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/user.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/user.rb index e04db76b0a3..019809fa77b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/user.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/user.rb @@ -89,12 +89,22 @@ class User < ActiveRecord::Base # However, all related data is removed from the DB. def deactivate self.active = false + self.groups.clear self.save! self.user_roles.each {|role| role.delete} self.properties.each {|prop| prop.delete} self.filters.each {|f| f.destroy} self.dashboards.each {|d| d.destroy} - self.active_dashboards.each {|ad| ad.destroy} + self.active_dashboards.each {|ad| ad.destroy} + end + + # SONAR-3258 + def reactivate(default_group_name) + if default_group_name + default_group=Group.find_by_name(default_group_name) + self.groups<<default_group if default_group + end + self.active = true end def self.find_active_by_login(login) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb index eed786fafad..ef853651188 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb @@ -66,22 +66,14 @@ <% if @user && !@user.active %> <%= @user.name -%> <%= f.hidden_field :login %> - <%= f.hidden_field :name %> - <%= f.hidden_field :email %> <tr> <td> <p class="error"> - A user with login "<%= @user.login -%>" already exists in the database but had been deleted.<br/> + A user with login "<%= @user.login -%>" already exists in the database but is deactivated.<br/> <br/> - Do you want to reactivate this user? (if yes, please provide a new password) + Do you really want to reactivate this user ? </p> </td> - <tr> - <td class="left" valign="top">New password:<br/><%= f.password_field :password, :size => 30, :maxLength => 50 %></td> - </tr> - <tr> - <td class="left" valign="top">Confirm new password:<br/><%= f.password_field :password_confirmation, :size => 30, :maxLength => 50 %></td> - </tr> <tr> <% else %> <tr> |