diff --git a/CHANGELOG.md b/CHANGELOG.md index 84c690d..c8c4561 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.9.4 +* Support Redmine 4 +* Upgrade deprecated calls + ## 0.9.3 * fix problem with symbols vs. strings usage diff --git a/db/migrate/001_create_oic_sessions.rb b/db/migrate/001_create_oic_sessions.rb index ece6714..286402d 100644 --- a/db/migrate/001_create_oic_sessions.rb +++ b/db/migrate/001_create_oic_sessions.rb @@ -1,4 +1,4 @@ -class CreateOicSessions < ActiveRecord::Migration +class CreateOicSessions < ActiveRecord::Migration[4.2] def self.up create_table :oic_sessions do |t| t.references :user, foreign_key: true diff --git a/init.rb b/init.rb index 4b7ed92..865b0e9 100644 --- a/init.rb +++ b/init.rb @@ -7,7 +7,7 @@ name 'Redmine Openid Connect plugin' author 'Alfonso Juan Dillera / Markus M. May' description 'OpenID Connect implementation for Redmine' - version '0.9.3' + version '0.9.4' url 'https://github.com/devopskube/redmine_openid_connect' author_url 'http://github.com/adillera' @@ -15,6 +15,6 @@ end Rails.configuration.to_prepare do - ApplicationController.send(:include, RedmineOpenidConnect::ApplicationControllerPatch) - AccountController.send(:include, RedmineOpenidConnect::AccountControllerPatch) + ApplicationController.prepend(RedmineOpenidConnect::ApplicationControllerPatch) + AccountController.prepend(RedmineOpenidConnect::AccountControllerPatch) end diff --git a/lib/redmine_openid_connect/account_controller_patch.rb b/lib/redmine_openid_connect/account_controller_patch.rb index c37712f..ea98bd4 100644 --- a/lib/redmine_openid_connect/account_controller_patch.rb +++ b/lib/redmine_openid_connect/account_controller_patch.rb @@ -1,29 +1,17 @@ module RedmineOpenidConnect module AccountControllerPatch - def self.included(base) - base.send(:include, InstanceMethods) - - base.class_eval do - # Add before filters and stuff here - alias_method_chain :login, :openid_connect - alias_method_chain :logout, :openid_connect - alias_method_chain :invalid_credentials, :openid_connect - end - end - end # AccountControllerPatch - module InstanceMethods - def login_with_openid_connect + def login if OicSession.disabled? || params[:local_login].present? || request.post? - return login_without_openid_connect + return super end redirect_to oic_login_url end - def logout_with_openid_connect + def logout if OicSession.disabled? || params[:local_login].present? - return logout_without_openid_connect + return super end oic_session = OicSession.find(session[:oic_session_id]) @@ -150,8 +138,8 @@ def oic_local_login end end - def invalid_credentials_with_openid_connect - return invalid_credentials_without_openid_connect unless OicSession.enabled? + def invalid_credentials + return super unless OicSession.enabled? logger.warn "Échec de connexion pour '#{params[:username]}' depuis #{request.remote_ip} à #{Time.now.utc}" flash.now[:error] = (l(:notice_account_invalid_creditentials) + ". " + "Essayez avec un autre identifiant").html_safe @@ -184,5 +172,5 @@ def authorize_params end end end - end # InstanceMethods + end # AccountControllerPatch end diff --git a/lib/redmine_openid_connect/application_controller_patch.rb b/lib/redmine_openid_connect/application_controller_patch.rb index f8b35a5..418888f 100644 --- a/lib/redmine_openid_connect/application_controller_patch.rb +++ b/lib/redmine_openid_connect/application_controller_patch.rb @@ -1,18 +1,7 @@ module RedmineOpenidConnect module ApplicationControllerPatch - def self.included(base) - base.send(:include, InstanceMethods) - - base.class_eval do - alias_method_chain :require_login, :openid_connect - alias_method_chain :logged_user=, :openid_connect - end - end - end # ApplicationControllerPatch - - module InstanceMethods - def require_login_with_openid_connect - return require_login_without_openid_connect unless OicSession.enabled? + def require_login + return super unless OicSession.enabled? if !User.current.logged? redirect_to oic_login_url @@ -21,8 +10,8 @@ def require_login_with_openid_connect end # set the current user _without_ resetting the session first - def logged_user_with_openid_connect=(user) - return send(:logged_user_without_openid_connect=, user) unless OicSession.enabled? + def logged_user=(user) + return super(user) unless OicSession.enabled? if user && user.is_a?(User) User.current = user @@ -31,5 +20,5 @@ def logged_user_with_openid_connect=(user) User.current = User.anonymous end end - end # InstanceMethods + end # ApplicationControllerPatch end