brandonaaron / redmine_rubycas

A Plugin for Redmine 2 that utilizes the RubyCAS Client for CAS authentication.
MIT License
7 stars 10 forks source link

error: find_or_initialize_by_login in Redmine 3.2.2 #17

Open dani-sanchez-dorado opened 7 years ago

dani-sanchez-dorado commented 7 years ago

Hello, I have been using Redmine Rubycas for years in my Redmine 2.3.3 installation without any problem. Now, I'm migrating to Redmine 3.3.2 and I have found another error (I reported another one: https://github.com/brandonaaron/redmine_rubycas/issues/16)

Ticket "ST-10260-ebR9LVc4nTlj0ofY9cKr1jykEdIAjOdVzb6-20" for service "http://my-server.xxx.com/login" belonging to user "XXXX-valid-user-XXXXX" is VALID. Extra user attributes provided along with ticket "ST-10260-ebR9LVc4nTlj0ofY9cKr1jykEdIAjOdVzb6-20": {}. Completed 500 Internal Server Error in 33ms (ActiveRecord: 2.0ms)

NoMethodError (undefined method find_or_initialize_by_login' for #<Class:0x0000000556b1c0>): plugins/redmine_rubycas/lib/account_controller_patch.rb:14:inlogin_with_cas' lib/redmine/sudo_mode.rb:63:in `sudo_mode'

My Redmine configuration is this:

Environment: Redmine version 3.3.2.stable Ruby version 2.1.2-p95 (2014-05-08) [x86_64-linux-gnu] Rails version 4.2.7.1 Environment production Database adapter Mysql2 SCM: Subversion 1.8.10 Cvs 1.12.12 Git 2.6.6 Filesystem
Redmine plugins: clipboard_image_paste 1.8 redmine_checklists 3.1.5 redmine_ckeditor 1.1.4 redmine_edit_custom_fields 0.0.4 redmine_rubycas 0.0.6

The problem is in the call to .find_or_initialize_by_login function

Here is the patch to fix it. In file "plugins/redmine_rubycas/lib/account_controller_patch.rb"

Line 14:

user = User.find_or_initialize_by_login(session[:"#{RedmineRubyCas.setting("username_session_key")}"])

for:

user = User.find_or_initialize_by(login: session[:"#{RedmineRubyCas.setting("username_session_key")}"])

Now it works perfect. I think it would be interesting to add to source code.

Thanks!