mirror of
https://github.com/anteo/redmine_custom_workflows.git
synced 2026-01-26 08:14:20 +00:00
#18: Ability to exit current workflow with return or return true and cancel workflows' execution chain with return false
This commit is contained in:
parent
0590df7928
commit
8a72491f60
@ -45,13 +45,20 @@ class CustomWorkflow < ActiveRecord::Base
|
|||||||
CustomWorkflow.new(attributes)
|
CustomWorkflow.new(attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log_message(str, object)
|
||||||
|
Rails.logger.info str + " for #{object.class} \"#{object}\" (\##{object.id})"
|
||||||
|
end
|
||||||
|
|
||||||
def run_shared_code(object)
|
def run_shared_code(object)
|
||||||
workflows = CustomWorkflow.observing(:shared).active
|
workflows = CustomWorkflow.observing(:shared).active
|
||||||
Rails.logger.info "= Running shared code for #{object.class} \"#{object}\" (\##{object.id})"
|
log_message '= Running shared code', object
|
||||||
workflows.each do |workflow|
|
workflows.each do |workflow|
|
||||||
return false unless workflow.run(object, :shared_code)
|
if workflow.run(object, :shared_code) == false
|
||||||
|
log_message '= Abort running shared code', object
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
Rails.logger.info "= Finished running shared code for #{object.class} \"#{object}\" (\##{object.id})"
|
end
|
||||||
|
log_message '= Finished running shared code', object
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -62,11 +69,14 @@ class CustomWorkflow < ActiveRecord::Base
|
|||||||
workflows = workflows.for_project(object.project)
|
workflows = workflows.for_project(object.project)
|
||||||
end
|
end
|
||||||
return true unless workflows.any?
|
return true unless workflows.any?
|
||||||
Rails.logger.info "= Running #{event} custom workflows for #{object.class} \"#{object}\" (\##{object.id})"
|
log_message "= Running #{event} custom workflows", object
|
||||||
workflows.each do |workflow|
|
workflows.each do |workflow|
|
||||||
return false unless workflow.run(object, event)
|
if workflow.run(object, event) == false
|
||||||
|
log_message "= Abort running #{event} custom workflows", object
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
Rails.logger.info "= Finished running #{event} custom workflows for #{object.class} \"#{object}\" (\##{object.id})"
|
end
|
||||||
|
log_message "= Finished running #{event} custom workflows", object
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -33,9 +33,10 @@ module RedmineCustomWorkflows
|
|||||||
@group = self
|
@group = self
|
||||||
@saved_attributes = attributes.dup
|
@saved_attributes = attributes.dup
|
||||||
CustomWorkflow.run_shared_code(self)
|
CustomWorkflow.run_shared_code(self)
|
||||||
result = CustomWorkflow.run_custom_workflows(:group, self, :before_save) && (@saved_attributes == attributes || valid?)
|
CustomWorkflow.run_custom_workflows(:group, self, :before_save)
|
||||||
|
errors.empty? && (@saved_attributes == attributes || valid?)
|
||||||
|
ensure
|
||||||
@saved_attributes = nil
|
@saved_attributes = nil
|
||||||
result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_save_custom_workflows
|
def after_save_custom_workflows
|
||||||
|
|||||||
@ -27,9 +27,10 @@ module RedmineCustomWorkflows
|
|||||||
@issue = self
|
@issue = self
|
||||||
@saved_attributes = attributes.dup
|
@saved_attributes = attributes.dup
|
||||||
CustomWorkflow.run_shared_code(self)
|
CustomWorkflow.run_shared_code(self)
|
||||||
result = CustomWorkflow.run_custom_workflows(:issue, self, :before_save) && (@saved_attributes == attributes || valid?)
|
CustomWorkflow.run_custom_workflows(:issue, self, :before_save)
|
||||||
|
errors.empty? && (@saved_attributes == attributes || valid?)
|
||||||
|
ensure
|
||||||
@saved_attributes = nil
|
@saved_attributes = nil
|
||||||
result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_save_custom_workflows
|
def after_save_custom_workflows
|
||||||
|
|||||||
@ -14,9 +14,10 @@ module RedmineCustomWorkflows
|
|||||||
@user = self
|
@user = self
|
||||||
@saved_attributes = attributes.dup
|
@saved_attributes = attributes.dup
|
||||||
CustomWorkflow.run_shared_code(self)
|
CustomWorkflow.run_shared_code(self)
|
||||||
result = CustomWorkflow.run_custom_workflows(:user, self, :before_save) && (@saved_attributes == attributes || valid?)
|
CustomWorkflow.run_custom_workflows(:user, self, :before_save)
|
||||||
|
errors.empty? && (@saved_attributes == attributes || valid?)
|
||||||
|
ensure
|
||||||
@saved_attributes = nil
|
@saved_attributes = nil
|
||||||
result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_save_custom_workflows
|
def after_save_custom_workflows
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user