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