From f7b1fce41208829944452f5e064f5198fbf2faa2 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Mon, 13 Feb 2012 11:33:23 +0100 Subject: [PATCH] SONAR-3258 No more delete users in the Sonar DB but deactivate them - When creating a user, if the login already exists on a deactivated user, adapt the UI to ask if user should be reactivated or not --- .../app/controllers/users_controller.rb | 36 +++++++++++++-- .../WEB-INF/app/views/users/index.html.erb | 46 ++++++++++++++++--- 2 files changed, 70 insertions(+), 12 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 fdb33b76046..850a3308e90 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 @@ -28,12 +28,22 @@ class UsersController < ApplicationController return unless request.post? cookies.delete :auth_token - user=prepare_user - if user.save - flash[:notice] = 'User is created.' - end + 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 + else + user=prepare_user + if user.save + flash[:notice] = 'User is created.' + end + to_index(user.errors, nil) + end - to_index(user.errors, nil) end def signup @@ -97,6 +107,22 @@ class UsersController < ApplicationController to_index(user.errors, nil) end + + 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 + user.save! + flash[:notice] = 'User was successfully reactivated.' + else + flash[:error] = "A user with login #{params[:user][:login]} does not exist." + end + to_index(user.errors, nil) + end def destroy @user = User.find(params[:id]) 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 81eb2de4f90..eed786fafad 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 @@ -40,20 +40,50 @@ <% action_name = 'create' title = 'Add new user' + submit_button_label = 'Create' if @user.id - action_name = 'update' - title = 'Edit user' - if params[:action] == 'change_password' - action_name = 'update_password' - title = 'Change password' + if @user.active + action_name = 'update' + title = 'Edit user' + submit_button_label = 'Update' + if params[:action] == 'change_password' + action_name = 'update_password' + title = 'Change password' + end + else + action_name = 'reactivate' + title = 'Reactivate user?' + submit_button_label = 'Reactivate user' end end %> <% form_for :user, @user, :url => { :id => @user.id, :action => action_name}, :html => { :method => @user.id.nil?? :post : :put } do |f| %> - + + + + <% if @user && !@user.active %> + <%= @user.name -%> + <%= f.hidden_field :login %> + <%= f.hidden_field :name %> + <%= f.hidden_field :email %> + + + + + + + + + <% else %> <% end %> + <% end %> + -- 2.39.5

<%= title %>

<%= title %>

+

+ A user with login "<%= @user.login -%>" already exists in the database but had been deleted.
+
+ Do you want to reactivate this user? (if yes, please provide a new password) +

+
New password:
<%= f.password_field :password, :size => 30, :maxLength => 50 %>
Confirm new password:
<%= f.password_field :password_confirmation, :size => 30, :maxLength => 50 %>
Login: <% if @user.id %> @@ -87,9 +117,11 @@ Confirm new password:
<%= f.password_field :password_confirmation, :size => 30, :maxLength => 50 %>
- <%= submit_tag @user.id.nil?? 'Create':'Update' %> + <%= submit_tag submit_button_label %> <%= link_to 'cancel', { :controller => 'users', :action => 'index'}, { :class => 'action' } %>