From: Eric Davis Date: Sun, 20 Jun 2010 19:30:51 +0000 (+0000) Subject: Handle unsuccessful destroys in TimelogController. #5700 X-Git-Tag: 1.0.0~38 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c98f46d691542baf769bc74e25f808277cd5878b;p=redmine.git Handle unsuccessful destroys in TimelogController. #5700 Contributed by Jan git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3805 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index 160c19974..73ff58b82 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -225,8 +225,11 @@ class TimelogController < ApplicationController def destroy (render_404; return) unless @time_entry (render_403; return) unless @time_entry.editable_by?(User.current) - @time_entry.destroy - flash[:notice] = l(:notice_successful_delete) + if @time_entry.destroy && @time_entry.destroyed? + flash[:notice] = l(:notice_successful_delete) + else + flash[:error] = l(:notice_unable_delete_time_entry) + end redirect_to :back rescue ::ActionController::RedirectBackError redirect_to :action => 'details', :project_id => @time_entry.project diff --git a/config/locales/de.yml b/config/locales/de.yml index 0e7e4c074..16b00d00b 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -175,6 +175,7 @@ de: notice_account_pending: "Ihr Konto wurde erstellt und wartet jetzt auf die Genehmigung des Administrators." notice_default_data_loaded: Die Standard-Konfiguration wurde erfolgreich geladen. notice_unable_delete_version: Die Version konnte nicht gelöscht werden. + notice_unable_delete_time_entry: Der Zeiterfassungseintrag konnte nicht gelöscht werden. notice_issue_done_ratios_updated: Der Ticket-Fortschritt wurde aktualisiert. error_can_t_load_default_data: "Die Standard-Konfiguration konnte nicht geladen werden: {{value}}" diff --git a/config/locales/en.yml b/config/locales/en.yml index 91ef3fa97..9d875e4b4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -153,6 +153,7 @@ en: notice_account_pending: "Your account was created and is now pending administrator approval." notice_default_data_loaded: Default configuration successfully loaded. notice_unable_delete_version: Unable to delete version. + notice_unable_delete_time_entry: Unable to delete time log entry. notice_issue_done_ratios_updated: Issue done ratios updated. error_can_t_load_default_data: "Default configuration could not be loaded: {{value}}" diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index 880527319..9e30a0ae8 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -116,9 +116,27 @@ class TimelogControllerTest < ActionController::TestCase @request.session[:user_id] = 2 post :destroy, :id => 1 assert_redirected_to :action => 'details', :project_id => 'ecookbook' + assert_equal I18n.t(:notice_successful_delete), flash[:notice] assert_nil TimeEntry.find_by_id(1) end + def test_destroy_should_fail + # simulate that this fails (e.g. due to a plugin), see #5700 + TimeEntry.class_eval do + before_destroy :stop_callback_chain + def stop_callback_chain ; return false ; end + end + + @request.session[:user_id] = 2 + post :destroy, :id => 1 + assert_redirected_to :action => 'details', :project_id => 'ecookbook' + assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error] + assert_not_nil TimeEntry.find_by_id(1) + + # remove the simulation + TimeEntry.before_destroy.reject! {|callback| callback.method == :stop_callback_chain } + end + def test_report_no_criteria get :report, :project_id => 1 assert_response :success