Thread.current[:current_user] not working in plugin
Added by Zach Hamman over 11 years ago
I have a customized version redmine_ssl_auth. I attempt to set the user for the session with self.logged_user = user. My debug steps through the method and runs User.current=(user) fine. But, whenever I attempt to use User.current, it returns AnonymousUser. The user object will either be a User or a custom subclass called GuestUser.
I had no problems on 1.x, but am running into this problem getting my plugin to 2.x standards.
user = User.find_by_cac_id_num(session[:cac_id]) if user.nil? logger.info "DBG: User not found. Attempting auto-insert for " + session[:cac_id] fng = GuestUser.find_or_initialize_by_login(session[:cac_id]) fng.login = session[:cac_id] self.logged_user = fng logger.info "DBG: Registration for " + fng.login + ' should be complete.' return true else logger.info "DBG: User found. Auto-login for " + session[:cac_id] user.update_attribute(:last_login_on, Time.now) if user && !user.new_record? if user.login != session[:cac_id] && !user.new_record? user.update_attribute(:login, session[:cac_id]) user.login = session[:cac_id] end self.logged_user = user return true end
Replies (2)
RE: Thread.current[:current_user] not working in plugin - Added by Zach Hamman over 11 years ago
Some added information. I am running Redmine on Ruby 1.8.7, so I don't know if that changes things. I noticed when watching Thread.current and Thread.list that Thread.current[:current_user] saves to a different thread than what my watch says is Thread.current.
RE: Thread.current[:current_user] not working in plugin - Added by Zach Hamman over 11 years ago
Images from debugger