mirror of
https://github.com/anteo/redmine_custom_workflows.git
synced 2026-01-26 00:04:20 +00:00
Create member_patch.rb
Patch required for memberships to be observable
This commit is contained in:
parent
3e1985fd16
commit
e0b602a9e0
78
lib/redmine_custom_workflows/patches/models/member_patch.rb
Normal file
78
lib/redmine_custom_workflows/patches/models/member_patch.rb
Normal file
@ -0,0 +1,78 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Redmine plugin for Custom Workflows
|
||||
#
|
||||
# Copyright © 2015-19 Anton Argirov
|
||||
# Copyright © 2019-23 Karel Pičman <karel.picman@kontron.com>
|
||||
#
|
||||
# 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 Models
|
||||
# Member model patch
|
||||
module MemberPatch
|
||||
def custom_workflow_messages
|
||||
@custom_workflow_messages ||= {}
|
||||
end
|
||||
|
||||
def custom_workflow_env
|
||||
@custom_workflow_env ||= {}
|
||||
end
|
||||
|
||||
def self.prepended(base)
|
||||
base.class_eval do
|
||||
before_save :before_save_custom_workflows
|
||||
after_save :after_save_custom_workflows
|
||||
before_destroy :before_destroy_custom_workflows
|
||||
after_destroy :after_destroy_custom_workflows
|
||||
end
|
||||
end
|
||||
|
||||
def before_save_custom_workflows
|
||||
@member = self
|
||||
@saved_attributes = attributes.dup
|
||||
CustomWorkflow.run_shared_code self
|
||||
CustomWorkflow.run_custom_workflows :member, 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 :member, self, :after_save
|
||||
end
|
||||
|
||||
def before_destroy_custom_workflows
|
||||
res = CustomWorkflow.run_custom_workflows :member, self, :before_destroy
|
||||
throw :abort if res == false
|
||||
end
|
||||
|
||||
def after_destroy_custom_workflows
|
||||
CustomWorkflow.run_custom_workflows :member, self, :after_destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Apply the patch
|
||||
if Redmine::Plugin.installed?('easy_extensions')
|
||||
RedmineExtensions::PatchManager.register_model_patch 'Member', 'RedmineCustomWorkflows::Patches::Models::MemberPatch'
|
||||
else
|
||||
User.prepend RedmineCustomWorkflows::Patches::Models::MemberPatch
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user