IssueRelation.to_s is broken #258

This commit is contained in:
Karel Pičman 2022-05-18 12:46:16 +02:00
parent 841c30d25c
commit 3b19b30648

View File

@ -30,51 +30,53 @@ module RedmineCustomWorkflows
after_save :after_save_custom_workflows after_save :after_save_custom_workflows
before_destroy :before_destroy_custom_workflows before_destroy :before_destroy_custom_workflows
after_destroy :after_destroy_custom_workflows after_destroy :after_destroy_custom_workflows
end
# override IssueRelation.to_s to rescue NoMethodError during CustomWorkflow.validate_syntax due to base.prepend InstanceMethods
# logging of temporarily instatiated IssueRelation with no related issues set
alias_method :old_to_s, :to_s end
def to_s(issue=nil) module InstanceMethods
if block_given?
if Gem.ruby_version < Gem::Version.new('3.0') ################################################################################################################
old_to_s issue, &Proc.new # Overriden methods
else
old_to_s issue, &Proc.new {} # Override IssueRelation.to_s to rescue NoMethodError during CustomWorkflow.validate_syntax due to
end # logging of temporarily instatiated IssueRelation with no related issues set.
else def to_s(issue=nil)
old_to_s issue super
end rescue NoMethodError => e
rescue NoMethodError => e if issue_from.present? || issue_to.present?
if issue_from.present? || issue_to.present? raise e
raise e
end
self.class.to_s
end end
end end
end
def before_save_custom_workflows ################################################################################################################
@issue_relation = self # New methods
@saved_attributes = attributes.dup
CustomWorkflow.run_shared_code self
CustomWorkflow.run_custom_workflows :issue_relation, self, :before_save
throw :abort if errors.any?
errors.empty? && (@saved_attributes == attributes || valid?)
ensure
@saved_attributes = nil
end
def after_save_custom_workflows def before_save_custom_workflows
CustomWorkflow.run_custom_workflows :issue_relation, self, :after_save @issue_relation = self
end @saved_attributes = attributes.dup
CustomWorkflow.run_shared_code self
CustomWorkflow.run_custom_workflows :issue_relation, self, :before_save
throw :abort if errors.any?
errors.empty? && (@saved_attributes == attributes || valid?)
ensure
@saved_attributes = nil
end
def before_destroy_custom_workflows def after_save_custom_workflows
CustomWorkflow.run_custom_workflows :issue_relation, self, :before_destroy CustomWorkflow.run_custom_workflows :issue_relation, self, :after_save
end end
def before_destroy_custom_workflows
CustomWorkflow.run_custom_workflows :issue_relation, self, :before_destroy
end
def after_destroy_custom_workflows
CustomWorkflow.run_custom_workflows :issue_relation, self, :after_destroy
end
def after_destroy_custom_workflows
CustomWorkflow.run_custom_workflows :issue_relation, self, :after_destroy
end end
end end