enable custom workflows for issue relations

This commit is contained in:
Björn Friebel 2020-09-30 17:22:16 +02:00
parent d0d2abb08f
commit d6b55cf0e5
4 changed files with 86 additions and 3 deletions

View File

@ -21,11 +21,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class CustomWorkflow < ActiveRecord::Base
OBSERVABLES = [:issue, :issue_attachments, :user, :attachment, :group, :group_users, :project, :project_attachments,
OBSERVABLES = [:issue, :issue_relation, :issue_attachments, :user, :attachment, :group, :group_users, :project, :project_attachments,
:wiki_content, :wiki_page_attachments, :time_entry, :version, :shared]
PROJECT_OBSERVABLES = [:issue, :issue_attachments, :project, :project_attachments, :wiki_content, :wiki_page_attachments, :time_entry, :version]
COLLECTION_OBSERVABLES = [:group_users, :issue_attachments, :project_attachments, :wiki_page_attachments]
SINGLE_OBSERVABLES = [:issue, :user, :group, :attachment, :project, :wiki_content, :time_entry, :version]
SINGLE_OBSERVABLES = [:issue, :issue_relation, :user, :group, :attachment, :project, :wiki_content, :time_entry, :version]
has_and_belongs_to_many :projects
acts_as_list

View File

@ -73,6 +73,9 @@ en:
text_custom_workflow_issue_code_note: Scripts are executed in the context of Issue object like ordinary
before_save and after_save callbacks. So use methods and properties of the issue directly (or through `self`).
Instance variables (@variable) are also allowed and may be used if needed.
text_custom_workflow_issue_relation_code_note: Scripts are executed in the context of IssueRelation object like ordinary
before_save and after_save callbacks. So use methods and properties of the issue relation directly (or through `self`).
Instance variables (@variable) are also allowed and may be used if needed.
text_custom_workflow_shared_code_note: This code will run before any other workflow and may contain shared code,
e.g. functions and classes needed by other workflows
text_custom_workflow_user_code_note: Scripts are executed in the context of User object when user object changes
@ -107,6 +110,7 @@ en:
custom_workflow_observable_shared: <shared code>
custom_workflow_observable_issue: Issue
custom_workflow_observable_issue_relation: Issue Relation
custom_workflow_observable_issue_attachments: Issue Attachments
custom_workflow_observable_group: Group
custom_workflow_observable_user: User

View File

@ -30,10 +30,11 @@ require 'redmine_custom_workflows/errors/workflow_error'
require 'redmine_custom_workflows/patches/attachment_patch'
require 'redmine_custom_workflows/patches/group_patch'
require 'redmine_custom_workflows/patches/issue_patch'
require 'redmine_custom_workflows/patches/issue_relation_patch'
require 'redmine_custom_workflows/patches/project_patch'
require 'redmine_custom_workflows/patches/projects_helper_patch'
require 'redmine_custom_workflows/patches/time_entry_patch'
require 'redmine_custom_workflows/patches/user_patch'
require 'redmine_custom_workflows/patches/version_patch'
require 'redmine_custom_workflows/patches/wiki_content_patch'
require 'redmine_custom_workflows/patches/wiki_page_patch'
require 'redmine_custom_workflows/patches/wiki_page_patch'

View File

@ -0,0 +1,78 @@
# encoding: utf-8
# frozen_string_literal: true
#
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov
# Copyright © 2019-20 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 IssueRelationPatch
def self.included(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
# override IssueRelation.to_s to rescue NoMethodError during CustomWorkflow.validate_syntax due to
# logging of temporarily instatiated IssueRelation with no related issues set
alias_method :old_to_s, :to_s
def to_s(issue=nil)
block_given? ? old_to_s(issue, &Proc.new) : old_to_s(issue)
rescue NoMethodError => e
if issue_from.present? || issue_to.present?
raise e
end
self.class.to_s
end
end
end
def before_save_custom_workflows
@issue_relation = self
@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
CustomWorkflow.run_custom_workflows :issue_relation, self, :after_save
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
end
end
end
# Apply patch
RedmineExtensions::PatchManager.register_model_patch 'IssueRelation',
'RedmineCustomWorkflows::Patches::IssueRelationPatch'