diff --git a/init.rb b/init.rb index fe06cb1..a343c91 100644 --- a/init.rb +++ b/init.rb @@ -1,12 +1,16 @@ -require_dependency 'redmine_issues_tree/hook_listener' plugin_name = :redmine_issues_tree +plugin_root = File.dirname(__FILE__) + +if Rails.version < '6.0' || !Rails.autoloaders.zeitwerk_enabled? + require_dependency plugin_root + '/lib/redmine_issues_tree/hook_listener' +end Redmine::Plugin.register plugin_name do name 'Redmine Issues Tree plugin' author 'Ivan Zabrovskiy' description 'Provides a tree view of the issues list' - version RedmineIssuesTree::VERSION + version RedmineIssuesTree::Version::VERSION url 'https://github.com/Loriowar/redmine_issues_tree' author_url 'https://loriowar.com/about' @@ -17,7 +21,7 @@ } end -Rails.configuration.to_prepare do +def patch_init prepend_patches_map = { ::RedmineIssuesTree::IssuesControllerPatch => ::IssuesController @@ -35,6 +39,16 @@ end end +if Rails.version > '6.0' && Rails.autoloaders.zeitwerk_enabled? + Rails.application.config.after_initialize do + patch_init + end +else + Rails.configuration.to_prepare do + patch_init + end +end + # Assign permissions on a tree_view actions. Permissions is same as for :view_issues. # Doesn't work without :find_optional_project filter in controller. Redmine::AccessControl. diff --git a/lib/redmine_issues_tree/issues_controller_patch.rb b/lib/redmine_issues_tree/issues_controller_patch.rb index d7dc967..c18d794 100644 --- a/lib/redmine_issues_tree/issues_controller_patch.rb +++ b/lib/redmine_issues_tree/issues_controller_patch.rb @@ -8,7 +8,7 @@ def index if settings[:default_redirect_to_tree_view] == 'true' # @note: add additional parameter into all links on issues#index looks not so good as parsing a referer # @reason: we must prevent redirect to the tree_view if we do some actions on a plain view - if skip_issues_tree_redirect == 'true' || URI(request.referer).path == project_issues_path + if skip_issues_tree_redirect == 'true' || (request && request.referer && URI(request.referer).path == project_issues_path) super else redirect_to tree_index_project_issues_trees_path(request.query_parameters) @@ -20,7 +20,7 @@ def index if settings[:default_redirect_to_tree_view_without_project] == 'true' # @note: add additional parameter into all links on issues#index looks not so good as parsing a referer # @reason: we must prevent redirect to the tree_view if we do some actions on a plain view - if skip_issues_tree_redirect == 'true' || URI(request.referer).path == issues_path + if skip_issues_tree_redirect == 'true' || (request && request.referer && URI(request.referer).path == issues_path) super else redirect_to tree_index_issues_trees_path(request.query_parameters) diff --git a/lib/redmine_issues_tree/version.rb b/lib/redmine_issues_tree/version.rb index 486630f..d5954f9 100644 --- a/lib/redmine_issues_tree/version.rb +++ b/lib/redmine_issues_tree/version.rb @@ -1,3 +1,3 @@ -module RedmineIssuesTree +module RedmineIssuesTree::Version VERSION = '0.0.14' end