public final static int VERSION_UNKNOWN = -1;
- public static final int LAST_VERSION = 256;
+ public static final int LAST_VERSION = 257;
public static final int VERSION_2_13 = 241;
public final static String TABLE_NAME = "schema_migrations";
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('254');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('255');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('256');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('257');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP,
"REMEMBER_TOKEN" VARCHAR(500),
- "REMEMBER_TOKEN_EXPIRES_AT" TIMESTAMP
+ "REMEMBER_TOKEN_EXPIRES_AT" TIMESTAMP,
+ "ACTIVE" BOOLEAN DEFAULT TRUE,
);
CREATE TABLE "FILTERS" (
return unless request.post?
self.current_user = User.authenticate(params[:login], params[:password])
- if logged_in?
+ if logged_in? && current_user.active
if params[:remember_me] == '1'
self.current_user.remember_me
cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
end
def index
- @users = User.find(:all, :include => 'groups')
+ @users = User.find(:all, :conditions => ["active=?", true], :include => 'groups')
if params[:id]
@user = User.find(params[:id])
else
if current_user.id==@user.id
flash[:error] = 'Please log in with another user in order to delete yourself.'
- elsif @user.destroy
+ else
+ @user.deactivate
flash[:notice] = 'User is deleted.'
end
has_and_belongs_to_many :groups
has_many :user_roles, :dependent => :delete_all
+
has_many :properties, :foreign_key => 'user_id', :dependent => :delete_all
+
has_many :active_filters, :include => 'filter', :order => 'order_index'
has_many :filters, :dependent => :destroy
include NeedAuthorization::ForUser
include NeedAuthentication::ForUser
- validates_length_of :name, :maximum => 200, :allow_blank => true, :allow_nil => true
+ validates_length_of :name, :maximum => 200, :allow_blank => true, :allow_nil => true
validates_length_of :email, :maximum => 100, :allow_blank => true, :allow_nil => true
# The following two validations not needed, because they come with Authentication::ByPassword - see SONAR-2656
validates_presence_of :login
validates_length_of :login, :within => 2..40
- validates_uniqueness_of :login, :case_sensitive => true
+ validates_uniqueness_of :login, :case_sensitive => true
validates_format_of :login, :with => Authentication.login_regex, :message => Authentication.bad_login_message
return 1 if other.name.nil?
name.downcase<=>other.name.downcase
end
+
+ # SONAR-3258 : we do not delete users anymore. Users are just deactivated.
+ # However, all related data is removed from the DB.
+ def deactivate
+ self.active = false
+ 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}
+ end
#---------------------------------------------------------------------
--- /dev/null
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2012 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+
+#
+# Sonar 2.14
+#
+class AddActiveFieldOnUsers < ActiveRecord::Migration
+
+ def self.up
+ add_column 'users', 'active', :boolean, :null => true, :default => true
+ User.reset_column_information
+
+ User.find(:all).each do |user|
+ user.active = true
+ user.save
+ end
+ end
+
+end
+ sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql :
- add "INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('<THE MIGRATION ID>')"
* Update the migration id defined in sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
-* If a table is addded or removed, then edit sonar-core/src/main/java/org/sonar/core/persistence/DatabaseUtils.java
+* If a table is added or removed, then edit sonar-core/src/main/java/org/sonar/core/persistence/DatabaseUtils.java