jfqd / redmine_helpdesk

Lightweight helpdesk plugin for redmine.
MIT License
192 stars 102 forks source link

reopening closed issue not working (Redmine 4.1.1, latest plugin version) #162

Closed mgeerdsen closed 2 years ago

mgeerdsen commented 3 years ago

Environment: Redmine version 4.1.1.stable Ruby version 2.3.1-p112 (2016-04-26) [x86_64-linux-gnu] Rails version 5.2.4.2 Environment production Database adapter Mysql2 Mailer queue ActiveJob::QueueAdapters::AsyncAdapter Mailer delivery smtp SCM: Git 2.7.4 Filesystem
Redmine plugins: redmine_helpdesk 0.0.18

Hi,

using the latest version from git (3ba28037e85aa9e5ddb9a2066b11739655ee327d) it was not possible to reopen an issue by sending a mail. The custom field reopen-issues-with is set to the status value of our wanted target status.

It appears that status_id is always nil. Probably originating in e3a1794e087dda200afd5194da142706db293226

I was able to fix this via this patch, I am however not a Ruby dev at all...

diff --git a/lib/mail_handler_patch.rb b/lib/mail_handler_patch.rb
index d04f506..0106f39 100644
--- a/lib/mail_handler_patch.rb
+++ b/lib/mail_handler_patch.rb
@@ -92,9 +92,12 @@ module RedmineHelpdesk
         return unless issue

         # reopening a closed issues by email
-        custom_value = CustomField.find_by_name('reopen-issues-with')
+        custom_field = CustomField.find_by_name('reopen-issues-with')
+        custom_value = CustomValue.where(
+              "customized_type = 'Project' AND customized_id = ? AND custom_field_id = ?", issue.project.id, custom_field.id
+            ).first
         if issue.closed? && custom_value.present?
-          status_id = IssueStatus.where("name = ?", custom_value).try(:first).try(:id)
+          status_id = IssueStatus.where("name = ?", custom_value.value).try(:first).try(:id)
           unless status_id.nil?
             issue.status_id = status_id
             issue.save

I'll happily create a PR in case the above makes sense.

Best wishes Matthias

jfqd commented 2 years ago

You are absolutely right. Fixed it with commit c3177d8.