Skip to content

Commit

Permalink
Merge pull request #107 from southbridgeio/redmine_5.1_compatibility
Browse files Browse the repository at this point in the history
add compatibility with Redmine 5.1
  • Loading branch information
nevrfl authored Oct 8, 2024
2 parents 023d892 + acb6a73 commit 18b006f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ language: ruby
rvm:
- 2.4.9
- 2.6.5
- 2.7.2

addons:
postgresql: "9.4"

env:
- REDMINE_VER=3.4-stable
- REDMINE_VER=4.1-stable
- REDMINE_VER=5.1-stable

install: "echo skip bundle install"

Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 1.7.7

* Add compatibility with Redmine 5.1
* Add 2FA OTP instructions

# 1.7.6

* Bump version after redmine_bots

# 1.7.5

* Fix problem with telegram_id exceeding int.
Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
source 'https://rubygems.org'

gem 'active_model_otp', git: 'https://github.com/heapsource/active_model_otp.git', ref: '6ed9927'
gem 'rotp', '~> 4.0'
gem 'rqrcode', '~> 1.0'
gem 'active_model_otp'
gem 'rotp', '>= 5.0.0'
gem 'rqrcode'

group :test do
gem 'shoulda', '~> 3.6'
Expand Down
14 changes: 9 additions & 5 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

FileUtils.mkdir_p(Rails.root.join('log/redmine_2fa')) unless Dir.exist?(Rails.root.join('log/redmine_2fa'))

require 'redmine_two_fa'
require './plugins/redmine_2fa/lib/redmine_two_fa'
require 'telegram/bot'

# Rails 5.1/Rails 4
reloader = defined?(ActiveSupport::Reloader) ? ActiveSupport::Reloader : ActionDispatch::Reloader

reloader.to_prepare do
register_after_redmine_initialize_proc =
if Redmine::VERSION::MAJOR >= 5
Rails.application.config.public_method(:after_initialize)
else
reloader = defined?(ActiveSupport::Reloader) ? ActiveSupport::Reloader : ActionDispatch::Reloader
reloader.public_method(:to_prepare)
end
register_after_redmine_initialize_proc.call do
paths = '/lib/redmine_two_fa/{patches/*_patch,hooks/*_hook,*}.rb'
Dir.glob(File.dirname(__FILE__) + paths).each do |file|
require_dependency file
Expand Down
12 changes: 0 additions & 12 deletions lib/redmine_two_fa/patches/application_controller_patch.rb

This file was deleted.

15 changes: 15 additions & 0 deletions lib/redmine_two_fa/patches/two_fa_application_controller_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module RedmineTwoFa::Patches
module TwoFaApplicationControllerPatch
def find_current_user
user = super
return user unless api_request? || api_key_from_request.present?
return user unless Setting.rest_api_enabled? && Setting.plugin_redmine_2fa['restrict_api_access'] && accept_api_auth?
user&.api_allowed? ? user : nil
end
end
end

Rails.configuration.to_prepare do
ApplicationController.prepend(RedmineTwoFa::Patches::TwoFaApplicationControllerPatch)
end

0 comments on commit 18b006f

Please sign in to comment.