Skip to content

Commit

Permalink
Refactor patches to improve compatibility with Redmine 5
Browse files Browse the repository at this point in the history
  • Loading branch information
nanego committed Nov 24, 2023
1 parent f7951c5 commit 2b8b643
Show file tree
Hide file tree
Showing 28 changed files with 254 additions and 274 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/5_0_6.yml → .github/workflows/5_1_0.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Tests 5.0.6
name: Tests 5.1.0

env:
PLUGIN_NAME: redmine_templates
REDMINE_VERSION: 5.0.6
REDMINE_VERSION: 5.1.0
RAILS_ENV: test

on:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ You will also need a recent version of Ruby:
|Plugin branch| Redmine Version | Test Status |
|-------------|-----------------|-------------------|
|master | 4.2.11 | [![4.2.11][1]][5] |
|master | 5.0.6 | [![5.0.6][2]][5] |
|master | 5.1.0 | [![5.1.0][2]][5] |
|master | master | [![master][4]][5] |

[1]: https://github.com/nanego/redmine_templates/actions/workflows/4_2_11.yml/badge.svg
[2]: https://github.com/nanego/redmine_templates/actions/workflows/5_0_6.yml/badge.svg
[2]: https://github.com/nanego/redmine_templates/actions/workflows/5_1_0.yml/badge.svg
[4]: https://github.com/nanego/redmine_templates/actions/workflows/master.yml/badge.svg
[5]: https://github.com/nanego/redmine_templates/actions
2 changes: 1 addition & 1 deletion app/models/issue_template.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_dependency 'issue_template_description'
require_relative 'issue_template_description'

class IssueTemplate < ActiveRecord::Base
include Redmine::SafeAttributes
Expand Down
39 changes: 0 additions & 39 deletions app/overrides/issues/issues_new.rb

This file was deleted.

36 changes: 36 additions & 0 deletions app/overrides/issues/new.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
include IssueTemplatesHelper

Deface::Override.new :virtual_path => 'issues/new',
:name => 'add-save-template-button-to-issues-new',
:insert_after => 'erb[loud]:contains("submit_tag l(:button_create_and_continue)")',
:original => '4e67d6689fbd2c21613ffb301a5e8c92ff214b5c',
:text => '<% if @issue.project.present? && (User.current.admin? || User.current.allowed_to?(:create_issue_templates, @issue.project)) %>
<%= link_to "Enregistrer en tant que template",
"#",
id: "init_issue_template",
"data-href": init_issue_template_path(project_id: @issue.project.id),
class: "icon icon-copy pull-right" %>
<% end %>
<%= f.hidden_field :issue_template_id %>
<script type="text/javascript">
<%= render(:partial => "issue_templates/load_select_js_functions", :handlers => [:erb], :formats => [:js]) %>
</script>'

# Custom form
Deface::Override.new :virtual_path => "issues/new",
:name => "custom-form-from-templates",
:original => '1468c4be09f0521e1854cace7f8d7b444eb32074',
:replace_contents => "#all_attributes" do
%(
<% if @issue_template.present? && @issue_template.custom_form %>
<%= render :partial => "issues/" + @issue_template.custom_form_path, :locals => {:f => f} %>
<% else %>
<% if Redmine::Plugin.installed?(:redmine_customize_core_fields) %>
<%= render :partial => "issues/customized_form", :locals => {:f => f} %>
<% else %>
<%= render :partial => "issues/form", :locals => {:f => f} %>
<% end %>
<% end %>
)
end

Deface::Override.new :virtual_path => 'issues/new',
:name => 'change_form_title_if_tracker_read_only_mode',
:replace => 'erb[loud]:contains("title l(:label_issue_new)")',
Expand Down
23 changes: 1 addition & 22 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
require 'redmine'
require_dependency 'redmine_templates/hooks'

ActiveSupport::Reloader.to_prepare do
require_dependency 'redmine_templates/redmine_core_patch'
require_dependency 'redmine_templates/menu_manager_patch'
require_dependency 'redmine_templates/issues_controller_patch'
require_dependency 'redmine_templates/projects_controller_patch'
require_dependency 'redmine_templates/issue_patch'
require_dependency 'redmine_templates/project_query_patch'
require_dependency 'redmine_templates/queries_helper_patch'
require_dependency 'redmine_templates/issue_query_patch'
require_dependency 'redmine_templates/tracker_patch'
require_dependency 'redmine_templates/issue_status_patch'
require_dependency 'redmine_templates/issue_category_patch'
require_dependency 'redmine_templates/user_patch'
require_dependency 'redmine_templates/issue_priority_patch'
require_dependency 'redmine_templates/typology_patch' if Redmine::Plugin.installed?(:redmine_typologies)
require_dependency 'redmine_templates/helpers/projects_helper_patch'
require_dependency 'redmine_templates/helpers/issues_helper_patch'
require_dependency 'redmine_templates/helpers/application_helper_patch'
require_dependency 'redmine_templates/project_patch'
end
require_relative 'lib/redmine_templates/hooks'

Redmine::Plugin.register :redmine_templates do
name 'Redmine Issue Templates plugin'
Expand Down
6 changes: 2 additions & 4 deletions lib/redmine_templates/helpers/application_helper_patch.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
require_dependency 'application_helper'

module PluginRedmineTemplates
module RedmineTemplates::Helpers
module ApplicationHelperPatch

# adapted from standard method "is_descendant_of?(other)"
Expand Down Expand Up @@ -50,5 +48,5 @@ def render_project_nested_lists_by_attributes_for_template(projects, &block)
end
end

ApplicationHelper.prepend PluginRedmineTemplates::ApplicationHelperPatch
ApplicationHelper.prepend RedmineTemplates::Helpers::ApplicationHelperPatch
ActionView::Base.prepend ApplicationHelper
8 changes: 3 additions & 5 deletions lib/redmine_templates/helpers/issues_helper_patch.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require_dependency 'issues_helper'

module PluginRedmineTemplates
module IssuesHelper
module RedmineTemplates::Helpers
module IssuesHelperPatch
def projects_for_select_for_issue_via_template(issue, template)
projects = projects_for_select(issue)
projects &= template.template_projects if template.present?
Expand All @@ -10,5 +8,5 @@ def projects_for_select_for_issue_via_template(issue, template)
end
end

IssuesHelper.prepend PluginRedmineTemplates::IssuesHelper
IssuesHelper.prepend RedmineTemplates::Helpers::IssuesHelperPatch
ActionView::Base.send(:include, IssuesHelper)
8 changes: 3 additions & 5 deletions lib/redmine_templates/helpers/projects_helper_patch.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require_dependency 'projects_helper'

module PluginRedmineTemplates
module ProjectsHelper
module RedmineTemplates::Helpers
module ProjectsHelperPatch
def project_settings_tabs
super.tap do |tabs|
if User.current.allowed_to?(:manage_project_issue_templates, @project) || User.current.allowed_to?(:manage_issue_templates_visibility_per_project, @project)
Expand All @@ -17,5 +15,5 @@ def project_settings_tabs
end
end

ProjectsHelper.prepend PluginRedmineTemplates::ProjectsHelper
ProjectsHelper.prepend RedmineTemplates::Helpers::ProjectsHelperPatch
ActionView::Base.send(:include, ProjectsHelper)
22 changes: 22 additions & 0 deletions lib/redmine_templates/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,26 @@ def view_layouts_base_html_head(context)
# adds a link in the sidebar of the main issue page
render_on :view_issues_sidebar_queries_bottom, :partial => 'hooks/view_sidebar_manage_templates'
end

class ModelHook < Redmine::Hook::Listener
def after_plugins_loaded(_context = {})
require_relative 'menu_manager_patch'
require_relative 'issues_controller_patch'
require_relative 'projects_controller_patch'
require_relative 'issue_patch'
require_relative 'project_query_patch'
require_relative 'queries_helper_patch'
require_relative 'issue_query_patch'
require_relative 'tracker_patch'
require_relative 'issue_status_patch'
require_relative 'issue_category_patch'
require_relative 'user_patch'
require_relative 'issue_priority_patch'
require_relative 'typology_patch' if Redmine::Plugin.installed?(:redmine_typologies)
require_relative 'helpers/projects_helper_patch'
require_relative 'helpers/issues_helper_patch'
require_relative 'helpers/application_helper_patch'
require_relative 'project_patch'
end
end
end
9 changes: 5 additions & 4 deletions lib/redmine_templates/issue_category_patch.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require_dependency 'issue_category'
module RedmineTemplates::IssueCategoryPatch

class IssueCategory

has_many :issue_templates, :class_name => 'IssueTemplate', :foreign_key => 'category_id', :dependent => :nullify
def self.prepended(base)
base.has_many :issue_templates, :class_name => 'IssueTemplate', :foreign_key => 'category_id', :dependent => :nullify
end

end
IssueCategory.prepend RedmineTemplates::IssueCategoryPatch
11 changes: 8 additions & 3 deletions lib/redmine_templates/issue_patch.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
require_dependency 'issue'

class Issue < ActiveRecord::Base
module RedmineTemplates::IssuePatch

# Substitute variables with values
def substituted(text, sections_params = {})
Expand Down Expand Up @@ -44,3 +42,10 @@ def section_value_by_id(section_id, sections_params)
end

end

Issue.prepend RedmineTemplates::IssuePatch

class Issue < ActiveRecord::Base
belongs_to :issue_template, optional: true
safe_attributes 'issue_template_id'
end
6 changes: 2 additions & 4 deletions lib/redmine_templates/issue_priority_patch.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
require_dependency 'issue_priority'

class IssuePriority < Enumeration
has_many :issue_templates, :foreign_key => 'priority_id'
end

module PluginRedmineTemplates
module RedmineTemplates
module IssuePriorityPatch
def objects_count
count = super
Expand All @@ -19,4 +17,4 @@ def transfer_relations(to)
end
end

IssuePriority.prepend PluginRedmineTemplates::IssuePriorityPatch
IssuePriority.prepend RedmineTemplates::IssuePriorityPatch
6 changes: 2 additions & 4 deletions lib/redmine_templates/issue_query_patch.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
require_dependency 'issue_query'

class IssueQuery < Query
self.available_columns << QueryColumn.new(:issue_template, :sortable => "#{IssueTemplate.table_name}.template_title", :groupable => true)
end

module PluginRedmineTemplates
module RedmineTemplates
module IssueQueryPatch

def initialize_available_filters
Expand All @@ -26,4 +24,4 @@ def joins_for_order_statement(order_options)
end
end

IssueQuery.prepend PluginRedmineTemplates::IssueQueryPatch
IssueQuery.prepend RedmineTemplates::IssueQueryPatch
12 changes: 6 additions & 6 deletions lib/redmine_templates/issue_status_patch.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require_dependency 'issue_status'
module RedmineTemplates::IssueStatusPatch

class IssueStatus

has_many :issue_templates

before_destroy :set_default_status_id_in_issue_templates
def self.prepended(base)
base.has_many :issue_templates, :foreign_key => 'status_id'
base.before_destroy :set_default_status_id_in_issue_templates
end

def set_default_status_id_in_issue_templates
IssueTemplate.where('status_id = ?', id).update_all('status_id = 0')
end

end
IssueStatus.prepend RedmineTemplates::IssueStatusPatch
Loading

0 comments on commit 2b8b643

Please sign in to comment.