From 607b614c8cd7cdfe01b5e8c5b2b05f5b27ff616d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Fri, 23 Sep 2022 10:04:13 +0200 Subject: [PATCH] When using Before Destruction on issues, no error gets displayed #275 --- .../patches/models/attachment_patch.rb | 5 ++++- lib/redmine_custom_workflows/patches/models/group_patch.rb | 5 ++++- lib/redmine_custom_workflows/patches/models/issue_patch.rb | 2 +- .../patches/models/issue_relation_patch.rb | 5 ++++- .../patches/models/project_patch.rb | 5 ++++- .../patches/models/time_entry_patch.rb | 5 ++++- lib/redmine_custom_workflows/patches/models/user_patch.rb | 5 ++++- .../patches/models/version_patch.rb | 5 ++++- .../patches/models/wiki_content_patch.rb | 5 ++++- test/fixtures/custom_workflows.yml | 3 ++- test/functional/issues_controller_patch_test.rb | 7 +++++++ 11 files changed, 42 insertions(+), 10 deletions(-) diff --git a/lib/redmine_custom_workflows/patches/models/attachment_patch.rb b/lib/redmine_custom_workflows/patches/models/attachment_patch.rb index 4e3b519..79263be 100644 --- a/lib/redmine_custom_workflows/patches/models/attachment_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/attachment_patch.rb @@ -56,7 +56,10 @@ module RedmineCustomWorkflows end def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :attachment, self, :before_destroy + res = CustomWorkflow.run_custom_workflows :attachment, self, :before_destroy + if res == false + throw :abort + end end def after_destroy_custom_workflows diff --git a/lib/redmine_custom_workflows/patches/models/group_patch.rb b/lib/redmine_custom_workflows/patches/models/group_patch.rb index 9a286d9..8aac055 100644 --- a/lib/redmine_custom_workflows/patches/models/group_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/group_patch.rb @@ -70,7 +70,10 @@ module RedmineCustomWorkflows end def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :group, self, :before_destroy + res = CustomWorkflow.run_custom_workflows :group, self, :before_destroy + if res == false + throw :abort + end end def after_destroy_custom_workflows diff --git a/lib/redmine_custom_workflows/patches/models/issue_patch.rb b/lib/redmine_custom_workflows/patches/models/issue_patch.rb index 2631b80..eab3c32 100644 --- a/lib/redmine_custom_workflows/patches/models/issue_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/issue_patch.rb @@ -84,7 +84,7 @@ module RedmineCustomWorkflows def before_destroy_custom_workflows res = CustomWorkflow.run_custom_workflows(:issue, self, :before_destroy) - if res === false + if res == false throw :abort end end diff --git a/lib/redmine_custom_workflows/patches/models/issue_relation_patch.rb b/lib/redmine_custom_workflows/patches/models/issue_relation_patch.rb index 31d50e6..75df370 100644 --- a/lib/redmine_custom_workflows/patches/models/issue_relation_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/issue_relation_patch.rb @@ -77,7 +77,10 @@ module RedmineCustomWorkflows end def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :issue_relation, self, :before_destroy + res = CustomWorkflow.run_custom_workflows :issue_relation, self, :before_destroy + if res == false + throw :abort + end end def after_destroy_custom_workflows diff --git a/lib/redmine_custom_workflows/patches/models/project_patch.rb b/lib/redmine_custom_workflows/patches/models/project_patch.rb index 3f51249..e3e323b 100644 --- a/lib/redmine_custom_workflows/patches/models/project_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/project_patch.rb @@ -71,7 +71,10 @@ module RedmineCustomWorkflows end def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :project, self, :before_destroy + res = CustomWorkflow.run_custom_workflows :project, self, :before_destroy + if res == false + throw :abort + end end def after_destroy_custom_workflows diff --git a/lib/redmine_custom_workflows/patches/models/time_entry_patch.rb b/lib/redmine_custom_workflows/patches/models/time_entry_patch.rb index 14da014..2e5a77d 100644 --- a/lib/redmine_custom_workflows/patches/models/time_entry_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/time_entry_patch.rb @@ -56,7 +56,10 @@ module RedmineCustomWorkflows end def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :time_entry, self, :before_destroy + res = CustomWorkflow.run_custom_workflows :time_entry, self, :before_destroy + if res == false + throw :abort + end end def after_destroy_custom_workflows diff --git a/lib/redmine_custom_workflows/patches/models/user_patch.rb b/lib/redmine_custom_workflows/patches/models/user_patch.rb index d30af3c..e92a672 100644 --- a/lib/redmine_custom_workflows/patches/models/user_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/user_patch.rb @@ -56,7 +56,10 @@ module RedmineCustomWorkflows end def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :user, self, :before_destroy + res = CustomWorkflow.run_custom_workflows :user, self, :before_destroy + if res == false + throw :abort + end end def after_destroy_custom_workflows diff --git a/lib/redmine_custom_workflows/patches/models/version_patch.rb b/lib/redmine_custom_workflows/patches/models/version_patch.rb index 66577cc..d59601d 100644 --- a/lib/redmine_custom_workflows/patches/models/version_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/version_patch.rb @@ -56,7 +56,10 @@ module RedmineCustomWorkflows end def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :version, self, :before_destroy + res = CustomWorkflow.run_custom_workflows :version, self, :before_destroy + if res == false + throw :abort + end end def after_destroy_custom_workflows diff --git a/lib/redmine_custom_workflows/patches/models/wiki_content_patch.rb b/lib/redmine_custom_workflows/patches/models/wiki_content_patch.rb index 7d90b7b..858dd48 100644 --- a/lib/redmine_custom_workflows/patches/models/wiki_content_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/wiki_content_patch.rb @@ -56,7 +56,10 @@ module RedmineCustomWorkflows end def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :wiki_content, self, :before_destroy + res = CustomWorkflow.run_custom_workflows :wiki_content, self, :before_destroy + if res == false + throw :abort + end end def after_destroy_custom_workflows diff --git a/test/fixtures/custom_workflows.yml b/test/fixtures/custom_workflows.yml index a804d22..a0533f1 100644 --- a/test/fixtures/custom_workflows.yml +++ b/test/fixtures/custom_workflows.yml @@ -17,7 +17,8 @@ custom_workflows_001: after_add: NULL before_remove: NULL after_remove: NULL - before_destroy: '' + before_destroy: "self.custom_workflow_messages[:error] = 'Issue cannot be deleted'\n + return false" after_destroy : '' custom_workflows_002: diff --git a/test/functional/issues_controller_patch_test.rb b/test/functional/issues_controller_patch_test.rb index 40ce3a9..38840ff 100644 --- a/test/functional/issues_controller_patch_test.rb +++ b/test/functional/issues_controller_patch_test.rb @@ -40,4 +40,11 @@ class IssuesControllerPatchTest < RedmineCustomWorkflows::Test::TestCase assert_equal 'Custom workflow', @controller.flash[:notice] end + def test_delete_with_cw + delete :destroy, params: { id: @issue1.id, todo: 'destroy' } + assert_response :redirect + assert_equal 'Issue cannot be deleted', @controller.flash[:error] + assert Issue.find_by(id: @issue1.id) + end + end \ No newline at end of file