summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2010-04-11 17:47:29 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2010-04-11 17:47:29 +0000
commit9ccccb9984851dba181322f77d30be8f20e627b7 (patch)
treedf02abaa25b5942075ce118f545b5af8d3d057e0 /app
parentc76b9edf6c28a37731641d85be2bfbac3ba5b41c (diff)
downloadredmine-9ccccb9984851dba181322f77d30be8f20e627b7.tar.gz
redmine-9ccccb9984851dba181322f77d30be8f20e627b7.zip
Do not raise an error when destroying a Version with assigned issues.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3668 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/versions_controller.rb12
-rw-r--r--app/models/version.rb12
2 files changed, 11 insertions, 13 deletions
diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb
index dc1b7eb2b..05c9743eb 100644
--- a/app/controllers/versions_controller.rb
+++ b/app/controllers/versions_controller.rb
@@ -80,11 +80,13 @@ class VersionsController < ApplicationController
end
def destroy
- @version.destroy
- redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
- rescue
- flash[:error] = l(:notice_unable_delete_version)
- redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
+ if @version.fixed_issues.empty?
+ @version.destroy
+ redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
+ else
+ flash[:error] = l(:notice_unable_delete_version)
+ redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
+ end
end
def status_by
diff --git a/app/models/version.rb b/app/models/version.rb
index f9b48fb11..e8a416008 100644
--- a/app/models/version.rb
+++ b/app/models/version.rb
@@ -1,5 +1,5 @@
-# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2010 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -16,10 +16,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Version < ActiveRecord::Base
- before_destroy :check_integrity
after_update :update_issues_from_sharing_change
belongs_to :project
- has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id'
+ has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id', :dependent => :nullify
acts_as_customizable
acts_as_attachable :view_permission => :view_files,
:delete_permission => :manage_files
@@ -156,10 +155,7 @@ class Version < ActiveRecord::Base
end
end
-private
- def check_integrity
- raise "Can't delete version" if self.fixed_issues.find(:first)
- end
+ private
# Update the issue's fixed versions. Used if a version's sharing changes.
def update_issues_from_sharing_change