From 0e10dd4728b124717469508a9ab99dcaa62fc1f3 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Tue, 14 Feb 2012 11:01:58 +0100 Subject: [PATCH] SONAR-3258 Add feedback from Freddy --- .../app/controllers/users_controller.rb | 26 +++++++++---------- .../WEB-INF/app/helpers/roles_helper.rb | 2 +- .../main/webapp/WEB-INF/app/models/group.rb | 2 +- .../main/webapp/WEB-INF/app/models/user.rb | 12 ++++++++- .../WEB-INF/app/views/users/index.html.erb | 12 ++------- 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< <%= @user.name -%> <%= f.hidden_field :login %> - <%= f.hidden_field :name %> - <%= f.hidden_field :email %>

- A user with login "<%= @user.login -%>" already exists in the database but had been deleted.
+ A user with login "<%= @user.login -%>" already exists in the database but is deactivated.

- Do you want to reactivate this user? (if yes, please provide a new password) + Do you really want to reactivate this user ?

- - New password:
<%= f.password_field :password, :size => 30, :maxLength => 50 %> - - - Confirm new password:
<%= f.password_field :password_confirmation, :size => 30, :maxLength => 50 %> - <% else %> -- 2.39.5