From fb3b904b8ffbe65ba11ed68252cdb441421b9a2b Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 4 Feb 2012 17:36:15 +0000 Subject: Better handling of issue update conflicts (#8691). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8774 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 37 ++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'app/controllers/issues_controller.rb') 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 -- cgit v1.2.3