##// END OF EJS Templates
fixed: unable to delete an issue status even if it's not used yet...
Jean-Philippe Lang -
r177:b9ef10fe3fb6
parent child
Show More
@@ -1,50 +1,50
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class IssueStatus < ActiveRecord::Base
19 19 before_destroy :check_integrity
20 20 has_many :workflows, :foreign_key => "old_status_id"
21 21
22 22 validates_presence_of :name
23 23 validates_uniqueness_of :name
24 24 validates_format_of :name, :with => /^[\w\s\'\-]*$/i
25 25 validates_length_of :html_color, :is => 6
26 26 validates_format_of :html_color, :with => /^[a-f0-9]*$/i
27 27
28 28 def before_save
29 29 IssueStatus.update_all "is_default=#{connection.quoted_false}" if self.is_default?
30 30 end
31 31
32 32 # Returns the default status for new issues
33 33 def self.default
34 34 find(:first, :conditions =>["is_default=?", true])
35 35 end
36 36
37 37 # Returns an array of all statuses the given role can switch to
38 38 def new_statuses_allowed_to(role, tracker)
39 39 statuses = []
40 40 for workflow in self.workflows
41 41 statuses << workflow.new_status if workflow.role_id == role.id and workflow.tracker_id == tracker.id
42 42 end unless role.nil? or tracker.nil?
43 43 statuses
44 44 end
45 45
46 46 private
47 47 def check_integrity
48 raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id]) or IssueHistory.find(:first, :conditions => ["status_id=?", self.id])
48 raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id])
49 49 end
50 50 end
General Comments 0
You need to be logged in to leave comments. Login now