agileware-jp / redmine_issue_templates

Redmine Issue Template. Pull requests, reporting issues, stars and sponsoring are always welcome!
https://www.redmine.org/plugins/redmine_issue_templates
GNU General Public License v2.0
71 stars 33 forks source link

Compatibility Issue with Redmine Issue Templates Plugin Due to ApplicationRecord Inheritance Change #95

Closed ishikawa999 closed 6 months ago

ishikawa999 commented 7 months ago

Summary

Due to the changes made in https://www.redmine.org/issues/38975, when running the Redmine Issue Templates on Redmine trunk, exceptions are thrown during the execution of rake redmine:plugins:migrate or when accessing the issue templates settings page.

F, [2024-03-26T07:44:28.445517 #80101] FATAL -- :   
NoMethodError (undefined method `acts_as_positioned' for IssueTemplate:Class):

plugins/redmine_issue_templates/app/models/issue_template.rb:10:in `<class:IssueTemplate>'
plugins/redmine_issue_templates/app/models/issue_template.rb:3:in `<top (required)>'
plugins/redmine_issue_templates/app/controllers/issue_templates_controller.rb:14:in `index'
lib/redmine/sudo_mode.rb:78:in `sudo_mode'
I, [2024-03-26T07:44:28.513667 #80101]  INFO -- :   Rendered /usr/local/lib/ruby/gems/3.0.0/gems/actionpack-7.1.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (Duration: 4.3ms | Allocations: 8459)
I, [2024-03-26T07:44:28.514064 #80101]  INFO -- :   Rendered layout /usr/local/lib/ruby/gems/3.0.0/gems/actionpack-7.1.2/lib/action_dispatch/middleware/templates/rescues/layout.erb (Duration: 4.7ms | Allocations: 9539)

Description

https://www.redmine.org/issues/38975

However, the include destination of lib/plugins/acts_as_xxx will also change from ActiveRecord::Base to ApplicationRecord when this patch is applied, This will affect the Active Record model of Redmine plugins that use the acts_as_xxx method, and the base class will need to be changed to ApplicationRecord.

This changes affects Redmine plugins using the acts_as_xxx method, requiring a change in the base class to ApplicationRecord. The ApplicationRecord class does not exist before Redmine 5.1, so the class to be inherited should be changed depending on the situation.

Environment

Expected Results

Actual Results

Workaround

This is only a WORKAROUND. There are other model classes that should also be modified.

diff --git a/app/models/global_issue_template.rb b/app/models/global_issue_template.rb
index 1c7ff4f..bd9af86 100644
--- a/app/models/global_issue_template.rb
+++ b/app/models/global_issue_template.rb
@@ -1,6 +1,6 @@
 # frozen_string_literal: true

-class GlobalIssueTemplate < ActiveRecord::Base
+class GlobalIssueTemplate < (defined?(ApplicationRecord) == 'constant' ? ApplicationRecord : ActiveRecord::Base)
   include Redmine::SafeAttributes
   include IssueTemplateCommon
   include AttributeNameMapper