Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing status from sidebar should fire controller_issues_edit_after_save event #127

Open
serpi90 opened this issue Jan 13, 2022 · 6 comments

Comments

@serpi90
Copy link

serpi90 commented Jan 13, 2022

Event listeners triggered by controller_issues_edit_after_save are not being fired when status changes from the sidebar.

@alexandermeindl
Copy link
Collaborator

Thanks for reporting this. I added support with my last commit.

@alexandermeindl
Copy link
Collaborator

I revert the support for controller_issues_edit_after_save hook. The problem with it is, that some plugin developer use a before_action in controller instead of controller_issues_edit_before_save to prepare data for save.
I see no possibility which does not break this plugins.

Instead of controller_issues_edit_after_save hook, I introduced for new hooks for issue changes by additionals:

  • controller_additionals_assign_to_me_before_save
  • controller_additionals_assign_to_me_after_save
  • controller_additionals_change_status_before_save
  • controller_additionals_change_status_after_save

Of course this means, that other plugins have to include this hooks to detect issue changes. But at least now there is a possibility to do it.

@serpi90
Copy link
Author

serpi90 commented Mar 12, 2022

That's a shame, i can use the new hook, but imho this would require collaboration with the offending plugin to solve the issue to be properly fixed.

Thank you

@alexandermeindl
Copy link
Collaborator

One of them is RedmineUp with https://www.redmine.org/plugins/redmine_checklists. It would be great to teach them, but in the past I never succeeded.

@serpi90
Copy link
Author

serpi90 commented Mar 12, 2022

Oh 💩 I'm using that plugin. I could try making a patch and uploading it to them as an issue, but: 1. my experience ruby is very limited. 2 I think they won't listen to me.

If i do that and they listen, I'll update this thread.

In the meantime, i'll patch the webhooks plugin to use your hook, which is easier.

@alexandermeindl
Copy link
Collaborator

alexandermeindl commented Mar 12, 2022

Hi @serpi90,

the patch is trivial, I created it for you. It would be great, if "they" listen to you 😏

I cannot add a patch file here, but here is the code:

diff --git a/lib/redmine_checklists/hooks/controller_issues_hook.rb b/lib/redmine_checklists/hooks/controller_issues_hook.rb
index 25a4f15..4f0445b 100644
--- a/lib/redmine_checklists/hooks/controller_issues_hook.rb
+++ b/lib/redmine_checklists/hooks/controller_issues_hook.rb
@@ -20,7 +20,20 @@
 module RedmineChecklists
   module Hooks
     class ControllerIssuesHook < Redmine::Hook::ViewListener
-      def controller_issues_edit_after_save(context = {})
+      def controller_issues_edit_before_save(context = {})
+        issue = context[:issue]
+        params = context[:params]
+        issue.old_checklists = issue.checklists.to_json
+        checklists_params = params[:issue].present? && params[:issue][:checklists_attributes].present? ? params[:issue][:checklists_attributes] : {}
+        issue.removed_checklist_ids =
+          if checklists_params.present?
+            checklists_params = checklists_params.respond_to?(:to_unsafe_hash) ? checklists_params.to_unsafe_hash : checklists_params
+            checklists_params.map { |_k, v| v['id'].to_i if ['1', 'true'].include?(v['_destroy']) }.compact
+          else
+            []
+          end
+        end
+
+        def controller_issues_edit_after_save(context = {})
         old_checklists = context[:issue].old_checklists
         new_checklists = context[:issue].checklists.to_json
         journal = context[:journal]
diff --git a/lib/redmine_checklists/patches/issues_controller_patch.rb b/lib/redmine_checklists/patches/issues_controller_patch.rb
index c48a8a3..a1ee1a2 100644
--- a/lib/redmine_checklists/patches/issues_controller_patch.rb
+++ b/lib/redmine_checklists/patches/issues_controller_patch.rb
@@ -28,7 +28,6 @@ module RedmineChecklists
 
           alias_method :build_new_issue_from_params_without_checklist, :build_new_issue_from_params
           alias_method :build_new_issue_from_params, :build_new_issue_from_params_with_checklist
-          before_action :save_before_state, :only => [:update]
         end
       end
 
@@ -50,18 +49,6 @@ module RedmineChecklists
           @issue.checklists_from_params = true
         end
 
-        def save_before_state
-          @issue.old_checklists = @issue.checklists.to_json
-          checklists_params = params[:issue].present? && params[:issue][:checklists_attributes].present? ? params[:issue][:checklists_attributes] : {}
-          @issue.removed_checklist_ids =
-            if checklists_params.present?
-              checklists_params = checklists_params.respond_to?(:to_unsafe_hash) ? checklists_params.to_unsafe_hash : checklists_params
-              checklists_params.map { |_k, v| v['id'].to_i if ['1', 'true'].include?(v['_destroy']) }.compact
-            else
-              []
-            end
-        end
-
         def fill_checklist_attributes
           return unless params[:issue].blank?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants