Skip to content

Commit

Permalink
Merge pull request #22 from joshocalico/master
Browse files Browse the repository at this point in the history
Redmine 4 Support: Replace alias_method_chain
  • Loading branch information
triplem authored May 23, 2019
2 parents d80ff74 + 9d2bd54 commit 8958bd4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.9.4
* Support Redmine 4
* Upgrade deprecated calls

## 0.9.3
* fix problem with symbols vs. strings usage

Expand Down
2 changes: 1 addition & 1 deletion db/migrate/001_create_oic_sessions.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
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'

settings :default => { 'empty' => true }, partial: 'settings/redmine_openid_connect_settings'
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
26 changes: 7 additions & 19 deletions lib/redmine_openid_connect/account_controller_patch.rb
Original file line number Diff line number Diff line change
@@ -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])
Expand Down Expand Up @@ -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) + ". " + "<a href='#{signout_path}'>Essayez avec un autre identifiant</a>").html_safe
Expand Down Expand Up @@ -184,5 +172,5 @@ def authorize_params
end
end
end
end # InstanceMethods
end # AccountControllerPatch
end
21 changes: 5 additions & 16 deletions lib/redmine_openid_connect/application_controller_patch.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -31,5 +20,5 @@ def logged_user_with_openid_connect=(user)
User.current = User.anonymous
end
end
end # InstanceMethods
end # ApplicationControllerPatch
end

0 comments on commit 8958bd4

Please sign in to comment.