From b63e8f2a45983d743685adac4fb3cdcf08f2b563 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Sat, 21 Mar 2026 20:02:11 -0400 Subject: [PATCH] Updated hooks & patches --- init.rb | 8 +---- .../hooks/issues_save_hook_listener.rb | 4 +-- .../hooks/qbo_hook_listener.rb | 4 +-- .../hooks/view_hook_listener.rb | 2 +- .../patches/issue_patch.rb | 34 +++++-------------- lib/redmine_qbo_line_items.rb | 21 ++++++++++++ 6 files changed, 35 insertions(+), 38 deletions(-) rename lib/{redmine_qbo_line_items => line_items}/hooks/issues_save_hook_listener.rb (94%) rename lib/{redmine_qbo_line_items => line_items}/hooks/qbo_hook_listener.rb (94%) rename lib/{redmine_qbo_line_items => line_items}/hooks/view_hook_listener.rb (98%) rename lib/{redmine_qbo_line_items => line_items}/patches/issue_patch.rb (66%) create mode 100644 lib/redmine_qbo_line_items.rb diff --git a/init.rb b/init.rb index 02df0ca..595ccd9 100644 --- a/init.rb +++ b/init.rb @@ -39,10 +39,4 @@ Redmine::MenuManager.map :admin_menu do |menu| html: { class: 'icon icon-list' } end -# Dynamically load all Hooks & Patches recursively -base_dir = File.join(File.dirname(__FILE__), 'lib') - -# '**' looks inside subdirectories, '*.rb' matches Ruby files -Dir.glob(File.join(base_dir, '**', '*.rb')).sort.each do |file| - require file -end \ No newline at end of file +RedmineQboLineItems.setup \ No newline at end of file diff --git a/lib/redmine_qbo_line_items/hooks/issues_save_hook_listener.rb b/lib/line_items/hooks/issues_save_hook_listener.rb similarity index 94% rename from lib/redmine_qbo_line_items/hooks/issues_save_hook_listener.rb rename to lib/line_items/hooks/issues_save_hook_listener.rb index 1f1cc94..0bec426 100644 --- a/lib/redmine_qbo_line_items/hooks/issues_save_hook_listener.rb +++ b/lib/line_items/hooks/issues_save_hook_listener.rb @@ -8,10 +8,10 @@ # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -module RedmineQboLineItems +module LineItems module Hooks - class IssuesSaveHookListener < Redmine::Hook::ViewListener + class IssuesSaveHookListener < Redmine::Hook::Listener # Called After Issue Saved def controller_issues_edit_after_save(context={}) diff --git a/lib/redmine_qbo_line_items/hooks/qbo_hook_listener.rb b/lib/line_items/hooks/qbo_hook_listener.rb similarity index 94% rename from lib/redmine_qbo_line_items/hooks/qbo_hook_listener.rb rename to lib/line_items/hooks/qbo_hook_listener.rb index 4f77a8d..5246acc 100644 --- a/lib/redmine_qbo_line_items/hooks/qbo_hook_listener.rb +++ b/lib/line_items/hooks/qbo_hook_listener.rb @@ -8,10 +8,10 @@ # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -module RedmineQboLineItems +module LineItems module Hooks - class QboHookListener < Redmine::Hook::ViewListener + class QboHookListener < Redmine::Hook::Listener # Called by WebhookProcessJob def qbo_additional_entities(context={}) diff --git a/lib/redmine_qbo_line_items/hooks/view_hook_listener.rb b/lib/line_items/hooks/view_hook_listener.rb similarity index 98% rename from lib/redmine_qbo_line_items/hooks/view_hook_listener.rb rename to lib/line_items/hooks/view_hook_listener.rb index 420860d..914be09 100644 --- a/lib/redmine_qbo_line_items/hooks/view_hook_listener.rb +++ b/lib/line_items/hooks/view_hook_listener.rb @@ -8,7 +8,7 @@ # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -module RedmineQboLineItems +module LineItems module Hooks class ViewHookListener < Redmine::Hook::ViewListener diff --git a/lib/redmine_qbo_line_items/patches/issue_patch.rb b/lib/line_items/patches/issue_patch.rb similarity index 66% rename from lib/redmine_qbo_line_items/patches/issue_patch.rb rename to lib/line_items/patches/issue_patch.rb index f708795..5ca0d0b 100644 --- a/lib/redmine_qbo_line_items/patches/issue_patch.rb +++ b/lib/line_items/patches/issue_patch.rb @@ -8,35 +8,17 @@ # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -require_dependency 'issue' - -module RedmineQboLineItems +module LineItems module Patches module IssuePatch - - def self.included(base) - base.extend(ClassMethods) - base.send(:include, InstanceMethods) - - base.class_eval do - has_many :line_items, dependent: :destroy - accepts_nested_attributes_for :line_items, - allow_destroy: true, - reject_if: proc { |attrs| attrs['description'].blank? } - end - + extend ActiveSupport::Concern + + prepended do + has_many :line_items, dependent: :destroy + accepts_nested_attributes_for :line_items, + allow_destroy: true, + reject_if: proc { |attrs| attrs['description'].blank? } end - - module ClassMethods - - end - - module InstanceMethods - - end - end - - Issue.send(:include, IssuePatch) end end \ No newline at end of file diff --git a/lib/redmine_qbo_line_items.rb b/lib/redmine_qbo_line_items.rb new file mode 100644 index 0000000..fbe8e02 --- /dev/null +++ b/lib/redmine_qbo_line_items.rb @@ -0,0 +1,21 @@ +#The MIT License (MIT) +# +#Copyright (c) 2026 rick barrette +# +#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +module RedmineQboLineItems + + def self.setup + unless Issue.ancestors.include?(LineItems::Patches::IssuePatch) + Issue.prepend LineItems::Patches::IssuePatch + LineItems::Hooks::IssuesSaveHookListener + LineItems::Hooks::QboHookListener + LineItems::Hooks::ViewHookListener + end + end +end \ No newline at end of file