diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-02-04 17:36:15 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-02-04 17:36:15 +0000 |
commit | fb3b904b8ffbe65ba11ed68252cdb441421b9a2b (patch) | |
tree | 59a297f8cd97d158dd57d552bc00df1387173ace /app/controllers/issues_controller.rb | |
parent | b9c26d6ddcd3b2afa91637d0f81738e7d2e6c17a (diff) | |
download | redmine-fb3b904b8ffbe65ba11ed68252cdb441421b9a2b.tar.gz redmine-fb3b904b8ffbe65ba11ed68252cdb441421b9a2b.zip |
Better handling of issue update conflicts (#8691).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8774 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/issues_controller.rb')
-rw-r--r-- | app/controllers/issues_controller.rb | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 9976a93cc..df130f9d5 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -171,7 +171,7 @@ class IssuesController < ApplicationController end def edit - update_issue_from_params + return unless update_issue_from_params respond_to do |format| format.html { } @@ -180,9 +180,23 @@ class IssuesController < ApplicationController end def update - update_issue_from_params + return unless update_issue_from_params + saved = false + begin + saved = @issue.save_issue_with_child_records(params, @time_entry) + rescue ActiveRecord::StaleObjectError + @conflict = true + if params[:last_journal_id] + if params[:last_journal_id].present? + last_journal_id = params[:last_journal_id].to_i + @conflict_journals = @issue.journals.all(:conditions => ["#{Journal.table_name}.id > ?", last_journal_id]) + else + @conflict_journals = @issue.journals.all + end + end + end - if @issue.save_issue_with_child_records(params, @time_entry) + if saved render_attachment_warning_if_needed(@issue) flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? @@ -345,7 +359,22 @@ private @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil) @issue.init_journal(User.current, @notes) - @issue.safe_attributes = params[:issue] + + issue_attributes = params[:issue] + if issue_attributes && params[:conflict_resolution] + case params[:conflict_resolution] + when 'overwrite' + issue_attributes = issue_attributes.dup + issue_attributes.delete(:lock_version) + when 'add_notes' + issue_attributes = {} + when 'cancel' + redirect_to issue_path(@issue) + return false + end + end + @issue.safe_attributes = issue_attributes + true end # TODO: Refactor, lots of extra code in here |