Feature #2475

Hooks for IssuesController

Added by Sean Robins almost 9 years ago. Updated almost 8 years ago.

Status:ClosedStart date:2009-01-09
Priority:NormalDue date:
Assignee:Eric Davis% Done:

100%

Category:Plugin API
Target version:0.8.6
Resolution:Fixed

Description

I have been tasked with providing a plugin to allow Redmine to act as a controller for a 3rd party VCS system's built in issue tracker. In order to reduce situations where orphaned issue records could be created in the 3rd party tool, Hook events need to be called After issues have been saved in Redmine.

At present, I have modified my own Redmine installation's issues_controller.rb file to provide hooks in the new() and edit() methods of the IssuesController class, directly after the redirect_to statements in those methods.

In the add() method, I have done the following:

...
if @issue.save
  attach_files(@issue, params[:attachments])
  flash[:notice] = l(:notice_successful_create)
  Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
  redirect_to :controller => 'issues', :action => 'show', :id => @issue
  #
  call_hook(:controller_issues_new_after_save, { :issue => @issue })
  #
  return
end
...

... and in edit():

  ...
  if !journal.new_record?
    # Only send notification if something was actually changed
    flash[:notice] = l(:notice_successful_update)
    Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
  end
  redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
  #
  call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
  #
  ...

For my own most immediate requirements, this is the minimum I have needed to get the job done, and would very much appreciate if the feature could be added to future releases of Redmine, as this would save me needing to edit Redmine source whenever a new version is release.

I can however envisage situations where before and after events could be needed for issue creation, editing, deletion, or possibly anywhere that issue record changes are submitted.

Thanks.

Sean


Related issues

Related to Redmine - Defect #3118: hook controller_issues_new_after_save is missing from iss... Closed 2009-04-03

Associated revisions

Revision 2261
Added by Eric Davis almost 9 years ago

Added two new plugin hooks to IssuesController:

  • :controller_issues_new_after_save
  • :controller_issues_edit_after_save

    #2475

History

#1 Updated by Eric Davis almost 9 years ago

  • Category set to Plugin API
  • Assignee set to Eric Davis

I'll add some hooks in there. I might move them a bit, I think they should run before any redirects.

#2 Updated by Eric Davis almost 9 years ago

  • Subject changed from Improved Hook support related to Issue submission to Hooks for IssuesController
  • Status changed from New to Closed
  • Target version set to 0.8.1
  • % Done changed from 0 to 100
  • Resolution set to Fixed

I've added the hooks in r2261. If you need any other hooks, go ahead and open a new issue for them and assign it to me.

#3 Updated by Thales Ferreira almost 8 years ago

  • Status changed from Closed to Reopened

Eric, the revision @2261 associated with this issue (for the version 0.8.1) wasn't yet merged into 0.8-branche. I was using (:controller_issues_new_after_save, :controller_issues_edit_after_save) api hooks for issues controller using 0.8-branche and them simply did not work.

I make a svn diff to last revision of the 0.8-branche (@2900) and to revision @2261 showing that which was put in your revision wasnt find in 0.8-branche.

@ -147,8 +147,8 @
attach_files(@issue, params[:attachments])
flash[:notice] = l(:notice_successful_create)
Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('i
ssue_added')
- redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @iss
ue.tracker } :
- { :action => 'show', :id => @issue })
+ call_hook(:controller_issues_new_after_save, { :params => params, :issu
e => @issue})
+ redirect_to :controller => 'issues', :action => 'show', :id => @issue
return
end
end

@ -194,6 +194,7 @
flash[:notice] = l(:notice_successful_update)
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include
?('issue_updated')
end
+ call_hook(:controller_issues_edit_after_save, { :params => params, :iss
ue => @issue, :time_entry => @time_entry, :journal => journal})
redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
end
end

#4 Updated by Jean-Philippe Lang almost 8 years ago

  • Target version changed from 0.8.1 to 0.8.6

#5 Updated by Jean-Philippe Lang almost 8 years ago

  • Status changed from Reopened to Closed

Merged in 0.8-stable in r2997.

Also available in: Atom PDF