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
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
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
# 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)
<% 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>