From 72234820b5d034cc68843a70fa4bbcfa529933d1 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 21 Mar 2016 18:26:25 +0100 Subject: [PATCH] SONAR-7254 Fix update of user.local for first usage --- .../src/main/webapp/WEB-INF/app/models/user.rb | 16 ++-------------- .../db/migrate/1119_add_users_local_column.rb | 2 ++ .../webapp/WEB-INF/lib/need_authentication.rb | 11 ++++++++--- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/user.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/user.rb index 4d3c4dca84d..e6e3e2dc7cc 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/user.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/user.rb @@ -61,8 +61,8 @@ class User < ActiveRecord::Base # HACK HACK HACK -- how to do attr_accessible from here? # prevents a user from submitting a crafted form that bypasses activation # anything else you want your user to change should be added here. - attr_accessible :login, :email, :name, :password, :password_confirmation, :external_identity, :external_identity_provider, :user_local - attr_accessor :token_authenticated, :external_identity, :external_identity_provider, :user_local + attr_accessible :login, :email, :name, :password, :password_confirmation + attr_accessor :token_authenticated #### # As now dates are saved in long they should be no more automatically managed by Rails @@ -85,18 +85,6 @@ class User < ActiveRecord::Base write_attribute :email, (value && value.downcase) end - def external_identity=(value) - write_attribute :external_identity, value - end - - def external_identity_provider=(value) - write_attribute :external_identity_provider, value - end - - def user_local=(value) - write_attribute :user_local, value - end - # SCM accounts should also contain login and email def full_scm_accounts new_scm_accounts = self.scm_accounts.split(/\r?\n/).reject { |c| c.empty? } if self.scm_accounts diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1119_add_users_local_column.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1119_add_users_local_column.rb index 339033edeed..1222df5a798 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1119_add_users_local_column.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1119_add_users_local_column.rb @@ -26,6 +26,8 @@ class AddUsersLocalColumn < ActiveRecord::Migration def self.up add_column 'users', 'user_local', :boolean + # As user table was already loaded, we need to reset rails cache in order for rails to 'see' this new column + User.reset_column_information end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/lib/need_authentication.rb b/server/sonar-web/src/main/webapp/WEB-INF/lib/need_authentication.rb index e6c0bd18d87..ba9341233fe 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/lib/need_authentication.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/lib/need_authentication.rb @@ -132,9 +132,9 @@ class PluginRealm return nil if !Api::Utils.java_facade.getSettings().getBoolean('sonar.authenticator.createUsers') # Automatically create a user in the sonar db if authentication has been successfully done user = User.new(:login => username, :name => username, :email => '', :created_at => now, :updated_at => now) - user.external_identity = username - user.external_identity_provider = 'sonarqube' - user.user_local = false + user.external_identity= username + user.external_identity_provider= 'sonarqube' + user.user_local= false if details user.name = details.getName() @@ -154,6 +154,11 @@ class PluginRealm user.email = details.getEmail() end + # Update external identity and local info for existing users + user.external_identity= username + user.external_identity_provider= 'sonarqube' + user.user_local= false + # Force the update of updated_at in order to execute an SQL update to block other session user.updated_at = now end -- 2.39.5