diff --git a/Gemfile b/Gemfile index ea74dde..c63fead 100644 --- a/Gemfile +++ b/Gemfile @@ -21,7 +21,10 @@ source 'https://rubygems.org' -# In order to the plugin in Redmine < 4 (Rails < 5), comment out the following lines -# I don't know how to check Redmine or better Rails version here :-( gem 'acts_as_list' gem 'activemodel-serializers-xml' + +# Redmine extensions +unless %w(easyproject easy_gantt).any? { |plugin| Dir.exist?(File.expand_path("../../#{plugin}", __FILE__)) } + gem 'redmine_extensions', '~> 0.2.5' +end diff --git a/after_init.rb b/after_init.rb new file mode 100644 index 0000000..3d9c552 --- /dev/null +++ b/after_init.rb @@ -0,0 +1,40 @@ +# encoding: utf-8 +# +# Redmine plugin for Custom Workflows +# +# Copyright Anton Argirov +# Copyright Karel Pičman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require_dependency File.dirname(__FILE__) + '/lib/redmine_custom_workflows.rb' + +ActiveSupport::Dependencies.autoload_paths << File.join(File.dirname(__FILE__), 'app') + +def custom_workflows_init + # Administration menu extension + Redmine::MenuManager.map :admin_menu do |menu| + menu.push :custom_workflows, { controller: 'custom_workflows', action: 'index'}, + caption: :label_custom_workflow_plural, html: { class: 'icon icon-custom-workflows'} + end +end + +if Redmine::Plugin.installed?(:easy_extensions) + ActiveSupport.on_load(:easyproject, yield: true) do + custom_workflows_init + end +else + custom_workflows_init +end diff --git a/assets/stylesheets/custom_workflows.css b/assets/stylesheets/custom_workflows.css new file mode 100644 index 0000000..2b41b2f --- /dev/null +++ b/assets/stylesheets/custom_workflows.css @@ -0,0 +1,64 @@ +/* +* Redmine plugin for Document Management System "Features" +* +* Copyright Anton Argirov +* Copyright Karel Pičman +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#tab-content-custom_workflows .disabled { + color: silver; +} + +table.list.custom-workflows td { + vertical-align: middle; +} + +table.list.custom-workflows td.description { + text-align: left; + width: 40%; +} + +table.list.custom-workflows td.buttons { + white-space: normal; + width: 10%; + text-align: left; +} + +table.list.custom-workflows tr.disabled { + color: silver; +} + +#custom_workflow_description, #custom_workflow_name { + width: 98%; +} + +.custom_workflow_script { + width: 98%; + font-size: 11px; +} + +#custom_workflow_enabled_projects ul { + max-height: 200px; + overflow-y: auto; +} + +/* Icons */ +.icon-export { background-image: url(../images/export.png); } +.icon-import { background-image: url(../images/import.png); } +.icon-active { background-image: url(../images/active.png); } +.icon-inactive { background-image: url(../images/inactive.png); } +.icon-custom-workflows { background-image: url(../../../images/ticket_go.png); } \ No newline at end of file diff --git a/db/migrate/20150526132244_create_example_workflow.rb b/db/migrate/20150526132244_create_example_workflow.rb index d892653..0d7051b 100644 --- a/db/migrate/20150526132244_create_example_workflow.rb +++ b/db/migrate/20150526132244_create_example_workflow.rb @@ -23,38 +23,43 @@ class CreateExampleWorkflow < ActiveRecord::Migration[4.2] def up CustomWorkflow.reset_column_information - old = CustomWorkflow.where(:name => 'Duration/Done Ratio/Status correlation').first + name = 'Duration/Done Ratio/Status correlation' + old = CustomWorkflow.where(name: name).first old.destroy if old + cw = CustomWorkflow.new + cw.name = name + cw.author = 'anton.argirov@gmail.com' + cw.description = %{ + Set up a correlation between the start date, due date, done ratio and status of issues. - CustomWorkflow.create!(:name => 'Duration/Done Ratio/Status correlation', :author => 'anton.argirov@gmail.com', :description => < < :member end -require_dependency File.dirname(__FILE__) + '/lib/redmine_custom_workflows.rb' - -# Administration menu extension -Redmine::MenuManager.map :admin_menu do |menu| - menu.push :custom_workflows, { controller: 'custom_workflows', action: 'index'}, - caption: :label_custom_workflow_plural, html: { class: 'icon icon-workflows'} +unless Redmine::Plugin.installed?(:easy_extensions) + require_relative 'after_init' end diff --git a/lib/redmine_custom_workflows/hooks/hooks.rb b/lib/redmine_custom_workflows/hooks/hooks.rb index 454b59f..d3f7cba 100644 --- a/lib/redmine_custom_workflows/hooks/hooks.rb +++ b/lib/redmine_custom_workflows/hooks/hooks.rb @@ -22,9 +22,20 @@ module RedmineCustomWorkflows class Hooks < Redmine::Hook::ViewListener + def view_layouts_base_html_head(context) - stylesheet_link_tag :style, :plugin => 'redmine_custom_workflows' + return if defined?(EasyExtensions) + "\n".html_safe + stylesheet_link_tag('custom_workflows.css', plugin: :redmine_custom_workflows) end + + def easy_extensions_javascripts_hook(context={}) + context[:template].require_asset('tab_override.js') + end + + def easy_extensions_stylesheets_hook(context={}) + context[:template].require_asset('custom_workflows.css') + end + end end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/attachment_patch.rb b/lib/redmine_custom_workflows/patches/attachment_patch.rb index 85f4fa2..e73fbd1 100644 --- a/lib/redmine_custom_workflows/patches/attachment_patch.rb +++ b/lib/redmine_custom_workflows/patches/attachment_patch.rb @@ -24,7 +24,6 @@ module RedmineCustomWorkflows module AttachmentPatch def self.included(base) - base.send(:include, InstanceMethods) base.class_eval do before_save :before_save_custom_workflows after_save :after_save_custom_workflows @@ -33,37 +32,33 @@ module RedmineCustomWorkflows end end - module InstanceMethods + def before_save_custom_workflows + @attachment = self + @saved_attributes = attributes.dup + CustomWorkflow.run_shared_code(self) + CustomWorkflow.run_custom_workflows(:attachment, self, :before_save) + throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) + ensure + @saved_attributes = nil + end - def before_save_custom_workflows - @attachment = self - @saved_attributes = attributes.dup - CustomWorkflow.run_shared_code(self) - CustomWorkflow.run_custom_workflows(:attachment, self, :before_save) - throw :abort if errors.any? - errors.empty? && (@saved_attributes == attributes || valid?) - ensure - @saved_attributes = nil - end + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows(:attachment, self, :after_save) + end - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows(:attachment, self, :after_save) - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:attachment, self, :before_destroy) - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:attachment, self, :after_destroy) - end + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:attachment, self, :before_destroy) + end + def after_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:attachment, self, :after_destroy) end end end end -unless Attachment.include?(RedmineCustomWorkflows::Patches::AttachmentPatch) - Attachment.send(:include, RedmineCustomWorkflows::Patches::AttachmentPatch) -end \ No newline at end of file +# Apply patch +RedmineExtensions::PatchManager.register_model_patch 'Attachment', + 'RedmineCustomWorkflows::Patches::AttachmentPatch' \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/group_patch.rb b/lib/redmine_custom_workflows/patches/group_patch.rb index 464e6df..de7d18c 100644 --- a/lib/redmine_custom_workflows/patches/group_patch.rb +++ b/lib/redmine_custom_workflows/patches/group_patch.rb @@ -24,7 +24,6 @@ module RedmineCustomWorkflows module GroupPatch def self.included(base) - base.send(:include, InstanceMethods) base.class_eval do before_save :before_save_custom_workflows after_save :after_save_custom_workflows @@ -47,37 +46,33 @@ module RedmineCustomWorkflows end end - module InstanceMethods + def before_save_custom_workflows + @group = self + @saved_attributes = attributes.dup + CustomWorkflow.run_shared_code(self) + CustomWorkflow.run_custom_workflows(:group, self, :before_save) + throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) + ensure + @saved_attributes = nil + end - def before_save_custom_workflows - @group = self - @saved_attributes = attributes.dup - CustomWorkflow.run_shared_code(self) - CustomWorkflow.run_custom_workflows(:group, self, :before_save) - throw :abort if errors.any? - errors.empty? && (@saved_attributes == attributes || valid?) - ensure - @saved_attributes = nil - end + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows(:group, self, :after_save) + end - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows(:group, self, :after_save) - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:group, self, :before_destroy) - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:group, self, :after_destroy) - end + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:group, self, :before_destroy) + end + def after_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:group, self, :after_destroy) end end end end -unless Group.include?(RedmineCustomWorkflows::Patches::GroupPatch) - Group.send(:include, RedmineCustomWorkflows::Patches::GroupPatch) -end \ No newline at end of file +# Apply patch +RedmineExtensions::PatchManager.register_model_patch 'Group', + 'RedmineCustomWorkflows::Patches::GroupPatch' \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/issue_patch.rb b/lib/redmine_custom_workflows/patches/issue_patch.rb index be0f9ae..1ad2a6b 100644 --- a/lib/redmine_custom_workflows/patches/issue_patch.rb +++ b/lib/redmine_custom_workflows/patches/issue_patch.rb @@ -24,7 +24,6 @@ module RedmineCustomWorkflows module IssuePatch def self.included(base) - base.send(:include, InstanceMethods) base.class_eval do before_save :before_save_custom_workflows after_save :after_save_custom_workflows @@ -49,8 +48,6 @@ module RedmineCustomWorkflows end end - module InstanceMethods - def validate_status return true unless @saved_attributes && @saved_attributes['status_id'] != status_id && !new_statuses_allowed_to(User.current, new_record?).collect(&:id).include?(status_id) @@ -86,12 +83,10 @@ module RedmineCustomWorkflows CustomWorkflow.run_custom_workflows(:issue, self, :after_destroy) end - end - end end end -unless Issue.include?(RedmineCustomWorkflows::Patches::IssuePatch) - Issue.send(:include, RedmineCustomWorkflows::Patches::IssuePatch) -end \ No newline at end of file +# Apply patch +RedmineExtensions::PatchManager.register_model_patch 'Issue', + 'RedmineCustomWorkflows::Patches::IssuePatch' \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/mailer_patch.rb b/lib/redmine_custom_workflows/patches/mailer_patch.rb new file mode 100644 index 0000000..10c9d92 --- /dev/null +++ b/lib/redmine_custom_workflows/patches/mailer_patch.rb @@ -0,0 +1,54 @@ +# encoding: utf-8 +# +# Redmine plugin for Custom Workflows +# +# Copyright Anton Argirov +# Copyright Karel Pičman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module RedmineCustomWorkflows + module Patches + module MailerPatch + + def self.deliver_custom_email(headers={}) + user = headers.delete :user + headers[:to] = user.mail if user + text_body = headers.delete :text_body + html_body = headers.delete :html_body + template_name = headers.delete :template_name + template_params = headers.delete(:template_params) || {} + if text_body || html_body + mail headers do |format| + format.text { render :text => text_body } if text_body + format.html { render :text => html_body } if html_body + end + elsif template_name + template_params.each { |k,v| instance_variable_set("@#{k}", v) } + mail headers do |format| + format.text { render template_name } + format.html { render template_name } unless Setting.plain_text_mail? + end + else + raise 'Not :text_body, :html_body or :template_name specified' + end + end + + end + end +end + +RedmineExtensions::PatchManager.register_model_patch 'Mailer', + 'RedmineCustomWorkflows::Patches::MailerPatch' \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/project_patch.rb b/lib/redmine_custom_workflows/patches/project_patch.rb index 5bca9b2..93206ba 100644 --- a/lib/redmine_custom_workflows/patches/project_patch.rb +++ b/lib/redmine_custom_workflows/patches/project_patch.rb @@ -24,7 +24,6 @@ module RedmineCustomWorkflows module ProjectPatch def self.included(base) - base.send :include, InstanceMethods base.class_eval do has_and_belongs_to_many :custom_workflows safe_attributes :custom_workflow_ids, :if => @@ -48,37 +47,33 @@ module RedmineCustomWorkflows end end - module InstanceMethods + def before_save_custom_workflows + @project = self + @saved_attributes = attributes.dup + CustomWorkflow.run_shared_code(self) + CustomWorkflow.run_custom_workflows(:project, self, :before_save) + throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) + ensure + @saved_attributes = nil + end - def before_save_custom_workflows - @project = self - @saved_attributes = attributes.dup - CustomWorkflow.run_shared_code(self) - CustomWorkflow.run_custom_workflows(:project, self, :before_save) - throw :abort if errors.any? - errors.empty? && (@saved_attributes == attributes || valid?) - ensure - @saved_attributes = nil - end + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows(:project, self, :after_save) + end - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows(:project, self, :after_save) - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:project, self, :before_destroy) - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:project, self, :after_destroy) - end + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:project, self, :before_destroy) + end + def after_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:project, self, :after_destroy) end end end end -unless Project.include?(RedmineCustomWorkflows::Patches::ProjectPatch) - Project.send(:include, RedmineCustomWorkflows::Patches::ProjectPatch) -end \ No newline at end of file +# Apply patch +RedmineExtensions::PatchManager.register_model_patch 'Project', + 'RedmineCustomWorkflows::Patches::ProjectPatch' \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/projects_helper_patch.rb b/lib/redmine_custom_workflows/patches/projects_helper_patch.rb index d3ddc7d..ac353a8 100644 --- a/lib/redmine_custom_workflows/patches/projects_helper_patch.rb +++ b/lib/redmine_custom_workflows/patches/projects_helper_patch.rb @@ -34,4 +34,9 @@ module RedmineCustomWorkflows end end -ProjectsController.send :helper, RedmineCustomWorkflows::Patches::ProjectsHelperPatch +if Redmine::Plugin.installed?(:easy_extensions) + RedmineExtensions::PatchManager.register_helper_patch 'ProjectsHelper', + 'RedmineCustomWorkflows::Patches::ProjectsHelperPatch', prepend: true +else + ProjectsController.send :helper, RedmineCustomWorkflows::Patches::ProjectsHelperPatch +end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/time_entry_patch.rb b/lib/redmine_custom_workflows/patches/time_entry_patch.rb index e060caf..563a1ae 100644 --- a/lib/redmine_custom_workflows/patches/time_entry_patch.rb +++ b/lib/redmine_custom_workflows/patches/time_entry_patch.rb @@ -24,7 +24,6 @@ module RedmineCustomWorkflows module TimeEntryPatch def self.included(base) - base.send(:include, InstanceMethods) base.class_eval do before_save :before_save_custom_workflows after_save :after_save_custom_workflows @@ -33,37 +32,33 @@ module RedmineCustomWorkflows end end - module InstanceMethods + def before_save_custom_workflows + @time_entry = self + @saved_attributes = attributes.dup + CustomWorkflow.run_shared_code(self) + CustomWorkflow.run_custom_workflows(:time_entry, self, :before_save) + throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) + ensure + @saved_attributes = nil + end - def before_save_custom_workflows - @time_entry = self - @saved_attributes = attributes.dup - CustomWorkflow.run_shared_code(self) - CustomWorkflow.run_custom_workflows(:time_entry, self, :before_save) - throw :abort if errors.any? - errors.empty? && (@saved_attributes == attributes || valid?) - ensure - @saved_attributes = nil - end + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows(:time_entry, self, :after_save) + end - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows(:time_entry, self, :after_save) - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:time_entry, self, :before_destroy) - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:time_entry, self, :after_destroy) - end + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:time_entry, self, :before_destroy) + end + def after_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:time_entry, self, :after_destroy) end end end end -unless TimeEntry.include?(RedmineCustomWorkflows::Patches::TimeEntryPatch) - TimeEntry.send(:include, RedmineCustomWorkflows::Patches::TimeEntryPatch) -end \ No newline at end of file +# Apply patch +RedmineExtensions::PatchManager.register_model_patch 'TimeEntry', + 'RedmineCustomWorkflows::Patches::TimeEntryPatch' \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/user_patch.rb b/lib/redmine_custom_workflows/patches/user_patch.rb index 8092029..31934ae 100644 --- a/lib/redmine_custom_workflows/patches/user_patch.rb +++ b/lib/redmine_custom_workflows/patches/user_patch.rb @@ -24,7 +24,6 @@ module RedmineCustomWorkflows module UserPatch def self.included(base) - base.send(:include, InstanceMethods) base.class_eval do before_save :before_save_custom_workflows after_save :after_save_custom_workflows @@ -33,37 +32,33 @@ module RedmineCustomWorkflows end end - module InstanceMethods + def before_save_custom_workflows + @user = self + @saved_attributes = attributes.dup + CustomWorkflow.run_shared_code(self) + CustomWorkflow.run_custom_workflows(:user, self, :before_save) + throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) + ensure + @saved_attributes = nil + end - def before_save_custom_workflows - @user = self - @saved_attributes = attributes.dup - CustomWorkflow.run_shared_code(self) - CustomWorkflow.run_custom_workflows(:user, self, :before_save) - throw :abort if errors.any? - errors.empty? && (@saved_attributes == attributes || valid?) - ensure - @saved_attributes = nil - end + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows(:user, self, :after_save) + end - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows(:user, self, :after_save) - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:user, self, :before_destroy) - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:user, self, :after_destroy) - end + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:user, self, :before_destroy) + end + def after_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:user, self, :after_destroy) end end end end -unless User.include?(RedmineCustomWorkflows::Patches::UserPatch) - User.send(:include, RedmineCustomWorkflows::Patches::UserPatch) -end \ No newline at end of file +# Apply patch +RedmineExtensions::PatchManager.register_model_patch 'User', + 'RedmineCustomWorkflows::Patches::UserPatch' \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/version_patch.rb b/lib/redmine_custom_workflows/patches/version_patch.rb index 743c92a..9c9e0ed 100644 --- a/lib/redmine_custom_workflows/patches/version_patch.rb +++ b/lib/redmine_custom_workflows/patches/version_patch.rb @@ -24,7 +24,6 @@ module RedmineCustomWorkflows module VersionPatch def self.included(base) - base.send(:include, InstanceMethods) base.class_eval do before_save :before_save_custom_workflows after_save :after_save_custom_workflows @@ -33,37 +32,33 @@ module RedmineCustomWorkflows end end - module InstanceMethods + def before_save_custom_workflows + @version = self + @saved_attributes = attributes.dup + CustomWorkflow.run_shared_code(self) + CustomWorkflow.run_custom_workflows(:version, self, :before_save) + throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) + ensure + @saved_attributes = nil + end - def before_save_custom_workflows - @version = self - @saved_attributes = attributes.dup - CustomWorkflow.run_shared_code(self) - CustomWorkflow.run_custom_workflows(:version, self, :before_save) - throw :abort if errors.any? - errors.empty? && (@saved_attributes == attributes || valid?) - ensure - @saved_attributes = nil - end + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows(:version, self, :after_save) + end - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows(:version, self, :after_save) - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:version, self, :before_destroy) - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:version, self, :after_destroy) - end + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:version, self, :before_destroy) + end + def after_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:version, self, :after_destroy) end end end end -unless Version.include?(RedmineCustomWorkflows::Patches::VersionPatch) - Version.send(:include, RedmineCustomWorkflows::Patches::VersionPatch) -end \ No newline at end of file +# Apply patch +RedmineExtensions::PatchManager.register_model_patch 'Version', +'RedmineCustomWorkflows::Patches::VersionPatch' \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/wiki_content_patch.rb b/lib/redmine_custom_workflows/patches/wiki_content_patch.rb index 0230032..3b7bfc0 100644 --- a/lib/redmine_custom_workflows/patches/wiki_content_patch.rb +++ b/lib/redmine_custom_workflows/patches/wiki_content_patch.rb @@ -24,7 +24,6 @@ module RedmineCustomWorkflows module WikiContentPatch def self.included(base) - base.send(:include, InstanceMethods) base.class_eval do before_save :before_save_custom_workflows after_save :after_save_custom_workflows @@ -33,37 +32,33 @@ module RedmineCustomWorkflows end end - module InstanceMethods + def before_save_custom_workflows + @content = self + @saved_attributes = attributes.dup + CustomWorkflow.run_shared_code(self) + CustomWorkflow.run_custom_workflows(:wiki_content, self, :before_save) + throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) + ensure + @saved_attributes = nil + end - def before_save_custom_workflows - @content = self - @saved_attributes = attributes.dup - CustomWorkflow.run_shared_code(self) - CustomWorkflow.run_custom_workflows(:wiki_content, self, :before_save) - throw :abort if errors.any? - errors.empty? && (@saved_attributes == attributes || valid?) - ensure - @saved_attributes = nil - end + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows(:wiki_content, self, :after_save) + end - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows(:wiki_content, self, :after_save) - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:wiki_content, self, :before_destroy) - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows(:wiki_content, self, :after_destroy) - end + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:wiki_content, self, :before_destroy) + end + def after_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:wiki_content, self, :after_destroy) end end end end -unless WikiContent.include?(RedmineCustomWorkflows::Patches::WikiContentPatch) - WikiContent.send(:include, RedmineCustomWorkflows::Patches::WikiContentPatch) -end +# Apply patch +RedmineExtensions::PatchManager.register_model_patch 'WikiContent', + 'RedmineCustomWorkflows::Patches::WikiContentPatch' \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/wiki_page_patch.rb b/lib/redmine_custom_workflows/patches/wiki_page_patch.rb index e560dcc..228bc6b 100644 --- a/lib/redmine_custom_workflows/patches/wiki_page_patch.rb +++ b/lib/redmine_custom_workflows/patches/wiki_page_patch.rb @@ -42,6 +42,6 @@ module RedmineCustomWorkflows end end -unless WikiPage.include?(RedmineCustomWorkflows::Patches::WikiPagePatch) - WikiPage.send(:include, RedmineCustomWorkflows::Patches::WikiPagePatch) -end +# Apply patch +RedmineExtensions::PatchManager.register_model_patch 'WikiPage', + 'RedmineCustomWorkflows::Patches::WikiPagePatch' \ No newline at end of file