From 1e65c8bba094af1e760bfc9ef97b0f637ff05372 Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Thu, 22 Mar 2018 16:07:58 +0100 Subject: [PATCH] RedmineExtensions::PatchManager usage --- app/views/dmsf/_custom_fields.html.erb | 16 +- lib/redmine_dmsf.rb | 5 +- .../patches/acts_as_customizable.rb | 30 --- lib/redmine_dmsf/patches/attachable_patch.rb | 2 +- .../patches/custom_fields_helper_patch.rb | 8 +- .../patches/easy_crm_case_patch.rb | 248 +++++++++--------- .../easy_crm_cases_controller_patch.rb | 2 +- lib/redmine_dmsf/patches/issue_patch.rb | 241 +++++++++-------- lib/redmine_dmsf/patches/project_patch.rb | 8 +- ...s_extended.rb => projects_helper_patch.rb} | 10 +- lib/redmine_dmsf/patches/role_patch.rb | 27 +- lib/redmine_dmsf/patches/user_patch.rb | 47 ++-- .../patches/user_preference_patch.rb | 37 ++- 13 files changed, 307 insertions(+), 374 deletions(-) delete mode 100644 lib/redmine_dmsf/patches/acts_as_customizable.rb rename lib/redmine_dmsf/patches/{project_tabs_extended.rb => projects_helper_patch.rb} (86%) diff --git a/app/views/dmsf/_custom_fields.html.erb b/app/views/dmsf/_custom_fields.html.erb index cb3801a3..c1a6fb82 100644 --- a/app/views/dmsf/_custom_fields.html.erb +++ b/app/views/dmsf/_custom_fields.html.erb @@ -24,13 +24,15 @@ <% if object %>
- <% object.show_custom_field_values.each do |custom_value| %> -
- <%= content_tag :div, h(custom_value.custom_field.name), :class => 'label' %> -
- <%= show_value custom_value %> + <% object.custom_field_values.each do |custom_value| %> + <% if !custom_value.value.blank? %> +
+ <%= content_tag :div, h(custom_value.custom_field.name), :class => 'label' %> +
+ <%= show_value custom_value %> +
-
+ <% end %> <% end %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index 7c753ee6..ec28985c 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -26,9 +26,8 @@ DMSF_MAX_NOTIFICATION_RECEIVERS_INFO = 10 # Plugin's patches require 'redmine_dmsf/patches/custom_fields_helper_patch' -require 'redmine_dmsf/patches/acts_as_customizable' +require 'redmine_dmsf/patches/projects_helper_patch' require 'redmine_dmsf/patches/project_patch' -require 'redmine_dmsf/patches/project_tabs_extended' require 'redmine_dmsf/patches/user_preference_patch' require 'redmine_dmsf/patches/user_patch' require 'redmine_dmsf/patches/issue_patch' @@ -70,4 +69,4 @@ require 'redmine_dmsf/hooks/helpers/issues_helper_hooks' require 'redmine_dmsf/hooks/helpers/search_helper_hooks' # Macros -require 'redmine_dmsf/macros' +require 'redmine_dmsf/macros' \ No newline at end of file diff --git a/lib/redmine_dmsf/patches/acts_as_customizable.rb b/lib/redmine_dmsf/patches/acts_as_customizable.rb deleted file mode 100644 index cc7a5cea..00000000 --- a/lib/redmine_dmsf/patches/acts_as_customizable.rb +++ /dev/null @@ -1,30 +0,0 @@ -# Redmine plugin for Document Management System "Features" -# -# Copyright © 2011 Vít Jonáš -# Copyright © 2011-18 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 Redmine - module Acts - module Customizable - module InstanceMethods - def show_custom_field_values - custom_field_values.delete_if { |v| v.custom_field.blank? || v.value.blank? } - end - end - end - end -end diff --git a/lib/redmine_dmsf/patches/attachable_patch.rb b/lib/redmine_dmsf/patches/attachable_patch.rb index 51da3e1a..98ad64e3 100644 --- a/lib/redmine_dmsf/patches/attachable_patch.rb +++ b/lib/redmine_dmsf/patches/attachable_patch.rb @@ -33,5 +33,5 @@ module RedmineDmsf end end -RedmineExtensions::PatchManager.register_helper_patch 'Redmine::Acts::Attachable::InstanceMethods', +RedmineExtensions::PatchManager.register_model_patch 'Redmine::Acts::Attachable::InstanceMethods', 'RedmineDmsf::Patches::AttachablePatch', prepend: true \ No newline at end of file diff --git a/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb b/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb index e74c32a0..214f7953 100644 --- a/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb +++ b/lib/redmine_dmsf/patches/custom_fields_helper_patch.rb @@ -47,9 +47,5 @@ module RedmineDmsf end end -if defined?(EasyExtensions) - RedmineExtensions::PatchManager.register_helper_patch 'CustomFieldsHelper', - 'RedmineDmsf::Patches::CustomFieldsHelperPatch', prepend: true -else - CustomFieldsHelper.send(:prepend, RedmineDmsf::Patches::CustomFieldsHelperPatch) -end +RedmineExtensions::PatchManager.register_concern_patch 'CustomFieldsHelper', + 'RedmineDmsf::Patches::CustomFieldsHelperPatch', prepend: true \ No newline at end of file diff --git a/lib/redmine_dmsf/patches/easy_crm_case_patch.rb b/lib/redmine_dmsf/patches/easy_crm_case_patch.rb index 873077be..5f6af81c 100644 --- a/lib/redmine_dmsf/patches/easy_crm_case_patch.rb +++ b/lib/redmine_dmsf/patches/easy_crm_case_patch.rb @@ -22,165 +22,159 @@ module RedmineDmsf module Patches module EasyCrmCasePatch + ################################################################################################################## + # New methods + def self.included(base) - base.send(:include, InstanceMethods) base.class_eval do before_destroy :delete_system_folder end end - module InstanceMethods + def attributes_editable? + true + end - def attributes_editable? - true - end - - def save_dmsf_attachments(dmsf_attachments) - @saved_dmsf_attachments = [] - if dmsf_attachments - dmsf_attachments = dmsf_attachments.map(&:last) - dmsf_attachments.each do |dmsf_attachment| - a = Attachment.find_by_token(dmsf_attachment[:token]) - @saved_dmsf_attachments << a if a - end + def save_dmsf_attachments(dmsf_attachments) + @saved_dmsf_attachments = [] + if dmsf_attachments + dmsf_attachments = dmsf_attachments.map(&:last) + dmsf_attachments.each do |dmsf_attachment| + a = Attachment.find_by_token(dmsf_attachment[:token]) + @saved_dmsf_attachments << a if a end end + end - def saved_dmsf_attachments - @saved_dmsf_attachments || [] - end + def saved_dmsf_attachments + @saved_dmsf_attachments || [] + end - def save_dmsf_links(dmsf_links) - @saved_dmsf_links = [] - if dmsf_links - ids = dmsf_links.map(&:last) - ids.each do |id| - l = DmsfLink.find_by_id(id) - @saved_dmsf_links << l if l - end + def save_dmsf_links(dmsf_links) + @saved_dmsf_links = [] + if dmsf_links + ids = dmsf_links.map(&:last) + ids.each do |id| + l = DmsfLink.find_by_id(id) + @saved_dmsf_links << l if l end end + end - def saved_dmsf_links - @saved_dmsf_links || [] - end + def saved_dmsf_links + @saved_dmsf_links || [] + end - def save_dmsf_attachments_wfs(dmsf_attachments_wfs, dmsf_attachments) - if dmsf_attachments_wfs - @dmsf_attachments_wfs = {} - dmsf_attachments_wfs.each do |attachment_id, approval_workflow_id| - attachment = dmsf_attachments[attachment_id] - if attachment - a = Attachment.find_by_token(attachment[:token]) - wf = DmsfWorkflow.find_by_id approval_workflow_id - @dmsf_attachments_wfs[a.id] = wf if wf && a - end - end - end - end - - def saved_dmsf_attachments_wfs - @dmsf_attachments_wfs || [] - end - - def save_dmsf_links_wfs(dmsf_links_wfs) - if dmsf_links_wfs - @saved_dmsf_links_wfs = {} - dmsf_links_wfs.each do |dmsf_link_id, approval_workflow_id| + def save_dmsf_attachments_wfs(dmsf_attachments_wfs, dmsf_attachments) + if dmsf_attachments_wfs + @dmsf_attachments_wfs = {} + dmsf_attachments_wfs.each do |attachment_id, approval_workflow_id| + attachment = dmsf_attachments[attachment_id] + if attachment + a = Attachment.find_by_token(attachment[:token]) wf = DmsfWorkflow.find_by_id approval_workflow_id - @saved_dmsf_links_wfs[dmsf_link_id.to_i] = wf if wf + @dmsf_attachments_wfs[a.id] = wf if wf && a end end end + end - def saved_dmsf_links_wfs - @saved_dmsf_links_wfs || {} - end + def saved_dmsf_attachments_wfs + @dmsf_attachments_wfs || [] + end - def system_folder(create = false) - parent = DmsfFolder.system.where(:project_id => self.project_id, :title => '.CRM cases').first - if create && !parent - parent = DmsfFolder.new - parent.project_id = self.project_id - parent.title = '.CRM cases' - parent.description = 'Documents assigned to CRM cases' - parent.user_id = User.anonymous.id - parent.system = true - parent.save - end - if parent - folder = DmsfFolder.system.where(['project_id = ? AND dmsf_folder_id = ? AND CAST(title AS DECIMAL) = ?', - self.project_id, parent.id, self.id]).first - if create && !folder - folder = DmsfFolder.new - folder.dmsf_folder_id = parent.id - folder.project_id = self.project_id - folder.title = "#{self.id} - #{self.name}" - folder.user_id = User.anonymous.id - folder.system = true - folder.save - end - end - folder - end - - def dmsf_files - files = [] - folder = self.system_folder - if folder - files = folder.dmsf_files.to_a - end - files - end - - def dmsf_links - links = [] - folder = self.system_folder - if folder - links = folder.dmsf_links - end - links - end - - def delete_system_folder - folder = self.system_folder - folder.destroy if folder - end - - def dmsf_file_added(dmsf_file) - unless dmsf_file.new_record? - self.journalize_dmsf_file(dmsf_file, :added) + def save_dmsf_links_wfs(dmsf_links_wfs) + if dmsf_links_wfs + @saved_dmsf_links_wfs = {} + dmsf_links_wfs.each do |dmsf_link_id, approval_workflow_id| + wf = DmsfWorkflow.find_by_id approval_workflow_id + @saved_dmsf_links_wfs[dmsf_link_id.to_i] = wf if wf end end + end - def dmsf_file_removed(dmsf_file) - unless dmsf_file.new_record? - self.journalize_dmsf_file(dmsf_file, :removed) + def saved_dmsf_links_wfs + @saved_dmsf_links_wfs || {} + end + + def system_folder(create = false) + parent = DmsfFolder.system.where(:project_id => self.project_id, :title => '.CRM cases').first + if create && !parent + parent = DmsfFolder.new + parent.project_id = self.project_id + parent.title = '.CRM cases' + parent.description = 'Documents assigned to CRM cases' + parent.user_id = User.anonymous.id + parent.system = true + parent.save + end + if parent + folder = DmsfFolder.system.where(['project_id = ? AND dmsf_folder_id = ? AND CAST(title AS DECIMAL) = ?', + self.project_id, parent.id, self.id]).first + if create && !folder + folder = DmsfFolder.new + folder.dmsf_folder_id = parent.id + folder.project_id = self.project_id + folder.title = "#{self.id} - #{self.name}" + folder.user_id = User.anonymous.id + folder.system = true + folder.save end end + folder + end - # Adds a journal detail for an attachment that was added or removed - def journalize_dmsf_file(dmsf_file, added_or_removed) - init_journal(User.current) - key = (added_or_removed == :removed ? :old_value : :value) - current_journal.details << JournalDetail.new( - :property => 'dmsf_file', - :prop_key => dmsf_file.id, - key => dmsf_file.title - ) - current_journal.save + def dmsf_files + files = [] + folder = self.system_folder + if folder + files = folder.dmsf_files.to_a end + files + end + def dmsf_links + links = [] + folder = self.system_folder + if folder + links = folder.dmsf_links + end + links + end + + def delete_system_folder + folder = self.system_folder + folder.destroy if folder + end + + def dmsf_file_added(dmsf_file) + unless dmsf_file.new_record? + self.journalize_dmsf_file(dmsf_file, :added) + end + end + + def dmsf_file_removed(dmsf_file) + unless dmsf_file.new_record? + self.journalize_dmsf_file(dmsf_file, :removed) + end + end + + # Adds a journal detail for an attachment that was added or removed + def journalize_dmsf_file(dmsf_file, added_or_removed) + init_journal(User.current) + key = (added_or_removed == :removed ? :old_value : :value) + current_journal.details << JournalDetail.new( + :property => 'dmsf_file', + :prop_key => dmsf_file.id, + key => dmsf_file.title + ) + current_journal.save end end end end -if Redmine::Plugin.installed?(:easy_crm) - Rails.configuration.to_prepare do - unless EasyCrmCase.included_modules.include?(RedmineDmsf::Patches::EasyCrmCasePatch) - EasyCrmCase.send(:include, RedmineDmsf::Patches::EasyCrmCasePatch) - end - end -end \ No newline at end of file +RedmineExtensions::PatchManager.register_model_patch 'EasyCrmCasePatch', + 'RedmineDmsf::Patches::RedmineDmsf::Patches::EasyCrmCasePatch', + if: proc { Redmine::Plugin.installed?(:easy_crm) } \ No newline at end of file diff --git a/lib/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb b/lib/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb index 186e4cbe..8bd4ee3f 100644 --- a/lib/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb +++ b/lib/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb @@ -118,4 +118,4 @@ end RedmineExtensions::PatchManager.register_controller_patch 'EasyCrmCasesController', 'RedmineDmsf::Patches::EasyCrmCasesControllerPatch', prepend: true, - if: proc { Redmine::Plugin.installed?(:easy_crm) } + if: proc { Redmine::Plugin.installed?(:easy_crm) } \ No newline at end of file diff --git a/lib/redmine_dmsf/patches/issue_patch.rb b/lib/redmine_dmsf/patches/issue_patch.rb index 63944825..a8596a9b 100644 --- a/lib/redmine_dmsf/patches/issue_patch.rb +++ b/lib/redmine_dmsf/patches/issue_patch.rb @@ -22,152 +22,150 @@ module RedmineDmsf module Patches module IssuePatch + ################################################################################################################## + # New methods + def self.included(base) - base.send(:include, InstanceMethods) base.class_eval do before_destroy :delete_system_folder end end - module InstanceMethods - - def save_dmsf_attachments(dmsf_attachments) - @saved_dmsf_attachments = [] - if dmsf_attachments - dmsf_attachments = dmsf_attachments.map(&:last) - dmsf_attachments.each do |dmsf_attachment| - a = Attachment.find_by_token(dmsf_attachment[:token]) - @saved_dmsf_attachments << a if a - end + def save_dmsf_attachments(dmsf_attachments) + @saved_dmsf_attachments = [] + if dmsf_attachments + dmsf_attachments = dmsf_attachments.map(&:last) + dmsf_attachments.each do |dmsf_attachment| + a = Attachment.find_by_token(dmsf_attachment[:token]) + @saved_dmsf_attachments << a if a end end + end - def saved_dmsf_attachments - @saved_dmsf_attachments || [] - end + def saved_dmsf_attachments + @saved_dmsf_attachments || [] + end - def save_dmsf_links(dmsf_links) - @saved_dmsf_links = [] - if dmsf_links - ids = dmsf_links.map(&:last) - ids.each do |id| - l = DmsfLink.find_by_id(id) - @saved_dmsf_links << l if l - end + def save_dmsf_links(dmsf_links) + @saved_dmsf_links = [] + if dmsf_links + ids = dmsf_links.map(&:last) + ids.each do |id| + l = DmsfLink.find_by_id(id) + @saved_dmsf_links << l if l end end + end - def saved_dmsf_links - @saved_dmsf_links || [] - end + def saved_dmsf_links + @saved_dmsf_links || [] + end - def save_dmsf_attachments_wfs(dmsf_attachments_wfs, dmsf_attachments) - if dmsf_attachments_wfs - @dmsf_attachments_wfs = {} - dmsf_attachments_wfs.each do |attachment_id, approval_workflow_id| - attachment = dmsf_attachments[attachment_id] - if attachment - a = Attachment.find_by_token(attachment[:token]) - wf = DmsfWorkflow.find_by_id approval_workflow_id - @dmsf_attachments_wfs[a.id] = wf if wf && a - end - end - end - end - - def saved_dmsf_attachments_wfs - @dmsf_attachments_wfs || [] - end - - def save_dmsf_links_wfs(dmsf_links_wfs) - if dmsf_links_wfs - @saved_dmsf_links_wfs = {} - dmsf_links_wfs.each do |dmsf_link_id, approval_workflow_id| + def save_dmsf_attachments_wfs(dmsf_attachments_wfs, dmsf_attachments) + if dmsf_attachments_wfs + @dmsf_attachments_wfs = {} + dmsf_attachments_wfs.each do |attachment_id, approval_workflow_id| + attachment = dmsf_attachments[attachment_id] + if attachment + a = Attachment.find_by_token(attachment[:token]) wf = DmsfWorkflow.find_by_id approval_workflow_id - @saved_dmsf_links_wfs[dmsf_link_id.to_i] = wf if wf + @dmsf_attachments_wfs[a.id] = wf if wf && a end end end + end - def saved_dmsf_links_wfs - @saved_dmsf_links_wfs || {} - end + def saved_dmsf_attachments_wfs + @dmsf_attachments_wfs || [] + end - def system_folder(create = false, prj_id = nil) - prj_id ||= self.project_id - parent = DmsfFolder.system.where(:project_id => prj_id, :title => '.Issues').first - if create && !parent - parent = DmsfFolder.new - parent.project_id = prj_id - parent.title = '.Issues' - parent.description = 'Documents assigned to issues' - parent.user_id = User.anonymous.id - parent.system = true - parent.save - end - if parent - folder = DmsfFolder.system.where(["project_id = ? AND dmsf_folder_id = ? AND title LIKE '? - %'", - prj_id, parent.id, self.id]).first - if create && !folder - folder = DmsfFolder.new - folder.dmsf_folder_id = parent.id - folder.project_id = prj_id - folder.title = "#{self.id} - #{self.subject}" - folder.user_id = User.anonymous.id - folder.system = true - folder.save - end - end - folder - end - - def dmsf_files - files = [] - folder = self.system_folder - if folder - files = folder.dmsf_files.to_a - end - files - end - - def dmsf_links - links = [] - folder = self.system_folder - if folder - links = folder.dmsf_links - end - links - end - - def delete_system_folder - folder = self.system_folder - folder.destroy if folder - end - - def dmsf_file_added(dmsf_file) - unless dmsf_file.new_record? - self.journalize_dmsf_file(dmsf_file, :added) + def save_dmsf_links_wfs(dmsf_links_wfs) + if dmsf_links_wfs + @saved_dmsf_links_wfs = {} + dmsf_links_wfs.each do |dmsf_link_id, approval_workflow_id| + wf = DmsfWorkflow.find_by_id approval_workflow_id + @saved_dmsf_links_wfs[dmsf_link_id.to_i] = wf if wf end end + end - def dmsf_file_removed(dmsf_file) - unless dmsf_file.new_record? - self.journalize_dmsf_file(dmsf_file, :removed) + def saved_dmsf_links_wfs + @saved_dmsf_links_wfs || {} + end + + def system_folder(create = false, prj_id = nil) + prj_id ||= self.project_id + parent = DmsfFolder.system.where(:project_id => prj_id, :title => '.Issues').first + if create && !parent + parent = DmsfFolder.new + parent.project_id = prj_id + parent.title = '.Issues' + parent.description = 'Documents assigned to issues' + parent.user_id = User.anonymous.id + parent.system = true + parent.save + end + if parent + folder = DmsfFolder.system.where(["project_id = ? AND dmsf_folder_id = ? AND title LIKE '? - %'", + prj_id, parent.id, self.id]).first + if create && !folder + folder = DmsfFolder.new + folder.dmsf_folder_id = parent.id + folder.project_id = prj_id + folder.title = "#{self.id} - #{self.subject}" + folder.user_id = User.anonymous.id + folder.system = true + folder.save end end + folder + end - # Adds a journal detail for an attachment that was added or removed - def journalize_dmsf_file(dmsf_file, added_or_removed) - init_journal(User.current) - key = (added_or_removed == :removed ? :old_value : :value) - current_journal.details << JournalDetail.new( - :property => 'dmsf_file', - :prop_key => dmsf_file.id, - key => dmsf_file.title - ) - current_journal.save + def dmsf_files + files = [] + folder = self.system_folder + if folder + files = folder.dmsf_files.to_a end + files + end + def dmsf_links + links = [] + folder = self.system_folder + if folder + links = folder.dmsf_links + end + links + end + + def delete_system_folder + folder = self.system_folder + folder.destroy if folder + end + + def dmsf_file_added(dmsf_file) + unless dmsf_file.new_record? + self.journalize_dmsf_file(dmsf_file, :added) + end + end + + def dmsf_file_removed(dmsf_file) + unless dmsf_file.new_record? + self.journalize_dmsf_file(dmsf_file, :removed) + end + end + + # Adds a journal detail for an attachment that was added or removed + def journalize_dmsf_file(dmsf_file, added_or_removed) + init_journal(User.current) + key = (added_or_removed == :removed ? :old_value : :value) + current_journal.details << JournalDetail.new( + :property => 'dmsf_file', + :prop_key => dmsf_file.id, + key => dmsf_file.title + ) + current_journal.save end end @@ -175,8 +173,5 @@ module RedmineDmsf end # Apply patch -Rails.configuration.to_prepare do - unless Issue.included_modules.include?(RedmineDmsf::Patches::IssuePatch) - Issue.send(:include, RedmineDmsf::Patches::IssuePatch) - end -end +RedmineExtensions::PatchManager.register_model_patch 'Issue', + 'RedmineDmsf::Patches::IssuePatch' \ No newline at end of file diff --git a/lib/redmine_dmsf/patches/project_patch.rb b/lib/redmine_dmsf/patches/project_patch.rb index 003e429c..52679710 100644 --- a/lib/redmine_dmsf/patches/project_patch.rb +++ b/lib/redmine_dmsf/patches/project_patch.rb @@ -115,9 +115,5 @@ module RedmineDmsf end end -if defined?(EasyExtensions) - RedmineExtensions::PatchManager.register_model_patch 'Project', - 'RedmineDmsf::Patches::ProjectPatch', prepend: true -else - Project.send(:prepend, RedmineDmsf::Patches::ProjectPatch) -end +RedmineExtensions::PatchManager.register_model_patch 'Project', + 'RedmineDmsf::Patches::ProjectPatch', prepend: true \ No newline at end of file diff --git a/lib/redmine_dmsf/patches/project_tabs_extended.rb b/lib/redmine_dmsf/patches/projects_helper_patch.rb similarity index 86% rename from lib/redmine_dmsf/patches/project_tabs_extended.rb rename to lib/redmine_dmsf/patches/projects_helper_patch.rb index 96108cc8..44f699b9 100644 --- a/lib/redmine_dmsf/patches/project_tabs_extended.rb +++ b/lib/redmine_dmsf/patches/projects_helper_patch.rb @@ -20,7 +20,7 @@ module RedmineDmsf module Patches - module ProjectTabsExtended + module ProjectHelperPatch ################################################################################################################## # Overridden methods @@ -41,9 +41,5 @@ module RedmineDmsf end end -if defined?(EasyExtensions) - RedmineExtensions::PatchManager.register_helper_patch 'ProjectsHelper', - 'RedmineDmsf::Patches::ProjectTabsExtended', prepend: true -else - ProjectsHelper.send(:prepend, RedmineDmsf::Patches::ProjectTabsExtended) -end \ No newline at end of file +RedmineExtensions::PatchManager.register_concern_patch 'ProjectsHelper', + 'RedmineDmsf::Patches::ProjectHelperPatch', prepend: true \ No newline at end of file diff --git a/lib/redmine_dmsf/patches/role_patch.rb b/lib/redmine_dmsf/patches/role_patch.rb index a635c43a..386b1997 100644 --- a/lib/redmine_dmsf/patches/role_patch.rb +++ b/lib/redmine_dmsf/patches/role_patch.rb @@ -22,22 +22,20 @@ module RedmineDmsf module Patches module RolePatch - def self.included(base) # :nodoc: - base.send(:include, InstanceMethods) + ################################################################################################################## + # New methods + + def self.included(base) base.class_eval do before_destroy :remove_dmsf_references end end - module InstanceMethods - - def remove_dmsf_references - return if self.id.nil? - substitute = Role.anonymous - DmsfFolderPermission.where(:object_id => self.id, :object_type => 'Role').update_all( - :object_id => substitute.id) - end - + def remove_dmsf_references + return if self.id.nil? + substitute = Role.anonymous + DmsfFolderPermission.where(:object_id => self.id, :object_type => 'Role').update_all( + :object_id => substitute.id) end end @@ -45,8 +43,5 @@ module RedmineDmsf end # Apply patch -Rails.configuration.to_prepare do - unless Role.included_modules.include?(RedmineDmsf::Patches::RolePatch) - Role.send(:include, RedmineDmsf::Patches::RolePatch) - end -end +RedmineExtensions::PatchManager.register_model_patch 'Role', + 'RedmineDmsf::Patches::RolePatch', prepend: true \ No newline at end of file diff --git a/lib/redmine_dmsf/patches/user_patch.rb b/lib/redmine_dmsf/patches/user_patch.rb index 8b54eb4d..adf11ea2 100644 --- a/lib/redmine_dmsf/patches/user_patch.rb +++ b/lib/redmine_dmsf/patches/user_patch.rb @@ -22,33 +22,31 @@ module RedmineDmsf module Patches module UserPatch + ################################################################################################################## + # New methods + def self.included(base) # :nodoc: - base.send(:include, InstanceMethods) base.class_eval do before_destroy :remove_dmsf_references end end - module InstanceMethods - - def remove_dmsf_references - return if self.id.nil? - substitute = User.anonymous - DmsfFileRevisionAccess.where(:user_id => id).update_all(:user_id => substitute.id) - DmsfFileRevision.where(:user_id => id).update_all(:user_id => substitute.id) - DmsfFile.where(:deleted_by_user_id => id).update_all(:deleted_by_user_id => substitute.id) - DmsfFolder.where(:user_id => id).update_all(:user_id => substitute.id) - DmsfFolder.where(:deleted_by_user_id => id).update_all(:deleted_by_user_id => substitute.id) - DmsfLink.where(:user_id => id).update_all(:user_id => substitute.id) - DmsfLink.where(:deleted_by_user_id => id).update_all(:deleted_by_user_id => substitute.id) - DmsfLock.where(:user_id => id).delete_all - DmsfWorkflowStepAction.where(:author_id => id).update_all(:author_id => substitute.id) - DmsfWorkflowStepAssignment.where(:user_id => id).update_all(:user_id => substitute.id) - DmsfWorkflowStep.where(:user_id => id).update_all(:user_id => substitute.id) - DmsfWorkflow.where(:author_id => id).update_all(:author_id => substitute.id) - DmsfFolderPermission.where(:object_id => id, :object_type => 'User').update_all(:object_id => substitute.id) - end - + def remove_dmsf_references + return if self.id.nil? + substitute = User.anonymous + DmsfFileRevisionAccess.where(:user_id => id).update_all(:user_id => substitute.id) + DmsfFileRevision.where(:user_id => id).update_all(:user_id => substitute.id) + DmsfFile.where(:deleted_by_user_id => id).update_all(:deleted_by_user_id => substitute.id) + DmsfFolder.where(:user_id => id).update_all(:user_id => substitute.id) + DmsfFolder.where(:deleted_by_user_id => id).update_all(:deleted_by_user_id => substitute.id) + DmsfLink.where(:user_id => id).update_all(:user_id => substitute.id) + DmsfLink.where(:deleted_by_user_id => id).update_all(:deleted_by_user_id => substitute.id) + DmsfLock.where(:user_id => id).delete_all + DmsfWorkflowStepAction.where(:author_id => id).update_all(:author_id => substitute.id) + DmsfWorkflowStepAssignment.where(:user_id => id).update_all(:user_id => substitute.id) + DmsfWorkflowStep.where(:user_id => id).update_all(:user_id => substitute.id) + DmsfWorkflow.where(:author_id => id).update_all(:author_id => substitute.id) + DmsfFolderPermission.where(:object_id => id, :object_type => 'User').update_all(:object_id => substitute.id) end end @@ -56,8 +54,5 @@ module RedmineDmsf end # Apply patch -Rails.configuration.to_prepare do - unless User.included_modules.include?(RedmineDmsf::Patches::UserPatch) - User.send(:include, RedmineDmsf::Patches::UserPatch) - end -end +RedmineExtensions::PatchManager.register_model_patch 'User', + 'RedmineDmsf::Patches::UserPatch' \ No newline at end of file diff --git a/lib/redmine_dmsf/patches/user_preference_patch.rb b/lib/redmine_dmsf/patches/user_preference_patch.rb index 25b5443a..1447f70d 100644 --- a/lib/redmine_dmsf/patches/user_preference_patch.rb +++ b/lib/redmine_dmsf/patches/user_preference_patch.rb @@ -22,31 +22,29 @@ module RedmineDmsf module Patches module UserPreference + ################################################################################################################## + # New methods + def self.included(base) - base.send(:include, InstanceMethods) base.class_eval do safe_attributes 'dmsf_tree_view', 'dmsf_attachments_upload_choice' if self.included_modules.include?(Redmine::SafeAttributes) end end - module InstanceMethods + def dmsf_tree_view + self[:dmsf_tree_view] || '1' + end - def dmsf_tree_view - self[:dmsf_tree_view] || '1' - end + def dmsf_tree_view=(value) + self[:dmsf_tree_view] = value + end - def dmsf_tree_view=(value) - self[:dmsf_tree_view] = value - end - - def dmsf_attachments_upload_choice - self[:dmsf_attachments_upload_choice] || 'DMSF' - end - - def dmsf_attachments_upload_choice=(value) - self[:dmsf_attachments_upload_choice] = value - end + def dmsf_attachments_upload_choice + self[:dmsf_attachments_upload_choice] || 'DMSF' + end + def dmsf_attachments_upload_choice=(value) + self[:dmsf_attachments_upload_choice] = value end end @@ -54,8 +52,5 @@ module RedmineDmsf end # Apply patch -Rails.configuration.to_prepare do - unless UserPreference.included_modules.include?(RedmineDmsf::Patches::UserPreference) - UserPreference.send(:include, RedmineDmsf::Patches::UserPreference) - end -end +RedmineExtensions::PatchManager.register_model_patch 'UserPreference', + 'RedmineDmsf::Patches::UserPreference' \ No newline at end of file