##// END OF EJS Templates
Fixed that controller_issues_edit_before/after_save hooks have no controller context (#15044)....
Jean-Philippe Lang -
r11989:94e7df78ca52
parent child
Show More
@@ -181,7 +181,7 class IssuesController < ApplicationController
181 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
181 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
182 saved = false
182 saved = false
183 begin
183 begin
184 saved = @issue.save_issue_with_child_records(params, @time_entry)
184 saved = save_issue_with_child_records
185 rescue ActiveRecord::StaleObjectError
185 rescue ActiveRecord::StaleObjectError
186 @conflict = true
186 @conflict = true
187 if params[:last_journal_id]
187 if params[:last_journal_id]
@@ -452,4 +452,26 class IssuesController < ApplicationController
452 end
452 end
453 attributes
453 attributes
454 end
454 end
455
456 # Saves @issue and a time_entry from the parameters
457 def save_issue_with_child_records
458 Issue.transaction do
459 if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, @issue.project)
460 time_entry = @time_entry || TimeEntry.new
461 time_entry.project = @issue.project
462 time_entry.issue = @issue
463 time_entry.user = User.current
464 time_entry.spent_on = User.current.today
465 time_entry.attributes = params[:time_entry]
466 @issue.time_entries << time_entry
467 end
468
469 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
470 if @issue.save
471 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
472 else
473 raise ActiveRecord::Rollback
474 end
475 end
476 end
455 end
477 end
@@ -1087,30 +1087,6 class Issue < ActiveRecord::Base
1087 s
1087 s
1088 end
1088 end
1089
1089
1090 # Saves an issue and a time_entry from the parameters
1091 def save_issue_with_child_records(params, existing_time_entry=nil)
1092 Issue.transaction do
1093 if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, project)
1094 @time_entry = existing_time_entry || TimeEntry.new
1095 @time_entry.project = project
1096 @time_entry.issue = self
1097 @time_entry.user = User.current
1098 @time_entry.spent_on = User.current.today
1099 @time_entry.attributes = params[:time_entry]
1100 self.time_entries << @time_entry
1101 end
1102
1103 # TODO: Rename hook
1104 Redmine::Hook.call_hook(:controller_issues_edit_before_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
1105 if save
1106 # TODO: Rename hook
1107 Redmine::Hook.call_hook(:controller_issues_edit_after_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
1108 else
1109 raise ActiveRecord::Rollback
1110 end
1111 end
1112 end
1113
1114 # Unassigns issues from +version+ if it's no longer shared with issue's project
1090 # Unassigns issues from +version+ if it's no longer shared with issue's project
1115 def self.update_versions_from_sharing_change(version)
1091 def self.update_versions_from_sharing_change(version)
1116 # Update issues assigned to the version
1092 # Update issues assigned to the version
General Comments 0
You need to be logged in to leave comments. Login now